diff --git a/server/src/main/java/org/elasticsearch/env/NodeEnvironment.java b/server/src/main/java/org/elasticsearch/env/NodeEnvironment.java index 745820348a4ec..73ddbce5f82df 100644 --- a/server/src/main/java/org/elasticsearch/env/NodeEnvironment.java +++ b/server/src/main/java/org/elasticsearch/env/NodeEnvironment.java @@ -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); } } } diff --git a/server/src/test/java/org/elasticsearch/env/NodeEnvironmentIT.java b/server/src/test/java/org/elasticsearch/env/NodeEnvironmentIT.java index c5d7dd5bb61e1..f49b3b45aad53 100644 --- a/server/src/test/java/org/elasticsearch/env/NodeEnvironmentIT.java +++ b/server/src/test/java/org/elasticsearch/env/NodeEnvironmentIT.java @@ -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); } @@ -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");