Skip to content

Commit

Permalink
change server.isRunning() checking to FollowerState.
Browse files Browse the repository at this point in the history
  • Loading branch information
133tosakarin committed Oct 10, 2024
1 parent 09f6b39 commit 2fc4b9a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,14 @@ public void run() {
}
}

private boolean roleChangeChecking(TimeDuration electionTimeout) {
return outstandingOp.get() == 0
&& isRunning && server.getInfo().isFollower()
&& lastRpcTime.elapsedTime().compareTo(electionTimeout) >= 0
&& !lostMajorityHeartbeatsRecently()
&& server.isRunning();
}

private void runImpl() {
final TimeDuration sleepDeviationThreshold = server.getSleepDeviationThreshold();
while (shouldRun()) {
Expand All @@ -149,10 +157,7 @@ private void runImpl() {
break;
}
synchronized (server) {
if (outstandingOp.get() == 0
&& isRunning && server.getInfo().isFollower()
&& lastRpcTime.elapsedTime().compareTo(electionTimeout) >= 0
&& !lostMajorityHeartbeatsRecently()) {
if (roleChangeChecking(electionTimeout)) {
LOG.info("{}: change to CANDIDATE, lastRpcElapsedTime:{}, electionTimeout:{}",
this, lastRpcTime.elapsedTime(), electionTimeout);
server.getLeaderElectionMetrics().onLeaderElectionTimeout(); // Update timeout metric counters.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,10 +253,6 @@ private void runImpl() {
}

try (AutoCloseable ignored = Timekeeper.start(server.getLeaderElectionMetrics().getLeaderElectionTimer())) {
if (!server.isRunning()) {
LOG.info("{}: skip since the server is not running", this);
return;
}
for (int round = 0; shouldRun(); round++) {
if (skipPreVote || askForVotes(Phase.PRE_VOTE, round)) {
if (askForVotes(Phase.ELECTION, round)) {
Expand Down

0 comments on commit 2fc4b9a

Please sign in to comment.