From c89fdd938edc7a6d9fb2423ba0a4b93aeeef2049 Mon Sep 17 00:00:00 2001 From: Boaz Leskes Date: Wed, 5 Apr 2017 14:31:32 +0200 Subject: [PATCH] ZenDiscovery - only validate min_master_nodes values if local node is master (#23915) The purpose of this validation is to make sure that the master doesn't step down due to a change in master nodes, which also means that there is no way to revert an accidental change. Since we validate using the current cluster state (and not the one from which the settings come from) we have to be careful and only validate if the local node is already a master. Doing so all the time causes subtle issues. For example, a node that joins a cluster has no nodes in its current cluster state. When it receives a cluster state from the master with a dynamic minimum master nodes setting int it, we must make sure we don't reject it. Closes #23695 --- .../elasticsearch/discovery/zen/ZenDiscovery.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/org/elasticsearch/discovery/zen/ZenDiscovery.java b/core/src/main/java/org/elasticsearch/discovery/zen/ZenDiscovery.java index 7b24536346c..72c33c873d4 100644 --- a/core/src/main/java/org/elasticsearch/discovery/zen/ZenDiscovery.java +++ b/core/src/main/java/org/elasticsearch/discovery/zen/ZenDiscovery.java @@ -170,7 +170,17 @@ public class ZenDiscovery extends AbstractLifecycleComponent implements Discover this::handleMinimumMasterNodesChanged, (value) -> { final ClusterState clusterState = clusterService.state(); int masterNodes = clusterState.nodes().getMasterNodes().size(); - if (value > masterNodes) { + // the purpose of this validation is to make sure that the master doesn't step down + // due to a change in master nodes, which also means that there is no way to revert + // an accidental change. Since we validate using the current cluster state (and + // not the one from which the settings come from) we have to be careful and only + // validate if the local node is already a master. Doing so all the time causes + // subtle issues. For example, a node that joins a cluster has no nodes in its + // current cluster state. When it receives a cluster state from the master with + // a dynamic minimum master nodes setting int it, we must make sure we don't reject + // it. + + if (clusterState.nodes().isLocalNodeElectedMaster() && value > masterNodes) { throw new IllegalArgumentException("cannot set " + ElectMasterService.DISCOVERY_ZEN_MINIMUM_MASTER_NODES_SETTING.getKey() + " to more than the current" + " master nodes count [" + masterNodes + "]");