Skip to content

Commit

Permalink
Do not set path.data in environment if not set
Browse files Browse the repository at this point in the history
When preparing the final settings in the environment, we unconditionally
set path.data even if path.data was not explicitly set. This confounds
detection for whether or not path.data was explicitly set, and this is
trappy. This commit adds logic to only set path.data in the final
settings if path.data was explicitly set, and provides a test case that
fails without this logic.

Relates #24132
  • Loading branch information
jasontedor committed Apr 17, 2017
1 parent b2d62ae commit 5f9cf58
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
4 changes: 3 additions & 1 deletion core/src/main/java/org/elasticsearch/env/Environment.java
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,9 @@ public Environment(Settings settings) {

Settings.Builder finalSettings = Settings.builder().put(settings);
finalSettings.put(PATH_HOME_SETTING.getKey(), homeFile);
finalSettings.putArray(PATH_DATA_SETTING.getKey(), dataPaths);
if (PATH_DATA_SETTING.exists(settings)) {
finalSettings.putArray(PATH_DATA_SETTING.getKey(), dataPaths);
}
finalSettings.put(PATH_LOGS_SETTING.getKey(), logsFile);
this.settings = finalSettings.build();

Expand Down
13 changes: 13 additions & 0 deletions core/src/test/java/org/elasticsearch/env/EnvironmentTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,19 @@ public void testPathDataWhenNotSet() {
assertThat(environment.dataFiles(), equalTo(new Path[]{pathHome.resolve("data")}));
}

public void testPathDataNotSetInEnvironmentIfNotSet() {
final Path defaultPathData = createTempDir().toAbsolutePath();
final Settings settings = Settings.builder()
.put("path.home", createTempDir().toAbsolutePath())
.put("default.path.data", defaultPathData)
.build();
assertFalse(Environment.PATH_DATA_SETTING.exists(settings));
assertTrue(Environment.DEFAULT_PATH_DATA_SETTING.exists(settings));
final Environment environment = new Environment(settings);
assertFalse(Environment.PATH_DATA_SETTING.exists(environment.settings()));
assertTrue(Environment.DEFAULT_PATH_DATA_SETTING.exists(environment.settings()));
}

public void testDefaultPathLogs() {
final Path defaultPathLogs = createTempDir().toAbsolutePath();
final Settings settings = Settings.builder()
Expand Down

0 comments on commit 5f9cf58

Please sign in to comment.