PragmaTwice commented on code in PR #3313:
URL: https://github.com/apache/kvrocks/pull/3313#discussion_r2649717951


##########
src/types/redis_string.cc:
##########
@@ -657,4 +659,20 @@ rocksdb::Status String::LCS(engine::Context &ctx, const 
std::string &user_key1,
   return rocksdb::Status::OK();
 }
 
+std::string String::ComputeXXH3Hash(const std::string &data) {
+  uint64_t hash = XXH3_64bits(data.data(), data.size());
+  return fmt::format("{:016x}", hash);
+}
+
+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();
+}
+

Review Comment:
   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 



##########
src/commands/cmd_string.cc:
##########
@@ -721,10 +721,39 @@ class CommandLCS : public Commander {
   int64_t min_match_len_ = 0;
 };
 
+class CommandDigest : public Commander {
+ public:
+  Status Execute(engine::Context &ctx, Server *srv, Connection *conn, 
std::string *output) override {
+    redis::String string_db(srv->storage, conn->GetNamespace());
+    std::string digest;
+    auto s = string_db.Digest(ctx, args_[1], &digest);
+    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 = redis::String::ComputeXXH3Hash(value);
+      }

Review Comment:
   Should we put them in redis_bitmap.cc? @git-hulk 



##########
src/types/redis_string.cc:
##########
@@ -657,4 +659,20 @@ rocksdb::Status String::LCS(engine::Context &ctx, const 
std::string &user_key1,
   return rocksdb::Status::OK();
 }
 
+std::string String::ComputeXXH3Hash(const std::string &data) {
+  uint64_t hash = XXH3_64bits(data.data(), data.size());
+  return fmt::format("{:016x}", hash);
+}

Review Comment:
   This method seems unnecessary.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to