-
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 <[email protected]>
Co-authored-by: hulk <[email protected]>
|
@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 <[email protected]>
…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.
| 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.
| #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.
| 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.
| #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.
| return s; | ||
| } | ||
|
|
||
| std::string ComputeXXH3Hash(const std::string &data) { |
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.
| std::string ComputeXXH3Hash(const std::string &data) { | |
| std::string StringDigest(std::string_view data) { |
| } | ||
|
|
||
| std::string ComputeXXH3Hash(const std::string &data) { | ||
| uint64_t hash = XXH3_64bits(data.data(), data.size()); |
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.
| uint64_t hash = XXH3_64bits(data.data(), data.size()); | |
| XXH64_hash_t hash = XXH3_64bits(data.data(), data.size()); |
| {"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..
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.
Fixes #3309