diff --git a/server/src/internalClusterTest/java/org/opensearch/remotestore/RemoteRestoreSnapshotIT.java b/server/src/internalClusterTest/java/org/opensearch/remotestore/RemoteRestoreSnapshotIT.java index 73de2fffb471a..8fc119d49c3d1 100644 --- a/server/src/internalClusterTest/java/org/opensearch/remotestore/RemoteRestoreSnapshotIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/remotestore/RemoteRestoreSnapshotIT.java @@ -8,7 +8,6 @@ package org.opensearch.remotestore; -import org.opensearch.Version; import org.opensearch.action.DocWriteResponse; import org.opensearch.action.LatchedActionListener; import org.opensearch.action.admin.cluster.remotestore.restore.RestoreRemoteStoreRequest; @@ -51,7 +50,6 @@ import org.opensearch.repositories.blobstore.BlobStoreRepository; import org.opensearch.repositories.fs.FsRepository; import org.opensearch.snapshots.SnapshotInfo; -import org.opensearch.snapshots.SnapshotRestoreException; import org.opensearch.snapshots.SnapshotState; import org.opensearch.test.InternalTestCluster; import org.opensearch.test.OpenSearchIntegTestCase; @@ -494,7 +492,7 @@ public void testRemoteRestoreIndexRestoredFromSnapshot() throws IOException, Exe assertDocsPresentInIndex(client(), indexName1, numDocsInIndex1); } - public void testIndexRestoredFromSnapshotWithUpdateSetting() throws IOException, ExecutionException, InterruptedException { + public void testSuccessfulIndexRestoredFromSnapshotWithUpdatedSetting() throws IOException, ExecutionException, InterruptedException { internalCluster().startClusterManagerOnlyNode(); internalCluster().startDataOnlyNodes(2); @@ -710,309 +708,6 @@ public void testRestoreShallowSnapshotIndexAfterSnapshot() throws ExecutionExcep assertDocsPresentInIndex(client, restoredIndexName1, numDocsInIndex1 + 2); } - public void testInvalidRestoreRequestScenarios() throws Exception { - internalCluster().startClusterManagerOnlyNode(); - internalCluster().startDataOnlyNode(); - String index = "test-index"; - String snapshotRepo = "test-restore-snapshot-repo"; - String newRemoteStoreRepo = "test-new-rs-repo"; - String snapshotName1 = "test-restore-snapshot1"; - String snapshotName2 = "test-restore-snapshot2"; - Path absolutePath1 = randomRepoPath().toAbsolutePath(); - logger.info("Snapshot Path [{}]", absolutePath1); - String restoredIndex = index + "-restored"; - - createRepository(snapshotRepo, "fs", getRepositorySettings(absolutePath1, true)); - - Client client = client(); - Settings indexSettings = getIndexSettings(1, 0).build(); - createIndex(index, indexSettings); - - final int numDocsInIndex = 5; - indexDocuments(client, index, numDocsInIndex); - ensureGreen(index); - - internalCluster().startDataOnlyNode(); - logger.info("--> snapshot"); - - SnapshotInfo snapshotInfo = createSnapshot(snapshotRepo, snapshotName1, new ArrayList<>(List.of(index))); - assertThat(snapshotInfo.state(), equalTo(SnapshotState.SUCCESS)); - assertThat(snapshotInfo.successfulShards(), greaterThan(0)); - assertThat(snapshotInfo.successfulShards(), equalTo(snapshotInfo.totalShards())); - - updateRepository(snapshotRepo, "fs", getRepositorySettings(absolutePath1, false)); - SnapshotInfo snapshotInfo2 = createSnapshot(snapshotRepo, snapshotName2, new ArrayList<>(List.of(index))); - assertThat(snapshotInfo2.state(), equalTo(SnapshotState.SUCCESS)); - assertThat(snapshotInfo2.successfulShards(), greaterThan(0)); - assertThat(snapshotInfo2.successfulShards(), equalTo(snapshotInfo2.totalShards())); - - DeleteResponse deleteResponse = client().prepareDelete(index, "0").execute().actionGet(); - assertEquals(deleteResponse.getResult(), DocWriteResponse.Result.DELETED); - indexDocuments(client, index, numDocsInIndex, numDocsInIndex + randomIntBetween(2, 5)); - ensureGreen(index); - - // try index restore with USER_UNREMOVABLE_SETTINGS setting disabled - SnapshotRestoreException exception = expectThrows( - SnapshotRestoreException.class, - () -> client().admin() - .cluster() - .prepareRestoreSnapshot(snapshotRepo, snapshotName1) - .setWaitForCompletion(false) - .setIgnoreIndexSettings(IndexMetadata.SETTING_REMOTE_STORE_ENABLED) - .setIndices(index) - .setRenamePattern(index) - .setRenameReplacement(restoredIndex) - .get() - ); - assertTrue(exception.getMessage().contains("cannot remove setting [index.remote_store.enabled] on restore")); - - // try index restore with UnmodifiableOnRestore setting disabled - exception = expectThrows( - SnapshotRestoreException.class, - () -> client().admin() - .cluster() - .prepareRestoreSnapshot(snapshotRepo, snapshotName1) - .setWaitForCompletion(false) - .setIgnoreIndexSettings(IndexMetadata.SETTING_NUMBER_OF_SHARDS) - .setIndices(index) - .setRenamePattern(index) - .setRenameReplacement(restoredIndex) - .get() - ); - assertTrue(exception.getMessage().contains("cannot remove UnmodifiableOnRestore setting [index.number_of_shards] on restore")); - - // try index restore with mix of removable and UnmodifiableOnRestore settings disabled - // index.version.created is UnmodifiableOnRestore, index.number_of_search_only_replicas is removable - exception = expectThrows( - SnapshotRestoreException.class, - () -> client().admin() - .cluster() - .prepareRestoreSnapshot(snapshotRepo, snapshotName1) - .setWaitForCompletion(false) - .setIgnoreIndexSettings(IndexMetadata.SETTING_VERSION_CREATED, IndexMetadata.SETTING_NUMBER_OF_SEARCH_REPLICAS) - .setIndices(index) - .setRenamePattern(index) - .setRenameReplacement(restoredIndex) - .get() - ); - assertTrue(exception.getMessage().contains("cannot remove UnmodifiableOnRestore setting [index.version.created] on restore")); - - // try index restore with mix of removable and USER_UNREMOVABLE_SETTINGS settings disabled - // index.number_of_replicas is USER_UNREMOVABLE_SETTINGS, index.number_of_search_only_replicas is removable - exception = expectThrows( - SnapshotRestoreException.class, - () -> client().admin() - .cluster() - .prepareRestoreSnapshot(snapshotRepo, snapshotName1) - .setWaitForCompletion(false) - .setIgnoreIndexSettings(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, IndexMetadata.SETTING_NUMBER_OF_SEARCH_REPLICAS) - .setIndices(index) - .setRenamePattern(index) - .setRenameReplacement(restoredIndex) - .get() - ); - assertTrue(exception.getMessage().contains("cannot remove setting [index.number_of_replicas] on restore")); - - // try index restore with multiple UnmodifiableOnRestore settings disabled - exception = expectThrows( - SnapshotRestoreException.class, - () -> client().admin() - .cluster() - .prepareRestoreSnapshot(snapshotRepo, snapshotName1) - .setWaitForCompletion(false) - .setIgnoreIndexSettings(IndexMetadata.SETTING_NUMBER_OF_SHARDS, IndexMetadata.SETTING_VERSION_CREATED) - .setIndices(index) - .setRenamePattern(index) - .setRenameReplacement(restoredIndex) - .get() - ); - assertTrue(exception.getMessage().contains("cannot remove UnmodifiableOnRestore setting [index.number_of_shards]" + " on restore")); - - // try index restore with multiple USER_UNREMOVABLE_SETTINGS settings disabled - exception = expectThrows( - SnapshotRestoreException.class, - () -> client().admin() - .cluster() - .prepareRestoreSnapshot(snapshotRepo, snapshotName1) - .setWaitForCompletion(false) - .setIgnoreIndexSettings(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, IndexMetadata.SETTING_AUTO_EXPAND_REPLICAS) - .setIndices(index) - .setRenamePattern(index) - .setRenameReplacement(restoredIndex) - .get() - ); - assertTrue(exception.getMessage().contains("cannot remove setting [index.number_of_replicas]" + " on restore")); - - // try index restore with mix of UnmodifiableOnRestore and USER_UNREMOVABLE_SETTINGS settings disabled - exception = expectThrows( - SnapshotRestoreException.class, - () -> client().admin() - .cluster() - .prepareRestoreSnapshot(snapshotRepo, snapshotName1) - .setWaitForCompletion(false) - .setIgnoreIndexSettings(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, IndexMetadata.SETTING_NUMBER_OF_SHARDS) - .setIndices(index) - .setRenamePattern(index) - .setRenameReplacement(restoredIndex) - .get() - ); - assertTrue(exception.getMessage().contains("cannot remove setting [index.number_of_replicas]" + " on restore")); - - // try index restore with UnmodifiableOnRestore setting modified - Settings numberOfShardsSettingsDiff = Settings.builder().put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 3).build(); - - exception = expectThrows( - SnapshotRestoreException.class, - () -> client().admin() - .cluster() - .prepareRestoreSnapshot(snapshotRepo, snapshotName1) - .setWaitForCompletion(false) - .setIndexSettings(numberOfShardsSettingsDiff) - .setIndices(index) - .setRenamePattern(index) - .setRenameReplacement(restoredIndex) - .get() - ); - assertTrue(exception.getMessage().contains("cannot modify UnmodifiableOnRestore setting [index.number_of_shards]" + " on restore")); - - // try index restore with UnmodifiableOnRestore setting same - Settings numberOfShardsSettingsSame = Settings.builder().put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1).build(); - - exception = expectThrows( - SnapshotRestoreException.class, - () -> client().admin() - .cluster() - .prepareRestoreSnapshot(snapshotRepo, snapshotName1) - .setWaitForCompletion(false) - .setIndexSettings(numberOfShardsSettingsSame) - .setIndices(index) - .setRenamePattern(index) - .setRenameReplacement(restoredIndex) - .get() - ); - assertTrue(exception.getMessage().contains("cannot modify UnmodifiableOnRestore setting [index.number_of_shards]" + " on restore")); - - // try index restore with USER_UNMODIFIABLE_SETTINGS setting modified - Settings remoteStoreEnabledSetting = Settings.builder().put(IndexMetadata.SETTING_REMOTE_STORE_ENABLED, false).build(); - - exception = expectThrows( - SnapshotRestoreException.class, - () -> client().admin() - .cluster() - .prepareRestoreSnapshot(snapshotRepo, snapshotName1) - .setWaitForCompletion(false) - .setIndexSettings(remoteStoreEnabledSetting) - .setIndices(index) - .setRenamePattern(index) - .setRenameReplacement(restoredIndex) - .get() - ); - assertTrue(exception.getMessage().contains("cannot modify setting [index.remote_store.enabled]" + " on restore")); - - // try index restore with mix of modifiable and UnmodifiableOnRestore settings modified - // index.version.created is UnmodifiableOnRestore, index.number_of_search_only_replicas is modifiable - Settings mixedSettingsUnmodifiableOnRestore = Settings.builder() - .put(IndexMetadata.SETTING_VERSION_CREATED, Version.V_EMPTY) - .put(IndexMetadata.SETTING_NUMBER_OF_SEARCH_REPLICAS, 1) - .build(); - - exception = expectThrows( - SnapshotRestoreException.class, - () -> client().admin() - .cluster() - .prepareRestoreSnapshot(snapshotRepo, snapshotName1) - .setWaitForCompletion(false) - .setIndexSettings(mixedSettingsUnmodifiableOnRestore) - .setIndices(index) - .setRenamePattern(index) - .setRenameReplacement(restoredIndex) - .get() - ); - assertTrue(exception.getMessage().contains("cannot modify UnmodifiableOnRestore setting [index.version.created]" + " on restore")); - - // try index restore with mix of modifiable and USER_UNMODIFIABLE_SETTINGS settings modified - // index.remote_store.enabled is USER_UNMODIFIABLE_SETTINGS, index.number_of_search_only_replicas is modifiable - Settings mixedSettingsUserUnmodifiableSettings = Settings.builder() - .put(IndexMetadata.SETTING_REMOTE_STORE_ENABLED, false) - .put(IndexMetadata.SETTING_NUMBER_OF_SEARCH_REPLICAS, 1) - .build(); - - exception = expectThrows( - SnapshotRestoreException.class, - () -> client().admin() - .cluster() - .prepareRestoreSnapshot(snapshotRepo, snapshotName1) - .setWaitForCompletion(false) - .setIndexSettings(mixedSettingsUserUnmodifiableSettings) - .setIndices(index) - .setRenamePattern(index) - .setRenameReplacement(restoredIndex) - .get() - ); - assertTrue(exception.getMessage().contains("cannot modify setting [index.remote_store.enabled]" + " on restore")); - - // try index restore with mix of UnmodifiableOnRestore and USER_UNMODIFIABLE_SETTINGS settings modified - // index.remote_store.enabled is USER_UNMODIFIABLE_SETTINGS, index.version.created is UnmodifiableOnRestore - Settings mixedSettings = Settings.builder() - .put(IndexMetadata.SETTING_REMOTE_STORE_ENABLED, false) - .put(IndexMetadata.SETTING_VERSION_CREATED, Version.V_EMPTY) - .build(); - - exception = expectThrows( - SnapshotRestoreException.class, - () -> client().admin() - .cluster() - .prepareRestoreSnapshot(snapshotRepo, snapshotName1) - .setWaitForCompletion(false) - .setIndexSettings(mixedSettings) - .setIndices(index) - .setRenamePattern(index) - .setRenameReplacement(restoredIndex) - .get() - ); - assertTrue(exception.getMessage().contains("cannot modify setting [index.remote_store.enabled]" + " on restore")); - - // try index restore with multiple UnmodifiableOnRestore settings modified - Settings unmodifiableOnRestoreSettings = Settings.builder() - .put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1) - .put(IndexMetadata.SETTING_VERSION_CREATED, Version.V_EMPTY) - .build(); - - exception = expectThrows( - SnapshotRestoreException.class, - () -> client().admin() - .cluster() - .prepareRestoreSnapshot(snapshotRepo, snapshotName1) - .setWaitForCompletion(false) - .setIndexSettings(unmodifiableOnRestoreSettings) - .setIndices(index) - .setRenamePattern(index) - .setRenameReplacement(restoredIndex) - .get() - ); - assertTrue(exception.getMessage().contains("cannot modify UnmodifiableOnRestore setting [index.number_of_shards]" + " on restore")); - - // try index restore with multiple USER_UNMODIFIABLE_SETTINGS settings modified - Settings userUnmodifiableSettings = Settings.builder() - .put(IndexMetadata.SETTING_REMOTE_STORE_ENABLED, false) - .put(IndexMetadata.SETTING_NUMBER_OF_SEARCH_REPLICAS, 1) - .build(); - - exception = expectThrows( - SnapshotRestoreException.class, - () -> client().admin() - .cluster() - .prepareRestoreSnapshot(snapshotRepo, snapshotName1) - .setWaitForCompletion(false) - .setIndexSettings(userUnmodifiableSettings) - .setIndices(index) - .setRenamePattern(index) - .setRenameReplacement(restoredIndex) - .get() - ); - assertTrue(exception.getMessage().contains("cannot modify setting [index.remote_store.enabled]" + " on restore")); - } - public void testCreateSnapshotV2_Orphan_Timestamp_Cleanup() throws Exception { internalCluster().startClusterManagerOnlyNode(pinnedTimestampSettings()); internalCluster().startDataOnlyNode(pinnedTimestampSettings()); diff --git a/server/src/internalClusterTest/java/org/opensearch/remotestore/RestoreShallowSnapshotV2IT.java b/server/src/internalClusterTest/java/org/opensearch/remotestore/RestoreShallowSnapshotV2IT.java index cf719f6e6024d..555860fa6a1db 100644 --- a/server/src/internalClusterTest/java/org/opensearch/remotestore/RestoreShallowSnapshotV2IT.java +++ b/server/src/internalClusterTest/java/org/opensearch/remotestore/RestoreShallowSnapshotV2IT.java @@ -8,7 +8,6 @@ package org.opensearch.remotestore; -import org.opensearch.Version; import org.opensearch.action.DocWriteResponse; import org.opensearch.action.admin.cluster.remotestore.restore.RestoreRemoteStoreRequest; import org.opensearch.action.admin.cluster.repositories.get.GetRepositoriesRequest; @@ -45,7 +44,6 @@ import org.opensearch.repositories.blobstore.BlobStoreRepository; import org.opensearch.snapshots.AbstractSnapshotIntegTestCase; import org.opensearch.snapshots.SnapshotInfo; -import org.opensearch.snapshots.SnapshotRestoreException; import org.opensearch.snapshots.SnapshotState; import org.opensearch.test.BackgroundIndexer; import org.opensearch.test.InternalTestCluster; @@ -561,7 +559,7 @@ public void testRemoteRestoreIndexRestoredFromSnapshot() throws IOException, Exe assertDocsPresentInIndex(client(), indexName1, numDocsInIndex1); } - public void testIndexRestoredFromSnapshotWithUpdateSetting() throws IOException, ExecutionException, InterruptedException { + public void testSuccessfulIndexRestoredFromSnapshotWithUpdatedSetting() throws IOException, ExecutionException, InterruptedException { internalCluster().startClusterManagerOnlyNode(); internalCluster().startDataOnlyNodes(2); @@ -777,309 +775,6 @@ public void testRestoreShallowSnapshotIndexAfterSnapshot() throws ExecutionExcep assertDocsPresentInIndex(client, restoredIndexName1, numDocsInIndex1 + 2); } - public void testInvalidRestoreRequestScenarios() throws Exception { - internalCluster().startClusterManagerOnlyNode(); - internalCluster().startDataOnlyNode(); - String index = "test-index"; - String snapshotRepo = "test-restore-snapshot-repo"; - String newRemoteStoreRepo = "test-new-rs-repo"; - String snapshotName1 = "test-restore-snapshot1"; - String snapshotName2 = "test-restore-snapshot2"; - Path absolutePath1 = randomRepoPath().toAbsolutePath(); - logger.info("Snapshot Path [{}]", absolutePath1); - String restoredIndex = index + "-restored"; - - createRepository(snapshotRepo, "fs", getRepositorySettings(absolutePath1, true)); - - Client client = client(); - Settings indexSettings = getIndexSettings(1, 0).build(); - createIndex(index, indexSettings); - - final int numDocsInIndex = 5; - indexDocuments(client, index, numDocsInIndex); - ensureGreen(index); - - internalCluster().startDataOnlyNode(); - logger.info("--> snapshot"); - - SnapshotInfo snapshotInfo = createSnapshot(snapshotRepo, snapshotName1, new ArrayList<>(List.of(index))); - assertThat(snapshotInfo.state(), equalTo(SnapshotState.SUCCESS)); - assertThat(snapshotInfo.successfulShards(), greaterThan(0)); - assertThat(snapshotInfo.successfulShards(), equalTo(snapshotInfo.totalShards())); - - updateRepository(snapshotRepo, "fs", getRepositorySettings(absolutePath1, false)); - SnapshotInfo snapshotInfo2 = createSnapshot(snapshotRepo, snapshotName2, new ArrayList<>(List.of(index))); - assertThat(snapshotInfo2.state(), equalTo(SnapshotState.SUCCESS)); - assertThat(snapshotInfo2.successfulShards(), greaterThan(0)); - assertThat(snapshotInfo2.successfulShards(), equalTo(snapshotInfo2.totalShards())); - - DeleteResponse deleteResponse = client().prepareDelete(index, "0").execute().actionGet(); - assertEquals(deleteResponse.getResult(), DocWriteResponse.Result.DELETED); - indexDocuments(client, index, numDocsInIndex, numDocsInIndex + randomIntBetween(2, 5)); - ensureGreen(index); - - // try index restore with USER_UNREMOVABLE_SETTINGS setting disabled - SnapshotRestoreException exception = expectThrows( - SnapshotRestoreException.class, - () -> client().admin() - .cluster() - .prepareRestoreSnapshot(snapshotRepo, snapshotName1) - .setWaitForCompletion(false) - .setIgnoreIndexSettings(IndexMetadata.SETTING_REMOTE_STORE_ENABLED) - .setIndices(index) - .setRenamePattern(index) - .setRenameReplacement(restoredIndex) - .get() - ); - assertTrue(exception.getMessage().contains("cannot remove setting [index.remote_store.enabled] on restore")); - - // try index restore with UnmodifiableOnRestore setting disabled - exception = expectThrows( - SnapshotRestoreException.class, - () -> client().admin() - .cluster() - .prepareRestoreSnapshot(snapshotRepo, snapshotName1) - .setWaitForCompletion(false) - .setIgnoreIndexSettings(IndexMetadata.SETTING_NUMBER_OF_SHARDS) - .setIndices(index) - .setRenamePattern(index) - .setRenameReplacement(restoredIndex) - .get() - ); - assertTrue(exception.getMessage().contains("cannot remove UnmodifiableOnRestore setting [index.number_of_shards] on restore")); - - // try index restore with mix of removable and UnmodifiableOnRestore settings disabled - // index.version.created is UnmodifiableOnRestore, index.number_of_search_only_replicas is removable - exception = expectThrows( - SnapshotRestoreException.class, - () -> client().admin() - .cluster() - .prepareRestoreSnapshot(snapshotRepo, snapshotName1) - .setWaitForCompletion(false) - .setIgnoreIndexSettings(IndexMetadata.SETTING_VERSION_CREATED, IndexMetadata.SETTING_NUMBER_OF_SEARCH_REPLICAS) - .setIndices(index) - .setRenamePattern(index) - .setRenameReplacement(restoredIndex) - .get() - ); - assertTrue(exception.getMessage().contains("cannot remove UnmodifiableOnRestore setting [index.version.created] on restore")); - - // try index restore with mix of removable and USER_UNREMOVABLE_SETTINGS settings disabled - // index.number_of_replicas is USER_UNREMOVABLE_SETTINGS, index.number_of_search_only_replicas is removable - exception = expectThrows( - SnapshotRestoreException.class, - () -> client().admin() - .cluster() - .prepareRestoreSnapshot(snapshotRepo, snapshotName1) - .setWaitForCompletion(false) - .setIgnoreIndexSettings(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, IndexMetadata.SETTING_NUMBER_OF_SEARCH_REPLICAS) - .setIndices(index) - .setRenamePattern(index) - .setRenameReplacement(restoredIndex) - .get() - ); - assertTrue(exception.getMessage().contains("cannot remove setting [index.number_of_replicas] on restore")); - - // try index restore with multiple UnmodifiableOnRestore settings disabled - exception = expectThrows( - SnapshotRestoreException.class, - () -> client().admin() - .cluster() - .prepareRestoreSnapshot(snapshotRepo, snapshotName1) - .setWaitForCompletion(false) - .setIgnoreIndexSettings(IndexMetadata.SETTING_NUMBER_OF_SHARDS, IndexMetadata.SETTING_VERSION_CREATED) - .setIndices(index) - .setRenamePattern(index) - .setRenameReplacement(restoredIndex) - .get() - ); - assertTrue(exception.getMessage().contains("cannot remove UnmodifiableOnRestore setting [index.number_of_shards]" + " on restore")); - - // try index restore with multiple USER_UNREMOVABLE_SETTINGS settings disabled - exception = expectThrows( - SnapshotRestoreException.class, - () -> client().admin() - .cluster() - .prepareRestoreSnapshot(snapshotRepo, snapshotName1) - .setWaitForCompletion(false) - .setIgnoreIndexSettings(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, IndexMetadata.SETTING_AUTO_EXPAND_REPLICAS) - .setIndices(index) - .setRenamePattern(index) - .setRenameReplacement(restoredIndex) - .get() - ); - assertTrue(exception.getMessage().contains("cannot remove setting [index.number_of_replicas]" + " on restore")); - - // try index restore with mix of UnmodifiableOnRestore and USER_UNREMOVABLE_SETTINGS settings disabled - exception = expectThrows( - SnapshotRestoreException.class, - () -> client().admin() - .cluster() - .prepareRestoreSnapshot(snapshotRepo, snapshotName1) - .setWaitForCompletion(false) - .setIgnoreIndexSettings(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, IndexMetadata.SETTING_NUMBER_OF_SHARDS) - .setIndices(index) - .setRenamePattern(index) - .setRenameReplacement(restoredIndex) - .get() - ); - assertTrue(exception.getMessage().contains("cannot remove setting [index.number_of_replicas]" + " on restore")); - - // try index restore with UnmodifiableOnRestore setting modified - Settings numberOfShardsSettingsDiff = Settings.builder().put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 3).build(); - - exception = expectThrows( - SnapshotRestoreException.class, - () -> client().admin() - .cluster() - .prepareRestoreSnapshot(snapshotRepo, snapshotName1) - .setWaitForCompletion(false) - .setIndexSettings(numberOfShardsSettingsDiff) - .setIndices(index) - .setRenamePattern(index) - .setRenameReplacement(restoredIndex) - .get() - ); - assertTrue(exception.getMessage().contains("cannot modify UnmodifiableOnRestore setting [index.number_of_shards]" + " on restore")); - - // try index restore with UnmodifiableOnRestore setting same - Settings numberOfShardsSettingsSame = Settings.builder().put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1).build(); - - exception = expectThrows( - SnapshotRestoreException.class, - () -> client().admin() - .cluster() - .prepareRestoreSnapshot(snapshotRepo, snapshotName1) - .setWaitForCompletion(false) - .setIndexSettings(numberOfShardsSettingsSame) - .setIndices(index) - .setRenamePattern(index) - .setRenameReplacement(restoredIndex) - .get() - ); - assertTrue(exception.getMessage().contains("cannot modify UnmodifiableOnRestore setting [index.number_of_shards]" + " on restore")); - - // try index restore with USER_UNMODIFIABLE_SETTINGS setting modified - Settings remoteStoreEnabledSetting = Settings.builder().put(IndexMetadata.SETTING_REMOTE_STORE_ENABLED, false).build(); - - exception = expectThrows( - SnapshotRestoreException.class, - () -> client().admin() - .cluster() - .prepareRestoreSnapshot(snapshotRepo, snapshotName1) - .setWaitForCompletion(false) - .setIndexSettings(remoteStoreEnabledSetting) - .setIndices(index) - .setRenamePattern(index) - .setRenameReplacement(restoredIndex) - .get() - ); - assertTrue(exception.getMessage().contains("cannot modify setting [index.remote_store.enabled]" + " on restore")); - - // try index restore with mix of modifiable and UnmodifiableOnRestore settings modified - // index.version.created is UnmodifiableOnRestore, index.number_of_search_only_replicas is modifiable - Settings mixedSettingsUnmodifiableOnRestore = Settings.builder() - .put(IndexMetadata.SETTING_VERSION_CREATED, Version.V_EMPTY) - .put(IndexMetadata.SETTING_NUMBER_OF_SEARCH_REPLICAS, 1) - .build(); - - exception = expectThrows( - SnapshotRestoreException.class, - () -> client().admin() - .cluster() - .prepareRestoreSnapshot(snapshotRepo, snapshotName1) - .setWaitForCompletion(false) - .setIndexSettings(mixedSettingsUnmodifiableOnRestore) - .setIndices(index) - .setRenamePattern(index) - .setRenameReplacement(restoredIndex) - .get() - ); - assertTrue(exception.getMessage().contains("cannot modify UnmodifiableOnRestore setting [index.version.created]" + " on restore")); - - // try index restore with mix of modifiable and USER_UNMODIFIABLE_SETTINGS settings modified - // index.remote_store.enabled is USER_UNMODIFIABLE_SETTINGS, index.number_of_search_only_replicas is modifiable - Settings mixedSettingsUserUnmodifiableSettings = Settings.builder() - .put(IndexMetadata.SETTING_REMOTE_STORE_ENABLED, false) - .put(IndexMetadata.SETTING_NUMBER_OF_SEARCH_REPLICAS, 1) - .build(); - - exception = expectThrows( - SnapshotRestoreException.class, - () -> client().admin() - .cluster() - .prepareRestoreSnapshot(snapshotRepo, snapshotName1) - .setWaitForCompletion(false) - .setIndexSettings(mixedSettingsUserUnmodifiableSettings) - .setIndices(index) - .setRenamePattern(index) - .setRenameReplacement(restoredIndex) - .get() - ); - assertTrue(exception.getMessage().contains("cannot modify setting [index.remote_store.enabled]" + " on restore")); - - // try index restore with mix of UnmodifiableOnRestore and USER_UNMODIFIABLE_SETTINGS settings modified - // index.remote_store.enabled is USER_UNMODIFIABLE_SETTINGS, index.version.created is UnmodifiableOnRestore - Settings mixedSettings = Settings.builder() - .put(IndexMetadata.SETTING_REMOTE_STORE_ENABLED, false) - .put(IndexMetadata.SETTING_VERSION_CREATED, Version.V_EMPTY) - .build(); - - exception = expectThrows( - SnapshotRestoreException.class, - () -> client().admin() - .cluster() - .prepareRestoreSnapshot(snapshotRepo, snapshotName1) - .setWaitForCompletion(false) - .setIndexSettings(mixedSettings) - .setIndices(index) - .setRenamePattern(index) - .setRenameReplacement(restoredIndex) - .get() - ); - assertTrue(exception.getMessage().contains("cannot modify setting [index.remote_store.enabled]" + " on restore")); - - // try index restore with multiple UnmodifiableOnRestore settings modified - Settings unmodifiableOnRestoreSettings = Settings.builder() - .put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1) - .put(IndexMetadata.SETTING_VERSION_CREATED, Version.V_EMPTY) - .build(); - - exception = expectThrows( - SnapshotRestoreException.class, - () -> client().admin() - .cluster() - .prepareRestoreSnapshot(snapshotRepo, snapshotName1) - .setWaitForCompletion(false) - .setIndexSettings(unmodifiableOnRestoreSettings) - .setIndices(index) - .setRenamePattern(index) - .setRenameReplacement(restoredIndex) - .get() - ); - assertTrue(exception.getMessage().contains("cannot modify UnmodifiableOnRestore setting [index.number_of_shards]" + " on restore")); - - // try index restore with multiple USER_UNMODIFIABLE_SETTINGS settings modified - Settings userUnmodifiableSettings = Settings.builder() - .put(IndexMetadata.SETTING_REMOTE_STORE_ENABLED, false) - .put(IndexMetadata.SETTING_NUMBER_OF_SEARCH_REPLICAS, 1) - .build(); - - exception = expectThrows( - SnapshotRestoreException.class, - () -> client().admin() - .cluster() - .prepareRestoreSnapshot(snapshotRepo, snapshotName1) - .setWaitForCompletion(false) - .setIndexSettings(userUnmodifiableSettings) - .setIndices(index) - .setRenamePattern(index) - .setRenameReplacement(restoredIndex) - .get() - ); - assertTrue(exception.getMessage().contains("cannot modify setting [index.remote_store.enabled]" + " on restore")); - } - public void testRestoreOperationsUsingDifferentRepos() throws Exception { disableRepoConsistencyCheck("Remote store repo"); String clusterManagerNode = internalCluster().startClusterManagerOnlyNode(); diff --git a/server/src/internalClusterTest/java/org/opensearch/snapshots/RestoreSnapshotIT.java b/server/src/internalClusterTest/java/org/opensearch/snapshots/RestoreSnapshotIT.java index e76587653e99a..36ab97d0b730f 100644 --- a/server/src/internalClusterTest/java/org/opensearch/snapshots/RestoreSnapshotIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/snapshots/RestoreSnapshotIT.java @@ -32,6 +32,7 @@ package org.opensearch.snapshots; +import org.opensearch.Version; import org.opensearch.action.admin.cluster.snapshots.create.CreateSnapshotResponse; import org.opensearch.action.admin.cluster.snapshots.restore.RestoreSnapshotResponse; import org.opensearch.action.admin.indices.settings.get.GetSettingsResponse; @@ -49,10 +50,12 @@ import org.opensearch.common.xcontent.XContentFactory; import org.opensearch.core.common.unit.ByteSizeUnit; import org.opensearch.core.rest.RestStatus; +import org.opensearch.index.IndexSettings; import org.opensearch.indices.InvalidIndexNameException; import org.opensearch.repositories.RepositoriesService; import java.nio.file.Path; +import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Locale; @@ -1112,4 +1115,389 @@ public void testRestoreBalancedReplica() { } } + private String index; + private String snapshotRepo; + private String snapshotName1; + private String snapshotName2; + private Path absolutePath1; + private String restoredIndex; + private Settings indexSettings; + private SnapshotInfo snapshotInfo; + private SnapshotInfo snapshotInfo2; + + public void setupSnapshotRestore() { + index = "test-index"; + snapshotRepo = "test-restore-snapshot-repo"; + snapshotName1 = "test-restore-snapshot1"; + snapshotName2 = "test-restore-snapshot2"; + absolutePath1 = randomRepoPath().toAbsolutePath(); + + logger.info("Snapshot Path [{}]", absolutePath1); + restoredIndex = index + "-restored"; + + createRepository(snapshotRepo, "fs", getRepositorySettings(absolutePath1, true)); + + indexSettings = getIndexSettings(1, 0).build(); + createIndex(index, indexSettings); + ensureGreen(index); + + logger.info("--> snapshot"); + + snapshotInfo = createSnapshot(snapshotRepo, snapshotName1, new ArrayList<>(List.of(index))); + assertThat(snapshotInfo.state(), equalTo(SnapshotState.SUCCESS)); + assertThat(snapshotInfo.successfulShards(), greaterThan(0)); + assertThat(snapshotInfo.successfulShards(), equalTo(snapshotInfo.totalShards())); + + updateRepository(snapshotRepo, "fs", getRepositorySettings(absolutePath1, false)); + snapshotInfo2 = createSnapshot(snapshotRepo, snapshotName2, new ArrayList<>(List.of(index))); + assertThat(snapshotInfo2.state(), equalTo(SnapshotState.SUCCESS)); + assertThat(snapshotInfo2.successfulShards(), greaterThan(0)); + assertThat(snapshotInfo2.successfulShards(), equalTo(snapshotInfo2.totalShards())); + ensureGreen(index); + } + + public void testInvalidRestoreRequest_UserUnRemovableSettingsIgnored() throws Exception { + setupSnapshotRestore(); + + // try index restore with USER_UNREMOVABLE_SETTINGS setting ignored + SnapshotRestoreException exception = expectThrows( + SnapshotRestoreException.class, + () -> client().admin() + .cluster() + .prepareRestoreSnapshot(snapshotRepo, snapshotName1) + .setWaitForCompletion(false) + .setIgnoreIndexSettings(IndexMetadata.SETTING_REMOTE_STORE_ENABLED) + .setIndices(index) + .setRenamePattern(index) + .setRenameReplacement(restoredIndex) + .get() + ); + assertTrue(exception.getMessage().contains("cannot remove setting [index.remote_store.enabled] on restore")); + + } + + public void testInvalidRestoreRequest_UnmodifiableOnRestoreIgnored() throws Exception { + setupSnapshotRestore(); + + // try index restore with UnmodifiableOnRestore setting ignored + SnapshotRestoreException exception = expectThrows( + SnapshotRestoreException.class, + () -> client().admin() + .cluster() + .prepareRestoreSnapshot(snapshotRepo, snapshotName1) + .setWaitForCompletion(false) + .setIgnoreIndexSettings(IndexMetadata.SETTING_NUMBER_OF_SHARDS) + .setIndices(index) + .setRenamePattern(index) + .setRenameReplacement(restoredIndex) + .get() + ); + assertTrue(exception.getMessage().contains("cannot remove UnmodifiableOnRestore setting [index.number_of_shards] on restore")); + + } + + public void testInvalidRestoreRequest_MixRemovableAndUnmodifiableOnRestoreIgnored() throws Exception { + setupSnapshotRestore(); + + // try index restore with mix of removable and UnmodifiableOnRestore settings ignored + // index.version.created is UnmodifiableOnRestore, index.number_of_search_only_replicas is removable + SnapshotRestoreException exception = expectThrows( + SnapshotRestoreException.class, + () -> client().admin() + .cluster() + .prepareRestoreSnapshot(snapshotRepo, snapshotName1) + .setWaitForCompletion(false) + .setIgnoreIndexSettings(IndexMetadata.SETTING_VERSION_CREATED, IndexMetadata.SETTING_NUMBER_OF_SEARCH_REPLICAS) + .setIndices(index) + .setRenamePattern(index) + .setRenameReplacement(restoredIndex) + .get() + ); + assertTrue(exception.getMessage().contains("cannot remove UnmodifiableOnRestore setting [index.version.created] on restore")); + } + + public void testInvalidRestoreRequest_MixRemovableAndUserUnRemovableSettingsIgnored() throws Exception { + setupSnapshotRestore(); + + // try index restore with mix of removable and USER_UNREMOVABLE_SETTINGS settings ignored + // index.number_of_replicas is USER_UNREMOVABLE_SETTINGS, index.number_of_search_only_replicas is removable + SnapshotRestoreException exception = expectThrows( + SnapshotRestoreException.class, + () -> client().admin() + .cluster() + .prepareRestoreSnapshot(snapshotRepo, snapshotName1) + .setWaitForCompletion(false) + .setIgnoreIndexSettings(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, IndexMetadata.SETTING_NUMBER_OF_SEARCH_REPLICAS) + .setIndices(index) + .setRenamePattern(index) + .setRenameReplacement(restoredIndex) + .get() + ); + assertTrue(exception.getMessage().contains("cannot remove setting [index.number_of_replicas] on restore")); + + } + + public void testInvalidRestoreRequest_MixUnmodifiableOnRestoreAndUserUnRemovableSettingsIgnored() throws Exception { + setupSnapshotRestore(); + + // try index restore with mix of UnmodifiableOnRestore and USER_UNREMOVABLE_SETTINGS settings ignored + SnapshotRestoreException exception = expectThrows( + SnapshotRestoreException.class, + () -> client().admin() + .cluster() + .prepareRestoreSnapshot(snapshotRepo, snapshotName1) + .setWaitForCompletion(false) + .setIgnoreIndexSettings(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, IndexMetadata.SETTING_NUMBER_OF_SHARDS) + .setIndices(index) + .setRenamePattern(index) + .setRenameReplacement(restoredIndex) + .get() + ); + assertTrue(exception.getMessage().contains("cannot remove setting [index.number_of_replicas]" + " on restore")); + + } + + public void testInvalidRestoreRequest_MultipleUnmodifiableOnRestoreIgnored() throws Exception { + setupSnapshotRestore(); + + // try index restore with multiple UnmodifiableOnRestore settings ignored + SnapshotRestoreException exception = expectThrows( + SnapshotRestoreException.class, + () -> client().admin() + .cluster() + .prepareRestoreSnapshot(snapshotRepo, snapshotName1) + .setWaitForCompletion(false) + .setIgnoreIndexSettings(IndexMetadata.SETTING_NUMBER_OF_SHARDS, IndexMetadata.SETTING_VERSION_CREATED) + .setIndices(index) + .setRenamePattern(index) + .setRenameReplacement(restoredIndex) + .get() + ); + assertTrue(exception.getMessage().contains("cannot remove UnmodifiableOnRestore setting [index.number_of_shards]" + " on restore")); + + } + + public void testInvalidRestoreRequest_MultipleUserUnRemovableSettingsIgnored() throws Exception { + setupSnapshotRestore(); + + // try index restore with multiple USER_UNREMOVABLE_SETTINGS settings ignored + SnapshotRestoreException exception = expectThrows( + SnapshotRestoreException.class, + () -> client().admin() + .cluster() + .prepareRestoreSnapshot(snapshotRepo, snapshotName1) + .setWaitForCompletion(false) + .setIgnoreIndexSettings(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, IndexMetadata.SETTING_AUTO_EXPAND_REPLICAS) + .setIndices(index) + .setRenamePattern(index) + .setRenameReplacement(restoredIndex) + .get() + ); + assertTrue(exception.getMessage().contains("cannot remove setting [index.number_of_replicas]" + " on restore")); + + } + + public void testInvalidRestoreRequest_UnmodifiableOnRestoreModified() throws Exception { + setupSnapshotRestore(); + + // try index restore with UnmodifiableOnRestore setting modified + Settings numberOfShardsSettingsDiff = Settings.builder().put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 3).build(); + + SnapshotRestoreException exception = expectThrows( + SnapshotRestoreException.class, + () -> client().admin() + .cluster() + .prepareRestoreSnapshot(snapshotRepo, snapshotName1) + .setWaitForCompletion(false) + .setIndexSettings(numberOfShardsSettingsDiff) + .setIndices(index) + .setRenamePattern(index) + .setRenameReplacement(restoredIndex) + .get() + ); + assertTrue(exception.getMessage().contains("cannot modify UnmodifiableOnRestore setting [index.number_of_shards]" + " on restore")); + + } + + public void testInvalidRestoreRequest_UnmodifiableOnRestoreUnchanged() throws Exception { + setupSnapshotRestore(); + + // try index restore with UnmodifiableOnRestore setting unchanged + Settings numberOfShardsSettingsSame = Settings.builder().put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1).build(); + + SnapshotRestoreException exception = expectThrows( + SnapshotRestoreException.class, + () -> client().admin() + .cluster() + .prepareRestoreSnapshot(snapshotRepo, snapshotName1) + .setWaitForCompletion(false) + .setIndexSettings(numberOfShardsSettingsSame) + .setIndices(index) + .setRenamePattern(index) + .setRenameReplacement(restoredIndex) + .get() + ); + assertTrue(exception.getMessage().contains("cannot modify UnmodifiableOnRestore setting [index.number_of_shards]" + " on restore")); + + } + + public void testInvalidRestoreRequest_UserUnmodifiableSettingsModified() throws Exception { + setupSnapshotRestore(); + + // try index restore with USER_UNMODIFIABLE_SETTINGS setting modified + Settings remoteStoreEnabledSetting = Settings.builder().put(IndexMetadata.SETTING_REMOTE_STORE_ENABLED, false).build(); + + SnapshotRestoreException exception = expectThrows( + SnapshotRestoreException.class, + () -> client().admin() + .cluster() + .prepareRestoreSnapshot(snapshotRepo, snapshotName1) + .setWaitForCompletion(false) + .setIndexSettings(remoteStoreEnabledSetting) + .setIndices(index) + .setRenamePattern(index) + .setRenameReplacement(restoredIndex) + .get() + ); + assertTrue(exception.getMessage().contains("cannot modify setting [index.remote_store.enabled]" + " on restore")); + + } + + public void testInvalidRestoreRequest_MixModifiableAndUnmodifiableOnRestoreModified() throws Exception { + setupSnapshotRestore(); + + // try index restore with mix of modifiable and UnmodifiableOnRestore settings modified + // index.version.created is UnmodifiableOnRestore, index.number_of_search_only_replicas is modifiable + Settings mixedSettingsUnmodifiableOnRestore = Settings.builder() + .put(IndexMetadata.SETTING_VERSION_CREATED, Version.V_EMPTY) + .put(IndexMetadata.SETTING_NUMBER_OF_SEARCH_REPLICAS, 1) + .build(); + + SnapshotRestoreException exception = expectThrows( + SnapshotRestoreException.class, + () -> client().admin() + .cluster() + .prepareRestoreSnapshot(snapshotRepo, snapshotName1) + .setWaitForCompletion(false) + .setIndexSettings(mixedSettingsUnmodifiableOnRestore) + .setIndices(index) + .setRenamePattern(index) + .setRenameReplacement(restoredIndex) + .get() + ); + assertTrue(exception.getMessage().contains("cannot modify UnmodifiableOnRestore setting [index.version.created]" + " on restore")); + + } + + public void testInvalidRestoreRequest_MixModifiableAndUserUnmodifiableSettingsModified() throws Exception { + setupSnapshotRestore(); + + // try index restore with mix of modifiable and USER_UNMODIFIABLE_SETTINGS settings modified + // index.remote_store.enabled is USER_UNMODIFIABLE_SETTINGS, index.number_of_search_only_replicas is modifiable + Settings mixedSettingsUserUnmodifiableSettings = Settings.builder() + .put(IndexMetadata.SETTING_REMOTE_STORE_ENABLED, false) + .put(IndexMetadata.SETTING_NUMBER_OF_SEARCH_REPLICAS, 1) + .build(); + + SnapshotRestoreException exception = expectThrows( + SnapshotRestoreException.class, + () -> client().admin() + .cluster() + .prepareRestoreSnapshot(snapshotRepo, snapshotName1) + .setWaitForCompletion(false) + .setIndexSettings(mixedSettingsUserUnmodifiableSettings) + .setIndices(index) + .setRenamePattern(index) + .setRenameReplacement(restoredIndex) + .get() + ); + assertTrue(exception.getMessage().contains("cannot modify setting [index.remote_store.enabled]" + " on restore")); + + } + + public void testInvalidRestoreRequest_MixUnmodifiableOnRestoreAndUserUnmodifiableSettingsModified() throws Exception { + setupSnapshotRestore(); + + // try index restore with mix of UnmodifiableOnRestore and USER_UNMODIFIABLE_SETTINGS settings modified + // index.remote_store.enabled is USER_UNMODIFIABLE_SETTINGS, index.version.created is UnmodifiableOnRestore + Settings mixedSettings = Settings.builder() + .put(IndexMetadata.SETTING_REMOTE_STORE_ENABLED, false) + .put(IndexMetadata.SETTING_VERSION_CREATED, Version.V_EMPTY) + .build(); + + SnapshotRestoreException exception = expectThrows( + SnapshotRestoreException.class, + () -> client().admin() + .cluster() + .prepareRestoreSnapshot(snapshotRepo, snapshotName1) + .setWaitForCompletion(false) + .setIndexSettings(mixedSettings) + .setIndices(index) + .setRenamePattern(index) + .setRenameReplacement(restoredIndex) + .get() + ); + assertTrue(exception.getMessage().contains("cannot modify setting [index.remote_store.enabled]" + " on restore")); + + } + + public void testInvalidRestoreRequest_MultipleUnmodifiableOnRestoreModified() throws Exception { + setupSnapshotRestore(); + + // try index restore with multiple UnmodifiableOnRestore settings modified + Settings unmodifiableOnRestoreSettings = Settings.builder() + .put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1) + .put(IndexMetadata.SETTING_VERSION_CREATED, Version.V_EMPTY) + .build(); + + SnapshotRestoreException exception = expectThrows( + SnapshotRestoreException.class, + () -> client().admin() + .cluster() + .prepareRestoreSnapshot(snapshotRepo, snapshotName1) + .setWaitForCompletion(false) + .setIndexSettings(unmodifiableOnRestoreSettings) + .setIndices(index) + .setRenamePattern(index) + .setRenameReplacement(restoredIndex) + .get() + ); + assertTrue(exception.getMessage().contains("cannot modify UnmodifiableOnRestore setting [index.number_of_shards]" + " on restore")); + + } + + public void testInvalidRestoreRequest_MultipleUserUnmodifiableSettingsModified() throws Exception { + setupSnapshotRestore(); + + // try index restore with multiple USER_UNMODIFIABLE_SETTINGS settings modified + Settings userUnmodifiableSettings = Settings.builder() + .put(IndexMetadata.SETTING_REMOTE_STORE_ENABLED, false) + .put(IndexMetadata.SETTING_NUMBER_OF_SEARCH_REPLICAS, 1) + .build(); + + SnapshotRestoreException exception = expectThrows( + SnapshotRestoreException.class, + () -> client().admin() + .cluster() + .prepareRestoreSnapshot(snapshotRepo, snapshotName1) + .setWaitForCompletion(false) + .setIndexSettings(userUnmodifiableSettings) + .setIndices(index) + .setRenamePattern(index) + .setRenameReplacement(restoredIndex) + .get() + ); + assertTrue(exception.getMessage().contains("cannot modify setting [index.remote_store.enabled]" + " on restore")); + + } + + protected Settings.Builder getIndexSettings(int numOfShards, int numOfReplicas) { + Settings.Builder settingsBuilder = Settings.builder() + .put(super.indexSettings()) + .put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, numOfShards) + .put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, numOfReplicas) + .put(IndexSettings.INDEX_REFRESH_INTERVAL_SETTING.getKey(), "300s"); + return settingsBuilder; + } + } diff --git a/server/src/main/java/org/opensearch/common/settings/Setting.java b/server/src/main/java/org/opensearch/common/settings/Setting.java index c915718e4a433..eb63522270e87 100644 --- a/server/src/main/java/org/opensearch/common/settings/Setting.java +++ b/server/src/main/java/org/opensearch/common/settings/Setting.java @@ -175,6 +175,7 @@ public enum Property { /** * Mark this setting as immutable on snapshot restore + * i.e. the setting will not be allowed to be removed or modified during restore */ UnmodifiableOnRestore } @@ -213,19 +214,13 @@ private Setting( final EnumSet propertiesAsSet = EnumSet.copyOf(Arrays.asList(properties)); if (propertiesAsSet.contains(Property.Dynamic) && propertiesAsSet.contains(Property.Final)) { throw new IllegalArgumentException("final setting [" + key + "] cannot be dynamic"); - } else if (propertiesAsSet.contains(Property.UnmodifiableOnRestore) - && (propertiesAsSet.contains(Property.Dynamic) || !propertiesAsSet.contains(Property.IndexScope))) { - throw new IllegalArgumentException( - "unmodifiableOnRestore setting [" - + key - + "] cannot be dynamic, or unmodifiableOnRestore setting [" - + key - + "] must have indexScope" - ); - } + } else if (propertiesAsSet.contains(Property.UnmodifiableOnRestore) && propertiesAsSet.contains(Property.Dynamic)) { + throw new IllegalArgumentException("UnmodifiableOnRestore setting [" + key + "] cannot be dynamic"); + } checkPropertyRequiresIndexScope(propertiesAsSet, Property.NotCopyableOnResize); checkPropertyRequiresIndexScope(propertiesAsSet, Property.InternalIndex); checkPropertyRequiresIndexScope(propertiesAsSet, Property.PrivateIndex); + checkPropertyRequiresIndexScope(propertiesAsSet, Property.UnmodifiableOnRestore); checkPropertyRequiresNodeScope(propertiesAsSet, Property.Consistent); this.properties = propertiesAsSet; } diff --git a/server/src/test/java/org/opensearch/common/settings/SettingTests.java b/server/src/test/java/org/opensearch/common/settings/SettingTests.java index a582da2141304..a0788b0c83e11 100644 --- a/server/src/test/java/org/opensearch/common/settings/SettingTests.java +++ b/server/src/test/java/org/opensearch/common/settings/SettingTests.java @@ -1444,25 +1444,15 @@ public void testRejectConflictingDynamicAndUnmodifiableOnRestoreProperties() { IllegalArgumentException.class, () -> Setting.simpleString("foo.bar", Property.UnmodifiableOnRestore, Property.Dynamic) ); - assertThat( - ex.getMessage(), - containsString( - "unmodifiableOnRestore setting [foo.bar] cannot be dynamic, or unmodifiableOnRestore setting [foo.bar] must have indexScope" - ) - ); + assertThat(ex.getMessage(), containsString("UnmodifiableOnRestore setting [foo.bar] cannot be dynamic")); } - public void testRejectMissingIndexScopeAndUnmodifiableOnRestoreProperties() { - IllegalArgumentException ex = expectThrows( + public void testRejectNonIndexScopedUnmodifiableOnRestoreSetting() { + final IllegalArgumentException e = expectThrows( IllegalArgumentException.class, () -> Setting.simpleString("foo.bar", Property.UnmodifiableOnRestore) ); - assertThat( - ex.getMessage(), - containsString( - "unmodifiableOnRestore setting [foo.bar] cannot be dynamic, or unmodifiableOnRestore setting [foo.bar] must have indexScope" - ) - ); + assertThat(e, hasToString(containsString("non-index-scoped setting [foo.bar] can not have property [UnmodifiableOnRestore]"))); } public void testRejectNonIndexScopedNotCopyableOnResizeSetting() {