Feat/expire ttl#13
Merged
Merged
Conversation
Introduce an internal ValueEntry carrying an optional monotonic deadline, and expose expire_at_ms / persist / ttl_ms / sweep_expired on KvEngine. All read and write paths honour the deadline: lazy expiration drops stale entries on access, and sweep_expired supports an adaptive background sampler. The AOF writer learns two new records, PEXPIREAT (absolute epoch ms) and PERSIST, and the replay loader applies them. PEXPIREAT entries whose deadline is already past cause the key to be dropped during replay, keeping the log idempotent across restarts. SET overwrites clear the existing TTL to match Redis semantics; INCR and APPEND preserve it.
…ctive expiration sweeper Extend the RESP2 parser and the command executor with the full TTL command family. EXPIRE/PEXPIRE translate relative offsets into absolute epoch milliseconds before calling the engine, so replay always sees a stable deadline. TTL returns whole seconds (rounded up from the remaining millis) and PTTL returns the raw millisecond count; both surface the Redis -2 / -1 sentinels. Add a dedicated background sweeper (storage::expire) that samples twenty keys every hundred milliseconds and follows up immediately when more than a quarter of the sample was expired. The main binary spawns the sweeper on startup and joins it during graceful shutdown. End-to-end tests cover the new wire contract as well as the sweeper actually evicting keys without a foreground read.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.