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

Enforce TTL #409

Closed danielealbano closed 1 year ago

danielealbano commented 1 year ago

This PR implements a new functionality to allow the enforcment of the TTL via a default value, which, when enabled, is applied when the TTL is not set, and a max value, which, when enabled, limit the TTL to the max value if there is a ttl set.

The new config file properties are under an optional section named enforced_ttl and are named default and max, the properties are optional as well although one or the other has to be present for the YAML config file to be valid.

The default ttl and max ttl properties support time units, so it's possible to write 7d instead of 604800 or 1h instead of 3600.

Example with a default TTL set to 1d

127.0.0.1:6379> SET a_key a_value
OK
127.0.0.1:6379> TTL a_key
(integer) 86397
127.0.0.1:6379> SET a_key a_value
OK
127.0.0.1:6379> PTTL a_key
(integer) 86396632
127.0.0.1:6379> 

Example with a max TTL set to 7d

127.0.0.1:6379> SET a_key a_value EX 1234567
OK
127.0.0.1:6379> TTL a_key
(integer) 604798
127.0.0.1:6379> PTTL a_key
(integer) 604796556

If the parameters are not set cachegrand will behave normally as expected

127.0.0.1:6379> SET a_key a_value
OK
127.0.0.1:6379> TTL a_key
(integer) -1
127.0.0.1:6379> PTTL a_key
(integer) -1
127.0.0.1:6379> SET a_key a_value EX 1234567
OK
127.0.0.1:6379> TTL a_key
(integer) 1234566
127.0.0.1:6379> PTTL a_key
(integer) 1234563896
codecov[bot] commented 1 year ago

Codecov Report

Patch coverage: 68.42% and project coverage change: +0.05 :tada:

Comparison is base (078c235) 77.95% compared to head (97bda05) 77.99%.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #409 +/- ## ========================================== + Coverage 77.95% 77.99% +0.05% ========================================== Files 196 196 Lines 13281 13319 +38 ========================================== + Hits 10352 10388 +36 - Misses 2929 2931 +2 ``` | Flag | Coverage Δ | | |---|---|---| | unittests | `77.99% <68.42%> (+0.05%)` | :arrow_up: | Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Daniele+Salvatore+Albano#carryforward-flags-in-the-pull-request-comment) to find out more. | [Impacted Files](https://app.codecov.io/gh/danielealbano/cachegrand/pull/409?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Daniele+Salvatore+Albano) | Coverage Δ | | |---|---|---| | [src/config\_cyaml\_schema.c](https://app.codecov.io/gh/danielealbano/cachegrand/pull/409?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Daniele+Salvatore+Albano#diff-c3JjL2NvbmZpZ19jeWFtbF9zY2hlbWEuYw==) | `100.00% <ø> (ø)` | | | [src/storage/db/storage\_db.h](https://app.codecov.io/gh/danielealbano/cachegrand/pull/409?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Daniele+Salvatore+Albano#diff-c3JjL3N0b3JhZ2UvZGIvc3RvcmFnZV9kYi5o) | `27.27% <ø> (ø)` | | | [src/program.c](https://app.codecov.io/gh/danielealbano/cachegrand/pull/409?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Daniele+Salvatore+Albano#diff-c3JjL3Byb2dyYW0uYw==) | `38.20% <42.86%> (+0.09%)` | :arrow_up: | | [src/storage/db/storage\_db.c](https://app.codecov.io/gh/danielealbano/cachegrand/pull/409?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Daniele+Salvatore+Albano#diff-c3JjL3N0b3JhZ2UvZGIvc3RvcmFnZV9kYi5j) | `59.49% <66.67%> (+0.11%)` | :arrow_up: | | [src/config.c](https://app.codecov.io/gh/danielealbano/cachegrand/pull/409?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Daniele+Salvatore+Albano#diff-c3JjL2NvbmZpZy5j) | `78.02% <78.95%> (+0.03%)` | :arrow_up: | ... and [2 files with indirect coverage changes](https://app.codecov.io/gh/danielealbano/cachegrand/pull/409/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Daniele+Salvatore+Albano)

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Do you have feedback about the report comment? Let us know in this issue.