|
85 | 85 | import org.elasticsearch.plugins.Plugin;
|
86 | 86 | import org.elasticsearch.repositories.IndexId;
|
87 | 87 | import org.elasticsearch.repositories.RepositoriesService;
|
| 88 | +import org.elasticsearch.repositories.Repository; |
88 | 89 | import org.elasticsearch.repositories.RepositoryData;
|
89 | 90 | import org.elasticsearch.repositories.RepositoryException;
|
90 | 91 | import org.elasticsearch.script.MockScriptEngine;
|
91 | 92 | import org.elasticsearch.script.StoredScriptsIT;
|
92 | 93 | import org.elasticsearch.snapshots.mockstore.MockRepository;
|
93 | 94 | import org.elasticsearch.test.junit.annotations.TestLogging;
|
94 | 95 |
|
| 96 | +import java.io.IOException; |
95 | 97 | import java.nio.channels.SeekableByteChannel;
|
96 | 98 | import java.nio.file.Files;
|
97 | 99 | import java.nio.file.Path;
|
@@ -1241,30 +1243,44 @@ public void testDeleteSnapshotWithMissingIndexAndShardMetadata() throws Exceptio
|
1241 | 1243 | .put("compress", false)
|
1242 | 1244 | .put("chunk_size", randomIntBetween(100, 1000), ByteSizeUnit.BYTES)));
|
1243 | 1245 |
|
1244 |
| - createIndex("test-idx-1", "test-idx-2"); |
| 1246 | + final String[] indices = {"test-idx-1", "test-idx-2"}; |
| 1247 | + createIndex(indices); |
1245 | 1248 | logger.info("--> indexing some data");
|
1246 | 1249 | indexRandom(true,
|
1247 | 1250 | client().prepareIndex("test-idx-1", "_doc").setSource("foo", "bar"),
|
1248 | 1251 | client().prepareIndex("test-idx-2", "_doc").setSource("foo", "bar"));
|
1249 | 1252 |
|
1250 | 1253 | logger.info("--> creating snapshot");
|
1251 |
| - CreateSnapshotResponse createSnapshotResponse = client.admin().cluster().prepareCreateSnapshot("test-repo", "test-snap-1").setWaitForCompletion(true).setIndices("test-idx-*").get(); |
1252 |
| - assertThat(createSnapshotResponse.getSnapshotInfo().successfulShards(), greaterThan(0)); |
1253 |
| - assertThat(createSnapshotResponse.getSnapshotInfo().successfulShards(), equalTo(createSnapshotResponse.getSnapshotInfo().totalShards())); |
| 1254 | + CreateSnapshotResponse createSnapshotResponse = client.admin().cluster().prepareCreateSnapshot("test-repo", "test-snap-1") |
| 1255 | + .setWaitForCompletion(true).setIndices(indices).get(); |
| 1256 | + final SnapshotInfo snapshotInfo = createSnapshotResponse.getSnapshotInfo(); |
| 1257 | + assertThat(snapshotInfo.successfulShards(), greaterThan(0)); |
| 1258 | + assertThat(snapshotInfo.successfulShards(), equalTo(snapshotInfo.totalShards())); |
| 1259 | + |
| 1260 | + RepositoriesService service = internalCluster().getInstance(RepositoriesService.class, internalCluster().getMasterName()); |
| 1261 | + Repository repository = service.repository("test-repo"); |
| 1262 | + |
| 1263 | + final Map<String, IndexId> indexIds = repository.getRepositoryData().getIndices(); |
| 1264 | + final Path indicesPath = repo.resolve("indices"); |
1254 | 1265 |
|
1255 | 1266 | logger.info("--> delete index metadata and shard metadata");
|
1256 |
| - Path indices = repo.resolve("indices"); |
1257 |
| - Path testIndex1 = indices.resolve("test-idx-1"); |
1258 |
| - Path testIndex2 = indices.resolve("test-idx-2"); |
1259 |
| - Path testIndex2Shard0 = testIndex2.resolve("0"); |
1260 |
| - IOUtils.deleteFilesIgnoringExceptions(testIndex1.resolve("snapshot-test-snap-1")); |
1261 |
| - IOUtils.deleteFilesIgnoringExceptions(testIndex2Shard0.resolve("snapshot-test-snap-1")); |
| 1267 | + for (String index : indices) { |
| 1268 | + Path shardZero = indicesPath.resolve(indexIds.get(index).getId()).resolve("0"); |
| 1269 | + if (randomBoolean()) { |
| 1270 | + Files.delete(shardZero.resolve("index-0")); |
| 1271 | + } |
| 1272 | + Files.delete(shardZero.resolve("snap-" + snapshotInfo.snapshotId().getUUID() + ".dat")); |
| 1273 | + } |
1262 | 1274 |
|
1263 | 1275 | logger.info("--> delete snapshot");
|
1264 | 1276 | client.admin().cluster().prepareDeleteSnapshot("test-repo", "test-snap-1").get();
|
1265 | 1277 |
|
1266 | 1278 | logger.info("--> make sure snapshot doesn't exist");
|
1267 | 1279 | assertThrows(client.admin().cluster().prepareGetSnapshots("test-repo").addSnapshots("test-snap-1"), SnapshotMissingException.class);
|
| 1280 | + |
| 1281 | + for (String index : indices) { |
| 1282 | + assertTrue(Files.notExists(indicesPath.resolve(indexIds.get(index).getId()))); |
| 1283 | + } |
1268 | 1284 | }
|
1269 | 1285 |
|
1270 | 1286 | public void testDeleteSnapshotWithMissingMetadata() throws Exception {
|
@@ -1357,9 +1373,13 @@ public void testSnapshotWithMissingShardLevelIndexFile() throws Exception {
|
1357 | 1373 |
|
1358 | 1374 | logger.info("--> deleting shard level index file");
|
1359 | 1375 | try (Stream<Path> files = Files.list(repo.resolve("indices"))) {
|
1360 |
| - files.forEach(indexPath -> |
1361 |
| - IOUtils.deleteFilesIgnoringExceptions(indexPath.resolve("0").resolve("index-0")) |
1362 |
| - ); |
| 1376 | + files.forEach(indexPath -> { |
| 1377 | + try { |
| 1378 | + Files.delete(indexPath.resolve("0").resolve("index-0")); |
| 1379 | + } catch (IOException e) { |
| 1380 | + throw new RuntimeException("Failed to delete expected file", e); |
| 1381 | + } |
| 1382 | + }); |
1363 | 1383 | }
|
1364 | 1384 |
|
1365 | 1385 | logger.info("--> creating another snapshot");
|
|
0 commit comments