[Discovery] when master is gone, flush all pending cluster states

If the master FD flags master as gone while there are still pending cluster states, the processing of those cluster states we re-instate that node a master again.

Closes #6526
This commit is contained in:
Boaz Leskes 2014-06-17 10:05:36 +02:00
parent 8b85d97ea6
commit 5d13571dbe
1 changed files with 11 additions and 0 deletions

View File

@ -61,6 +61,7 @@ import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.transport.*; import org.elasticsearch.transport.*;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
@ -524,6 +525,11 @@ public class ZenDiscovery extends AbstractLifecycleComponent<Discovery> implemen
.masterNodeId(null).build(); .masterNodeId(null).build();
latestDiscoNodes = discoveryNodes; latestDiscoNodes = discoveryNodes;
// flush any pending cluster states from old master, so it will not be set as master again
ArrayList<ProcessClusterState> pendingNewClusterStates = new ArrayList<>();
processNewClusterStates.drainTo(pendingNewClusterStates);
logger.trace("removed [{}] pending cluster states", pendingNewClusterStates.size());
if (rejoinOnMasterGone) { if (rejoinOnMasterGone) {
return rejoin(ClusterState.builder(currentState).nodes(discoveryNodes).build(), "master left (reason = " + reason + ")"); return rejoin(ClusterState.builder(currentState).nodes(discoveryNodes).build(), "master left (reason = " + reason + ")");
} }
@ -680,6 +686,11 @@ public class ZenDiscovery extends AbstractLifecycleComponent<Discovery> implemen
// we are going to use it for sure, poll (remove) it // we are going to use it for sure, poll (remove) it
potentialState = processNewClusterStates.poll(); potentialState = processNewClusterStates.poll();
if (potentialState == null) {
// might happen if the queue is drained
break;
}
potentialState.processed = true; potentialState.processed = true;
if (potentialState.clusterState.version() > stateToProcess.clusterState.version()) { if (potentialState.clusterState.version() > stateToProcess.clusterState.version()) {