Skip to content

Commit

Permalink
fix deadlock
Browse files Browse the repository at this point in the history
  • Loading branch information
critical27 committed Nov 9, 2021
1 parent 272940e commit 74ceaea
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/kvstore/raftex/RaftPart.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1129,27 +1129,29 @@ folly::Future<bool> RaftPart::leaderElection() {

bool RaftPart::handleElectionResponses(const cpp2::AskForVoteRequest& voteReq,
const ElectionResponses& resps,
const std::vector<std::shared_ptr<Host>>& hosts,
const std::vector<std::shared_ptr<Host>>& peers,
TermID proposedTerm) {
// Process the responses
switch (processElectionResponses(resps, std::move(hosts), proposedTerm)) {
switch (processElectionResponses(resps, std::move(peers), proposedTerm)) {
case Role::LEADER: {
// Elected
LOG(INFO) << idStr_ << "The partition is elected as the leader";
std::vector<std::shared_ptr<Host>> hosts;
{
std::lock_guard<std::mutex> g(raftLock_);
if (status_ == Status::RUNNING) {
leader_ = addr_;
for (auto& host : hosts_) {
host->reset();
}
hosts = hosts_;
bgWorkers_->addTask(
[self = shared_from_this(), term = voteReq.get_term()] { self->onElected(term); });
lastMsgAcceptedTime_ = 0;
}
weight_ = 1;
commitInThisTerm_ = false;
}
for (auto& host : hosts) {
host->reset();
}
sendHeartbeat();
return true;
}
Expand Down

0 comments on commit 74ceaea

Please sign in to comment.