From 5662281562174a0b02dc966170b885b0ba3b7b21 Mon Sep 17 00:00:00 2001 From: Armin Braun Date: Fri, 12 Jun 2020 15:27:48 +0200 Subject: [PATCH] Fix ExtraFS Breaking SharedClusterSnapshotRestoreIT (#58026) (#58040) If `ExtraFS` decides to put `extra0/0` into the indices folder then the previous logic in this test would have interpreted the `0` as shard `0` of index `extra0` and fail to list its contents (since it's a file and not an actual shard directory). => simplified the logic to use actually referenced `IndexId` for iterating over indices instead. --- .../SharedClusterSnapshotRestoreIT.java | 23 +++++++------------ 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/server/src/internalClusterTest/java/org/elasticsearch/snapshots/SharedClusterSnapshotRestoreIT.java b/server/src/internalClusterTest/java/org/elasticsearch/snapshots/SharedClusterSnapshotRestoreIT.java index 9f7078e02a0..a297a921731 100644 --- a/server/src/internalClusterTest/java/org/elasticsearch/snapshots/SharedClusterSnapshotRestoreIT.java +++ b/server/src/internalClusterTest/java/org/elasticsearch/snapshots/SharedClusterSnapshotRestoreIT.java @@ -93,7 +93,6 @@ import org.elasticsearch.script.StoredScriptsIT; import org.elasticsearch.snapshots.mockstore.MockRepository; import org.elasticsearch.threadpool.ThreadPool; -import java.io.IOException; import java.nio.channels.SeekableByteChannel; import java.nio.file.Files; import java.nio.file.Path; @@ -1523,20 +1522,14 @@ public class SharedClusterSnapshotRestoreIT extends AbstractSnapshotIntegTestCas .setWaitForCompletion(true).setIndices("test-idx-*").get(); logger.info("--> deleting shard level index file"); - try (Stream files = Files.list(repo.resolve("indices"))) { - files.forEach(indexPath -> { - try { - final Path shardGen; - try (Stream shardFiles = Files.list(indexPath.resolve("0"))) { - shardGen = shardFiles - .filter(file -> file.getFileName().toString().startsWith(BlobStoreRepository.INDEX_FILE_PREFIX)) - .findFirst().orElseThrow(() -> new AssertionError("Failed to find shard index blob")); - } - Files.delete(shardGen); - } catch (IOException e) { - throw new RuntimeException("Failed to delete expected file", e); - } - }); + final Path indicesPath = repo.resolve("indices"); + for (IndexId indexId : getRepositoryData("test-repo").getIndices().values()) { + final Path shardGen; + try (Stream shardFiles = Files.list(indicesPath.resolve(indexId.getId()).resolve("0"))) { + shardGen = shardFiles.filter(file -> file.getFileName().toString().startsWith(BlobStoreRepository.INDEX_FILE_PREFIX)) + .findFirst().orElseThrow(() -> new AssertionError("Failed to find shard index blob")); + } + Files.delete(shardGen); } logger.info("--> creating another snapshot");