You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kvrocks.apache.org by hu...@apache.org on 2023/05/22 05:27:47 UTC
[incubator-kvrocks] branch unstable updated: Use the rocksdb mget to improve the performance (#1453)
This is an automated email from the ASF dual-hosted git repository.
hulk pushed a commit to branch unstable
in repository https://gitbox.apache.org/repos/asf/incubator-kvrocks.git
The following commit(s) were added to refs/heads/unstable by this push:
new 60d13ef9 Use the rocksdb mget to improve the performance (#1453)
60d13ef9 is described below
commit 60d13ef9c71a401b59a011f686a1b8e6024360e4
Author: Zevin <ze...@gmail.com>
AuthorDate: Mon May 22 13:27:41 2023 +0800
Use the rocksdb mget to improve the performance (#1453)
DB::MultiGet pushes fields query to RocksDB, thus RocksDB can perform optimizations, such as async io by io uring.
Although this optimization is less than mget for strings, it is valuable
because different fields may lies in different levels of the LSM Tree, thus async io can take effect.
---
src/types/redis_hash.cc | 25 ++++++++++++++++++-------
1 file changed, 18 insertions(+), 7 deletions(-)
diff --git a/src/types/redis_hash.cc b/src/types/redis_hash.cc
index 389b8e19..8cec66ad 100644
--- a/src/types/redis_hash.cc
+++ b/src/types/redis_hash.cc
@@ -174,16 +174,27 @@ rocksdb::Status Hash::MGet(const Slice &user_key, const std::vector<Slice> &fiel
rocksdb::ReadOptions read_options;
read_options.snapshot = ss.GetSnapShot();
storage_->SetReadOptions(read_options);
+ std::vector<rocksdb::Slice> keys;
- std::string sub_key, value;
+ keys.reserve(fields.size());
+ std::vector<std::string> sub_keys;
+ sub_keys.resize(fields.size());
+ int i = 0;
for (const auto &field : fields) {
- InternalKey(ns_key, field, metadata.version, storage_->IsSlotIdEncoded()).Encode(&sub_key);
- value.clear();
- s = storage_->Get(read_options, sub_key, &value);
- if (!s.ok() && !s.IsNotFound()) return s;
+ InternalKey(ns_key, field, metadata.version, storage_->IsSlotIdEncoded()).Encode(&(sub_keys[i]));
+ keys.emplace_back(sub_keys[i++]);
+ }
- values->emplace_back(value);
- statuses->emplace_back(s);
+ std::vector<rocksdb::PinnableSlice> values_vector;
+ values_vector.resize(keys.size());
+ std::vector<rocksdb::Status> statuses_vector;
+ statuses_vector.resize(keys.size());
+ storage_->MultiGet(read_options, storage_->GetDB()->DefaultColumnFamily(), keys.size(), keys.data(),
+ values_vector.data(), statuses_vector.data());
+ for (size_t i = 0; i < keys.size(); i++) {
+ if (!statuses_vector[i].ok() && !statuses_vector[i].IsNotFound()) return statuses_vector[i];
+ values->emplace_back(values_vector[i].ToString());
+ statuses->emplace_back(statuses_vector[i]);
}
return rocksdb::Status::OK();
}