Skip to content

Commit

Permalink
Handle master failure in NodeSeenService (elastic#77220)
Browse files Browse the repository at this point in the history
* Handle master failure in NodeSeenService

NodeSeenService can miss seeing nodes if the master changes while it's
processing the cluster state update which adds the nodes to the cluster.
This caused occasional test failures in the test intended to check that
NodeSeenService is working as intended.

This commit adjusts NodeSeenService's early returns to ensure that, if
the master changed, the new master checks for seen nodes even if nodes
were not added in that particular cluster state update.

* Clarify & correct "just-became-master" check

* Remove leftover debug logging (d'oh!)

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
  • Loading branch information
2 people authored and Gordon Brown committed Sep 9, 2021
1 parent c6180cf commit 213a38c
Showing 1 changed file with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

package org.elasticsearch.xpack.shutdown;

import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.message.ParameterizedMessage;
import org.elasticsearch.cluster.ClusterChangedEvent;
import org.elasticsearch.cluster.ClusterState;
Expand Down Expand Up @@ -46,8 +46,10 @@ public void clusterChanged(ClusterChangedEvent event) {
return;
}

if (event.nodesAdded() == false) {
// If there's no new nodes this cluster state update, nothing to do.
final boolean thisNodeJustBecameMaster = event.previousState().nodes().isLocalNodeElectedMaster() == false
&& event.state().nodes().isLocalNodeElectedMaster();
if ((event.nodesAdded() || thisNodeJustBecameMaster) == false) {
// If there's both 1) no new nodes this cluster state update and 2) this node has not just become the master node, nothing to do
return;
}

Expand Down

0 comments on commit 213a38c

Please sign in to comment.