feat(hash): add support of hash expiration commands#2717
feat(hash): add support of hash expiration commands#2717ltagliamonte-dd wants to merge 29 commits intoapache:unstablefrom
Conversation
|
@ltagliamonte-dd Hi. Did you set this config |
Hello @jjz921024 thanks for getting back to me, yes I did test all hash commands having |
|
@jjz921024 the CI seems to pass removing the check in GetMetadata and fixing GetTime. |
|
@jjz921024 @ltagliamonte-dd Thanks for your great efforts. I took my first pass in a new PR and generally look in good shape from my perspective. Two nit points can be improved:
if (metadata.Type() == kRedisHash) {
HashMetadata hash_metadata(false);
s = hash_metadata.Decode(rocksdb::Slice(pin_values[i].data(), pin_values[i].size()));
if (!s.ok()) continue;
redis::Hash hash_db(storage_, namespace_);
if (hash_db.ExistValidField(ctx, slice_keys[i], hash_metadata)) { |
|
@ltagliamonte-dd Hi, I create a PR #1 in your kvrocks fork repo. There are some polish about this feature for your reference. The purpose of this this commit aac63cc is to avoid unnecessary field expiration checks when executing the hset/hmset command, which comes from #2402 (comment) @PragmaTwice suggestion. The purpose of this this commit 7306231 is make |
|
Hello @jjz921024 thank you for the help on getting this through the finish line. Discussing this check with @PragmaTwice and @git-hulk on zulipchat we decided to move the check up in the call stack and perform it only when required. As the CI on this PR is showing (and my verification) it looks like there is no need for expiration check in GetMetadata, I would love to hear from you if i'm missing something and why the check is required. Please join us on zulipchat so we can discuss this in a more interactive way. by removing the check in GetMetadata commit aac63cc is not needed thank you for commit 7306231 i will be importing it. |
|
@git-hulk I gave a look at your suggestion to remove duplicated code, it looks like duplicated but if you look closely they are all slightly different checks... we may be able to refactor with something like this: so we pass an handleFunction into the refactored function |
|
I'll take a look at this weekend if no other things happen : ) cc @mapleFU PTAL. Also now we need to solve git conflicts before reviewing and merging. cc @ltagliamonte-dd |
|
@PragmaTwice can you please re-trigger the CI it looks like a flaky test |
src/types/redis_hash.cc
Outdated
| rocksdb::Status Hash::encodeExpireToValue(std::string *value, uint64_t expire) { | ||
| std::string buf; | ||
| PutFixed64(&buf, expire); | ||
| buf.append(*value); | ||
| value->assign(buf.data(), buf.size()); | ||
| return rocksdb::Status::OK(); | ||
| } |
There was a problem hiding this comment.
| rocksdb::Status Hash::encodeExpireToValue(std::string *value, uint64_t expire) { | |
| std::string buf; | |
| PutFixed64(&buf, expire); | |
| buf.append(*value); | |
| value->assign(buf.data(), buf.size()); | |
| return rocksdb::Status::OK(); | |
| } | |
| rocksdb::Status Hash::encodeExpireAndValue(std::string_view value, uint64_t expire, std::string *out) { | |
| PutFixed64(out, expire); | |
| out->append(value); | |
| return rocksdb::Status::OK(); | |
| } |
Also for all places that uses this function.
There was a problem hiding this comment.
@PragmaTwice I have trouble understanding the suggestion.. would be this correct:
rocksdb::Status Hash::encodeExpireAndValue(std::string value, uint64_t expire, std::string *enc_value) {
PutFixed64(enc_value, expire);
enc_value->append(value);
return rocksdb::Status::OK();
}
There was a problem hiding this comment.
I think string_view should be better here.
There was a problem hiding this comment.
@PragmaTwice please let me know how 3a726e1 looks, happy to address further if needed.
There was a problem hiding this comment.
@PragmaTwice string_view comment addressed via b10d710
There was a problem hiding this comment.
Ahh I revisited it and I think it can be std::string Hash::encodeExpireAndValue(std::string_view value, uint64_t expire).
The returned status here seems useless.
There was a problem hiding this comment.
std::string Hash::encodeExpireAndValue(std::string_view value, uint64_t expire) {
std::string out;
PutFixed64(&out, expire);
out.append(value);
return out;
}
Yes, we need to take care of this after introducing the hash expiration feature. But we can try to improve this before formally releasing it. |
Co-authored-by: Twice <twice@apache.org>
|
|
Hello Folks any updates on review/merge this PR? |
|
Folks do we have any updates on this? |
|
|
Hi @ltagliamonte-dd , sorry for late response. This PR includes massive changes to existing, critical code (the encoding logic of HASH data structure). So it requires lots of time to review to ensure that, not only users that need this feature, but also users that don't care this feature, can have a good and consistent experience while using Kvrocks. Also we need to make sure it doesn't affect old users, and the performance doesn't have a big drop. I currently don't have much time to complete a full review due to some personal affairs. Not sure if @git-hulk and @mapleFU have time to review. But if I get some time I'll move on for this PR : ) |
From the implementation, it should not affect the user who doesn't use the hash expiration feature. But the performance would be heavily impacted once enabled, because it needs to count the valid field number at each operation. And it would be hard to improve once we have released this, so I have no confidence to say it's fine to have a try from my perspective. But I admit the hash expiration is a key feature for Kvrocks and desire to introduce this feature. |
|
thanks @git-hulk , what do you prefer to do? back to the drawing board? |
|
I'm not sure, but maybe Redis (according to this PR, I'll try to double check) tracks the latest expiration time of the element in the hash so we can save it to Metadata and take it into consideration without checking all valid elements in the hash. So this solution will bring the same performance to both "normal hash" and the "hash with elements that have TTL". @git-hulk @PragmaTwice @mapleFU WDYT? |
|
Any updates or progress on this feature? |
|
need this feature. |



based on #2402
@jjz921024 I verified all hash cmds and they seem to work without the additional check in GetMetadata do you happen to remember if there was a specific use case you added it there?