cyningsun commented on code in PR #3194:
URL: https://github.com/apache/kvrocks/pull/3194#discussion_r2365349718


##########
src/storage/redis_db.cc:
##########
@@ -208,12 +208,39 @@ rocksdb::Status Database::MDel(engine::Context &ctx, 
const std::vector<Slice> &k
 }
 
 rocksdb::Status Database::Exists(engine::Context &ctx, const 
std::vector<Slice> &keys, int *ret) {
+  *ret = 0;
+
+  if (keys.empty()) {
+    return rocksdb::Status::OK();
+  }
+
   std::vector<std::string> ns_keys;
+  std::vector<Slice> slice_keys;
   ns_keys.reserve(keys.size());
+  slice_keys.reserve(keys.size());
+
   for (const auto &key : keys) {
     ns_keys.emplace_back(AppendNamespacePrefix(key));
+    slice_keys.emplace_back(ns_keys.back());
+  }
+
+  std::vector<rocksdb::Status> statuses(slice_keys.size());
+  std::vector<rocksdb::PinnableSlice> pin_values(slice_keys.size());
+  storage_->MultiGet(ctx, ctx.DefaultMultiGetOptions(), metadata_cf_handle_, 
slice_keys.size(), slice_keys.data(),
+                     pin_values.data(), statuses.data());
+
+  for (size_t i = 0; i < slice_keys.size(); i++) {
+    if (!statuses[i].ok() && !statuses[i].IsNotFound()) return statuses[i];
+    if (statuses[i].ok()) {
+      Metadata metadata(kRedisNone, false);
+      // Explicit construct a rocksdb::Slice to avoid the implicit conversion 
from
+      // PinnableSlice to Slice.

Review Comment:
   @mapleFU  thanks for your comment!
   
   **If you're referring to the comment (A):** 
   I agree it's overly verbose. It can indeed be cleaned up.
   
   **If you're referring to the explicit construction (B):**
   The explicit construction is mainly for safety - since `Decode()` calls 
`remove_prefix()` internally, it would modify the original `pin_values[i]` 
state if passed directly. It's better to create a temporary `Slice` copy, 
leaving original data intact, which matches the pattern used elsewhere in the 
codebase. 
   
   **What's your take on this?** I'd be curious to hear your perspective



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