Skip to content

Commit

Permalink
RATIS-2149.Do not perform leader election if the current RaftServer h…
Browse files Browse the repository at this point in the history
…as not started yet (apache#1143)
  • Loading branch information
133tosakarin authored Sep 7, 2024
1 parent d1e76cf commit 3e38e6d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,10 @@ public void run() {
}

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
Original file line number Diff line number Diff line change
Expand Up @@ -1911,4 +1911,8 @@ public RaftServerMetricsImpl getRaftServerMetrics() {
void onGroupLeaderElected() {
transferLeadership.complete(TransferLeadership.Result.SUCCESS);
}

boolean isRunning() {
return startComplete.get() && lifeCycle.getCurrentState() == State.RUNNING;
}
}

0 comments on commit 3e38e6d

Please sign in to comment.