Skip to content

Commit

Permalink
Fail if any other file/dir in nodes dir
Browse files Browse the repository at this point in the history
  • Loading branch information
ywelsch committed May 28, 2019
1 parent 74d6bdb commit b139f14
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,9 @@ private static boolean upgradeLegacyNodeFolders(Logger logger, Settings settings
if (Files.isDirectory(nodeLockIdPath) && fileName.chars().allMatch(Character::isDigit)) {
int nodeLockId = Integer.parseInt(fileName);
nodeLockIds.add(nodeLockId);
} else if (FileSystemUtils.isDesktopServicesStore(nodeLockIdPath) == false) {
throw new IllegalStateException("unexpected file/folder encountered during data folder upgrade: " +
nodeLockIdPath);
}
}
}
Expand Down
16 changes: 12 additions & 4 deletions server/src/test/java/org/elasticsearch/env/NodeEnvironmentIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,6 @@ public void testUpgradeDataFolder() throws IOException, InterruptedException {
}
}
}
IOUtils.fsync(targetPath, true);
IOUtils.fsync(path, true);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
Expand All @@ -173,14 +171,24 @@ public void testUpgradeDataFolder() throws IOException, InterruptedException {

// create extra file/folder, and check that upgrade fails
if (dataPaths.isEmpty() == false) {
final Path badFile = Files.createTempFile(randomFrom(dataPaths).resolve("nodes").resolve("0"), "bad", "file");
final Path badFileInNodesDir = Files.createTempFile(randomFrom(dataPaths).resolve("nodes"), "bad", "file");
IllegalStateException ise = expectThrows(IllegalStateException.class, () -> internalCluster().startNode(dataPathSettings));
assertThat(ise.getMessage(), containsString("unexpected file/folder encountered during data folder upgrade"));
Files.delete(badFileInNodesDir);

final Path badFolderInNodesDir = Files.createDirectories(randomFrom(dataPaths).resolve("nodes").resolve("bad-folder"));
ise = expectThrows(IllegalStateException.class, () -> internalCluster().startNode(dataPathSettings));
assertThat(ise.getMessage(), containsString("unexpected file/folder encountered during data folder upgrade"));
Files.delete(badFolderInNodesDir);

final Path badFile = Files.createTempFile(randomFrom(dataPaths).resolve("nodes").resolve("0"), "bad", "file");
ise = expectThrows(IllegalStateException.class, () -> internalCluster().startNode(dataPathSettings));
assertThat(ise.getMessage(), containsString("unexpected file/folder encountered during data folder upgrade"));
Files.delete(badFile);

final Path badFolder = Files.createDirectories(randomFrom(dataPaths).resolve("nodes").resolve("0").resolve("bad-folder"));
ise = expectThrows(IllegalStateException.class, () -> internalCluster().startNode(dataPathSettings));
assertThat(ise.getMessage(), containsString("unexpected folder encountered during data folder upgrad"));
assertThat(ise.getMessage(), containsString("unexpected folder encountered during data folder upgrade"));
Files.delete(badFolder);

final Path conflictingFolder = randomFrom(dataPaths).resolve("indices");
Expand Down

0 comments on commit b139f14

Please sign in to comment.