Skip to content

Commit 3227d08

Browse files
author
AnnTian Shao
committed
fixes and move tests to RestoreSnapshotIT
Signed-off-by: AnnTian Shao <[email protected]>
1 parent dc281ce commit 3227d08

File tree

5 files changed

+399
-636
lines changed

5 files changed

+399
-636
lines changed

server/src/internalClusterTest/java/org/opensearch/remotestore/RemoteRestoreSnapshotIT.java

Lines changed: 1 addition & 306 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
package org.opensearch.remotestore;
1010

11-
import org.opensearch.Version;
1211
import org.opensearch.action.DocWriteResponse;
1312
import org.opensearch.action.LatchedActionListener;
1413
import org.opensearch.action.admin.cluster.remotestore.restore.RestoreRemoteStoreRequest;
@@ -51,7 +50,6 @@
5150
import org.opensearch.repositories.blobstore.BlobStoreRepository;
5251
import org.opensearch.repositories.fs.FsRepository;
5352
import org.opensearch.snapshots.SnapshotInfo;
54-
import org.opensearch.snapshots.SnapshotRestoreException;
5553
import org.opensearch.snapshots.SnapshotState;
5654
import org.opensearch.test.InternalTestCluster;
5755
import org.opensearch.test.OpenSearchIntegTestCase;
@@ -494,7 +492,7 @@ public void testRemoteRestoreIndexRestoredFromSnapshot() throws IOException, Exe
494492
assertDocsPresentInIndex(client(), indexName1, numDocsInIndex1);
495493
}
496494

497-
public void testIndexRestoredFromSnapshotWithUpdateSetting() throws IOException, ExecutionException, InterruptedException {
495+
public void testSuccessfulIndexRestoredFromSnapshotWithUpdatedSetting() throws IOException, ExecutionException, InterruptedException {
498496
internalCluster().startClusterManagerOnlyNode();
499497
internalCluster().startDataOnlyNodes(2);
500498

@@ -710,309 +708,6 @@ public void testRestoreShallowSnapshotIndexAfterSnapshot() throws ExecutionExcep
710708
assertDocsPresentInIndex(client, restoredIndexName1, numDocsInIndex1 + 2);
711709
}
712710

713-
public void testInvalidRestoreRequestScenarios() throws Exception {
714-
internalCluster().startClusterManagerOnlyNode();
715-
internalCluster().startDataOnlyNode();
716-
String index = "test-index";
717-
String snapshotRepo = "test-restore-snapshot-repo";
718-
String newRemoteStoreRepo = "test-new-rs-repo";
719-
String snapshotName1 = "test-restore-snapshot1";
720-
String snapshotName2 = "test-restore-snapshot2";
721-
Path absolutePath1 = randomRepoPath().toAbsolutePath();
722-
logger.info("Snapshot Path [{}]", absolutePath1);
723-
String restoredIndex = index + "-restored";
724-
725-
createRepository(snapshotRepo, "fs", getRepositorySettings(absolutePath1, true));
726-
727-
Client client = client();
728-
Settings indexSettings = getIndexSettings(1, 0).build();
729-
createIndex(index, indexSettings);
730-
731-
final int numDocsInIndex = 5;
732-
indexDocuments(client, index, numDocsInIndex);
733-
ensureGreen(index);
734-
735-
internalCluster().startDataOnlyNode();
736-
logger.info("--> snapshot");
737-
738-
SnapshotInfo snapshotInfo = createSnapshot(snapshotRepo, snapshotName1, new ArrayList<>(List.of(index)));
739-
assertThat(snapshotInfo.state(), equalTo(SnapshotState.SUCCESS));
740-
assertThat(snapshotInfo.successfulShards(), greaterThan(0));
741-
assertThat(snapshotInfo.successfulShards(), equalTo(snapshotInfo.totalShards()));
742-
743-
updateRepository(snapshotRepo, "fs", getRepositorySettings(absolutePath1, false));
744-
SnapshotInfo snapshotInfo2 = createSnapshot(snapshotRepo, snapshotName2, new ArrayList<>(List.of(index)));
745-
assertThat(snapshotInfo2.state(), equalTo(SnapshotState.SUCCESS));
746-
assertThat(snapshotInfo2.successfulShards(), greaterThan(0));
747-
assertThat(snapshotInfo2.successfulShards(), equalTo(snapshotInfo2.totalShards()));
748-
749-
DeleteResponse deleteResponse = client().prepareDelete(index, "0").execute().actionGet();
750-
assertEquals(deleteResponse.getResult(), DocWriteResponse.Result.DELETED);
751-
indexDocuments(client, index, numDocsInIndex, numDocsInIndex + randomIntBetween(2, 5));
752-
ensureGreen(index);
753-
754-
// try index restore with USER_UNREMOVABLE_SETTINGS setting disabled
755-
SnapshotRestoreException exception = expectThrows(
756-
SnapshotRestoreException.class,
757-
() -> client().admin()
758-
.cluster()
759-
.prepareRestoreSnapshot(snapshotRepo, snapshotName1)
760-
.setWaitForCompletion(false)
761-
.setIgnoreIndexSettings(IndexMetadata.SETTING_REMOTE_STORE_ENABLED)
762-
.setIndices(index)
763-
.setRenamePattern(index)
764-
.setRenameReplacement(restoredIndex)
765-
.get()
766-
);
767-
assertTrue(exception.getMessage().contains("cannot remove setting [index.remote_store.enabled] on restore"));
768-
769-
// try index restore with UnmodifiableOnRestore setting disabled
770-
exception = expectThrows(
771-
SnapshotRestoreException.class,
772-
() -> client().admin()
773-
.cluster()
774-
.prepareRestoreSnapshot(snapshotRepo, snapshotName1)
775-
.setWaitForCompletion(false)
776-
.setIgnoreIndexSettings(IndexMetadata.SETTING_NUMBER_OF_SHARDS)
777-
.setIndices(index)
778-
.setRenamePattern(index)
779-
.setRenameReplacement(restoredIndex)
780-
.get()
781-
);
782-
assertTrue(exception.getMessage().contains("cannot remove UnmodifiableOnRestore setting [index.number_of_shards] on restore"));
783-
784-
// try index restore with mix of removable and UnmodifiableOnRestore settings disabled
785-
// index.version.created is UnmodifiableOnRestore, index.number_of_search_only_replicas is removable
786-
exception = expectThrows(
787-
SnapshotRestoreException.class,
788-
() -> client().admin()
789-
.cluster()
790-
.prepareRestoreSnapshot(snapshotRepo, snapshotName1)
791-
.setWaitForCompletion(false)
792-
.setIgnoreIndexSettings(IndexMetadata.SETTING_VERSION_CREATED, IndexMetadata.SETTING_NUMBER_OF_SEARCH_REPLICAS)
793-
.setIndices(index)
794-
.setRenamePattern(index)
795-
.setRenameReplacement(restoredIndex)
796-
.get()
797-
);
798-
assertTrue(exception.getMessage().contains("cannot remove UnmodifiableOnRestore setting [index.version.created] on restore"));
799-
800-
// try index restore with mix of removable and USER_UNREMOVABLE_SETTINGS settings disabled
801-
// index.number_of_replicas is USER_UNREMOVABLE_SETTINGS, index.number_of_search_only_replicas is removable
802-
exception = expectThrows(
803-
SnapshotRestoreException.class,
804-
() -> client().admin()
805-
.cluster()
806-
.prepareRestoreSnapshot(snapshotRepo, snapshotName1)
807-
.setWaitForCompletion(false)
808-
.setIgnoreIndexSettings(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, IndexMetadata.SETTING_NUMBER_OF_SEARCH_REPLICAS)
809-
.setIndices(index)
810-
.setRenamePattern(index)
811-
.setRenameReplacement(restoredIndex)
812-
.get()
813-
);
814-
assertTrue(exception.getMessage().contains("cannot remove setting [index.number_of_replicas] on restore"));
815-
816-
// try index restore with multiple UnmodifiableOnRestore settings disabled
817-
exception = expectThrows(
818-
SnapshotRestoreException.class,
819-
() -> client().admin()
820-
.cluster()
821-
.prepareRestoreSnapshot(snapshotRepo, snapshotName1)
822-
.setWaitForCompletion(false)
823-
.setIgnoreIndexSettings(IndexMetadata.SETTING_NUMBER_OF_SHARDS, IndexMetadata.SETTING_VERSION_CREATED)
824-
.setIndices(index)
825-
.setRenamePattern(index)
826-
.setRenameReplacement(restoredIndex)
827-
.get()
828-
);
829-
assertTrue(exception.getMessage().contains("cannot remove UnmodifiableOnRestore setting [index.number_of_shards]" + " on restore"));
830-
831-
// try index restore with multiple USER_UNREMOVABLE_SETTINGS settings disabled
832-
exception = expectThrows(
833-
SnapshotRestoreException.class,
834-
() -> client().admin()
835-
.cluster()
836-
.prepareRestoreSnapshot(snapshotRepo, snapshotName1)
837-
.setWaitForCompletion(false)
838-
.setIgnoreIndexSettings(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, IndexMetadata.SETTING_AUTO_EXPAND_REPLICAS)
839-
.setIndices(index)
840-
.setRenamePattern(index)
841-
.setRenameReplacement(restoredIndex)
842-
.get()
843-
);
844-
assertTrue(exception.getMessage().contains("cannot remove setting [index.number_of_replicas]" + " on restore"));
845-
846-
// try index restore with mix of UnmodifiableOnRestore and USER_UNREMOVABLE_SETTINGS settings disabled
847-
exception = expectThrows(
848-
SnapshotRestoreException.class,
849-
() -> client().admin()
850-
.cluster()
851-
.prepareRestoreSnapshot(snapshotRepo, snapshotName1)
852-
.setWaitForCompletion(false)
853-
.setIgnoreIndexSettings(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, IndexMetadata.SETTING_NUMBER_OF_SHARDS)
854-
.setIndices(index)
855-
.setRenamePattern(index)
856-
.setRenameReplacement(restoredIndex)
857-
.get()
858-
);
859-
assertTrue(exception.getMessage().contains("cannot remove setting [index.number_of_replicas]" + " on restore"));
860-
861-
// try index restore with UnmodifiableOnRestore setting modified
862-
Settings numberOfShardsSettingsDiff = Settings.builder().put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 3).build();
863-
864-
exception = expectThrows(
865-
SnapshotRestoreException.class,
866-
() -> client().admin()
867-
.cluster()
868-
.prepareRestoreSnapshot(snapshotRepo, snapshotName1)
869-
.setWaitForCompletion(false)
870-
.setIndexSettings(numberOfShardsSettingsDiff)
871-
.setIndices(index)
872-
.setRenamePattern(index)
873-
.setRenameReplacement(restoredIndex)
874-
.get()
875-
);
876-
assertTrue(exception.getMessage().contains("cannot modify UnmodifiableOnRestore setting [index.number_of_shards]" + " on restore"));
877-
878-
// try index restore with UnmodifiableOnRestore setting same
879-
Settings numberOfShardsSettingsSame = Settings.builder().put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1).build();
880-
881-
exception = expectThrows(
882-
SnapshotRestoreException.class,
883-
() -> client().admin()
884-
.cluster()
885-
.prepareRestoreSnapshot(snapshotRepo, snapshotName1)
886-
.setWaitForCompletion(false)
887-
.setIndexSettings(numberOfShardsSettingsSame)
888-
.setIndices(index)
889-
.setRenamePattern(index)
890-
.setRenameReplacement(restoredIndex)
891-
.get()
892-
);
893-
assertTrue(exception.getMessage().contains("cannot modify UnmodifiableOnRestore setting [index.number_of_shards]" + " on restore"));
894-
895-
// try index restore with USER_UNMODIFIABLE_SETTINGS setting modified
896-
Settings remoteStoreEnabledSetting = Settings.builder().put(IndexMetadata.SETTING_REMOTE_STORE_ENABLED, false).build();
897-
898-
exception = expectThrows(
899-
SnapshotRestoreException.class,
900-
() -> client().admin()
901-
.cluster()
902-
.prepareRestoreSnapshot(snapshotRepo, snapshotName1)
903-
.setWaitForCompletion(false)
904-
.setIndexSettings(remoteStoreEnabledSetting)
905-
.setIndices(index)
906-
.setRenamePattern(index)
907-
.setRenameReplacement(restoredIndex)
908-
.get()
909-
);
910-
assertTrue(exception.getMessage().contains("cannot modify setting [index.remote_store.enabled]" + " on restore"));
911-
912-
// try index restore with mix of modifiable and UnmodifiableOnRestore settings modified
913-
// index.version.created is UnmodifiableOnRestore, index.number_of_search_only_replicas is modifiable
914-
Settings mixedSettingsUnmodifiableOnRestore = Settings.builder()
915-
.put(IndexMetadata.SETTING_VERSION_CREATED, Version.V_EMPTY)
916-
.put(IndexMetadata.SETTING_NUMBER_OF_SEARCH_REPLICAS, 1)
917-
.build();
918-
919-
exception = expectThrows(
920-
SnapshotRestoreException.class,
921-
() -> client().admin()
922-
.cluster()
923-
.prepareRestoreSnapshot(snapshotRepo, snapshotName1)
924-
.setWaitForCompletion(false)
925-
.setIndexSettings(mixedSettingsUnmodifiableOnRestore)
926-
.setIndices(index)
927-
.setRenamePattern(index)
928-
.setRenameReplacement(restoredIndex)
929-
.get()
930-
);
931-
assertTrue(exception.getMessage().contains("cannot modify UnmodifiableOnRestore setting [index.version.created]" + " on restore"));
932-
933-
// try index restore with mix of modifiable and USER_UNMODIFIABLE_SETTINGS settings modified
934-
// index.remote_store.enabled is USER_UNMODIFIABLE_SETTINGS, index.number_of_search_only_replicas is modifiable
935-
Settings mixedSettingsUserUnmodifiableSettings = Settings.builder()
936-
.put(IndexMetadata.SETTING_REMOTE_STORE_ENABLED, false)
937-
.put(IndexMetadata.SETTING_NUMBER_OF_SEARCH_REPLICAS, 1)
938-
.build();
939-
940-
exception = expectThrows(
941-
SnapshotRestoreException.class,
942-
() -> client().admin()
943-
.cluster()
944-
.prepareRestoreSnapshot(snapshotRepo, snapshotName1)
945-
.setWaitForCompletion(false)
946-
.setIndexSettings(mixedSettingsUserUnmodifiableSettings)
947-
.setIndices(index)
948-
.setRenamePattern(index)
949-
.setRenameReplacement(restoredIndex)
950-
.get()
951-
);
952-
assertTrue(exception.getMessage().contains("cannot modify setting [index.remote_store.enabled]" + " on restore"));
953-
954-
// try index restore with mix of UnmodifiableOnRestore and USER_UNMODIFIABLE_SETTINGS settings modified
955-
// index.remote_store.enabled is USER_UNMODIFIABLE_SETTINGS, index.version.created is UnmodifiableOnRestore
956-
Settings mixedSettings = Settings.builder()
957-
.put(IndexMetadata.SETTING_REMOTE_STORE_ENABLED, false)
958-
.put(IndexMetadata.SETTING_VERSION_CREATED, Version.V_EMPTY)
959-
.build();
960-
961-
exception = expectThrows(
962-
SnapshotRestoreException.class,
963-
() -> client().admin()
964-
.cluster()
965-
.prepareRestoreSnapshot(snapshotRepo, snapshotName1)
966-
.setWaitForCompletion(false)
967-
.setIndexSettings(mixedSettings)
968-
.setIndices(index)
969-
.setRenamePattern(index)
970-
.setRenameReplacement(restoredIndex)
971-
.get()
972-
);
973-
assertTrue(exception.getMessage().contains("cannot modify setting [index.remote_store.enabled]" + " on restore"));
974-
975-
// try index restore with multiple UnmodifiableOnRestore settings modified
976-
Settings unmodifiableOnRestoreSettings = Settings.builder()
977-
.put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1)
978-
.put(IndexMetadata.SETTING_VERSION_CREATED, Version.V_EMPTY)
979-
.build();
980-
981-
exception = expectThrows(
982-
SnapshotRestoreException.class,
983-
() -> client().admin()
984-
.cluster()
985-
.prepareRestoreSnapshot(snapshotRepo, snapshotName1)
986-
.setWaitForCompletion(false)
987-
.setIndexSettings(unmodifiableOnRestoreSettings)
988-
.setIndices(index)
989-
.setRenamePattern(index)
990-
.setRenameReplacement(restoredIndex)
991-
.get()
992-
);
993-
assertTrue(exception.getMessage().contains("cannot modify UnmodifiableOnRestore setting [index.number_of_shards]" + " on restore"));
994-
995-
// try index restore with multiple USER_UNMODIFIABLE_SETTINGS settings modified
996-
Settings userUnmodifiableSettings = Settings.builder()
997-
.put(IndexMetadata.SETTING_REMOTE_STORE_ENABLED, false)
998-
.put(IndexMetadata.SETTING_NUMBER_OF_SEARCH_REPLICAS, 1)
999-
.build();
1000-
1001-
exception = expectThrows(
1002-
SnapshotRestoreException.class,
1003-
() -> client().admin()
1004-
.cluster()
1005-
.prepareRestoreSnapshot(snapshotRepo, snapshotName1)
1006-
.setWaitForCompletion(false)
1007-
.setIndexSettings(userUnmodifiableSettings)
1008-
.setIndices(index)
1009-
.setRenamePattern(index)
1010-
.setRenameReplacement(restoredIndex)
1011-
.get()
1012-
);
1013-
assertTrue(exception.getMessage().contains("cannot modify setting [index.remote_store.enabled]" + " on restore"));
1014-
}
1015-
1016711
public void testCreateSnapshotV2_Orphan_Timestamp_Cleanup() throws Exception {
1017712
internalCluster().startClusterManagerOnlyNode(pinnedTimestampSettings());
1018713
internalCluster().startDataOnlyNode(pinnedTimestampSettings());

0 commit comments

Comments
 (0)