Skip to content

Commit

Permalink
Merge pull request #52832 from ClickHouse/backport/23.7/52804
Browse files Browse the repository at this point in the history
Backport #52804 to 23.7: Fix data race in Keeper reconfiguration
  • Loading branch information
antonio2368 committed Aug 1, 2023
2 parents d07a28d + 6aba6b7 commit 07f60d6
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/Coordination/KeeperServer.cpp
Expand Up @@ -794,8 +794,14 @@ bool KeeperServer::applyConfigUpdate(const ClusterUpdateAction & action)
std::lock_guard _{server_write_mutex};

if (const auto * add = std::get_if<AddRaftServer>(&action))
return raft_instance->get_srv_config(add->id) != nullptr
|| raft_instance->add_srv(static_cast<nuraft::srv_config>(*add))->get_accepted();
{
if (raft_instance->get_srv_config(add->id) != nullptr)
return true;

auto resp = raft_instance->add_srv(static_cast<nuraft::srv_config>(*add));
resp->get();
return resp->get_accepted();
}
else if (const auto * remove = std::get_if<RemoveRaftServer>(&action))
{
if (remove->id == raft_instance->get_leader())
Expand All @@ -807,8 +813,12 @@ bool KeeperServer::applyConfigUpdate(const ClusterUpdateAction & action)
return false;
}

return raft_instance->get_srv_config(remove->id) == nullptr
|| raft_instance->remove_srv(remove->id)->get_accepted();
if (raft_instance->get_srv_config(remove->id) == nullptr)
return true;

auto resp = raft_instance->remove_srv(remove->id);
resp->get();
return resp->get_accepted();
}
else if (const auto * update = std::get_if<UpdateRaftServerPriority>(&action))
{
Expand Down

0 comments on commit 07f60d6

Please sign in to comment.