From fe1674174f612384a60a0e63a1f6bc13c994a4ff Mon Sep 17 00:00:00 2001 From: David Turner Date: Mon, 3 Jun 2019 09:01:13 +0100 Subject: [PATCH] Remove some leftover refs to minimum_master_nodes (#42700) Today `InternalTestCluster` has a few vestigial mentions of the `minimum_master_nodes` setting. This commit removes them and simplifies some of the surrounding logic. --- .../rest/discovery/Zen2RestApiIT.java | 2 +- .../admin/indices/exists/IndicesExistsIT.java | 2 +- .../master/IndexingMasterFailoverIT.java | 2 +- .../cluster/MinimumMasterNodesIT.java | 2 +- .../cluster/SpecificMasterNodesIT.java | 2 +- .../UnsafeBootstrapAndDetachCommandIT.java | 2 +- .../single/SingleNodeDiscoveryIT.java | 2 +- .../gateway/RecoverAfterNodesIT.java | 2 +- .../elasticsearch/test/ESIntegTestCase.java | 11 +- .../test/InternalTestCluster.java | 104 +++++++----------- .../test/disruption/NetworkDisruptionIT.java | 2 +- 11 files changed, 54 insertions(+), 79 deletions(-) diff --git a/modules/transport-netty4/src/test/java/org/elasticsearch/rest/discovery/Zen2RestApiIT.java b/modules/transport-netty4/src/test/java/org/elasticsearch/rest/discovery/Zen2RestApiIT.java index fcb8e75700d0c..664632cb527f8 100644 --- a/modules/transport-netty4/src/test/java/org/elasticsearch/rest/discovery/Zen2RestApiIT.java +++ b/modules/transport-netty4/src/test/java/org/elasticsearch/rest/discovery/Zen2RestApiIT.java @@ -47,7 +47,7 @@ // These tests are here today so they have access to a proper REST client. They cannot be in :server:integTest since the REST client needs a // proper transport implementation, and they cannot be REST tests today since they need to restart nodes. When #35599 and friends land we // should be able to move these tests to run against a proper cluster instead. TODO do this. -@ESIntegTestCase.ClusterScope(scope = ESIntegTestCase.Scope.TEST, numDataNodes = 0, autoMinMasterNodes = false) +@ESIntegTestCase.ClusterScope(scope = ESIntegTestCase.Scope.TEST, numDataNodes = 0, autoManageMasterNodes = false) public class Zen2RestApiIT extends ESNetty4IntegTestCase { @Override diff --git a/server/src/test/java/org/elasticsearch/action/admin/indices/exists/IndicesExistsIT.java b/server/src/test/java/org/elasticsearch/action/admin/indices/exists/IndicesExistsIT.java index 51d3ecc89afc7..9cb435762aa19 100644 --- a/server/src/test/java/org/elasticsearch/action/admin/indices/exists/IndicesExistsIT.java +++ b/server/src/test/java/org/elasticsearch/action/admin/indices/exists/IndicesExistsIT.java @@ -30,7 +30,7 @@ import java.io.IOException; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertThrows; -@ClusterScope(scope = ESIntegTestCase.Scope.TEST, numDataNodes = 0, numClientNodes = 0, autoMinMasterNodes = false) +@ClusterScope(scope = ESIntegTestCase.Scope.TEST, numDataNodes = 0, numClientNodes = 0, autoManageMasterNodes = false) public class IndicesExistsIT extends ESIntegTestCase { public void testIndexExistsWithBlocksInPlace() throws IOException { diff --git a/server/src/test/java/org/elasticsearch/action/support/master/IndexingMasterFailoverIT.java b/server/src/test/java/org/elasticsearch/action/support/master/IndexingMasterFailoverIT.java index 1317183f286b3..45d8f4c8c0bf0 100644 --- a/server/src/test/java/org/elasticsearch/action/support/master/IndexingMasterFailoverIT.java +++ b/server/src/test/java/org/elasticsearch/action/support/master/IndexingMasterFailoverIT.java @@ -39,7 +39,7 @@ import static org.hamcrest.Matchers.equalTo; -@ESIntegTestCase.ClusterScope(scope = ESIntegTestCase.Scope.TEST, numDataNodes = 0, autoMinMasterNodes = false) +@ESIntegTestCase.ClusterScope(scope = ESIntegTestCase.Scope.TEST, numDataNodes = 0, autoManageMasterNodes = false) public class IndexingMasterFailoverIT extends ESIntegTestCase { @Override diff --git a/server/src/test/java/org/elasticsearch/cluster/MinimumMasterNodesIT.java b/server/src/test/java/org/elasticsearch/cluster/MinimumMasterNodesIT.java index cb1443bdf3765..164c74423aa7f 100644 --- a/server/src/test/java/org/elasticsearch/cluster/MinimumMasterNodesIT.java +++ b/server/src/test/java/org/elasticsearch/cluster/MinimumMasterNodesIT.java @@ -62,7 +62,7 @@ import static org.hamcrest.Matchers.notNullValue; import static org.hamcrest.Matchers.nullValue; -@ClusterScope(scope = Scope.TEST, numDataNodes = 0, autoMinMasterNodes = false) +@ClusterScope(scope = Scope.TEST, numDataNodes = 0, autoManageMasterNodes = false) @TestLogging("_root:DEBUG,org.elasticsearch.cluster.service:TRACE,org.elasticsearch.cluster.coordination:TRACE") public class MinimumMasterNodesIT extends ESIntegTestCase { diff --git a/server/src/test/java/org/elasticsearch/cluster/SpecificMasterNodesIT.java b/server/src/test/java/org/elasticsearch/cluster/SpecificMasterNodesIT.java index 38b9579eff046..7e4c1c5c3435e 100644 --- a/server/src/test/java/org/elasticsearch/cluster/SpecificMasterNodesIT.java +++ b/server/src/test/java/org/elasticsearch/cluster/SpecificMasterNodesIT.java @@ -39,7 +39,7 @@ import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.nullValue; -@ClusterScope(scope = Scope.TEST, numDataNodes = 0, autoMinMasterNodes = false) +@ClusterScope(scope = Scope.TEST, numDataNodes = 0, autoManageMasterNodes = false) @TestLogging("_root:DEBUG,org.elasticsearch.action.admin.cluster.state:TRACE") public class SpecificMasterNodesIT extends ESIntegTestCase { diff --git a/server/src/test/java/org/elasticsearch/cluster/coordination/UnsafeBootstrapAndDetachCommandIT.java b/server/src/test/java/org/elasticsearch/cluster/coordination/UnsafeBootstrapAndDetachCommandIT.java index 44f4d7bf4aa53..cb7a6916bb68d 100644 --- a/server/src/test/java/org/elasticsearch/cluster/coordination/UnsafeBootstrapAndDetachCommandIT.java +++ b/server/src/test/java/org/elasticsearch/cluster/coordination/UnsafeBootstrapAndDetachCommandIT.java @@ -52,7 +52,7 @@ import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.greaterThan; -@ESIntegTestCase.ClusterScope(scope = ESIntegTestCase.Scope.TEST, numDataNodes = 0, autoMinMasterNodes = false) +@ESIntegTestCase.ClusterScope(scope = ESIntegTestCase.Scope.TEST, numDataNodes = 0, autoManageMasterNodes = false) @TestLogging("_root:DEBUG,org.elasticsearch.cluster.service:TRACE,org.elasticsearch.cluster.coordination:TRACE") public class UnsafeBootstrapAndDetachCommandIT extends ESIntegTestCase { diff --git a/server/src/test/java/org/elasticsearch/discovery/single/SingleNodeDiscoveryIT.java b/server/src/test/java/org/elasticsearch/discovery/single/SingleNodeDiscoveryIT.java index 1b90ea691c1cd..ead77e71bf816 100644 --- a/server/src/test/java/org/elasticsearch/discovery/single/SingleNodeDiscoveryIT.java +++ b/server/src/test/java/org/elasticsearch/discovery/single/SingleNodeDiscoveryIT.java @@ -50,7 +50,7 @@ numDataNodes = 1, numClientNodes = 0, supportsDedicatedMasters = false, - autoMinMasterNodes = false) + autoManageMasterNodes = false) public class SingleNodeDiscoveryIT extends ESIntegTestCase { @Override diff --git a/server/src/test/java/org/elasticsearch/gateway/RecoverAfterNodesIT.java b/server/src/test/java/org/elasticsearch/gateway/RecoverAfterNodesIT.java index 86976d553fa2a..84188f80aaed3 100644 --- a/server/src/test/java/org/elasticsearch/gateway/RecoverAfterNodesIT.java +++ b/server/src/test/java/org/elasticsearch/gateway/RecoverAfterNodesIT.java @@ -34,7 +34,7 @@ import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.hasItem; -@ClusterScope(scope = Scope.TEST, numDataNodes = 0, autoMinMasterNodes = false) +@ClusterScope(scope = Scope.TEST, numDataNodes = 0, autoManageMasterNodes = false) public class RecoverAfterNodesIT extends ESIntegTestCase { private static final TimeValue BLOCK_WAIT_TIMEOUT = TimeValue.timeValueSeconds(10); diff --git a/test/framework/src/main/java/org/elasticsearch/test/ESIntegTestCase.java b/test/framework/src/main/java/org/elasticsearch/test/ESIntegTestCase.java index 0ab0afb6b0e7a..cff0c6b4cf2d7 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/ESIntegTestCase.java +++ b/test/framework/src/main/java/org/elasticsearch/test/ESIntegTestCase.java @@ -1608,9 +1608,10 @@ public enum Scope { boolean supportsDedicatedMasters() default true; /** - * The cluster automatically manages the bootstrap voting configuration. Set this to false to manage the setting manually. + * Indicates whether the cluster automatically manages cluster bootstrapping and the removal of any master-eligible nodes. If + * set to {@code false} then the tests must manage these processes explicitly. */ - boolean autoMinMasterNodes() default true; + boolean autoManageMasterNodes() default true; /** * Returns the number of client nodes in the cluster. Default is {@link InternalTestCluster#DEFAULT_NUM_CLIENT_NODES}, a @@ -1698,9 +1699,9 @@ private boolean getSupportsDedicatedMasters() { return annotation == null ? true : annotation.supportsDedicatedMasters(); } - private boolean getAutoMinMasterNodes() { + private boolean getAutoManageMasterNodes() { ClusterScope annotation = getAnnotation(this.getClass(), ClusterScope.class); - return annotation == null ? true : annotation.autoMinMasterNodes(); + return annotation == null ? true : annotation.autoManageMasterNodes(); } private int getNumDataNodes() { @@ -1838,7 +1839,7 @@ protected TestCluster buildTestCluster(Scope scope, long seed) throws IOExceptio } mockPlugins = mocks; } - return new InternalTestCluster(seed, createTempDir(), supportsDedicatedMasters, getAutoMinMasterNodes(), + return new InternalTestCluster(seed, createTempDir(), supportsDedicatedMasters, getAutoManageMasterNodes(), minNumDataNodes, maxNumDataNodes, InternalTestCluster.clusterName(scope.name(), seed) + "-cluster", nodeConfigurationSource, getNumClientNodes(), nodePrefix, mockPlugins, getClientWrapper(), forbidPrivateIndexSettings()); diff --git a/test/framework/src/main/java/org/elasticsearch/test/InternalTestCluster.java b/test/framework/src/main/java/org/elasticsearch/test/InternalTestCluster.java index 695564690c4b1..4780bc4fba8bd 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/InternalTestCluster.java +++ b/test/framework/src/main/java/org/elasticsearch/test/InternalTestCluster.java @@ -227,7 +227,7 @@ public final class InternalTestCluster extends TestCluster { private final ExecutorService executor; - private final boolean autoManageMinMasterNodes; + private final boolean autoManageMasterNodes; private final Collection> mockPlugins; @@ -250,7 +250,7 @@ public InternalTestCluster( final long clusterSeed, final Path baseDir, final boolean randomlyAddDedicatedMasters, - final boolean autoManageMinMasterNodes, + final boolean autoManageMasterNodes, final int minNumDataNodes, final int maxNumDataNodes, final String clusterName, @@ -263,7 +263,7 @@ public InternalTestCluster( clusterSeed, baseDir, randomlyAddDedicatedMasters, - autoManageMinMasterNodes, + autoManageMasterNodes, minNumDataNodes, maxNumDataNodes, clusterName, @@ -279,7 +279,7 @@ public InternalTestCluster( final long clusterSeed, final Path baseDir, final boolean randomlyAddDedicatedMasters, - final boolean autoManageMinMasterNodes, + final boolean autoManageMasterNodes, final int minNumDataNodes, final int maxNumDataNodes, final String clusterName, @@ -290,7 +290,7 @@ public InternalTestCluster( final Function clientWrapper, final boolean forbidPrivateIndexSettings) { super(clusterSeed); - this.autoManageMinMasterNodes = autoManageMinMasterNodes; + this.autoManageMasterNodes = autoManageMasterNodes; this.clientWrapper = clientWrapper; this.forbidPrivateIndexSettings = forbidPrivateIndexSettings; this.baseDir = baseDir; @@ -305,7 +305,7 @@ public InternalTestCluster( Random random = new Random(clusterSeed); - boolean useDedicatedMasterNodes = randomlyAddDedicatedMasters ? random.nextBoolean() : false; + boolean useDedicatedMasterNodes = randomlyAddDedicatedMasters && random.nextBoolean(); this.numSharedDataNodes = RandomNumbers.randomIntBetween(random, minNumDataNodes, maxNumDataNodes); assert this.numSharedDataNodes >= 0; @@ -345,10 +345,10 @@ public InternalTestCluster( } logger.info("Setup InternalTestCluster [{}] with seed [{}] using [{}] dedicated masters, " + - "[{}] (data) nodes and [{}] coord only nodes (min_master_nodes are [{}])", + "[{}] (data) nodes and [{}] coord only nodes (master nodes are [{}])", clusterName, SeedUtils.formatSeed(clusterSeed), numSharedDedicatedMasterNodes, numSharedDataNodes, numSharedCoordOnlyNodes, - autoManageMinMasterNodes ? "auto-managed" : "manual"); + autoManageMasterNodes ? "auto-managed" : "manual"); this.nodeConfigurationSource = nodeConfigurationSource; numDataPaths = random.nextInt(5) == 0 ? 2 + random.nextInt(3) : 1; Builder builder = Settings.builder(); @@ -394,12 +394,11 @@ public InternalTestCluster( /** * Sets {@link #bootstrapMasterNodeIndex} to the given value, see {@link #bootstrapMasterNodeWithSpecifiedIndex(List)} * for the description of how this field is used. - * It's only possible to change {@link #bootstrapMasterNodeIndex} value if autoManageMinMasterNodes is false. + * It's only possible to change {@link #bootstrapMasterNodeIndex} value if autoManageMasterNodes is false. */ public void setBootstrapMasterNodeIndex(int bootstrapMasterNodeIndex) { - if (autoManageMinMasterNodes && bootstrapMasterNodeIndex != -1) { - throw new AssertionError("bootstrapMasterNodeIndex should be -1 if autoManageMinMasterNodes is true"); - } + assert autoManageMasterNodes == false || bootstrapMasterNodeIndex == -1 + : "bootstrapMasterNodeIndex should be -1 if autoManageMasterNodes is true, but was " + bootstrapMasterNodeIndex; this.bootstrapMasterNodeIndex = bootstrapMasterNodeIndex; } @@ -531,7 +530,7 @@ private NodeAndClient getOrBuildRandomNode() { final Runnable onTransportServiceStarted = () -> {}; // do not create unicast host file for this one node. final int nodeId = nextNodeId.getAndIncrement(); - final Settings settings = getNodeSettings(nodeId, random.nextLong(), Settings.EMPTY, 1); + final Settings settings = getNodeSettings(nodeId, random.nextLong(), Settings.EMPTY); final Settings nodeSettings = Settings.builder() .putList(INITIAL_MASTER_NODES_SETTING.getKey(), Node.NODE_NAME_SETTING.get(settings)) .put(settings) @@ -605,7 +604,7 @@ public synchronized void ensureAtMostNumDataNodes(int n) throws IOException { } } - private Settings getNodeSettings(final int nodeId, final long seed, final Settings extraSettings, final int defaultMinMasterNodes) { + private Settings getNodeSettings(final int nodeId, final long seed, final Settings extraSettings) { final Settings settings = getSettings(nodeId, seed, extraSettings); final String name = buildNodeName(nodeId, settings); @@ -629,8 +628,8 @@ private Settings getNodeSettings(final int nodeId, final long seed, final Settin updatedSettings.put("node.name", name); updatedSettings.put(NodeEnvironment.NODE_ID_SEED_SETTING.getKey(), seed); - if (autoManageMinMasterNodes) { - assertThat("automatically managing min master nodes require nodes to complete a join cycle when starting", + if (autoManageMasterNodes) { + assertThat("if master nodes are automatically managed then nodes must complete a join cycle when starting", updatedSettings.get(INITIAL_STATE_TIMEOUT_SETTING.getKey()), nullValue()); } @@ -810,8 +809,6 @@ public synchronized void close() throws IOException { } } - private static final int REMOVED_MINIMUM_MASTER_NODES = Integer.MAX_VALUE; - private final class NodeAndClient implements Closeable { private MockNode node; private final Settings originalNodeSettings; @@ -889,18 +886,16 @@ void startNode() { /** * closes the node and prepares it to be restarted */ - Settings closeForRestart(RestartCallback callback, int minMasterNodes) throws Exception { + Settings closeForRestart(RestartCallback callback) throws Exception { assert callback != null; close(); Settings callbackSettings = callback.onNodeStopped(name); assert callbackSettings != null; Settings.Builder newSettings = Settings.builder(); - newSettings.put(callbackSettings); - if (minMasterNodes >= 0) { - if (INITIAL_MASTER_NODES_SETTING.exists(callbackSettings) == false) { - newSettings.putList(INITIAL_MASTER_NODES_SETTING.getKey()); - } + if (autoManageMasterNodes) { + newSettings.putList(INITIAL_MASTER_NODES_SETTING.getKey()); } + newSettings.put(callbackSettings); // delete data folders now, before we start other nodes that may claim it clearDataIfNeeded(callback); return newSettings.build(); @@ -1026,9 +1021,7 @@ private synchronized void reset(boolean wipeData) throws IOException { // start any missing node assert newSize == numSharedDedicatedMasterNodes + numSharedDataNodes + numSharedCoordOnlyNodes; - final int numberOfMasterNodes = numSharedDedicatedMasterNodes > 0 ? numSharedDedicatedMasterNodes : numSharedDataNodes; - final int defaultMinMasterNodes = (numberOfMasterNodes / 2) + 1; - final List toStartAndPublish = new ArrayList<>(); // we want to start nodes in one go due to min master nodes + final List toStartAndPublish = new ArrayList<>(); // we want to start nodes in one go final Runnable onTransportServiceStarted = () -> rebuildUnicastHostFiles(toStartAndPublish); final List settings = new ArrayList<>(); @@ -1037,7 +1030,7 @@ private synchronized void reset(boolean wipeData) throws IOException { final Settings.Builder extraSettings = Settings.builder(); extraSettings.put(Node.NODE_MASTER_SETTING.getKey(), true); extraSettings.put(Node.NODE_DATA_SETTING.getKey(), false); - settings.add(getNodeSettings(i, sharedNodesSeeds[i], extraSettings.build(), defaultMinMasterNodes)); + settings.add(getNodeSettings(i, sharedNodesSeeds[i], extraSettings.build())); } for (int i = numSharedDedicatedMasterNodes; i < numSharedDedicatedMasterNodes + numSharedDataNodes; i++) { final Settings.Builder extraSettings = Settings.builder(); @@ -1046,13 +1039,13 @@ private synchronized void reset(boolean wipeData) throws IOException { extraSettings.put(Node.NODE_MASTER_SETTING.getKey(), false).build(); extraSettings.put(Node.NODE_DATA_SETTING.getKey(), true).build(); } - settings.add(getNodeSettings(i, sharedNodesSeeds[i], extraSettings.build(), defaultMinMasterNodes)); + settings.add(getNodeSettings(i, sharedNodesSeeds[i], extraSettings.build())); } for (int i = numSharedDedicatedMasterNodes + numSharedDataNodes; i < numSharedDedicatedMasterNodes + numSharedDataNodes + numSharedCoordOnlyNodes; i++) { final Builder extraSettings = Settings.builder().put(Node.NODE_MASTER_SETTING.getKey(), false) .put(Node.NODE_DATA_SETTING.getKey(), false).put(Node.NODE_INGEST_SETTING.getKey(), false); - settings.add(getNodeSettings(i, sharedNodesSeeds[i], extraSettings.build(), defaultMinMasterNodes)); + settings.add(getNodeSettings(i, sharedNodesSeeds[i], extraSettings.build())); } int autoBootstrapMasterNodeIndex = -1; @@ -1061,7 +1054,7 @@ private synchronized void reset(boolean wipeData) throws IOException { .map(Node.NODE_NAME_SETTING::get) .collect(Collectors.toList()); - if (prevNodeCount == 0 && autoManageMinMasterNodes) { + if (prevNodeCount == 0 && autoManageMasterNodes) { if (numSharedDedicatedMasterNodes > 0) { autoBootstrapMasterNodeIndex = RandomNumbers.randomIntBetween(random, 0, numSharedDedicatedMasterNodes - 1); } else if (numSharedDataNodes > 0) { @@ -1084,7 +1077,7 @@ private synchronized void reset(boolean wipeData) throws IOException { nextNodeId.set(newSize); assert size() == newSize; - if (autoManageMinMasterNodes && newSize > 0) { + if (autoManageMasterNodes && newSize > 0) { validateClusterFormed(); } logger.debug("Cluster is consistent again - nodes: [{}] nextNodeId: [{}] numSharedNodes: [{}]", @@ -1469,7 +1462,7 @@ public InetSocketAddress[] httpAddresses() { for (HttpServerTransport httpServerTransport : getInstances(HttpServerTransport.class)) { addresses.add(httpServerTransport.boundAddress().publishAddress().address()); } - return addresses.toArray(new InetSocketAddress[addresses.size()]); + return addresses.toArray(new InetSocketAddress[0]); } /** @@ -1543,8 +1536,7 @@ private synchronized void startAndPublishNodesAndClients(List nod } nodeAndClients.forEach(this::publishNode); - if (autoManageMinMasterNodes && currentMasters > 0 && newMasters > 0 && - getMinMasterNodes(currentMasters + newMasters) > currentMasters) { + if (autoManageMasterNodes && newMasters > 0) { // update once masters have joined validateClusterFormed(); } @@ -1652,11 +1644,8 @@ private void restartNode(NodeAndClient nodeAndClient, RestartCallback callback) activeDisruptionScheme.removeFromNode(nodeAndClient.name, this); } - Set excludedNodeIds = excludeMasters(Collections.singleton(nodeAndClient)); - - final Settings newSettings = nodeAndClient.closeForRestart(callback, - autoManageMinMasterNodes ? getMinMasterNodes(getMasterNodesCount()) : -1); - + final Set excludedNodeIds = excludeMasters(Collections.singleton(nodeAndClient)); + final Settings newSettings = nodeAndClient.closeForRestart(callback); removeExclusions(excludedNodeIds); boolean success = false; @@ -1675,10 +1664,8 @@ private void restartNode(NodeAndClient nodeAndClient, RestartCallback callback) } if (callback.validateClusterForming() || excludedNodeIds.isEmpty() == false) { - // we have to validate cluster size if updateMinMaster == true, because we need the - // second node to join in order to increment min_master_nodes back to 2. - // we also have to do via the node that was just restarted as it may be that the master didn't yet process - // the fact it left + // we have to validate cluster size to ensure that the restarted node has rejoined the cluster if it was master-eligible; + // we have to do this via the node that was just restarted as it may be that the master didn't yet process the fact that it left validateClusterFormed(nodeAndClient.name); } } @@ -1694,7 +1681,7 @@ private NodeAndClient removeNode(NodeAndClient nodeAndClient) { private Set excludeMasters(Collection nodeAndClients) { assert Thread.holdsLock(this); final Set excludedNodeIds = new HashSet<>(); - if (autoManageMinMasterNodes && nodeAndClients.size() > 0) { + if (autoManageMasterNodes && nodeAndClients.size() > 0) { final long currentMasters = nodes.values().stream().filter(NodeAndClient::isMasterEligible).count(); final long stoppingMasters = nodeAndClients.stream().filter(NodeAndClient::isMasterEligible).count(); @@ -1741,7 +1728,6 @@ public synchronized void fullRestart(RestartCallback callback) throws Exception final Settings[] newNodeSettings = new Settings[nextNodeId.get()]; Map, List> nodesByRoles = new HashMap<>(); Set[] rolesOrderedByOriginalStartupOrder = new Set[nextNodeId.get()]; - final int minMasterNodes = autoManageMinMasterNodes ? getMinMasterNodes(getMasterNodesCount()) : -1; for (NodeAndClient nodeAndClient : nodes.values()) { callback.doAfterNodes(numNodesRestarted++, nodeAndClient.nodeClient()); logger.info("Stopping and resetting node [{}] ", nodeAndClient.name); @@ -1749,7 +1735,7 @@ public synchronized void fullRestart(RestartCallback callback) throws Exception activeDisruptionScheme.removeFromNode(nodeAndClient.name, this); } DiscoveryNode discoveryNode = getInstanceFromNode(ClusterService.class, nodeAndClient.node()).localNode(); - final Settings newSettings = nodeAndClient.closeForRestart(callback, minMasterNodes); + final Settings newSettings = nodeAndClient.closeForRestart(callback); newNodeSettings[nodeAndClient.nodeAndClientId()] = newSettings; rolesOrderedByOriginalStartupOrder[nodeAndClient.nodeAndClientId()] = discoveryNode.getRoles(); nodesByRoles.computeIfAbsent(discoveryNode.getRoles(), k -> new ArrayList<>()).add(nodeAndClient); @@ -1934,25 +1920,18 @@ public List startNodes(int numOfNodes, Settings settings) { */ public synchronized List startNodes(Settings... extraSettings) { final int newMasterCount = Math.toIntExact(Stream.of(extraSettings).filter(Node.NODE_MASTER_SETTING::get).count()); - final int defaultMinMasterNodes; - if (autoManageMinMasterNodes) { - defaultMinMasterNodes = getMinMasterNodes(getMasterNodesCount() + newMasterCount); - } else { - defaultMinMasterNodes = -1; - } final List nodes = new ArrayList<>(); final int prevMasterCount = getMasterNodesCount(); - int autoBootstrapMasterNodeIndex = - prevMasterCount == 0 && autoManageMinMasterNodes && newMasterCount > 0 && Arrays.stream(extraSettings) - .allMatch(s -> Node.NODE_MASTER_SETTING.get(s) == false - || ZEN2_DISCOVERY_TYPE.equals(DISCOVERY_TYPE_SETTING.get(s))) + int autoBootstrapMasterNodeIndex = autoManageMasterNodes && prevMasterCount == 0 && newMasterCount > 0 + && Arrays.stream(extraSettings) + .allMatch(s -> Node.NODE_MASTER_SETTING.get(s) == false || ZEN2_DISCOVERY_TYPE.equals(DISCOVERY_TYPE_SETTING.get(s))) ? RandomNumbers.randomIntBetween(random, 0, newMasterCount - 1) : -1; final int numOfNodes = extraSettings.length; final int firstNodeId = nextNodeId.getAndIncrement(); final List settings = new ArrayList<>(); for (int i = 0; i < numOfNodes; i++) { - settings.add(getNodeSettings(firstNodeId + i, random.nextLong(), extraSettings[i], defaultMinMasterNodes)); + settings.add(getNodeSettings(firstNodeId + i, random.nextLong(), extraSettings[i])); } nextNodeId.set(firstNodeId + numOfNodes); @@ -1978,7 +1957,7 @@ public synchronized List startNodes(Settings... extraSettings) { nodes.add(nodeAndClient); } startAndPublishNodesAndClients(nodes); - if (autoManageMinMasterNodes) { + if (autoManageMasterNodes) { validateClusterFormed(); } return nodes.stream().map(NodeAndClient::getName).collect(Collectors.toList()); @@ -2004,11 +1983,6 @@ public List startDataOnlyNodes(int numNodes) { .put(Node.NODE_DATA_SETTING.getKey(), true).build()); } - /** calculates a min master nodes value based on the given number of master nodes */ - private static int getMinMasterNodes(int eligibleMasterNodes) { - return eligibleMasterNodes / 2 + 1; - } - private int getMasterNodesCount() { return (int) nodes.values().stream().filter(n -> Node.NODE_MASTER_SETTING.get(n.node().settings())).count(); } @@ -2143,7 +2117,7 @@ synchronized String routingKeyForShard(Index index, int shard, Random random) { greaterThan(shard)); OperationRouting operationRouting = clusterService.operationRouting(); while (true) { - String routing = RandomStrings.randomAsciiOfLength(random, 10); + String routing = RandomStrings.randomAsciiLettersOfLength(random, 10); final int targetShard = operationRouting .indexShards(clusterService.state(), index.getName(), null, routing) .shardId().getId(); diff --git a/test/framework/src/test/java/org/elasticsearch/test/disruption/NetworkDisruptionIT.java b/test/framework/src/test/java/org/elasticsearch/test/disruption/NetworkDisruptionIT.java index a2f6b3ed654e6..a018bc1663175 100644 --- a/test/framework/src/test/java/org/elasticsearch/test/disruption/NetworkDisruptionIT.java +++ b/test/framework/src/test/java/org/elasticsearch/test/disruption/NetworkDisruptionIT.java @@ -37,7 +37,7 @@ import static org.hamcrest.Matchers.greaterThanOrEqualTo; -@ESIntegTestCase.ClusterScope(scope = ESIntegTestCase.Scope.TEST, numDataNodes = 0, autoMinMasterNodes = false) +@ESIntegTestCase.ClusterScope(scope = ESIntegTestCase.Scope.TEST, numDataNodes = 0, autoManageMasterNodes = false) public class NetworkDisruptionIT extends ESIntegTestCase { @Override protected Collection> nodePlugins() {