Skip to content

Commit

Permalink
Add UnmodifiableOnRestore only to unmodifiable settings that are alre…
Browse files Browse the repository at this point in the history
…ady registered, will raise separate PR for settings not yet registered. Add validation check in Setting.java. Add UnmodifiableOnRestore settings cannot be removed on restore

Signed-off-by: AnnTian Shao <anntians@amazon.com>
  • Loading branch information
AnnTian Shao committed Jan 23, 2025
1 parent ba81816 commit c1c3593
Show file tree
Hide file tree
Showing 9 changed files with 377 additions and 72 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@
import java.util.stream.Collectors;
import java.util.stream.Stream;

import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_REMOTE_STORE_ENABLED;
import static org.opensearch.index.remote.RemoteStoreEnums.DataCategory.SEGMENTS;
import static org.opensearch.index.remote.RemoteStoreEnums.DataCategory.TRANSLOG;
import static org.opensearch.index.remote.RemoteStoreEnums.DataType.DATA;
Expand Down Expand Up @@ -752,39 +751,114 @@ public void testInvalidRestoreRequestScenarios() throws Exception {
indexDocuments(client, index, numDocsInIndex, numDocsInIndex + randomIntBetween(2, 5));
ensureGreen(index);

// try index restore with remote store disabled
// try index restore with USER_UNREMOVABLE_SETTINGS setting disabled
SnapshotRestoreException exception = expectThrows(
SnapshotRestoreException.class,
() -> client().admin()
.cluster()
.prepareRestoreSnapshot(snapshotRepo, snapshotName1)
.setWaitForCompletion(false)
.setIgnoreIndexSettings(SETTING_REMOTE_STORE_ENABLED)
.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 index.uuid setting modified
Settings uuidSetting = Settings.builder().put(IndexMetadata.SETTING_INDEX_UUID, IndexMetadata.INDEX_UUID_NA_VALUE).build();
// 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)
.setIndexSettings(uuidSetting)
.setIgnoreIndexSettings(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, IndexMetadata.SETTING_NUMBER_OF_SEARCH_REPLICAS)
.setIndices(index)
.setRenamePattern(index)
.setRenameReplacement(restoredIndex)
.get()
);
assertTrue(exception.getMessage().contains("cannot modify setting [index.uuid]" + " on restore"));
assertTrue(exception.getMessage().contains("cannot remove setting [index.number_of_replicas] on restore"));

// try index restore with index.number_of_shards setting modified
// 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(
Expand All @@ -801,7 +875,7 @@ public void testInvalidRestoreRequestScenarios() throws Exception {
);
assertTrue(exception.getMessage().contains("cannot modify UnmodifiableOnRestore setting [index.number_of_shards]" + " on restore"));

// try index restore with index.number_of_shards setting same
// try index restore with UnmodifiableOnRestore setting same
Settings numberOfShardsSettingsSame = Settings.builder().put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1).build();

exception = expectThrows(
Expand All @@ -818,11 +892,70 @@ public void testInvalidRestoreRequestScenarios() throws Exception {
);
assertTrue(exception.getMessage().contains("cannot modify UnmodifiableOnRestore setting [index.number_of_shards]" + " on restore"));

// try index restore with mix of modifiable and unmodifiable settings on restore
// index.version.created is unmodifiable, index.number_of_replicas is modifiable
// 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)
.put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 1)
.build();

exception = expectThrows(
Expand All @@ -837,13 +970,12 @@ public void testInvalidRestoreRequestScenarios() throws Exception {
.setRenameReplacement(restoredIndex)
.get()
);
assertTrue(exception.getMessage().contains("cannot modify UnmodifiableOnRestore setting [index.version.created]" + " on restore"));
assertTrue(exception.getMessage().contains("cannot modify setting [index.remote_store.enabled]" + " on restore"));

// try index restore with multiple UnmodifiableOnRestore settings on restore
Settings unmodifiableSettings = Settings.builder()
// 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)
.put(IndexMetadata.SETTING_REMOTE_STORE_ENABLED, false)
.build();

exception = expectThrows(
Expand All @@ -852,31 +984,33 @@ public void testInvalidRestoreRequestScenarios() throws Exception {
.cluster()
.prepareRestoreSnapshot(snapshotRepo, snapshotName1)
.setWaitForCompletion(false)
.setIndexSettings(unmodifiableSettings)
.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 remote store repository and translog store repository disabled
// 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)
.setIgnoreIndexSettings(
IndexMetadata.SETTING_REMOTE_SEGMENT_STORE_REPOSITORY,
IndexMetadata.SETTING_REMOTE_TRANSLOG_STORE_REPOSITORY
)
.setIndexSettings(userUnmodifiableSettings)
.setIndices(index)
.setRenamePattern(index)
.setRenameReplacement(restoredIndex)
.get()
);
assertTrue(exception.getMessage().contains("cannot remove setting [index.remote_store.segment.repository]" + " on restore"));
assertTrue(exception.getMessage().contains("cannot modify setting [index.remote_store.enabled]" + " on restore"));
}

public void testCreateSnapshotV2_Orphan_Timestamp_Cleanup() throws Exception {
Expand Down
Loading

0 comments on commit c1c3593

Please sign in to comment.