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: Fix the problem of possible slave_key conflict #2431

Merged
merged 1 commit into from
Feb 29, 2024
Merged
Changes from all commits
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
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
Loading