Repository navigation
Conversation
When the key was past its expire time but not yet reclaimed, SET ... KEEPTTL moved the dead expire onto the new value, so the next read expired the key and deleted the value that had just been acknowledged. Expire the key first on the KEEPTTL path, so the write starts from a clean key, as Redis does through its write lookup. Add a regression test. Fixes Snapchat#983 Signed-off-by: Stalin <[email protected]>
This branch has not been deployed
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.
Fixes #983
What changed
SET key value KEEPTTLcarries the existing expire over to the new value. If the key was already past its expire time but not reclaimed yet, the dead expire was moved onto the new value, theSETrepliedOK, and the next read expired the key and deleted the value.setGenericCommandnow callsexpireIfNeededfirst whenKEEPTTLis set, so the key is dropped and the new value is written without a stale expire. Live keys still keep their TTL, and a missing key behaves as before.expireIfNeededis used directly so no keyspace hit/miss stats or LRU are touched.Testing
Built from this branch (
make MALLOC=libc NO_MOTD=yes BUILD_TLS=no). Reproduced on the unfixed binary:SET k old PXAT 1; SET k new KEEPTTL; GET kreturned nil. With the fix it returnsnew,EXISTS kis 1 andTTL kis -1. A live key still keeps its TTL (SET live v EX 100; SET live v2 KEEPTTL; TTL live-> 100). Added a test intests/unit/expire.tcl;./runtest --single unit/expire --clients 1passes with the fix and the new test fails without it. I ran only the expire suite, not the full test suite. I did not check replica or active-replica behaviour.AI-assisted (Claude Code).