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 2022/09/24 09:00:54 UTC
[incubator-kvrocks] branch unstable updated: Avoid using Get when iterating sub-keys during migration (#906)
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 afd8668 Avoid using Get when iterating sub-keys during migration (#906)
afd8668 is described below
commit afd8668ed536f96d3efa0551c17819b2c28f5e7e
Author: Myth <ca...@outlook.com>
AuthorDate: Sat Sep 24 17:00:48 2022 +0800
Avoid using Get when iterating sub-keys during migration (#906)
---
src/slot_migrate.cc | 22 ++++------------------
src/slot_migrate.h | 3 +--
2 files changed, 5 insertions(+), 20 deletions(-)
diff --git a/src/slot_migrate.cc b/src/slot_migrate.cc
index 14a4b79..a65a3cb 100644
--- a/src/slot_migrate.cc
+++ b/src/slot_migrate.cc
@@ -302,7 +302,7 @@ Status SlotMigrate::SendSnapshot(void) {
// Add key's constructed cmd to restore_cmds, send pipeline
// or not according to current_pipeline_size_
- auto stat = MigrateOneKey(rocksdb::Slice(user_key), &restore_cmds);
+ auto stat = MigrateOneKey(user_key, iter->value(), &restore_cmds);
if (stat.IsOK()) {
if (stat.Msg() == "ok") migratedkey_cnt++;
if (stat.Msg() == "expired") expiredkey_cnt++;
@@ -543,29 +543,15 @@ bool SlotMigrate::CheckResponseWithCounts(int sock_fd, int total) {
return true; // Can't reach here
}
-bool SlotMigrate::GetSlotKeyMetadata(const rocksdb::Slice &prefix_key, std::string *bytes) {
- rocksdb::ReadOptions read_options;
- read_options.snapshot = slot_snapshot_;
- auto s = storage_->GetDB()->Get(read_options, storage_->GetCFHandle("metadata"), prefix_key, bytes);
- if (!s.ok()) {
- LOG(ERROR) << "[migrate] Failed to get metadata of key: " << prefix_key.ToString()
- << ", Err: " << s.ToString();
- return false;
- }
- return true;
-}
-
-Status SlotMigrate::MigrateOneKey(rocksdb::Slice key, std::string *restore_cmds) {
+Status SlotMigrate::MigrateOneKey(const rocksdb::Slice &key, const rocksdb::Slice &value, std::string *restore_cmds) {
std::string prefix_key;
AppendNamespacePrefix(key, &prefix_key);
- std::string bytes;
- bool st = GetSlotKeyMetadata(prefix_key, &bytes);
- if (!st) return Status(Status::NotOK, "[migrate] Failed to get key's metadata");
+ std::string bytes = value.ToString();
Metadata metadata(kRedisNone, false);
metadata.Decode(bytes);
if (metadata.Type() != kRedisString && metadata.size == 0) {
LOG(INFO) << "[migrate] No elements of key: " << prefix_key;
- return Status(Status::cOK, "empty");;
+ return Status(Status::cOK, "empty");
}
// Construct command according to type of the key
diff --git a/src/slot_migrate.h b/src/slot_migrate.h
index 4eae263..e8c6864 100644
--- a/src/slot_migrate.h
+++ b/src/slot_migrate.h
@@ -112,8 +112,7 @@ class SlotMigrate : public Redis::Database {
bool CheckResponseOnce(int sock_fd);
bool CheckResponseWithCounts(int sock_fd, int total);
- bool GetSlotKeyMetadata(const rocksdb::Slice &prefix_key, std::string *bytes);
- Status MigrateOneKey(rocksdb::Slice key, std::string *restore_cmds);
+ Status MigrateOneKey(const rocksdb::Slice &key, const rocksdb::Slice &value, std::string *restore_cmds);
bool MigrateSimpleKey(const rocksdb::Slice &key, const Metadata &metadata,
const std::string &bytes, std::string *restore_cmds);
bool MigrateComplexKey(const rocksdb::Slice &key, const Metadata &metadata, std::string *restore_cmds);