From 61d8af34729006496da554d7491117e3c2f8c07c Mon Sep 17 00:00:00 2001 From: Ryan Ernst Date: Wed, 12 Dec 2018 11:24:07 -0800 Subject: [PATCH 1/2] Internal: Remove originalSettings from Node This commit removes the originalSettings member from Node. It was only needed to allows test clusters to recreate the node in certain situations. Instead, the test cluster now keeps track of these settings. --- server/src/main/java/org/elasticsearch/node/Node.java | 9 --------- .../org/elasticsearch/test/InternalTestCluster.java | 11 +++++++---- 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/server/src/main/java/org/elasticsearch/node/Node.java b/server/src/main/java/org/elasticsearch/node/Node.java index aa49b10b8b19c..a3fb56542fc1c 100644 --- a/server/src/main/java/org/elasticsearch/node/Node.java +++ b/server/src/main/java/org/elasticsearch/node/Node.java @@ -238,7 +238,6 @@ public class Node implements Closeable { private final Logger logger; private final Injector injector; private final Settings settings; - private final Settings originalSettings; private final Environment environment; private final NodeEnvironment nodeEnvironment; private final PluginsService pluginsService; @@ -265,7 +264,6 @@ protected Node( final List resourcesToClose = new ArrayList<>(); // register everything we need to release in the case of an error boolean success = false; try { - originalSettings = environment.settings(); Settings tmpSettings = Settings.builder().put(environment.settings()) .put(Client.CLIENT_TYPE_SETTING_S.getKey(), CLIENT_TYPE).build(); @@ -594,13 +592,6 @@ protected void processRecoverySettings(ClusterSettings clusterSettings, Recovery // Noop in production, overridden by tests } - /** - * The original settings that were used to create the node - */ - public Settings originalSettings() { - return originalSettings; - } - /** * The settings that are used by this node. Contains original settings as well as additional settings provided by plugins. */ 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 6ebcdf6358cb5..3e8c4c7fe8c50 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/InternalTestCluster.java +++ b/test/framework/src/main/java/org/elasticsearch/test/InternalTestCluster.java @@ -661,8 +661,9 @@ private NodeAndClient buildNode(int nodeId, long seed, Settings settings, // we clone this here since in the case of a node restart we might need it again secureSettings = ((MockSecureSettings) secureSettings).clone(); } + final Settings nodeSettings = finalSettings.build(); MockNode node = new MockNode( - finalSettings.build(), + nodeSettings, plugins, nodeConfigurationSource.nodeConfigPath(nodeId), forbidPrivateIndexSettings); @@ -677,7 +678,7 @@ public void afterStart() { } catch (IOException e) { throw new UncheckedIOException(e); } - return new NodeAndClient(name, node, nodeId); + return new NodeAndClient(name, node, nodeSettings, nodeId); } private String buildNodeName(int id, Settings settings) { @@ -821,15 +822,17 @@ public synchronized void close() { private final class NodeAndClient implements Closeable { private MockNode node; + private Settings originalNodeSettings; private Client nodeClient; private Client transportClient; private final AtomicBoolean closed = new AtomicBoolean(false); private final String name; private final int nodeAndClientId; - NodeAndClient(String name, MockNode node, int nodeAndClientId) { + NodeAndClient(String name, MockNode node, Settings originalNodeSettings, int nodeAndClientId) { this.node = node; this.name = name; + this.originalNodeSettings = originalNodeSettings; this.nodeAndClientId = nodeAndClientId; markNodeDataDirsAsNotEligableForWipe(node); } @@ -955,7 +958,7 @@ private void recreateNode(final Settings newSettings, final Runnable onTransport // use a new seed to make sure we have new node id final long newIdSeed = NodeEnvironment.NODE_ID_SEED_SETTING.get(node.settings()) + 1; Settings finalSettings = Settings.builder() - .put(node.originalSettings()) + .put(originalNodeSettings) .put(newSettings) .put(NodeEnvironment.NODE_ID_SEED_SETTING.getKey(), newIdSeed) .build(); From 3ba434919367461bec055b60e8285442978c2f73 Mon Sep 17 00:00:00 2001 From: Ryan Ernst Date: Thu, 13 Dec 2018 11:28:16 -0800 Subject: [PATCH 2/2] make final --- .../main/java/org/elasticsearch/test/InternalTestCluster.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 3e8c4c7fe8c50..845987f11a7ed 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/InternalTestCluster.java +++ b/test/framework/src/main/java/org/elasticsearch/test/InternalTestCluster.java @@ -822,7 +822,7 @@ public synchronized void close() { private final class NodeAndClient implements Closeable { private MockNode node; - private Settings originalNodeSettings; + private final Settings originalNodeSettings; private Client nodeClient; private Client transportClient; private final AtomicBoolean closed = new AtomicBoolean(false);