danielealbano / cachegrand

cachegrand - a modern data ingestion, processing and serving platform built for today's hardware
BSD 3-Clause "New" or "Revised" License
975 stars 34 forks source link

#171 implement support for storage db entries expirations #172

Closed danielealbano closed 2 years ago

danielealbano commented 2 years ago

This PR implements the necessary bits and pieces to support expirations in the storage db entries.

Now every time a new entry is added a timeout in milliseconds can be specified, the storage_db_add_new_entry_index function has been modified to require passing the timeout in ms but otherwise the storage_db_set_entry_index will simply set the passed entry index as it is.

In storage_db_get_entry_index a check is carried out on the expiration time in ms using realtime coarse (which has a precision of 4ms on most of the systems but provides a notable performance benefit).

The SET command has been updated to take advantage of the newly implement functionality and now supports the options EX, PX, EXAT, PXAT.

Testing the commands was becoming really cumbersome and error prone so the tests have been revamped to be more understandable and a lot of code has been dropped, in the process a bug in the timeout handling has been found and fixed as well.

This PR closes #171

codecov[bot] commented 2 years ago

Codecov Report

Merging #172 (eda58c5) into main (0edd630) will increase coverage by 0.30%. The diff coverage is 88.89%.

@@            Coverage Diff             @@
##             main     #172      +/-   ##
==========================================
+ Coverage   78.43%   78.73%   +0.30%     
==========================================
  Files         103      103              
  Lines        6580     6574       -6     
==========================================
+ Hits         5161     5176      +15     
+ Misses       1419     1398      -21     
Impacted Files Coverage Δ
...c/module/redis/command/module_redis_command_mset.c 0.00% <ø> (ø)
src/module/redis/module_redis_connection.c 81.40% <ø> (-0.78%) :arrow_down:
src/clock.h 80.00% <80.00%> (ø)
...rc/module/redis/command/module_redis_command_set.c 80.95% <84.62%> (+5.95%) :arrow_up:
src/module/redis/module_redis.c 82.39% <100.00%> (-0.36%) :arrow_down:
src/network/channel/network_channel.c 92.65% <100.00%> (+0.22%) :arrow_up:
src/storage/db/storage_db.c 52.91% <100.00%> (+4.11%) :arrow_up:
src/worker/network/worker_network_iouring_op.c 67.74% <100.00%> (+0.42%) :arrow_up:
src/worker/network/worker_network_op.c 71.05% <100.00%> (ø)
src/slab_allocator.c 94.87% <0.00%> (-2.99%) :arrow_down:
... and 9 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.