Skip to content

Commit

Permalink
fix lastMsgAcceptedCostMs_ is not zero , new leader always invalid
Browse files Browse the repository at this point in the history
  • Loading branch information
tangyuanzhang committed May 4, 2023
1 parent 6e81584 commit 1f71ea3
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/kvstore/raftex/RaftPart.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1383,6 +1383,7 @@ bool RaftPart::handleElectionResponses(const ElectionResponses& resps,
bgWorkers_->addTask(
[self = shared_from_this(), proposedTerm] { self->onElected(proposedTerm); });
lastMsgAcceptedTime_ = 0;
lastMsgAcceptedCostMs_ = 0;
}
commitInThisTerm_ = false;
}
Expand Down Expand Up @@ -2115,9 +2116,12 @@ void RaftPart::sendHeartbeat() {
if (numSucceeded >= replica) {
VLOG(4) << idStr_ << "Heartbeat is accepted by quorum";
std::lock_guard<std::mutex> g(raftLock_);
auto now = time::WallClock::fastNowInMilliSec();
lastMsgAcceptedCostMs_ = now - startMs;
lastMsgAcceptedTime_ = now;
auto nowTime = static_cast<uint64_t>(time::WallClock::fastNowInMilliSec());
auto nowCostMs = nowTime - startMs;
if (nowTime - nowCostMs >= lastMsgAcceptedTime_ - lastMsgAcceptedCostMs_) {
lastMsgAcceptedCostMs_ = nowCostMs;
lastMsgAcceptedTime_ = nowTime;
}
}
});
}
Expand Down

0 comments on commit 1f71ea3

Please sign in to comment.