diff --git a/include/pika_admin.h b/include/pika_admin.h index da2b7d2c31..88c03e5be7 100644 --- a/include/pika_admin.h +++ b/include/pika_admin.h @@ -238,7 +238,9 @@ class InfoCmd : public Cmd { bool rescan_ = false; // whether to rescan the keyspace bool off_ = false; std::set keyspace_scan_dbs_; - + time_t db_size_last_time_ = 0; + uint64_t db_size_ = 0; + uint64_t log_size_ = 0; const static std::string kInfoSection; const static std::string kAllSection; const static std::string kServerSection; diff --git a/include/pika_set.h b/include/pika_set.h index 76643ce192..dca5bac17d 100644 --- a/include/pika_set.h +++ b/include/pika_set.h @@ -119,7 +119,6 @@ class SScanCmd : public Cmd { std::string key_, pattern_ = "*"; int64_t cursor_ = 0; int64_t count_ = 10; - rocksdb::Status s_; void DoInitial() override; void Clear() override { pattern_ = "*"; @@ -231,6 +230,7 @@ class SInterstoreCmd : public SetOperationCmd { private: void DoInitial() override; + rocksdb::Status s_; }; class SIsmemberCmd : public Cmd { @@ -339,6 +339,7 @@ class SRandmemberCmd : public Cmd { std::string key_; int64_t count_ = 1; bool reply_arr = false; + rocksdb::Status s_; void DoInitial() override; void Clear() override { count_ = 1; diff --git a/include/pika_zset.h b/include/pika_zset.h index 755f1b479e..f189ecf434 100644 --- a/include/pika_zset.h +++ b/include/pika_zset.h @@ -279,6 +279,7 @@ class ZRemCmd : public Cmd { std::string key_; std::vector members_; int32_t deleted_ = 0; + rocksdb::Status s_; void DoInitial() override; }; @@ -481,6 +482,7 @@ class ZRevrangebylexCmd : public ZsetRangebylexParentCmd { private: void DoInitial() override; + rocksdb::Status s_; }; class ZLexcountCmd : public Cmd { diff --git a/src/pika_admin.cc b/src/pika_admin.cc index 8bfa27edd3..03db6a99c6 100644 --- a/src/pika_admin.cc +++ b/src/pika_admin.cc @@ -1052,61 +1052,6 @@ void InfoCmd::InfoCPU(std::string& info) { info.append(tmp_stream.str()); } -void InfoCmd::InfoShardingReplication(std::string& info) { - int role = 0; - std::string slave_list_string; - uint32_t slave_num = g_pika_server->GetShardingSlaveListString(slave_list_string); - if (slave_num != 0U) { - role |= PIKA_ROLE_MASTER; - } - std::string common_master; - std::string master_ip; - int master_port = 0; - g_pika_rm->FindCommonMaster(&common_master); - if (!common_master.empty()) { - role |= PIKA_ROLE_SLAVE; - if (!pstd::ParseIpPortString(common_master, master_ip, master_port)) { - return; - } - } - - std::stringstream tmp_stream; - tmp_stream << "# Replication("; - switch (role) { - case PIKA_ROLE_SINGLE: - case PIKA_ROLE_MASTER: - tmp_stream << "MASTER)\r\nrole:master\r\n"; - break; - case PIKA_ROLE_SLAVE: - tmp_stream << "SLAVE)\r\nrole:slave\r\n"; - break; - case PIKA_ROLE_MASTER | PIKA_ROLE_SLAVE: - tmp_stream << "Master && SLAVE)\r\nrole:master&&slave\r\n"; - break; - default: - info.append("ERR: server role is error\r\n"); - return; - } - switch (role) { - case PIKA_ROLE_SLAVE: - tmp_stream << "master_host:" << master_ip << "\r\n"; - tmp_stream << "master_port:" << master_port << "\r\n"; - tmp_stream << "master_link_status:up" - << "\r\n"; - tmp_stream << "slave_priority:" << g_pika_conf->slave_priority() << "\r\n"; - break; - case PIKA_ROLE_MASTER | PIKA_ROLE_SLAVE: - tmp_stream << "master_host:" << master_ip << "\r\n"; - tmp_stream << "master_port:" << master_port << "\r\n"; - tmp_stream << "master_link_status:up" - << "\r\n"; - case PIKA_ROLE_SINGLE: - case PIKA_ROLE_MASTER: - tmp_stream << "connected_slaves:" << slave_num << "\r\n" << slave_list_string; - } - info.append(tmp_stream.str()); -} - void InfoCmd::InfoReplication(std::string& info) { int host_role = g_pika_server->role(); std::stringstream tmp_stream; @@ -1287,13 +1232,24 @@ void InfoCmd::InfoKeyspace(std::string& info) { void InfoCmd::InfoData(std::string& info) { std::stringstream tmp_stream; std::stringstream db_fatal_msg_stream; - - uint64_t db_size = pstd::Du(g_pika_conf->db_path()); + uint64_t db_size = 0; + time_t current_time_s = time(nullptr); + uint64_t log_size = 0; + + if (current_time_s - 60 >= db_size_last_time_) { + db_size_last_time_ = current_time_s; + db_size = pstd::Du(g_pika_conf->db_path()); + db_size_ = db_size; + log_size = pstd::Du(g_pika_conf->log_path()); + log_size_ = log_size; + } else { + db_size = db_size_; + log_size = log_size_; + } tmp_stream << "# Data" << "\r\n"; tmp_stream << "db_size:" << db_size << "\r\n"; tmp_stream << "db_size_human:" << (db_size >> 20) << "M\r\n"; - uint64_t log_size = pstd::Du(g_pika_conf->log_path()); tmp_stream << "log_size:" << log_size << "\r\n"; tmp_stream << "log_size_human:" << (log_size >> 20) << "M\r\n"; tmp_stream << "compression:" << g_pika_conf->compression() << "\r\n"; @@ -1302,8 +1258,8 @@ void InfoCmd::InfoData(std::string& info) { std::map background_errors; uint64_t total_background_errors = 0; uint64_t total_memtable_usage = 0; - uint64_t memtable_usage = 0; uint64_t total_table_reader_usage = 0; + uint64_t memtable_usage = 0; uint64_t table_reader_usage = 0; std::shared_lock db_rwl(g_pika_server->dbs_rw_); for (const auto& db_item : g_pika_server->dbs_) { diff --git a/src/pika_set.cc b/src/pika_set.cc index 4da4fad885..16d521614c 100644 --- a/src/pika_set.cc +++ b/src/pika_set.cc @@ -395,11 +395,11 @@ void SInterstoreCmd::DoInitial() { void SInterstoreCmd::Do(std::shared_ptr slot) { int32_t count = 0; - rocksdb::Status s = slot->db()->SInterstore(dest_key_, keys_, value_to_dest_, &count); - if (s.ok()) { + s_ = slot->db()->SInterstore(dest_key_, keys_, value_to_dest_, &count); + if (s_.ok()) { res_.AppendInteger(count); } else { - res_.SetRes(CmdRes::kErrOther, s.ToString()); + res_.SetRes(CmdRes::kErrOther, s_.ToString()); } } @@ -522,12 +522,12 @@ void SMoveCmd::DoInitial() { void SMoveCmd::Do(std::shared_ptr slot) { int32_t res = 0; - rocksdb::Status s = slot->db()->SMove(src_key_, dest_key_, member_, &res); - if (s.ok() || s.IsNotFound()) { + s_ = slot->db()->SMove(src_key_, dest_key_, member_, &res); + if (s_.ok() || s_.IsNotFound()) { res_.AppendInteger(res); move_success_ = res; } else { - res_.SetRes(CmdRes::kErrOther, s.ToString()); + res_.SetRes(CmdRes::kErrOther, s_.ToString()); } } @@ -595,8 +595,8 @@ void SRandmemberCmd::DoInitial() { void SRandmemberCmd::Do(std::shared_ptr slot) { std::vector members; - rocksdb::Status s = slot->db()->SRandmember(key_, static_cast(count_), &members); - if (s.ok() || s.IsNotFound()) { + s_ = slot->db()->SRandmember(key_, static_cast(count_), &members); + if (s_.ok() || s_.IsNotFound()) { if (!reply_arr && (static_cast(!members.empty()) != 0U)) { res_.AppendStringLenUint64(members[0].size()); res_.AppendContent(members[0]); @@ -608,7 +608,7 @@ void SRandmemberCmd::Do(std::shared_ptr slot) { } } } else { - res_.SetRes(CmdRes::kErrOther, s.ToString()); + res_.SetRes(CmdRes::kErrOther, s_.ToString()); } } diff --git a/src/pika_zset.cc b/src/pika_zset.cc index 555dd443fa..6b89e5b2a9 100644 --- a/src/pika_zset.cc +++ b/src/pika_zset.cc @@ -683,12 +683,12 @@ void ZRemCmd::DoInitial() { void ZRemCmd::Do(std::shared_ptr slot) { int32_t count = 0; - rocksdb::Status s = slot->db()->ZRem(key_, members_, &count); - if (s.ok() || s.IsNotFound()) { + s_ = slot->db()->ZRem(key_, members_, &count); + if (s_.ok() || s_.IsNotFound()) { AddSlotKey("z", key_, slot); res_.AppendInteger(count); } else { - res_.SetRes(CmdRes::kErrOther, s.ToString()); + res_.SetRes(CmdRes::kErrOther, s_.ToString()); } } @@ -1201,9 +1201,9 @@ void ZRevrangebylexCmd::Do(std::shared_ptr slot) { return; } std::vector members; - rocksdb::Status s = slot->db()->ZRangebylex(key_, min_member_, max_member_, left_close_, right_close_, &members); - if (!s.ok() && !s.IsNotFound()) { - res_.SetRes(CmdRes::kErrOther, s.ToString()); + s_ = slot->db()->ZRangebylex(key_, min_member_, max_member_, left_close_, right_close_, &members); + if (!s_.ok() && !s_.IsNotFound()) { + res_.SetRes(CmdRes::kErrOther, s_.ToString()); return; } FitLimit(count_, offset_, static_cast(members.size())); diff --git a/src/storage/src/base_value_format.h b/src/storage/src/base_value_format.h index c819f786d8..35b200c2ea 100644 --- a/src/storage/src/base_value_format.h +++ b/src/storage/src/base_value_format.h @@ -34,7 +34,6 @@ class InternalValue { } return Status::OK(); } - void set_version(int32_t version = 0) { version_ = version; } static const size_t kDefaultValueSuffixLength = sizeof(int32_t) * 2; virtual rocksdb::Slice Encode() { size_t usize = user_value_.size();