Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: function return value logic and variable initialization #2176

Merged
merged 3 commits into from
Dec 5, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Merge branch 'unstable' into dev
Mixficsol authored Dec 5, 2023
commit 4a03d08e31e036b5faac6f2520ebd0fa6633d970
43 changes: 43 additions & 0 deletions src/pika_admin.cc
Original file line number Diff line number Diff line change
@@ -1448,6 +1448,49 @@ void InfoCmd::InfoCommandStats(std::string& info) {
info.append(tmp_stream.str());
}

void InfoCmd::InfoCache(std::string& info, std::shared_ptr<Slot> slot) {
std::stringstream tmp_stream;
tmp_stream << "# Cache" << "\r\n";
if (PIKA_CACHE_NONE == g_pika_conf->cache_model()) {
tmp_stream << "cache_status:Disable" << "\r\n";
} else {
auto cache_info = slot->GetCacheInfo();
tmp_stream << "cache_status:" << CacheStatusToString(cache_info.status) << "\r\n";
tmp_stream << "cache_db_num:" << cache_info.cache_num << "\r\n";
tmp_stream << "cache_keys:" << cache_info.keys_num << "\r\n";
tmp_stream << "cache_memory:" << cache_info.used_memory << "\r\n";
tmp_stream << "cache_memory_human:" << (cache_info.used_memory >> 20) << "M\r\n";
tmp_stream << "hits:" << cache_info.hits << "\r\n";
tmp_stream << "all_cmds:" << cache_info.hits + cache_info.misses << "\r\n";
tmp_stream << "hits_per_sec:" << cache_info.hits_per_sec << "\r\n";
tmp_stream << "read_cmd_per_sec:" << cache_info.read_cmd_per_sec << "\r\n";
tmp_stream << "hitratio_per_sec:" << std::setprecision(4) << cache_info.hitratio_per_sec << "%" << "\r\n";
tmp_stream << "hitratio_all:" << std::setprecision(4) << cache_info.hitratio_all << "%" << "\r\n";
tmp_stream << "load_keys_per_sec:" << cache_info.load_keys_per_sec << "\r\n";
tmp_stream << "waitting_load_keys_num:" << cache_info.waitting_load_keys_num << "\r\n";
}
info.append(tmp_stream.str());
}

std::string InfoCmd::CacheStatusToString(int status) {
switch (status) {
case PIKA_CACHE_STATUS_NONE:
return std::string("None");
case PIKA_CACHE_STATUS_OK:
return std::string("Ok");
case PIKA_CACHE_STATUS_INIT:
return std::string("Init");
case PIKA_CACHE_STATUS_RESET:
return std::string("Reset");
case PIKA_CACHE_STATUS_DESTROY:
return std::string("Destroy");
case PIKA_CACHE_STATUS_CLEAR:
return std::string("Clear");
default:
return std::string("Unknown");
}
}

void InfoCmd::Execute() {
std::shared_ptr<Slot> slot = g_pika_server->GetSlotByDBName(db_name_);
Do(slot);
4 changes: 2 additions & 2 deletions src/pika_bit.cc
Original file line number Diff line number Diff line change
@@ -312,8 +312,8 @@ void BitOpCmd::DoInitial() {

void BitOpCmd::Do(std::shared_ptr<Slot> slot) {
int64_t result_length = 0;
rocksdb::Status s = slot->db()->BitOp(op_, dest_key_, src_keys_, value_to_dest_, &result_length);
if (s.ok()) {
s_ = slot->db()->BitOp(op_, dest_key_, src_keys_, value_to_dest_, &result_length);
if (s_.ok()) {
res_.AppendInteger(result_length);
} else {
res_.SetRes(CmdRes::kErrOther, s_.ToString());
4 changes: 2 additions & 2 deletions src/pika_hash.cc
Original file line number Diff line number Diff line change
@@ -259,8 +259,8 @@ void HIncrbyCmd::DoInitial() {

void HIncrbyCmd::Do(std::shared_ptr<Slot> slot) {
int64_t new_value = 0;
rocksdb::Status s = slot->db()->HIncrby(key_, field_, by_, &new_value);
if (s.ok() || s.IsNotFound()) {
s_ = slot->db()->HIncrby(key_, field_, by_, &new_value);
if (s_.ok() || s_.IsNotFound()) {
res_.AppendContent(":" + std::to_string(new_value));
AddSlotKey("h", key_, slot);
} else if (s_.IsCorruption() && s_.ToString() == "Corruption: hash value is not an integer") {
9 changes: 5 additions & 4 deletions src/pika_kv.cc
Original file line number Diff line number Diff line change
@@ -207,8 +207,9 @@ void DelCmd::Do(std::shared_ptr<Slot> slot) {
int64_t count = slot->db()->Del(keys_, &type_status);
if (count >= 0) {
res_.AppendInteger(count);
auto it = keys_.begin();
for (; it != keys_.end(); it++) {
s_ = rocksdb::Status::OK();
std::vector<std::string>::const_iterator it;
for (it = keys_.begin(); it != keys_.end(); it++) {
RemSlotKey(*it, slot);
}
} else {
@@ -1032,8 +1033,8 @@ void SetrangeCmd::DoInitial() {

void SetrangeCmd::Do(std::shared_ptr<Slot> slot) {
int32_t new_len = 0;
rocksdb::Status s = slot->db()->Setrange(key_, offset_, value_, &new_len);
if (s.ok()) {
s_ = slot->db()->Setrange(key_, offset_, value_, &new_len);
if (s_.ok()) {
res_.AppendInteger(new_len);
AddSlotKey("k", key_, slot);
} else {
11 changes: 11 additions & 0 deletions src/pika_list.cc
Original file line number Diff line number Diff line change
@@ -135,6 +135,17 @@ void LLenCmd::ReadCache(std::shared_ptr<Slot> slot) {
}
}

void LLenCmd::DoThroughDB(std::shared_ptr<Slot> slot) {
res_.clear();
Do(slot);
}

void LLenCmd::DoUpdateCache(std::shared_ptr<Slot> slot) {
if (s_.ok()) {
slot->cache()->PushKeyToAsyncLoadQueue(PIKA_KEY_TYPE_LIST, key_, slot);
}
}

void BlockingBaseCmd::TryToServeBLrPopWithThisKey(const std::string& key, std::shared_ptr<Slot> slot) {
std::shared_ptr<net::RedisConn> curr_conn = std::dynamic_pointer_cast<net::RedisConn>(GetConn());
if (!curr_conn) {
5 changes: 3 additions & 2 deletions src/pika_set.cc
Original file line number Diff line number Diff line change
@@ -24,8 +24,9 @@ void SAddCmd::DoInitial() {

void SAddCmd::Do(std::shared_ptr<Slot> slot) {
int32_t count = 0;
rocksdb::Status s = slot->db()->SAdd(key_, members_, &count);
if (!s.ok()) {
s_ = slot->db()->SAdd(key_, members_, &count);
if (!s_.ok()) {
res_.SetRes(CmdRes::kErrOther, s_.ToString());
return;
}
AddSlotKey("s", key_, slot);
18 changes: 17 additions & 1 deletion src/pika_zset.cc
Original file line number Diff line number Diff line change
@@ -1016,7 +1016,23 @@ void ZScoreCmd::DoInitial() {

void ZScoreCmd::Do(std::shared_ptr<Slot> slot) {
double score = 0.0;
rocksdb::Status s = slot->db()->ZScore(key_, member_, &score);
s_ = slot->db()->ZScore(key_, member_, &score);
if (s_.ok()) {
char buf[32];
int64_t len = pstd::d2string(buf, sizeof(buf), score);
res_.AppendStringLen(len);
res_.AppendContent(buf);
} else if (s_.IsNotFound()) {
res_.AppendContent("$-1");
} else {
res_.SetRes(CmdRes::kErrOther, s_.ToString());
}
}

void ZScoreCmd::ReadCache(std::shared_ptr<Slot> slot) {
double score = 0.0;
std::string CachePrefixKeyZ = PCacheKeyPrefixZ + key_;
auto s = slot->cache()->ZScore(CachePrefixKeyZ, member_, &score, slot);
if (s.ok()) {
char buf[32];
int64_t len = pstd::d2string(buf, sizeof(buf), score);
You are viewing a condensed version of this merge commit. You can view the full changes here.