Skip to content

Commit

Permalink
fix: per minite get disk size (#2184)
Browse files Browse the repository at this point in the history
* per minite get disk size

* fix

* fix ZRemCmd

* fix

* fixcmd

* Update pika_zset.cc

---------

Co-authored-by: chejinge <[email protected]>
  • Loading branch information
chejinge and brother-jin committed Dec 12, 2023
1 parent f674018 commit fda44ff
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 77 deletions.
4 changes: 3 additions & 1 deletion include/pika_admin.h
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,9 @@ class InfoCmd : public Cmd {
bool rescan_ = false; // whether to rescan the keyspace
bool off_ = false;
std::set<std::string> 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;
Expand Down
3 changes: 2 additions & 1 deletion include/pika_set.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_ = "*";
Expand Down Expand Up @@ -231,6 +230,7 @@ class SInterstoreCmd : public SetOperationCmd {

private:
void DoInitial() override;
rocksdb::Status s_;
};

class SIsmemberCmd : public Cmd {
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions include/pika_zset.h
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ class ZRemCmd : public Cmd {
std::string key_;
std::vector<std::string> members_;
int32_t deleted_ = 0;
rocksdb::Status s_;
void DoInitial() override;
};

Expand Down Expand Up @@ -481,6 +482,7 @@ class ZRevrangebylexCmd : public ZsetRangebylexParentCmd {

private:
void DoInitial() override;
rocksdb::Status s_;
};

class ZLexcountCmd : public Cmd {
Expand Down
74 changes: 15 additions & 59 deletions src/pika_admin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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";
Expand All @@ -1302,8 +1258,8 @@ void InfoCmd::InfoData(std::string& info) {
std::map<std::string, uint64_t> 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_) {
Expand Down
18 changes: 9 additions & 9 deletions src/pika_set.cc
Original file line number Diff line number Diff line change
Expand Up @@ -395,11 +395,11 @@ void SInterstoreCmd::DoInitial() {

void SInterstoreCmd::Do(std::shared_ptr<Slot> 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());
}
}

Expand Down Expand Up @@ -522,12 +522,12 @@ void SMoveCmd::DoInitial() {

void SMoveCmd::Do(std::shared_ptr<Slot> 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());
}
}

Expand Down Expand Up @@ -595,8 +595,8 @@ void SRandmemberCmd::DoInitial() {

void SRandmemberCmd::Do(std::shared_ptr<Slot> slot) {
std::vector<std::string> members;
rocksdb::Status s = slot->db()->SRandmember(key_, static_cast<int32_t>(count_), &members);
if (s.ok() || s.IsNotFound()) {
s_ = slot->db()->SRandmember(key_, static_cast<int32_t>(count_), &members);
if (s_.ok() || s_.IsNotFound()) {
if (!reply_arr && (static_cast<unsigned int>(!members.empty()) != 0U)) {
res_.AppendStringLenUint64(members[0].size());
res_.AppendContent(members[0]);
Expand All @@ -608,7 +608,7 @@ void SRandmemberCmd::Do(std::shared_ptr<Slot> slot) {
}
}
} else {
res_.SetRes(CmdRes::kErrOther, s.ToString());
res_.SetRes(CmdRes::kErrOther, s_.ToString());
}
}

Expand Down
12 changes: 6 additions & 6 deletions src/pika_zset.cc
Original file line number Diff line number Diff line change
Expand Up @@ -683,12 +683,12 @@ void ZRemCmd::DoInitial() {

void ZRemCmd::Do(std::shared_ptr<Slot> 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());
}
}

Expand Down Expand Up @@ -1201,9 +1201,9 @@ void ZRevrangebylexCmd::Do(std::shared_ptr<Slot> slot) {
return;
}
std::vector<std::string> 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<int32_t>(members.size()));
Expand Down
1 change: 0 additions & 1 deletion src/storage/src/base_value_format.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit fda44ff

Please sign in to comment.