Skip to content

Conversation

@chakkk309
Copy link

Fixes #3309

require.NoError(t, rdb.Set(ctx, "key1", "Hello world", 0).Err())

// DIGEST should return hex hash
digest := rdb.Do(ctx, "DIGEST", "key1").Val()
Copy link
Member

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.

Suggested change
digest := rdb.Do(ctx, "DIGEST", "key1").Val()
digest := rdb.Do(ctx, "DIGEST", "key1").String()

Copy link
Author

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.

Thanks for the suggestion, I will update other places.

@git-hulk git-hulk requested a review from PragmaTwice December 27, 2025 14:13
chakkk309 and others added 2 commits December 27, 2025 22:16
Co-authored-by: hulk <hulk.website@gmail.com>
Co-authored-by: hulk <hulk.website@gmail.com>
@git-hulk
Copy link
Member

@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

@chakkk309
Copy link
Author

@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~

@chakkk309 chakkk309 requested a review from git-hulk December 27, 2025 14:28
Copy link
Member

@git-hulk git-hulk left a 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?

@Valay17
Copy link

Valay17 commented Dec 28, 2025

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

@git-hulk
Copy link
Member

git-hulk commented Dec 28, 2025

@chakkk309 XXH3_64bits haven't been implemented in Kvrocks.

Comment on lines 662 to 665
std::string String::ComputeXXH3Hash(const std::string &data) {
uint64_t hash = XXH3_64bits(data.data(), data.size());
return fmt::format("{:016x}", hash);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method seems unnecessary.

Copy link

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.

Copy link
Member

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.

Copy link
Member

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.

Copy link
Author

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.

Comment on lines 731 to 738
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);
}
Copy link
Member

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

Comment on lines 667 to 677
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();
}

Copy link
Member

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

Copy link
Member

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>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this pls.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Comment on lines 731 to 740
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);
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto.

Copy link
Author

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.

#include "commander.h"
#include <fmt/format.h>
#include "commands/command_parser.h"
#include "common/string_util.h"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and this.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment on lines 131 to 134
{"simple string", "hello", ""},
{"number as string", "123", ""},
{"special chars", "!@#$%^&*()", ""},
{"unicode", "こんにちは", ""},
Copy link
Member

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..

Copy link
Author

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.

Copy link
Member

@PragmaTwice PragmaTwice left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@chakkk309
Copy link
Author

Please read https://kvrocks.apache.org/community/contributing#guidelines-for-ai-assisted-contributions.

Thanks for sharing. I've read the AI contribution guidelines and will follow them, ensuring code quality through manual review and testing.

@PragmaTwice
Copy link
Member

CI workflow failed: https://github.com/apache/kvrocks/actions/runs/20572608610/job/59082847157?pr=3313.

Please format your code before pushing them.

@git-hulk
Copy link
Member

@chakkk309 You could try to build and test this PR on your side first.

@PragmaTwice
Copy link
Member

PragmaTwice commented Dec 30, 2025

@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.

@chakkk309
Copy link
Author

@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 ./x.py check golangci-lint locally to make sure I’ve fixed all the lint errors.

@chakkk309
Copy link
Author

@chakkk309 You could try to build and test this PR on your side first.

Thanks, I’ve built it successfully on my local machine and also tested to make sure I fixed the lint error.

@sonarqubecloud
Copy link

Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add support of the DIGEST command

4 participants