diff --git a/server/src/main/java/org/elasticsearch/env/Environment.java b/server/src/main/java/org/elasticsearch/env/Environment.java index 261406db2f7..afe4a814e00 100644 --- a/server/src/main/java/org/elasticsearch/env/Environment.java +++ b/server/src/main/java/org/elasticsearch/env/Environment.java @@ -20,7 +20,6 @@ package org.elasticsearch.env; import org.elasticsearch.cluster.ClusterName; -import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.common.SuppressForbidden; import org.elasticsearch.common.io.PathUtils; import org.elasticsearch.common.settings.Setting; @@ -92,11 +91,15 @@ public class Environment { private final Path tmpFile; public Environment(final Settings settings, final Path configPath) { - this(settings, configPath, PathUtils.get(System.getProperty("java.io.tmpdir"))); + this(settings, configPath, true); + } + + public Environment(final Settings settings, final Path configPath, final boolean nodeLocalStorage) { + this(settings, configPath, nodeLocalStorage, PathUtils.get(System.getProperty("java.io.tmpdir"))); } // Should only be called directly by this class's unit tests - Environment(final Settings settings, final Path configPath, final Path tmpPath) { + Environment(final Settings settings, final Path configPath, final boolean nodeLocalStorage, final Path tmpPath) { final Path homeFile; if (PATH_HOME_SETTING.exists(settings)) { homeFile = PathUtils.get(PATH_HOME_SETTING.get(settings)).toAbsolutePath().normalize(); @@ -116,7 +119,7 @@ public class Environment { List dataPaths = PATH_DATA_SETTING.get(settings); final ClusterName clusterName = ClusterName.CLUSTER_NAME_SETTING.get(settings); - if (DiscoveryNode.nodeRequiresLocalStorage(settings)) { + if (nodeLocalStorage) { if (dataPaths.isEmpty() == false) { dataFiles = new Path[dataPaths.size()]; for (int i = 0; i < dataPaths.size(); i++) { diff --git a/server/src/main/java/org/elasticsearch/node/Node.java b/server/src/main/java/org/elasticsearch/node/Node.java index fe94f621a36..e61a00b05db 100644 --- a/server/src/main/java/org/elasticsearch/node/Node.java +++ b/server/src/main/java/org/elasticsearch/node/Node.java @@ -332,7 +332,7 @@ public class Node implements Closeable { // create the environment based on the finalized (processed) view of the settings // this is just to makes sure that people get the same settings, no matter where they ask them from - this.environment = new Environment(settings, initialEnvironment.configFile()); + this.environment = new Environment(settings, initialEnvironment.configFile(), Node.NODE_LOCAL_STORAGE_SETTING.get(settings)); Environment.assertEquivalent(initialEnvironment, this.environment); final List> executorBuilders = pluginsService.getExecutorBuilders(settings); diff --git a/server/src/test/java/org/elasticsearch/env/EnvironmentTests.java b/server/src/test/java/org/elasticsearch/env/EnvironmentTests.java index ee9fc0b694e..ba5020827c9 100644 --- a/server/src/test/java/org/elasticsearch/env/EnvironmentTests.java +++ b/server/src/test/java/org/elasticsearch/env/EnvironmentTests.java @@ -130,11 +130,10 @@ public class EnvironmentTests extends ESTestCase { final Settings settings = Settings.builder() .put("path.home", pathHome) - .put("node.local_storage", false) .put("node.master", false) .put("node.data", false) .build(); - final Environment environment = new Environment(settings, null); + final Environment environment = new Environment(settings, null, false); assertThat(environment.dataFiles(), arrayWithSize(0)); } @@ -145,11 +144,10 @@ public class EnvironmentTests extends ESTestCase { Settings.builder() .put("path.home", pathHome) .put("path.data", pathData) - .put("node.local_storage", false) .put("node.master", false) .put("node.data", false) .build(); - final IllegalStateException e = expectThrows(IllegalStateException.class, () -> new Environment(settings, null)); + final IllegalStateException e = expectThrows(IllegalStateException.class, () -> new Environment(settings, null, false)); assertThat(e, hasToString(containsString("node does not require local storage yet path.data is set to [" + pathData + "]"))); } @@ -157,7 +155,7 @@ public class EnvironmentTests extends ESTestCase { Settings build = Settings.builder() .put(Environment.PATH_HOME_SETTING.getKey(), createTempDir()) .build(); - Environment environment = new Environment(build, null, createTempDir().resolve("this_does_not_exist")); + Environment environment = new Environment(build, null, true, createTempDir().resolve("this_does_not_exist")); FileNotFoundException e = expectThrows(FileNotFoundException.class, environment::validateTmpFile); assertThat(e.getMessage(), startsWith("Temporary file directory [")); assertThat(e.getMessage(), endsWith("this_does_not_exist] does not exist or is not accessible")); @@ -167,7 +165,7 @@ public class EnvironmentTests extends ESTestCase { Settings build = Settings.builder() .put(Environment.PATH_HOME_SETTING.getKey(), createTempDir()) .build(); - Environment environment = new Environment(build, null, createTempFile("something", ".test")); + Environment environment = new Environment(build, null, true, createTempFile("something", ".test")); IOException e = expectThrows(IOException.class, environment::validateTmpFile); assertThat(e.getMessage(), startsWith("Configured temporary file directory [")); assertThat(e.getMessage(), endsWith(".test] is not a directory")); @@ -194,7 +192,7 @@ public class EnvironmentTests extends ESTestCase { // the above paths will be treated as relative to the working directory final Path workingDirectory = PathUtils.get(System.getProperty("user.dir")); - final Environment environment = new Environment(settings, null, createTempDir()); + final Environment environment = new Environment(settings, null, true, createTempDir()); final String homePath = Environment.PATH_HOME_SETTING.get(environment.settings()); assertPath(homePath, workingDirectory.resolve("home"));