feat(hash): add per-field expiration support#3346
Open
dashjay wants to merge 10 commits intoapache:unstablefrom
Open
feat(hash): add per-field expiration support#3346dashjay wants to merge 10 commits intoapache:unstablefrom
dashjay wants to merge 10 commits intoapache:unstablefrom
Conversation
bad48a7 to
88be89e
Compare
6775b84 to
471b3da
Compare
dashjay
commented
Jan 27, 2026
| if (!s.ok() && !s.IsNotFound()) { | ||
| return s; | ||
| } | ||
| if (expire_at != NoExpireTime && expire_at < util::GetTimeStampMS()) { |
Author
There was a problem hiding this comment.
a lot expired key in hash may block scanner here
dashjay
commented
Jan 27, 2026
| [[nodiscard]] rocksdb::Status GetSubKeyExpireTimestampMS(engine::Context &ctx, const Slice &user_key, | ||
| const Slice &hash_field, uint64_t metadata_version, | ||
| uint64_t *expired_at); | ||
| void MGetSubKeyExpireTimestampMS(engine::Context &ctx, const Slice &user_key, const std::vector<Slice> &hash_fields, |
Author
There was a problem hiding this comment.
this three function define in SubKeyScanner but only used in hash for now
dashjay
commented
Jan 27, 2026
| if (!s.ok()) { | ||
| return s; | ||
| } | ||
| *size = fields.size(); |
dashjay
commented
Jan 27, 2026
dashjay
commented
Jan 27, 2026
acfc017 to
701c404
Compare
Signed-off-by: kevin <kevin@kevin-desktop.lightspeed.mssnks.sbcglobal.net>
Signed-off-by: kevin <kevin@kevin-desktop.lightspeed.mssnks.sbcglobal.net>
Signed-off-by: kevin <kevin@kevin-desktop.lightspeed.mssnks.sbcglobal.net>
Signed-off-by: kevin <kevin@kevin-desktop.lightspeed.mssnks.sbcglobal.net> Signed-off-by: dashjay <dashjwz@gmail.com>
Signed-off-by: dashjay <dashjwz@gmail.com>
Signed-off-by: dashjay <dashjwz@gmail.com>
701c404 to
5180789
Compare
Signed-off-by: dashjay <dashjwz@gmail.com>
707a8bc to
692386b
Compare
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.
In Short
I introduce a way to store the TTL in an extra key, this can help make ugprade easily, no breaking change, no option for kvrocks. But the disadvantages are:
advantages:
TL;DR;
this pr want to close the origin issue: #2269
With reading all codes in this pr:
I came up with a way that differ from these three pr, I did learn alot from 3269 which encode the expire time into value.
But the compatibility is limited. The comment I said here: #3269 (comment) told that:
I have read all these PRs, and find the key problem of this new feature...
So the key problem of add support of hash expiration commands for kvrocks is: Let some(every) key in hash carry a TTL while keeping the read/write hot-path still O(1) and keep all function as origin, correct and fast.
Sorry I can't agree that cmd "hlen" or any other redis command is not correct at any time, kvrocks should be 100% compactable with redis. I can just agree that if one command like "hrangebylex" is origin not exists in redis, that we can modify it's API(better not).
Following is the content of the proposal and trade off things:
Detail
redis command need to be implemented
Old commands (need compatibility)
Where to store the timestamp ?
there must be an count N which make different implements has better performance, a lot trade-off work need to be done.
If I take
store the expire time in another encoded keythe origin command will be effect as following:all read operation will execute twice
following command will be affected:
hrangebylex, hrandfieldand how the key encoded is a problem, I came up with to ways:
HLen problem
ok the final problem is this:
the cmd "hlen" which is origin O(1) but now need to be O(N)
I came up with two ways to solve this problem:
GC CompationFilter
there is a problem, if hash metadata version not change,
{key} AND {key_expire}both exists, we delete the{key}because we check the{key_expire}and found expired, but user set a new key in db, when this happen, we have to do the deletion on{key_expire}if{key} AND {key_expire}both exists.