Skip to content

Commit

Permalink
fix: Fix the problem of possible slave_key conflict (OpenAtomFoundati…
Browse files Browse the repository at this point in the history
  • Loading branch information
happy-v587 authored and luky116 committed Mar 18, 2024
1 parent ad008d9 commit 4c7661f
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/pika_consensus.cc
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,12 @@ void Context::Reset(const LogOffset& offset) {

/* SyncProgress */

std::string MakeSlaveKey(const std::string& ip, int port) {
return ip + ":" + std::to_string(port);
}

std::shared_ptr<SlaveNode> SyncProgress::GetSlaveNode(const std::string& ip, int port) {
std::string slave_key = ip + std::to_string(port);
std::string slave_key = MakeSlaveKey(ip, port);
std::shared_lock l(rwlock_);
if (slaves_.find(slave_key) == slaves_.end()) {
return nullptr;
Expand All @@ -96,7 +100,7 @@ std::unordered_map<std::string, std::shared_ptr<SlaveNode>> SyncProgress::GetAll
}

Status SyncProgress::AddSlaveNode(const std::string& ip, int port, const std::string& db_name, int session_id) {
std::string slave_key = ip + std::to_string(port);
std::string slave_key = MakeSlaveKey(ip, port);
std::shared_ptr<SlaveNode> exist_ptr = GetSlaveNode(ip, port);
if (exist_ptr) {
LOG(WARNING) << "SlaveNode " << exist_ptr->ToString() << " already exist, set new session " << session_id;
Expand All @@ -117,7 +121,7 @@ Status SyncProgress::AddSlaveNode(const std::string& ip, int port, const std::st
}

Status SyncProgress::RemoveSlaveNode(const std::string& ip, int port) {
std::string slave_key = ip + std::to_string(port);
std::string slave_key = MakeSlaveKey(ip, port);
{
std::lock_guard l(rwlock_);
slaves_.erase(slave_key);
Expand Down

0 comments on commit 4c7661f

Please sign in to comment.