|
43 | 43 | import java.nio.file.Path;
|
44 | 44 | import java.util.ArrayList;
|
45 | 45 | import java.util.Arrays;
|
| 46 | +import java.util.List; |
46 | 47 | import java.util.Optional;
|
47 | 48 | import java.util.concurrent.ExecutionException;
|
48 | 49 | import java.util.stream.Collectors;
|
@@ -617,4 +618,71 @@ public void testRestoreShallowSnapshotRepository() throws ExecutionException, In
|
617 | 618 | assertDocsPresentInIndex(client, restoredIndexName1, numDocsInIndex1 + 2);
|
618 | 619 | }
|
619 | 620 |
|
| 621 | + public void testRestoreShallowSnapshotIndexAfterSnapshot() throws ExecutionException, InterruptedException { |
| 622 | + String indexName1 = "testindex1"; |
| 623 | + String snapshotRepoName = "test-restore-snapshot-repo"; |
| 624 | + String remoteStoreRepoNameUpdated = "test-rs-repo-updated" + TEST_REMOTE_STORE_REPO_SUFFIX; |
| 625 | + String snapshotName1 = "test-restore-snapshot1"; |
| 626 | + Path absolutePath1 = randomRepoPath().toAbsolutePath(); |
| 627 | + Path absolutePath2 = randomRepoPath().toAbsolutePath(); |
| 628 | + String[] pathTokens = absolutePath1.toString().split("/"); |
| 629 | + String basePath = pathTokens[pathTokens.length - 1]; |
| 630 | + Arrays.copyOf(pathTokens, pathTokens.length - 1); |
| 631 | + Path location = PathUtils.get(String.join("/", pathTokens)); |
| 632 | + pathTokens = absolutePath2.toString().split("/"); |
| 633 | + String basePath2 = pathTokens[pathTokens.length - 1]; |
| 634 | + Arrays.copyOf(pathTokens, pathTokens.length - 1); |
| 635 | + Path location2 = PathUtils.get(String.join("/", pathTokens)); |
| 636 | + logger.info("Path 1 [{}]", absolutePath1); |
| 637 | + logger.info("Path 2 [{}]", absolutePath2); |
| 638 | + String restoredIndexName1 = indexName1 + "-restored"; |
| 639 | + |
| 640 | + createRepository(snapshotRepoName, "fs", getRepositorySettings(location, basePath, true)); |
| 641 | + |
| 642 | + Client client = client(); |
| 643 | + Settings indexSettings = Settings.builder() |
| 644 | + .put(super.indexSettings()) |
| 645 | + .put(IndexMetadata.SETTING_REPLICATION_TYPE, ReplicationType.SEGMENT) |
| 646 | + .put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1) |
| 647 | + .put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0) |
| 648 | + .build(); |
| 649 | + createIndex(indexName1, indexSettings); |
| 650 | + |
| 651 | + int numDocsInIndex1 = randomIntBetween(2, 5); |
| 652 | + indexDocuments(client, indexName1, numDocsInIndex1); |
| 653 | + |
| 654 | + ensureGreen(indexName1); |
| 655 | + |
| 656 | + logger.info("--> snapshot"); |
| 657 | + SnapshotInfo snapshotInfo1 = createSnapshot(snapshotRepoName, snapshotName1, new ArrayList<>(List.of(indexName1))); |
| 658 | + assertThat(snapshotInfo1.successfulShards(), greaterThan(0)); |
| 659 | + assertThat(snapshotInfo1.successfulShards(), equalTo(snapshotInfo1.totalShards())); |
| 660 | + assertThat(snapshotInfo1.state(), equalTo(SnapshotState.SUCCESS)); |
| 661 | + |
| 662 | + int extraNumDocsInIndex1 = randomIntBetween(20, 50); |
| 663 | + indexDocuments(client, indexName1, extraNumDocsInIndex1); |
| 664 | + refresh(indexName1); |
| 665 | + |
| 666 | + client().admin().indices().close(Requests.closeIndexRequest(indexName1)).get(); |
| 667 | + createRepository(remoteStoreRepoNameUpdated, "fs", remoteRepoPath); |
| 668 | + RestoreSnapshotResponse restoreSnapshotResponse2 = client.admin() |
| 669 | + .cluster() |
| 670 | + .prepareRestoreSnapshot(snapshotRepoName, snapshotName1) |
| 671 | + .setWaitForCompletion(true) |
| 672 | + .setIndices(indexName1) |
| 673 | + .setRenamePattern(indexName1) |
| 674 | + .setRenameReplacement(restoredIndexName1) |
| 675 | + .setSourceRemoteStoreRepository(remoteStoreRepoNameUpdated) |
| 676 | + .get(); |
| 677 | + |
| 678 | + assertTrue(restoreSnapshotResponse2.getRestoreInfo().failedShards() == 0); |
| 679 | + ensureGreen(restoredIndexName1); |
| 680 | + assertDocsPresentInIndex(client, restoredIndexName1, numDocsInIndex1); |
| 681 | + |
| 682 | + // indexing some new docs and validating |
| 683 | + indexDocuments(client, restoredIndexName1, numDocsInIndex1, numDocsInIndex1 + 2); |
| 684 | + ensureGreen(restoredIndexName1); |
| 685 | + assertDocsPresentInIndex(client, restoredIndexName1, numDocsInIndex1 + 2); |
| 686 | + } |
| 687 | + |
620 | 688 | }
|
0 commit comments