Skip to content

Commit

Permalink
skip prevoting for decommissioned nodes irrespective of cluster state
Browse files Browse the repository at this point in the history
  • Loading branch information
imRishN committed Sep 1, 2022
1 parent 8eb27f0 commit 5602013
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -1439,6 +1439,11 @@ private void startElectionScheduler() {
public void run() {
synchronized (mutex) {
if (mode == Mode.CANDIDATE) {
if(peerFinder.localNodeDecommissioned()) {
logger.debug("skip prevoting as local node is decommissioned");
return;
}

final ClusterState lastAcceptedState = coordinationState.get().getLastAcceptedState();

if (localNodeMayWinElection(lastAcceptedState) == false) {
Expand Down
13 changes: 12 additions & 1 deletion server/src/main/java/org/opensearch/discovery/PeerFinder.java
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ public abstract class PeerFinder {

private volatile long currentTerm;
private boolean active;
private boolean localNodeDecommissioned = false;
private DiscoveryNodes lastAcceptedNodes;
private final Map<TransportAddress, Peer> peersByAddress = new LinkedHashMap<>();
private Optional<DiscoveryNode> leader = Optional.empty();
Expand Down Expand Up @@ -143,17 +144,27 @@ public ActionListener<Void> nodeCommissionedListener() {
@Override
public void onResponse(Void unused) {
logger.info("setting findPeersInterval to [{}], due to recommissioning", findPeersInterval);
assert localNodeDecommissioned; // TODO: Do we need this?
localNodeDecommissioned = false;
findPeersInterval = DISCOVERY_FIND_PEERS_INTERVAL_SETTING.get(settings);

}

@Override
public void onFailure(Exception e) {
logger.info("setting findPeersInterval to [{}], due to decommissioning", findPeersInterval);
logger.info("setting findPeersInterval to [{}], due to decommissioning",
DISCOVERY_FIND_PEERS_INTERVAL_DURING_DECOMMISSION_SETTING.get(settings));
assert !localNodeDecommissioned;
localNodeDecommissioned = true;
findPeersInterval = DISCOVERY_FIND_PEERS_INTERVAL_DURING_DECOMMISSION_SETTING.get(settings);
}
};
}

public boolean localNodeDecommissioned() {
return localNodeDecommissioned;
}

public void activate(final DiscoveryNodes lastAcceptedNodes) {
logger.trace("activating with {}", lastAcceptedNodes);

Expand Down

0 comments on commit 5602013

Please sign in to comment.