Skip to content

Commit

Permalink
fix: function return value logic and variable initialization (OpenAto…
Browse files Browse the repository at this point in the history
…mFoundation#2176)

* code format

* code format

---------

Co-authored-by: wuxianrong <[email protected]>
  • Loading branch information
Mixficsol and wuxianrong authored Dec 5, 2023
1 parent 355a37f commit 22ea865
Show file tree
Hide file tree
Showing 12 changed files with 48 additions and 49 deletions.
7 changes: 3 additions & 4 deletions src/pika_admin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1273,7 +1273,7 @@ void InfoCmd::InfoKeyspace(std::string& info) {

std::string db_name;
KeyScanInfo key_scan_info;
int32_t duration;
int32_t duration = 0;
std::vector<storage::KeyInfo> key_infos;
std::stringstream tmp_stream;
tmp_stream << "# Keyspace"
Expand Down Expand Up @@ -1492,8 +1492,7 @@ std::string InfoCmd::CacheStatusToString(int status) {
}

void InfoCmd::Execute() {
std::shared_ptr<Slot> slot;
slot = g_pika_server->GetSlotByDBName(db_name_);
std::shared_ptr<Slot> slot = g_pika_server->GetSlotByDBName(db_name_);
Do(slot);
}

Expand Down Expand Up @@ -2129,7 +2128,7 @@ void ConfigCmd::ConfigSet(std::string& ret, std::shared_ptr<Slot> slot) {
EncodeString(&ret, "max-rsync-parallel-num");
return;
}
long int ival;
long int ival = 0;
std::string value = config_args_v_[2];
if (set_item == "timeout") {
if (pstd::string2int(value.data(), value.size(), &ival) == 0) {
Expand Down
4 changes: 2 additions & 2 deletions src/pika_bit.cc
Original file line number Diff line number Diff line change
Expand Up @@ -305,13 +305,13 @@ void BitOpCmd::DoInitial() {
}

dest_key_ = argv_[2];
for (unsigned int i = 3; i <= argv_.size() - 1; i++) {
for (size_t i = 3; i <= argv_.size() - 1; i++) {
src_keys_.emplace_back(argv_[i].data());
}
}

void BitOpCmd::Do(std::shared_ptr<Slot> slot) {
int64_t result_length;
int64_t result_length = 0;
s_ = slot->db()->BitOp(op_, dest_key_, src_keys_, value_to_dest_, &result_length);
if (s_.ok()) {
res_.AppendInteger(result_length);
Expand Down
12 changes: 6 additions & 6 deletions src/pika_geo.cc
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ void GeoPosCmd::DoInitial() {
}

void GeoPosCmd::Do(std::shared_ptr<Slot> slot) {
double score;
double score = 0.0;
res_.AppendArrayLenUint64(members_.size());
for (const auto& member : members_) {
rocksdb::Status s = slot->db()->ZScore(key_, member, &score);
Expand Down Expand Up @@ -153,8 +153,8 @@ void GeoDistCmd::DoInitial() {
}

void GeoDistCmd::Do(std::shared_ptr<Slot> slot) {
double first_score;
double second_score;
double first_score = 0.0;
double second_score = 0.0;
double first_xy[2];
double second_xy[2];
rocksdb::Status s = slot->db()->ZScore(key_, first_pos_, &first_score);
Expand Down Expand Up @@ -206,7 +206,7 @@ void GeoHashCmd::Do(std::shared_ptr<Slot> slot) {
const char* geoalphabet = "0123456789bcdefghjkmnpqrstuvwxyz";
res_.AppendArrayLenUint64(members_.size());
for (const auto& member : members_) {
double score;
double score = 0.0;
rocksdb::Status s = slot->db()->ZScore(key_, member, &score);
if (s.ok()) {
double xy[2];
Expand Down Expand Up @@ -307,7 +307,7 @@ static void GetAllNeighbors(const std::shared_ptr<Slot>& slot, std::string& key,
// Insert into result only if the point is within the search area.
for (auto & score_member : score_members) {
double xy[2];
double real_distance;
double real_distance = 0.0;
GeoHashBits hash = {.bits = static_cast<uint64_t>(score_member.score), .step = GEO_STEP_MAX};
geohashDecodeToLongLatWGS84(hash, xy);
if (geohashGetDistanceIfInRadiusWGS84(longitude, latitude, xy[0], xy[1], distance, &real_distance) != 0) {
Expand Down Expand Up @@ -542,7 +542,7 @@ void GeoRadiusByMemberCmd::DoInitial() {
}

void GeoRadiusByMemberCmd::Do(std::shared_ptr<Slot> slot) {
double score;
double score = 0.0;
rocksdb::Status s = slot->db()->ZScore(key_, range_.member, &score);
if (s.ok()) {
double xy[2];
Expand Down
2 changes: 1 addition & 1 deletion src/pika_hash.cc
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ void HIncrbyCmd::DoInitial() {
}

void HIncrbyCmd::Do(std::shared_ptr<Slot> slot) {
int64_t new_value;
int64_t new_value = 0;
s_ = slot->db()->HIncrby(key_, field_, by_, &new_value);
if (s_.ok() || s_.IsNotFound()) {
res_.AppendContent(":" + std::to_string(new_value));
Expand Down
7 changes: 4 additions & 3 deletions src/pika_kv.cc
Original file line number Diff line number Diff line change
Expand Up @@ -892,6 +892,7 @@ void MsetCmd::Split(std::shared_ptr<Slot> slot, const HintKeys& hint_keys) {
}

void MsetCmd::Merge() {}

void MsetCmd::DoBinlog(const std::shared_ptr<SyncMasterSlot>& slot) {
PikaCmdArgsType set_argv;
set_argv.resize(3);
Expand Down Expand Up @@ -938,7 +939,7 @@ void MsetnxCmd::Do(std::shared_ptr<Slot> slot) {
}

void MsetnxCmd::DoBinlog(const std::shared_ptr<SyncMasterSlot>& slot) {
if(!success_){
if (!success_) {
//some keys already exist, set operations aborted, no need of binlog
return;
}
Expand All @@ -948,7 +949,7 @@ void MsetnxCmd::DoBinlog(const std::shared_ptr<SyncMasterSlot>& slot) {
set_argv[0] = "set";
set_cmd_->SetConn(GetConn());
set_cmd_->SetResp(resp_.lock());
for(auto& kv: kvs_){
for (auto& kv: kvs_) {
set_argv[1] = kv.key;
set_argv[2] = kv.value;
set_cmd_->Initial(set_argv, db_name_);
Expand Down Expand Up @@ -1031,7 +1032,7 @@ void SetrangeCmd::DoInitial() {
}

void SetrangeCmd::Do(std::shared_ptr<Slot> slot) {
int32_t new_len;
int32_t new_len = 0;
s_ = slot->db()->Setrange(key_, offset_, value_, &new_len);
if (s_.ok()) {
res_.AppendInteger(new_len);
Expand Down
5 changes: 3 additions & 2 deletions src/pika_list.cc
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ void LPushCmd::DoInitial() {
values_.push_back(argv_[pos++]);
}
}

void LPushCmd::Do(std::shared_ptr<Slot> slot) {
uint64_t llen = 0;
s_ = slot->db()->LPush(key_, values_, &llen);
Expand Down Expand Up @@ -333,7 +334,7 @@ void BLPopCmd::DoInitial() {
// fetching all keys(*argv_.begin is the command itself and *argv_.end() is the timeout value)
keys_.assign(++argv_.begin(), --argv_.end());
removeDuplicates(keys_);
int64_t timeout;
int64_t timeout = 0;
if (!pstd::string2int(argv_.back().data(), argv_.back().size(), &timeout)) {
res_.SetRes(CmdRes::kInvalidInt);
return;
Expand Down Expand Up @@ -691,7 +692,7 @@ void BRPopCmd::DoInitial() {
// fetching all keys(*argv_.begin is the command itself and *argv_.end() is the timeout value)
keys_.assign(++argv_.begin(), --argv_.end());
removeDuplicates(keys_);
int64_t timeout;
int64_t timeout = 0;
if (!pstd::string2int(argv_.back().data(), argv_.back().size(), &timeout)) {
res_.SetRes(CmdRes::kInvalidInt);
return;
Expand Down
2 changes: 1 addition & 1 deletion src/pika_rm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ bool SyncMasterSlot::BinlogCloudPurge(uint32_t index) {
if (!s.ok()) {
return false;
}
if (index > boffset.filenum - 10) { // remain some more
if (index > (boffset.filenum - 10)) { // remain some more
return false;
} else {
std::unordered_map<std::string, std::shared_ptr<SlaveNode>> slaves = GetAllSlaveNodes();
Expand Down
9 changes: 4 additions & 5 deletions src/pika_set.cc
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ void SetOperationCmd::DoBinlog(const std::shared_ptr<SyncMasterSlot>& slot) {
del_cmd_->SetResp(resp_.lock());
del_cmd_->DoBinlog(slot);

if(value_to_dest_.size() == 0){
if (value_to_dest_.size() == 0) {
//The union/diff/inter operation got an empty set, just exec del to simulate overwrite an empty set to dest_key
return;
}
Expand All @@ -348,8 +348,8 @@ void SetOperationCmd::DoBinlog(const std::shared_ptr<SyncMasterSlot>& slot) {
auto& sadd_argv = sadd_cmd_->argv();
size_t data_size = value_to_dest_[0].size();

for(int i = 1; i < value_to_dest_.size(); i++){
if(data_size >= 131072){
for (size_t i = 1; i < value_to_dest_.size(); i++) {
if (data_size >= 131072) {
// If the binlog has reached the size of 128KB. (131,072 bytes = 128KB)
sadd_cmd_->DoBinlog(slot);
sadd_argv.clear();
Expand Down Expand Up @@ -547,7 +547,7 @@ void SMoveCmd::DoUpdateCache(std::shared_ptr<Slot> slot) {
}

void SMoveCmd::DoBinlog(const std::shared_ptr<SyncMasterSlot>& slot) {
if(!move_success_){
if (!move_success_) {
//the member is not in the source set, nothing changed
return;
}
Expand Down Expand Up @@ -588,7 +588,6 @@ void SRandmemberCmd::DoInitial() {
res_.SetRes(CmdRes::kInvalidInt);
} else {
reply_arr = true;
;
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/pika_slot_command.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1108,7 +1108,7 @@ void SlotsMgrtTagOneCmd::Do(std::shared_ptr<Slot> slot) {
int64_t ret = 0;
int32_t len = 0;
int hastag = 0;
uint32_t crc;
uint32_t crc = 0;
std::string detail;
rocksdb::Status s;
std::map<storage::DataType, rocksdb::Status> type_status;
Expand Down Expand Up @@ -1375,7 +1375,7 @@ void SlotsMgrtAsyncStatusCmd::Do(std::shared_ptr<Slot> slot) {
std::string status;
std::string ip;
int64_t port = -1, slots = -1, moved = -1, remained = -1;
bool migrating;
bool migrating = false;
g_pika_server->GetSlotsMgrtSenderStatus(&ip, &port, &slots, &migrating, &moved, &remained);
std::string mstatus = migrating ? "yes" : "no";
res_.AppendArrayLen(5);
Expand Down Expand Up @@ -1598,7 +1598,7 @@ void SlotsCleanupCmd::DoInitial() {

auto iter = argv_.begin() + 1;
std::string slot;
long slotLong;
long slotLong = 0;
std::vector<int> slots;
for (; iter != argv_.end(); iter++) {
slot = *iter;
Expand Down
7 changes: 3 additions & 4 deletions src/pika_transaction.cc
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ void ExecCmd::Do(std::shared_ptr<Slot> slot) {
auto client_conn = std::dynamic_pointer_cast<PikaClientConn>(conn);
std::vector<CmdRes> res_vec = {};
std::vector<std::shared_ptr<std::string>> resp_strs;
for (int i = 0; i < cmds_.size(); ++i) {
for (size_t i = 0; i < cmds_.size(); ++i) {
resp_strs.emplace_back(std::make_shared<std::string>());
}
auto resp_strs_iter = resp_strs.begin();
Expand Down Expand Up @@ -246,9 +246,8 @@ void WatchCmd::Do(std::shared_ptr<Slot> slot) {
}

void WatchCmd::Execute() {
std::shared_ptr<Slot> slot;
slot = g_pika_server->GetSlotByDBName(db_name_);
Do(slot);
std::shared_ptr<Slot> slot = g_pika_server->GetSlotByDBName(db_name_);
Do(slot);
}

void WatchCmd::DoInitial() {
Expand Down
32 changes: 16 additions & 16 deletions src/pika_zset.cc
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ void ZIncrbyCmd::DoInitial() {
}

void ZIncrbyCmd::Do(std::shared_ptr<Slot> slot) {
double score = 0;
double score = 0.0;
rocksdb::Status s = slot->db()->ZIncrby(key_, member_, by_, &score);
if (s.ok()) {
score_ = score;
Expand Down Expand Up @@ -220,7 +220,7 @@ void ZRangeCmd::Do(std::shared_ptr<Slot> slot) {
if (s_.ok() || s_.IsNotFound()) {
if (is_ws_) {
char buf[32];
int64_t len;
int64_t len = 0;
res_.AppendArrayLenUint64(score_members.size() * 2);
for (const auto& sm : score_members) {
res_.AppendStringLenUint64(sm.member.size());
Expand Down Expand Up @@ -296,7 +296,7 @@ void ZRevrangeCmd::Do(std::shared_ptr<Slot> slot) {
if (s_.ok() || s_.IsNotFound()) {
if (is_ws_) {
char buf[32];
int64_t len;
int64_t len = 0;
res_.AppendArrayLenUint64(score_members.size() * 2);
for (const auto& sm : score_members) {
res_.AppendStringLenUint64(sm.member.size());
Expand Down Expand Up @@ -525,12 +525,12 @@ void ZRevrangebyscoreCmd::DoInitial() {
return;
}
ZsetRangebyscoreParentCmd::DoInitial();
double tmp_score;
double tmp_score = 0.0;
tmp_score = min_score_;
min_score_ = max_score_;
max_score_ = tmp_score;

bool tmp_close;
bool tmp_close = false;
tmp_close = left_close_;
left_close_ = right_close_;
right_close_ = tmp_close;
Expand All @@ -552,7 +552,7 @@ void ZRevrangebyscoreCmd::Do(std::shared_ptr<Slot> slot) {
int64_t end = offset_ + count_;
if (with_scores_) {
char buf[32];
int64_t len;
int64_t len = 0;
res_.AppendArrayLen(count_ * 2);
for (; index < end; index++) {
res_.AppendStringLenUint64(score_members[index].member.size());
Expand Down Expand Up @@ -822,8 +822,8 @@ void ZUnionstoreCmd::DoBinlog(const std::shared_ptr<SyncMasterSlot>& slot) {
auto& zadd_argv = zadd_cmd_->argv();
size_t data_size = d_len + zadd_argv[3].size();
constexpr size_t kDataSize = 131072; //128KB
for(const auto& it : value_to_dest_){
if(data_size >= kDataSize) {
for (const auto& it : value_to_dest_) {
if (data_size >= kDataSize) {
// If the binlog has reached the size of 128KB. (131,072 bytes = 128KB)
zadd_cmd_->DoBinlog(slot);
zadd_argv.clear();
Expand Down Expand Up @@ -878,7 +878,7 @@ void ZInterstoreCmd::DoBinlog(const std::shared_ptr<SyncMasterSlot>& slot) {
del_cmd_->SetResp(resp_.lock());
del_cmd_->DoBinlog(slot);

if(value_to_dest_.size() == 0){
if (value_to_dest_.size() == 0) {
//The inter operation got an empty set, just exec del to simulate overwrite an empty set to dest_key
return;
}
Expand All @@ -897,8 +897,8 @@ void ZInterstoreCmd::DoBinlog(const std::shared_ptr<SyncMasterSlot>& slot) {
auto& zadd_argv = zadd_cmd_->argv();
size_t data_size = d_len + value_to_dest_[0].member.size();
constexpr size_t kDataSize = 131072; //128KB
for(int i = 1; i < value_to_dest_.size(); i++){
if(data_size >= kDataSize){
for (size_t i = 1; i < value_to_dest_.size(); i++) {
if (data_size >= kDataSize) {
// If the binlog has reached the size of 128KB. (131,072 bytes = 128KB)
zadd_cmd_->DoBinlog(slot);
zadd_argv.clear();
Expand Down Expand Up @@ -1015,7 +1015,7 @@ void ZScoreCmd::DoInitial() {
}

void ZScoreCmd::Do(std::shared_ptr<Slot> slot) {
double score = 0;
double score = 0.0;
s_ = slot->db()->ZScore(key_, member_, &score);
if (s_.ok()) {
char buf[32];
Expand All @@ -1030,7 +1030,7 @@ void ZScoreCmd::Do(std::shared_ptr<Slot> slot) {
}

void ZScoreCmd::ReadCache(std::shared_ptr<Slot> slot) {
double score = 0;
double score = 0.0;
std::string CachePrefixKeyZ = PCacheKeyPrefixZ + key_;
auto s = slot->cache()->ZScore(CachePrefixKeyZ, member_, &score, slot);
if (s.ok()) {
Expand Down Expand Up @@ -1189,7 +1189,7 @@ void ZRevrangebylexCmd::DoInitial() {
min_member_ = max_member_;
max_member_ = tmp_s;

bool tmp_b;
bool tmp_b = false;
tmp_b = left_close_;
left_close_ = right_close_;
right_close_ = tmp_b;
Expand Down Expand Up @@ -1440,7 +1440,7 @@ void ZPopmaxCmd::Do(std::shared_ptr<Slot> slot) {
rocksdb::Status s = slot->db()->ZPopMax(key_, count_, &score_members);
if (s.ok() || s.IsNotFound()) {
char buf[32];
int64_t len;
int64_t len = 0;
res_.AppendArrayLenUint64(score_members.size() * 2);
for (const auto& sm : score_members) {
res_.AppendString(sm.member);
Expand Down Expand Up @@ -1474,7 +1474,7 @@ void ZPopminCmd::Do(std::shared_ptr<Slot> slot) {
rocksdb::Status s = slot->db()->ZPopMin(key_, count_, &score_members);
if (s.ok() || s.IsNotFound()) {
char buf[32];
int64_t len;
int64_t len = 0;
res_.AppendArrayLenUint64(score_members.size() * 2);
for (const auto& sm : score_members) {
res_.AppendString(sm.member);
Expand Down
4 changes: 2 additions & 2 deletions src/rsync_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ void* RsyncClient::ThreadMain() {
uint64_t start_time = pstd::NowMicros();

while (state_.load() == RUNNING) {
uint64_t now = pstd::NowMicros();
uint64_t elapse = pstd::NowMicros() - start_time;
if (elapse < kFlushIntervalUs) {
int wait_for_us = kFlushIntervalUs - elapse;
Expand Down Expand Up @@ -386,7 +385,8 @@ Status RsyncClient::LoadLocalMeta(std::string* snapshot_uuid, std::map<std::stri

std::atomic_int8_t retry_times = 5;

while (retry_times-- > 0) {
while (retry_times > 0) {
retry_times--;
fp = fopen(meta_file_path.c_str(), "r");
if (fp == nullptr) {
LOG(WARNING) << "open meta file failed, meta_path: " << dir_;
Expand Down

0 comments on commit 22ea865

Please sign in to comment.