Skip to content

Commit

Permalink
Fix path.data as comma separated string (#76202)
Browse files Browse the repository at this point in the history
For multiple data paths, there are several allowed varieties of
specifcying the paths. The yaml list forms, both single and multi line,
are allowed, but another form is a string containing commas that is
parsed as a list. This latter form was broken recently by the
refactoring of path.data parsing to emit deprecation warnings for MDP.
This commit fixes the comma separated string case and adds a test.

closes #76181
  • Loading branch information
rjernst committed Aug 13, 2021
1 parent 11a1f35 commit 912d3b6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
3 changes: 2 additions & 1 deletion server/src/main/java/org/elasticsearch/env/Environment.java
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ public Environment(final Settings settings, final Path configPath, final boolean
finalSettings.putList(PATH_DATA_SETTING.getKey(),
Arrays.stream(dataFiles).map(Path::toString).collect(Collectors.toList()));
} else {
assert dataFiles.length == 1;
finalSettings.put(PATH_DATA_SETTING.getKey(), dataFiles[0]);
}
}
Expand Down Expand Up @@ -324,7 +325,7 @@ public static boolean dataPathUsesList(Settings settings) {
return false;
}
String rawDataPath = settings.get(PATH_DATA_SETTING.getKey());
return rawDataPath.startsWith("[");
return rawDataPath.startsWith("[") || rawDataPath.contains(",");
}

public static FileStore getFileStore(final Path path) throws IOException {
Expand Down
14 changes: 14 additions & 0 deletions server/src/test/java/org/elasticsearch/env/EnvironmentTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,15 @@ public void testPathDataNotSetInEnvironmentIfNotSet() {
assertFalse(Environment.PATH_DATA_SETTING.exists(environment.settings()));
}

public void testPathDataLegacyCommaList() {
final Settings settings = Settings.builder()
.put("path.home", createTempDir().toAbsolutePath())
.put("path.data", createTempDir().toAbsolutePath() + "," + createTempDir().toAbsolutePath())
.build();
final Environment environment = new Environment(settings, null);
assertThat(environment.dataFiles(), arrayWithSize(2));
}

public void testPathLogsWhenNotSet() {
final Path pathHome = createTempDir().toAbsolutePath();
final Settings settings = Settings.builder().put("path.home", pathHome).build();
Expand Down Expand Up @@ -214,6 +223,11 @@ public void testSingleDataPathListCheck() {
.putList(Environment.PATH_DATA_SETTING.getKey(), createTempDir().toString()).build();
assertThat(Environment.dataPathUsesList(settings), is(true));
}
{
final Settings settings = Settings.builder()
.put(Environment.PATH_DATA_SETTING.getKey(), createTempDir().toString() + "," + createTempDir().toString()).build();
assertThat(Environment.dataPathUsesList(settings), is(true));
}
}

public void testLegacyDataPathListPropagation() {
Expand Down

0 comments on commit 912d3b6

Please sign in to comment.