-
Notifications
You must be signed in to change notification settings - Fork 591
feat(digest): implement DIGEST command #3313
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: unstable
Are you sure you want to change the base?
feat(digest): implement DIGEST command #3313
Conversation
| require.NoError(t, rdb.Set(ctx, "key1", "Hello world", 0).Err()) | ||
|
|
||
| // DIGEST should return hex hash | ||
| digest := rdb.Do(ctx, "DIGEST", "key1").Val() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can use the String to avoid the typecast. The same as other places.
| digest := rdb.Do(ctx, "DIGEST", "key1").Val() | |
| digest := rdb.Do(ctx, "DIGEST", "key1").String() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can use the
Stringto avoid the typecast. The same as other places.
Thanks for the suggestion, I will update other places.
Co-authored-by: hulk <hulk.website@gmail.com>
Co-authored-by: hulk <hulk.website@gmail.com>
|
@chakkk309 The CI failure is due to the missing ASF license header in the new file; you could also fix it. https://github.com/apache/kvrocks/actions/runs/20540153574/job/59003405075?pr=3313#step:4:139 |
Thanks for the reminder, I have already added the license header~ |
git-hulk
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally looks good to me, one test case suggestion inline.
@chakkk309, Could you please remove the meaningless comments inside test cases?
Co-authored-by: hulk <hulk.website@gmail.com>
…o feat-implement-DIGEST-command
|
I was going through your commits and observed that you have implemented the digest function directly in the cmd_string.cc itself, making it noncallable as other commands depend on it and making it difficult to adapt changes further down the line. Type checking for key is not implemented as well, key must be of type string for it to be hashed |
|
@chakkk309 XXH3_64bits haven't been implemented in Kvrocks. |
src/types/redis_string.cc
Outdated
| std::string String::ComputeXXH3Hash(const std::string &data) { | ||
| uint64_t hash = XXH3_64bits(data.data(), data.size()); | ||
| return fmt::format("{:016x}", hash); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method seems unnecessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually no, because the DELEX and SET command relies on this command so keeping a method is the right way to do it. If we do it this way it will be easier to add more commands in the future that requires DIGEST and also change the hashing algorithm by just changing this 1 function instead of changing it multiple times in various places.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm fine with this utility. But it should not be a method of redis::String since it does nothing related to rocksdb IO.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It can be put into string_util.h.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It can be put into string_util.h.
Sure, i will move this method later.
src/commands/cmd_string.cc
Outdated
| Config *config = srv->GetConfig(); | ||
| uint32_t max_btos_size = static_cast<uint32_t>(config->max_bitmap_to_string_mb) * MiB; | ||
| redis::Bitmap bitmap_db(srv->storage, conn->GetNamespace()); | ||
| std::string value; | ||
| s = bitmap_db.GetString(ctx, args_[1], max_btos_size, &value); | ||
| if (s.ok()) { | ||
| digest = redis::String::ComputeXXH3Hash(value); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we put them in redis_bitmap.cc? @git-hulk
| rocksdb::Status String::Digest(engine::Context &ctx, const std::string &user_key, std::string *digest) { | ||
| std::string value; | ||
| auto s = Get(ctx, user_key, &value); | ||
| if (!s.ok()) { | ||
| return s; | ||
| } | ||
|
|
||
| *digest = ComputeXXH3Hash(value); | ||
| return rocksdb::Status::OK(); | ||
| } | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if we can unify the bitmap and string part into one place. Or maybe we can just drop the support of bitmap? @git-hulk
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I totally agree to drop the support of bitmap in string, because it might introduce the unexpected performance issue if users incorrectly read the bitmap as a string.
src/commands/cmd_string.cc
Outdated
| #include <string> | ||
|
|
||
| #include "commander.h" | ||
| #include <fmt/format.h> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove this pls.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
src/commands/cmd_string.cc
Outdated
| if (s.IsInvalidArgument()) { | ||
| Config *config = srv->GetConfig(); | ||
| uint32_t max_btos_size = static_cast<uint32_t>(config->max_bitmap_to_string_mb) * MiB; | ||
| redis::Bitmap bitmap_db(srv->storage, conn->GetNamespace()); | ||
| std::string value; | ||
| s = bitmap_db.GetString(ctx, args_[1], max_btos_size, &value); | ||
| if (s.ok()) { | ||
| digest = util::ComputeXXH3Hash(value); | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, i will remove bitmap related code.
src/commands/cmd_string.cc
Outdated
| #include "commander.h" | ||
| #include <fmt/format.h> | ||
| #include "commands/command_parser.h" | ||
| #include "common/string_util.h" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
| {"simple string", "hello", ""}, | ||
| {"number as string", "123", ""}, | ||
| {"special chars", "!@#$%^&*()", ""}, | ||
| {"unicode", "こんにちは", ""}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please fill these expcted value..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the reminder, i 've already added.
PragmaTwice
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Co-authored-by: Twice <twice@apache.org>
Co-authored-by: Twice <twice@apache.org>
Thanks for sharing. I've read the AI contribution guidelines and will follow them, ensuring code quality through manual review and testing. |
|
CI workflow failed: https://github.com/apache/kvrocks/actions/runs/20572608610/job/59082847157?pr=3313. Please format your code before pushing them. |
|
@chakkk309 You could try to build and test this PR on your side first. |
|
@chakkk309 Hey, please read our AI contribution guide again. Please make sure you can understand the AI-generated code and are able to build and test your changes yourself. This PR has been in a state for a while where it still can’t build successfully or pass tests, and if that continues, I will stop reviewing and close this PR. |
Thanks you, I ran |
Thanks, I’ve built it successfully on my local machine and also tested to make sure I fixed the lint error. |
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
digest is not a "type". please move this file to unit.



Fixes #3309