|
9 | 9 | package org.opensearch.snapshots;
|
10 | 10 |
|
11 | 11 | import org.opensearch.action.admin.cluster.snapshots.create.CreateSnapshotResponse;
|
| 12 | +import org.opensearch.action.admin.cluster.snapshots.restore.RestoreSnapshotResponse; |
12 | 13 | import org.opensearch.action.support.PlainActionFuture;
|
13 | 14 | import org.opensearch.action.support.master.AcknowledgedResponse;
|
14 | 15 | import org.opensearch.client.Client;
|
15 | 16 | import org.opensearch.common.action.ActionFuture;
|
16 | 17 | import org.opensearch.common.settings.Settings;
|
17 | 18 | import org.opensearch.common.unit.TimeValue;
|
18 | 19 | import org.opensearch.core.common.unit.ByteSizeUnit;
|
| 20 | +import org.opensearch.core.rest.RestStatus; |
19 | 21 | import org.opensearch.remotestore.RemoteSnapshotIT;
|
20 | 22 | import org.opensearch.repositories.RepositoriesService;
|
21 | 23 | import org.opensearch.repositories.Repository;
|
@@ -479,7 +481,6 @@ public void testCloneSnapshotV2MasterSwitch() throws Exception {
|
479 | 481 | assertThat(snapInfo, containsInAnyOrder(csr.getSnapshotInfo(), csr2.getSnapshotInfo()));
|
480 | 482 | }
|
481 | 483 |
|
482 |
| - @AwaitsFix(bugUrl = "https://github.com/opensearch-project/OpenSearch/pull/16191") |
483 | 484 | public void testDeleteWhileV2CreateOngoing() throws Exception {
|
484 | 485 | final String clusterManagerName = internalCluster().startClusterManagerOnlyNode(pinnedTimestampSettings());
|
485 | 486 | internalCluster().startDataOnlyNode(pinnedTimestampSettings());
|
@@ -538,7 +539,7 @@ public void testDeleteWhileV2CreateOngoing() throws Exception {
|
538 | 539 | assertThat(snapInfo, contains(csr.getSnapshotInfo()));
|
539 | 540 | }
|
540 | 541 |
|
541 |
| - @AwaitsFix(bugUrl = "https://github.com/opensearch-project/OpenSearch/pull/16191") |
| 542 | + @AwaitsFix(bugUrl = "https://github.com/opensearch-project/OpenSearch/issues/16205") |
542 | 543 | public void testDeleteAndCloneV1WhileV2CreateOngoing() throws Exception {
|
543 | 544 | final String clusterManagerName = internalCluster().startClusterManagerOnlyNode(pinnedTimestampSettings());
|
544 | 545 | internalCluster().startDataOnlyNode(pinnedTimestampSettings());
|
@@ -569,6 +570,7 @@ public void testDeleteAndCloneV1WhileV2CreateOngoing() throws Exception {
|
569 | 570 | indexDocuments(client, indexName1, numDocsInIndex1);
|
570 | 571 | indexDocuments(client, indexName2, numDocsInIndex2);
|
571 | 572 | ensureGreen(indexName1, indexName2);
|
| 573 | + ensureGreen(); |
572 | 574 |
|
573 | 575 | startFullSnapshot(repoName, "snapshot-v1").actionGet();
|
574 | 576 | startFullSnapshot(repoName, "snapshot-v1-2").actionGet();
|
@@ -597,6 +599,148 @@ public void testDeleteAndCloneV1WhileV2CreateOngoing() throws Exception {
|
597 | 599 | assertTrue(startCloneSnapshot.actionGet().isAcknowledged());
|
598 | 600 | List<SnapshotInfo> snapInfo = client().admin().cluster().prepareGetSnapshots(repoName).get().getSnapshots();
|
599 | 601 | assertEquals(3, snapInfo.size());
|
| 602 | + |
| 603 | + RestoreSnapshotResponse restoreSnapshotResponse = client.admin() |
| 604 | + .cluster() |
| 605 | + .prepareRestoreSnapshot(repoName, "snapshot-v1-2-clone") |
| 606 | + .setWaitForCompletion(true) |
| 607 | + .setIndices(indexName1) |
| 608 | + .setRenamePattern("(.+)") |
| 609 | + .setRenameReplacement("$1-copy") |
| 610 | + .get(); |
| 611 | + assertEquals(restoreSnapshotResponse.status(), RestStatus.OK); |
| 612 | + ensureGreen(); |
| 613 | + } |
| 614 | + |
| 615 | + @AwaitsFix(bugUrl = "https://github.com/opensearch-project/OpenSearch/issues/16205") |
| 616 | + public void testDeleteAndCloneV1WhileCreateOngoing() throws Exception { |
| 617 | + final String clusterManagerName = internalCluster().startClusterManagerOnlyNode(pinnedTimestampSettings()); |
| 618 | + internalCluster().startDataOnlyNode(pinnedTimestampSettings()); |
| 619 | + internalCluster().startDataOnlyNode(pinnedTimestampSettings()); |
| 620 | + String indexName1 = "testindex1"; |
| 621 | + String indexName2 = "testindex2"; |
| 622 | + String repoName = "test-create-snapshot-repo"; |
| 623 | + Path absolutePath1 = randomRepoPath().toAbsolutePath(); |
| 624 | + logger.info("Snapshot Path [{}]", absolutePath1); |
| 625 | + |
| 626 | + Settings.Builder settings = Settings.builder() |
| 627 | + .put(FsRepository.LOCATION_SETTING.getKey(), absolutePath1) |
| 628 | + .put(FsRepository.COMPRESS_SETTING.getKey(), randomBoolean()) |
| 629 | + .put(FsRepository.CHUNK_SIZE_SETTING.getKey(), randomIntBetween(100, 1000), ByteSizeUnit.BYTES) |
| 630 | + .put(BlobStoreRepository.REMOTE_STORE_INDEX_SHALLOW_COPY.getKey(), true) |
| 631 | + .put(BlobStoreRepository.SHALLOW_SNAPSHOT_V2.getKey(), false); |
| 632 | + createRepository(repoName, "mock", settings); |
| 633 | + |
| 634 | + Client client = client(); |
| 635 | + Settings indexSettings = getIndexSettings(10, 0).build(); |
| 636 | + createIndex(indexName1, indexSettings); |
| 637 | + |
| 638 | + Settings indexSettings2 = getIndexSettings(15, 0).build(); |
| 639 | + createIndex(indexName2, indexSettings2); |
| 640 | + |
| 641 | + final int numDocsInIndex1 = 10; |
| 642 | + final int numDocsInIndex2 = 20; |
| 643 | + indexDocuments(client, indexName1, numDocsInIndex1); |
| 644 | + indexDocuments(client, indexName2, numDocsInIndex2); |
| 645 | + ensureGreen(indexName1, indexName2); |
| 646 | + |
| 647 | + startFullSnapshot(repoName, "snapshot-v1").actionGet(); |
| 648 | + startFullSnapshot(repoName, "snapshot-v1-2").actionGet(); |
| 649 | + |
| 650 | + blockClusterManagerOnWriteIndexFile(repoName); |
| 651 | + |
| 652 | + final ActionFuture<CreateSnapshotResponse> snapshotFuture = startFullSnapshot(repoName, "snapshot-v2"); |
| 653 | + awaitNumberOfSnapshotsInProgress(1); |
| 654 | + |
| 655 | + ActionFuture<AcknowledgedResponse> startDeleteSnapshot = startDeleteSnapshot(repoName, "snapshot-v1"); |
| 656 | + ActionFuture<AcknowledgedResponse> startCloneSnapshot = startCloneSnapshot(repoName, "snapshot-v1-2", "snapshot-v1-2-clone"); |
| 657 | + |
| 658 | + unblockNode(repoName, clusterManagerName); |
| 659 | + snapshotFuture.actionGet(); |
| 660 | + assertTrue(startDeleteSnapshot.actionGet().isAcknowledged()); |
| 661 | + assertTrue(startCloneSnapshot.actionGet().isAcknowledged()); |
| 662 | + List<SnapshotInfo> snapInfo = client().admin().cluster().prepareGetSnapshots(repoName).get().getSnapshots(); |
| 663 | + assertEquals(3, snapInfo.size()); |
| 664 | + |
| 665 | + RestoreSnapshotResponse restoreSnapshotResponse = client.admin() |
| 666 | + .cluster() |
| 667 | + .prepareRestoreSnapshot(repoName, "snapshot-v1-2-clone") |
| 668 | + .setWaitForCompletion(true) |
| 669 | + .setIndices(indexName1) |
| 670 | + .setRenamePattern("(.+)") |
| 671 | + .setRenameReplacement("$1-copy") |
| 672 | + .get(); |
| 673 | + assertEquals(restoreSnapshotResponse.status(), RestStatus.OK); |
| 674 | + ensureGreen(); |
| 675 | + } |
| 676 | + |
| 677 | + public void testCloneV1WhileV2CreateOngoing() throws Exception { |
| 678 | + final String clusterManagerName = internalCluster().startClusterManagerOnlyNode(pinnedTimestampSettings()); |
| 679 | + internalCluster().startDataOnlyNode(pinnedTimestampSettings()); |
| 680 | + internalCluster().startDataOnlyNode(pinnedTimestampSettings()); |
| 681 | + String indexName1 = "testindex1"; |
| 682 | + String indexName2 = "testindex2"; |
| 683 | + String repoName = "test-create-snapshot-repo"; |
| 684 | + Path absolutePath1 = randomRepoPath().toAbsolutePath(); |
| 685 | + logger.info("Snapshot Path [{}]", absolutePath1); |
| 686 | + |
| 687 | + Settings.Builder settings = Settings.builder() |
| 688 | + .put(FsRepository.LOCATION_SETTING.getKey(), absolutePath1) |
| 689 | + .put(FsRepository.COMPRESS_SETTING.getKey(), randomBoolean()) |
| 690 | + .put(FsRepository.CHUNK_SIZE_SETTING.getKey(), randomIntBetween(100, 1000), ByteSizeUnit.BYTES) |
| 691 | + .put(BlobStoreRepository.REMOTE_STORE_INDEX_SHALLOW_COPY.getKey(), true) |
| 692 | + .put(BlobStoreRepository.SHALLOW_SNAPSHOT_V2.getKey(), false); |
| 693 | + createRepository(repoName, "mock", settings); |
| 694 | + |
| 695 | + Client client = client(); |
| 696 | + Settings indexSettings = getIndexSettings(20, 0).build(); |
| 697 | + createIndex(indexName1, indexSettings); |
| 698 | + |
| 699 | + Settings indexSettings2 = getIndexSettings(15, 0).build(); |
| 700 | + createIndex(indexName2, indexSettings2); |
| 701 | + |
| 702 | + final int numDocsInIndex1 = 10; |
| 703 | + final int numDocsInIndex2 = 20; |
| 704 | + indexDocuments(client, indexName1, numDocsInIndex1); |
| 705 | + indexDocuments(client, indexName2, numDocsInIndex2); |
| 706 | + ensureGreen(indexName1, indexName2); |
| 707 | + |
| 708 | + startFullSnapshot(repoName, "snapshot-v1").actionGet(); |
| 709 | + |
| 710 | + // Creating a v2 repo |
| 711 | + settings = Settings.builder() |
| 712 | + .put(FsRepository.LOCATION_SETTING.getKey(), absolutePath1) |
| 713 | + .put(FsRepository.COMPRESS_SETTING.getKey(), randomBoolean()) |
| 714 | + .put(FsRepository.CHUNK_SIZE_SETTING.getKey(), randomIntBetween(100, 1000), ByteSizeUnit.BYTES) |
| 715 | + .put(BlobStoreRepository.REMOTE_STORE_INDEX_SHALLOW_COPY.getKey(), true) |
| 716 | + .put(BlobStoreRepository.SHALLOW_SNAPSHOT_V2.getKey(), true); |
| 717 | + createRepository(repoName, "mock", settings); |
| 718 | + |
| 719 | + blockClusterManagerOnWriteIndexFile(repoName); |
| 720 | + |
| 721 | + final ActionFuture<CreateSnapshotResponse> snapshotFuture = startFullSnapshot(repoName, "snapshot-v2"); |
| 722 | + awaitNumberOfSnapshotsInProgress(1); |
| 723 | + |
| 724 | + ActionFuture<AcknowledgedResponse> startCloneSnapshot = startCloneSnapshot(repoName, "snapshot-v1", "snapshot-v1-2-clone"); |
| 725 | + |
| 726 | + unblockNode(repoName, clusterManagerName); |
| 727 | + CreateSnapshotResponse csr = snapshotFuture.actionGet(); |
| 728 | + assertTrue(csr.getSnapshotInfo().getPinnedTimestamp() != 0); |
| 729 | + assertTrue(startCloneSnapshot.actionGet().isAcknowledged()); |
| 730 | + List<SnapshotInfo> snapInfo = client().admin().cluster().prepareGetSnapshots(repoName).get().getSnapshots(); |
| 731 | + assertEquals(3, snapInfo.size()); |
| 732 | + |
| 733 | + RestoreSnapshotResponse restoreSnapshotResponse = client.admin() |
| 734 | + .cluster() |
| 735 | + .prepareRestoreSnapshot(repoName, "snapshot-v1-2-clone") |
| 736 | + .setWaitForCompletion(true) |
| 737 | + .setIndices(indexName1) |
| 738 | + .setRenamePattern(indexName1) |
| 739 | + .setRenamePattern("(.+)") |
| 740 | + .setRenameReplacement("$1-copy") |
| 741 | + .get(); |
| 742 | + assertEquals(restoreSnapshotResponse.status(), RestStatus.OK); |
| 743 | + ensureGreen(); |
600 | 744 | }
|
601 | 745 |
|
602 | 746 | protected ActionFuture<AcknowledgedResponse> startCloneSnapshot(String repoName, String sourceSnapshotName, String snapshotName) {
|
|
0 commit comments