Skip to content

Commit

Permalink
Fix path.data list deprecation to work in all cases (elastic#72503)
Browse files Browse the repository at this point in the history
path.data can appear as a list, or a string. On node startup, several
Environment and Setting objects are created. The Environment propagates
the path.data setting, but needs to choose whether it is propagated as a
list or a string. This commit adjusts how it is propagated so that if
the path.data is originally a string, it will stay a string, so that the
deprecation message for path.data as a list can properly detect a list
case.

relates elastic#71205
  • Loading branch information
rjernst authored Apr 29, 2021
1 parent 408db3b commit 0ad7d9c
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
6 changes: 3 additions & 3 deletions server/src/main/java/org/elasticsearch/env/Environment.java
Original file line number Diff line number Diff line change
Expand Up @@ -157,11 +157,11 @@ public Environment(final Settings settings, final Path configPath, final boolean

final Settings.Builder finalSettings = Settings.builder().put(settings);
if (PATH_DATA_SETTING.exists(settings)) {
if (dataFiles.length == 1) {
finalSettings.put(PATH_DATA_SETTING.getKey(), dataFiles[0]);
} else {
if (dataPathUsesList(settings)) {
finalSettings.putList(PATH_DATA_SETTING.getKey(),
Arrays.stream(dataFiles).map(Path::toString).collect(Collectors.toList()));
} else {
finalSettings.put(PATH_DATA_SETTING.getKey(), dataFiles[0]);
}
}
finalSettings.put(PATH_HOME_SETTING.getKey(), homeFile);
Expand Down
31 changes: 31 additions & 0 deletions server/src/test/java/org/elasticsearch/env/EnvironmentTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,37 @@ public void testSingleDataPathListCheck() {
}
}

public void testLegacyDataPathListPropagation() {
{
final Settings settings = Settings.builder()
.put(Environment.PATH_HOME_SETTING.getKey(), createTempDir())
.build();
Environment env = new Environment(settings, null);
assertThat(Environment.dataPathUsesList(env.settings()), is(false));
}
{
final Settings settings = Settings.builder()
.put(Environment.PATH_HOME_SETTING.getKey(), createTempDir())
.putList(Environment.PATH_DATA_SETTING.getKey(), createTempDir().toString(), createTempDir().toString()).build();
Environment env = new Environment(settings, null);
assertThat(Environment.dataPathUsesList(env.settings()), is(true));
}
{
final Settings settings = Settings.builder()
.put(Environment.PATH_HOME_SETTING.getKey(), createTempDir())
.putList(Environment.PATH_DATA_SETTING.getKey(), createTempDir().toString()).build();
Environment env = new Environment(settings, null);
assertThat(Environment.dataPathUsesList(env.settings()), is(true));
}
{
final Settings settings = Settings.builder()
.put(Environment.PATH_HOME_SETTING.getKey(), createTempDir())
.put(Environment.PATH_DATA_SETTING.getKey(), createTempDir().toString()).build();
Environment env = new Environment(settings, null);
assertThat(Environment.dataPathUsesList(env.settings()), is(false));
}
}

private void assertPath(final String actual, final Path expected) {
assertIsAbsolute(actual);
assertIsNormalized(actual);
Expand Down

0 comments on commit 0ad7d9c

Please sign in to comment.