diff --git a/server/src/main/java/org/opensearch/cluster/coordination/Coordinator.java b/server/src/main/java/org/opensearch/cluster/coordination/Coordinator.java index 5a07f964f94a4..07ad16cab4a8b 100644 --- a/server/src/main/java/org/opensearch/cluster/coordination/Coordinator.java +++ b/server/src/main/java/org/opensearch/cluster/coordination/Coordinator.java @@ -472,11 +472,18 @@ private static Optional joinWithDestination(Optional lastJoin, Disco } private void closePrevotingAndElectionScheduler() { + closePrevoting(); + closeElectionScheduler(); + } + + private void closePrevoting() { if (prevotingRound != null) { prevotingRound.close(); prevotingRound = null; } + } + private void closeElectionScheduler() { if (electionScheduler != null) { electionScheduler.close(); electionScheduler = null; @@ -724,7 +731,7 @@ void becomeLeader(String method) { lastKnownLeader = Optional.of(getLocalNode()); peerFinder.deactivate(getLocalNode()); clusterFormationFailureHelper.stop(); - closePrevotingAndElectionScheduler(); + closePrevoting(); preVoteCollector.update(getPreVoteResponse(), getLocalNode()); assert leaderChecker.leader() == null : leaderChecker.leader(); @@ -1447,13 +1454,12 @@ protected void onFoundPeersUpdated() { foundPeers.forEach(expectedVotes::addVote); expectedVotes.addVote(Coordinator.this.getLocalNode()); final boolean foundQuorum = coordinationState.get().isElectionQuorum(expectedVotes); - if (foundQuorum) { if (electionScheduler == null) { startElectionScheduler(); } } else { - closePrevotingAndElectionScheduler(); + closePrevoting(); } } } @@ -1735,6 +1741,7 @@ public void onSuccess(String source) { logIncompleteNodes(Level.WARN); } cancelTimeoutHandlers(); + closeElectionScheduler(); ackListener.onNodeAck(getLocalNode(), null); publishListener.onResponse(null); }