|
93 | 93 | import org.elasticsearch.snapshots.mockstore.MockRepository; |
94 | 94 | import org.elasticsearch.test.junit.annotations.TestLogging; |
95 | 95 |
|
| 96 | +import java.io.IOException; |
96 | 97 | import java.nio.channels.SeekableByteChannel; |
97 | 98 | import java.nio.file.Files; |
98 | 99 | import java.nio.file.Path; |
@@ -1243,30 +1244,44 @@ public void testDeleteSnapshotWithMissingIndexAndShardMetadata() throws Exceptio |
1243 | 1244 | .put("compress", false) |
1244 | 1245 | .put("chunk_size", randomIntBetween(100, 1000), ByteSizeUnit.BYTES))); |
1245 | 1246 |
|
1246 | | - createIndex("test-idx-1", "test-idx-2"); |
| 1247 | + final String[] indices = {"test-idx-1", "test-idx-2"}; |
| 1248 | + createIndex(indices); |
1247 | 1249 | logger.info("--> indexing some data"); |
1248 | 1250 | indexRandom(true, |
1249 | 1251 | client().prepareIndex("test-idx-1", "_doc").setSource("foo", "bar"), |
1250 | 1252 | client().prepareIndex("test-idx-2", "_doc").setSource("foo", "bar")); |
1251 | 1253 |
|
1252 | 1254 | logger.info("--> creating snapshot"); |
1253 | | - CreateSnapshotResponse createSnapshotResponse = client.admin().cluster().prepareCreateSnapshot("test-repo", "test-snap-1").setWaitForCompletion(true).setIndices("test-idx-*").get(); |
1254 | | - assertThat(createSnapshotResponse.getSnapshotInfo().successfulShards(), greaterThan(0)); |
1255 | | - assertThat(createSnapshotResponse.getSnapshotInfo().successfulShards(), equalTo(createSnapshotResponse.getSnapshotInfo().totalShards())); |
| 1255 | + CreateSnapshotResponse createSnapshotResponse = client.admin().cluster().prepareCreateSnapshot("test-repo", "test-snap-1") |
| 1256 | + .setWaitForCompletion(true).setIndices(indices).get(); |
| 1257 | + final SnapshotInfo snapshotInfo = createSnapshotResponse.getSnapshotInfo(); |
| 1258 | + assertThat(snapshotInfo.successfulShards(), greaterThan(0)); |
| 1259 | + assertThat(snapshotInfo.successfulShards(), equalTo(snapshotInfo.totalShards())); |
| 1260 | + |
| 1261 | + RepositoriesService service = internalCluster().getInstance(RepositoriesService.class, internalCluster().getMasterName()); |
| 1262 | + Repository repository = service.repository("test-repo"); |
| 1263 | + |
| 1264 | + final Map<String, IndexId> indexIds = repository.getRepositoryData().getIndices(); |
| 1265 | + final Path indicesPath = repo.resolve("indices"); |
1256 | 1266 |
|
1257 | 1267 | logger.info("--> delete index metadata and shard metadata"); |
1258 | | - Path indices = repo.resolve("indices"); |
1259 | | - Path testIndex1 = indices.resolve("test-idx-1"); |
1260 | | - Path testIndex2 = indices.resolve("test-idx-2"); |
1261 | | - Path testIndex2Shard0 = testIndex2.resolve("0"); |
1262 | | - IOUtils.deleteFilesIgnoringExceptions(testIndex1.resolve("snapshot-test-snap-1")); |
1263 | | - IOUtils.deleteFilesIgnoringExceptions(testIndex2Shard0.resolve("snapshot-test-snap-1")); |
| 1268 | + for (String index : indices) { |
| 1269 | + Path shardZero = indicesPath.resolve(indexIds.get(index).getId()).resolve("0"); |
| 1270 | + if (randomBoolean()) { |
| 1271 | + Files.delete(shardZero.resolve("index-0")); |
| 1272 | + } |
| 1273 | + Files.delete(shardZero.resolve("snap-" + snapshotInfo.snapshotId().getUUID() + ".dat")); |
| 1274 | + } |
1264 | 1275 |
|
1265 | 1276 | logger.info("--> delete snapshot"); |
1266 | 1277 | client.admin().cluster().prepareDeleteSnapshot("test-repo", "test-snap-1").get(); |
1267 | 1278 |
|
1268 | 1279 | logger.info("--> make sure snapshot doesn't exist"); |
1269 | 1280 | assertThrows(client.admin().cluster().prepareGetSnapshots("test-repo").addSnapshots("test-snap-1"), SnapshotMissingException.class); |
| 1281 | + |
| 1282 | + for (String index : indices) { |
| 1283 | + assertTrue(Files.notExists(indicesPath.resolve(indexIds.get(index).getId()))); |
| 1284 | + } |
1270 | 1285 | } |
1271 | 1286 |
|
1272 | 1287 | public void testDeleteSnapshotWithMissingMetadata() throws Exception { |
@@ -1420,9 +1435,13 @@ public void testSnapshotWithMissingShardLevelIndexFile() throws Exception { |
1420 | 1435 |
|
1421 | 1436 | logger.info("--> deleting shard level index file"); |
1422 | 1437 | try (Stream<Path> files = Files.list(repo.resolve("indices"))) { |
1423 | | - files.forEach(indexPath -> |
1424 | | - IOUtils.deleteFilesIgnoringExceptions(indexPath.resolve("0").resolve("index-0")) |
1425 | | - ); |
| 1438 | + files.forEach(indexPath -> { |
| 1439 | + try { |
| 1440 | + Files.delete(indexPath.resolve("0").resolve("index-0")); |
| 1441 | + } catch (IOException e) { |
| 1442 | + throw new RuntimeException("Failed to delete expected file", e); |
| 1443 | + } |
| 1444 | + }); |
1426 | 1445 | } |
1427 | 1446 |
|
1428 | 1447 | logger.info("--> creating another snapshot"); |
|
0 commit comments