Skip to content

Commit c3be320

Browse files
committed
Decouple environment from DiscoveryNode (#54373)
Today Environment is coupled to DiscoveryNode via the node.local_storage setting. This commit decouples Environment from this setting.
1 parent 37b59a3 commit c3be320

File tree

3 files changed

+13
-12
lines changed

3 files changed

+13
-12
lines changed

server/src/main/java/org/elasticsearch/env/Environment.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
package org.elasticsearch.env;
2121

2222
import org.elasticsearch.cluster.ClusterName;
23-
import org.elasticsearch.cluster.node.DiscoveryNode;
2423
import org.elasticsearch.common.SuppressForbidden;
2524
import org.elasticsearch.common.io.PathUtils;
2625
import org.elasticsearch.common.settings.Setting;
@@ -92,11 +91,15 @@ public class Environment {
9291
private final Path tmpFile;
9392

9493
public Environment(final Settings settings, final Path configPath) {
95-
this(settings, configPath, PathUtils.get(System.getProperty("java.io.tmpdir")));
94+
this(settings, configPath, true);
95+
}
96+
97+
public Environment(final Settings settings, final Path configPath, final boolean nodeLocalStorage) {
98+
this(settings, configPath, nodeLocalStorage, PathUtils.get(System.getProperty("java.io.tmpdir")));
9699
}
97100

98101
// Should only be called directly by this class's unit tests
99-
Environment(final Settings settings, final Path configPath, final Path tmpPath) {
102+
Environment(final Settings settings, final Path configPath, final boolean nodeLocalStorage, final Path tmpPath) {
100103
final Path homeFile;
101104
if (PATH_HOME_SETTING.exists(settings)) {
102105
homeFile = PathUtils.get(PATH_HOME_SETTING.get(settings)).toAbsolutePath().normalize();
@@ -116,7 +119,7 @@ public Environment(final Settings settings, final Path configPath) {
116119

117120
List<String> dataPaths = PATH_DATA_SETTING.get(settings);
118121
final ClusterName clusterName = ClusterName.CLUSTER_NAME_SETTING.get(settings);
119-
if (DiscoveryNode.nodeRequiresLocalStorage(settings)) {
122+
if (nodeLocalStorage) {
120123
if (dataPaths.isEmpty() == false) {
121124
dataFiles = new Path[dataPaths.size()];
122125
for (int i = 0; i < dataPaths.size(); i++) {

server/src/main/java/org/elasticsearch/node/Node.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ protected Node(final Environment initialEnvironment,
332332

333333
// create the environment based on the finalized (processed) view of the settings
334334
// this is just to makes sure that people get the same settings, no matter where they ask them from
335-
this.environment = new Environment(settings, initialEnvironment.configFile());
335+
this.environment = new Environment(settings, initialEnvironment.configFile(), Node.NODE_LOCAL_STORAGE_SETTING.get(settings));
336336
Environment.assertEquivalent(initialEnvironment, this.environment);
337337

338338
final List<ExecutorBuilder<?>> executorBuilders = pluginsService.getExecutorBuilders(settings);

server/src/test/java/org/elasticsearch/env/EnvironmentTests.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -130,11 +130,10 @@ public void testNodeDoesNotRequireLocalStorage() {
130130
final Settings settings =
131131
Settings.builder()
132132
.put("path.home", pathHome)
133-
.put("node.local_storage", false)
134133
.put("node.master", false)
135134
.put("node.data", false)
136135
.build();
137-
final Environment environment = new Environment(settings, null);
136+
final Environment environment = new Environment(settings, null, false);
138137
assertThat(environment.dataFiles(), arrayWithSize(0));
139138
}
140139

@@ -145,19 +144,18 @@ public void testNodeDoesNotRequireLocalStorageButHasPathData() {
145144
Settings.builder()
146145
.put("path.home", pathHome)
147146
.put("path.data", pathData)
148-
.put("node.local_storage", false)
149147
.put("node.master", false)
150148
.put("node.data", false)
151149
.build();
152-
final IllegalStateException e = expectThrows(IllegalStateException.class, () -> new Environment(settings, null));
150+
final IllegalStateException e = expectThrows(IllegalStateException.class, () -> new Environment(settings, null, false));
153151
assertThat(e, hasToString(containsString("node does not require local storage yet path.data is set to [" + pathData + "]")));
154152
}
155153

156154
public void testNonExistentTempPathValidation() {
157155
Settings build = Settings.builder()
158156
.put(Environment.PATH_HOME_SETTING.getKey(), createTempDir())
159157
.build();
160-
Environment environment = new Environment(build, null, createTempDir().resolve("this_does_not_exist"));
158+
Environment environment = new Environment(build, null, true, createTempDir().resolve("this_does_not_exist"));
161159
FileNotFoundException e = expectThrows(FileNotFoundException.class, environment::validateTmpFile);
162160
assertThat(e.getMessage(), startsWith("Temporary file directory ["));
163161
assertThat(e.getMessage(), endsWith("this_does_not_exist] does not exist or is not accessible"));
@@ -167,7 +165,7 @@ public void testTempPathValidationWhenRegularFile() throws IOException {
167165
Settings build = Settings.builder()
168166
.put(Environment.PATH_HOME_SETTING.getKey(), createTempDir())
169167
.build();
170-
Environment environment = new Environment(build, null, createTempFile("something", ".test"));
168+
Environment environment = new Environment(build, null, true, createTempFile("something", ".test"));
171169
IOException e = expectThrows(IOException.class, environment::validateTmpFile);
172170
assertThat(e.getMessage(), startsWith("Configured temporary file directory ["));
173171
assertThat(e.getMessage(), endsWith(".test] is not a directory"));
@@ -194,7 +192,7 @@ public void testPathNormalization() throws IOException {
194192
// the above paths will be treated as relative to the working directory
195193
final Path workingDirectory = PathUtils.get(System.getProperty("user.dir"));
196194

197-
final Environment environment = new Environment(settings, null, createTempDir());
195+
final Environment environment = new Environment(settings, null, true, createTempDir());
198196
final String homePath = Environment.PATH_HOME_SETTING.get(environment.settings());
199197
assertPath(homePath, workingDirectory.resolve("home"));
200198

0 commit comments

Comments
 (0)