From ba76b418272ff9dff109ac2a421e4e55f5a79c58 Mon Sep 17 00:00:00 2001 From: chejinge <945997690@qq.com> Date: Tue, 12 Mar 2024 11:44:23 +0800 Subject: [PATCH 1/3] fix:dbsize caculate error --- src/pika_admin.cc | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/pika_admin.cc b/src/pika_admin.cc index d41d6d5943..b884d00fb6 100644 --- a/src/pika_admin.cc +++ b/src/pika_admin.cc @@ -2725,6 +2725,20 @@ void DbsizeCmd::DoInitial() { void DbsizeCmd::Do() { std::shared_ptr dbs = g_pika_server->GetDB(db_name_); + if (g_pika_conf->slotmigrate()){ + int64_t dbsize = 0; + for (int i = 0; i < g_pika_conf->default_slot_num(); ++i){ + int32_t card = 0; + rocksdb::Status s = dbs->storage()->SCard(SlotKeyPrefix+std::to_string(i), &card); + if (s.ok() && card >= 0) { + dbsize += card; + }else { + res_.SetRes(CmdRes::kErrOther, "Get dbsize error"); + return; + } + } + res_.AppendInteger(dbsize); + } if (!dbs) { res_.SetRes(CmdRes::kInvalidDB); } else { From 68528b1efde5181144a3d7916388d99b3cb7ed09 Mon Sep 17 00:00:00 2001 From: chejinge <945997690@qq.com> Date: Tue, 12 Mar 2024 11:47:53 +0800 Subject: [PATCH 2/3] fix:dbsize --- src/pika_admin.cc | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/pika_admin.cc b/src/pika_admin.cc index b884d00fb6..948dd99306 100644 --- a/src/pika_admin.cc +++ b/src/pika_admin.cc @@ -2725,23 +2725,23 @@ void DbsizeCmd::DoInitial() { void DbsizeCmd::Do() { std::shared_ptr dbs = g_pika_server->GetDB(db_name_); - if (g_pika_conf->slotmigrate()){ - int64_t dbsize = 0; - for (int i = 0; i < g_pika_conf->default_slot_num(); ++i){ - int32_t card = 0; - rocksdb::Status s = dbs->storage()->SCard(SlotKeyPrefix+std::to_string(i), &card); - if (s.ok() && card >= 0) { - dbsize += card; - }else { - res_.SetRes(CmdRes::kErrOther, "Get dbsize error"); - return; - } - } - res_.AppendInteger(dbsize); - } if (!dbs) { res_.SetRes(CmdRes::kInvalidDB); } else { + if (g_pika_conf->slotmigrate()){ + int64_t dbsize = 0; + for (int i = 0; i < g_pika_conf->default_slot_num(); ++i){ + int32_t card = 0; + rocksdb::Status s = dbs->storage()->SCard(SlotKeyPrefix+std::to_string(i), &card); + if (s.ok() && card >= 0) { + dbsize += card; + }else { + res_.SetRes(CmdRes::kErrOther, "Get dbsize error"); + return; + } + } + res_.AppendInteger(dbsize); + } KeyScanInfo key_scan_info = dbs->GetKeyScanInfo(); std::vector key_infos = key_scan_info.key_infos; if (key_infos.size() != 5) { From 8fa929c8372cdb2022fbf3ce8c35cc86a2b050ab Mon Sep 17 00:00:00 2001 From: chejinge <945997690@qq.com> Date: Tue, 12 Mar 2024 13:51:00 +0800 Subject: [PATCH 3/3] format --- src/pika_admin.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pika_admin.cc b/src/pika_admin.cc index 948dd99306..5dd5688025 100644 --- a/src/pika_admin.cc +++ b/src/pika_admin.cc @@ -2735,7 +2735,7 @@ void DbsizeCmd::Do() { rocksdb::Status s = dbs->storage()->SCard(SlotKeyPrefix+std::to_string(i), &card); if (s.ok() && card >= 0) { dbsize += card; - }else { + } else { res_.SetRes(CmdRes::kErrOther, "Get dbsize error"); return; }