-
Couldn't load subscription status.
- Fork 2.3k
Reject Resize index requests. (i.e, split, shrink and… #12686
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
gbbafna
merged 12 commits into
opensearch-project:main
from
astute-decipher:serengity_personel
Apr 4, 2024
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
c9b0487
Adding checks to reject Resize index requests. i.e, split, shrink and…
4548951
Adding issue to changelog.md file
6672cbe
Some structural changes and added UTs to cover all possible configura…
ace7752
Added IT for ResizeIndex During migration
f262296
Addressed comments on PR by @gbbafna
872f742
code refactoring and spotless checks
60c77ea
Added javadoc and test descriptions
2789f8c
Merge branch 'main' of https://github.com/opensearch-project/OpenSear…
da459ae
Refactoring the code
df2aa33
Spotless apply
c99e50b
Merge branch 'main' of https://github.com/opensearch-project/OpenSear…
06ae8c0
Corrected CHANGELOG.md
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
208 changes: 208 additions & 0 deletions
208
...internalClusterTest/java/org/opensearch/remotemigration/ResizeIndexMigrationTestCase.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,208 @@ | ||
| /* | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| * | ||
| * The OpenSearch Contributors require contributions made to | ||
| * this file be licensed under the Apache-2.0 license or a | ||
| * compatible open source license. | ||
| */ | ||
|
|
||
| package org.opensearch.remotemigration; | ||
|
|
||
| import org.opensearch.action.admin.cluster.settings.ClusterUpdateSettingsRequest; | ||
| import org.opensearch.action.admin.indices.shrink.ResizeType; | ||
| import org.opensearch.action.support.ActiveShardCount; | ||
| import org.opensearch.client.Client; | ||
| import org.opensearch.common.settings.Settings; | ||
| import org.opensearch.indices.replication.common.ReplicationType; | ||
| import org.opensearch.test.OpenSearchIntegTestCase; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_REPLICATION_TYPE; | ||
| import static org.opensearch.node.remotestore.RemoteStoreNodeService.MIGRATION_DIRECTION_SETTING; | ||
| import static org.opensearch.node.remotestore.RemoteStoreNodeService.REMOTE_STORE_COMPATIBILITY_MODE_SETTING; | ||
| import static org.opensearch.test.hamcrest.OpenSearchAssertions.assertAcked; | ||
|
|
||
| @OpenSearchIntegTestCase.ClusterScope(scope = OpenSearchIntegTestCase.Scope.TEST, numDataNodes = 0, autoManageMasterNodes = false) | ||
| public class ResizeIndexMigrationTestCase extends MigrationBaseTestCase { | ||
| private static final String TEST_INDEX = "test_index"; | ||
| private final static String REMOTE_STORE_DIRECTION = "remote_store"; | ||
| private final static String DOC_REP_DIRECTION = "docrep"; | ||
| private final static String NONE_DIRECTION = "none"; | ||
| private final static String STRICT_MODE = "strict"; | ||
| private final static String MIXED_MODE = "mixed"; | ||
|
|
||
| /* | ||
| * This test will verify the resize request failure, when cluster mode is mixed | ||
| * and index is on DocRep node, and migration to remote store is in progress. | ||
| * */ | ||
| public void testFailResizeIndexWhileDocRepToRemoteStoreMigration() throws Exception { | ||
|
|
||
| internalCluster().setBootstrapClusterManagerNodeIndex(0); | ||
| List<String> cmNodes = internalCluster().startNodes(1); | ||
| Client client = internalCluster().client(cmNodes.get(0)); | ||
| ClusterUpdateSettingsRequest updateSettingsRequest = new ClusterUpdateSettingsRequest(); | ||
| updateSettingsRequest.persistentSettings(Settings.builder().put(REMOTE_STORE_COMPATIBILITY_MODE_SETTING.getKey(), MIXED_MODE)); | ||
| assertAcked(client().admin().cluster().updateSettings(updateSettingsRequest).actionGet()); | ||
|
|
||
| // Adding a non remote and a remote node | ||
| addRemote = false; | ||
| String nonRemoteNodeName = internalCluster().startNode(); | ||
|
|
||
| addRemote = true; | ||
| String remoteNodeName = internalCluster().startNode(); | ||
|
|
||
| logger.info("-->Create index on non-remote node and SETTING_REMOTE_STORE_ENABLED is false. Resize should not happen"); | ||
| Settings.Builder builder = Settings.builder().put(SETTING_REPLICATION_TYPE, ReplicationType.SEGMENT); | ||
| client.admin() | ||
| .indices() | ||
| .prepareCreate(TEST_INDEX) | ||
| .setSettings( | ||
| builder.put("index.number_of_shards", 10) | ||
| .put("index.number_of_replicas", 0) | ||
| .put("index.routing.allocation.include._name", nonRemoteNodeName) | ||
| .put("index.routing.allocation.exclude._name", remoteNodeName) | ||
| ) | ||
| .setWaitForActiveShards(ActiveShardCount.ALL) | ||
| .execute() | ||
| .actionGet(); | ||
|
|
||
| updateSettingsRequest.persistentSettings(Settings.builder().put(MIGRATION_DIRECTION_SETTING.getKey(), REMOTE_STORE_DIRECTION)); | ||
| assertAcked(client.admin().cluster().updateSettings(updateSettingsRequest).actionGet()); | ||
|
|
||
| ResizeType resizeType; | ||
| int resizeShardsNum; | ||
| String cause; | ||
| switch (randomIntBetween(0, 2)) { | ||
| case 0: | ||
| resizeType = ResizeType.SHRINK; | ||
| resizeShardsNum = 5; | ||
| cause = "shrink_index"; | ||
| break; | ||
| case 1: | ||
| resizeType = ResizeType.SPLIT; | ||
| resizeShardsNum = 20; | ||
| cause = "split_index"; | ||
| break; | ||
| default: | ||
| resizeType = ResizeType.CLONE; | ||
| resizeShardsNum = 10; | ||
| cause = "clone_index"; | ||
| } | ||
|
|
||
| client.admin() | ||
| .indices() | ||
| .prepareUpdateSettings(TEST_INDEX) | ||
| .setSettings(Settings.builder().put("index.blocks.write", true)) | ||
| .execute() | ||
| .actionGet(); | ||
|
|
||
| ensureGreen(TEST_INDEX); | ||
|
|
||
| Settings.Builder resizeSettingsBuilder = Settings.builder() | ||
| .put("index.number_of_replicas", 0) | ||
| .put("index.number_of_shards", resizeShardsNum) | ||
| .putNull("index.blocks.write"); | ||
|
|
||
| IllegalStateException ex = expectThrows( | ||
| IllegalStateException.class, | ||
| () -> client().admin() | ||
| .indices() | ||
| .prepareResizeIndex(TEST_INDEX, "first_split") | ||
| .setResizeType(resizeType) | ||
| .setSettings(resizeSettingsBuilder.build()) | ||
| .get() | ||
| ); | ||
| assertEquals( | ||
| ex.getMessage(), | ||
| "Index " + resizeType + " is not allowed as remote migration mode is mixed" + " and index is remote store disabled" | ||
| ); | ||
| } | ||
|
|
||
| /* | ||
| * This test will verify the resize request failure, when cluster mode is mixed | ||
| * and index is on Remote Store node, and migration to DocRep node is in progress. | ||
| * */ | ||
| public void testFailResizeIndexWhileRemoteStoreToDocRepMigration() throws Exception { | ||
|
|
||
| addRemote = true; | ||
| internalCluster().setBootstrapClusterManagerNodeIndex(0); | ||
| List<String> cmNodes = internalCluster().startNodes(1); | ||
| Client client = internalCluster().client(cmNodes.get(0)); | ||
| ClusterUpdateSettingsRequest updateSettingsRequest = new ClusterUpdateSettingsRequest(); | ||
| updateSettingsRequest.persistentSettings(Settings.builder().put(REMOTE_STORE_COMPATIBILITY_MODE_SETTING.getKey(), MIXED_MODE)); | ||
| assertAcked(client().admin().cluster().updateSettings(updateSettingsRequest).actionGet()); | ||
|
|
||
| // Adding a non remote and a remote node | ||
| String remoteNodeName = internalCluster().startNode(); | ||
|
|
||
| addRemote = false; | ||
| String nonRemoteNodeName = internalCluster().startNode(); | ||
|
|
||
| logger.info("-->Create index on remote node and SETTING_REMOTE_STORE_ENABLED is true. Resize should not happen"); | ||
| Settings.Builder builder = Settings.builder().put(SETTING_REPLICATION_TYPE, ReplicationType.SEGMENT); | ||
| client.admin() | ||
| .indices() | ||
| .prepareCreate(TEST_INDEX) | ||
| .setSettings( | ||
| builder.put("index.number_of_shards", 10) | ||
| .put("index.number_of_replicas", 0) | ||
| .put("index.routing.allocation.include._name", remoteNodeName) | ||
| .put("index.routing.allocation.exclude._name", nonRemoteNodeName) | ||
| ) | ||
| .setWaitForActiveShards(ActiveShardCount.ALL) | ||
| .execute() | ||
| .actionGet(); | ||
|
|
||
| updateSettingsRequest.persistentSettings(Settings.builder().put(MIGRATION_DIRECTION_SETTING.getKey(), DOC_REP_DIRECTION)); | ||
| assertAcked(client.admin().cluster().updateSettings(updateSettingsRequest).actionGet()); | ||
|
|
||
| ResizeType resizeType; | ||
| int resizeShardsNum; | ||
| String cause; | ||
| switch (randomIntBetween(0, 2)) { | ||
| case 0: | ||
| resizeType = ResizeType.SHRINK; | ||
| resizeShardsNum = 5; | ||
| cause = "shrink_index"; | ||
| break; | ||
| case 1: | ||
| resizeType = ResizeType.SPLIT; | ||
| resizeShardsNum = 20; | ||
| cause = "split_index"; | ||
| break; | ||
| default: | ||
| resizeType = ResizeType.CLONE; | ||
| resizeShardsNum = 10; | ||
| cause = "clone_index"; | ||
| } | ||
|
|
||
| client.admin() | ||
| .indices() | ||
| .prepareUpdateSettings(TEST_INDEX) | ||
| .setSettings(Settings.builder().put("index.blocks.write", true)) | ||
| .execute() | ||
| .actionGet(); | ||
|
|
||
| ensureGreen(TEST_INDEX); | ||
|
|
||
| Settings.Builder resizeSettingsBuilder = Settings.builder() | ||
| .put("index.number_of_replicas", 0) | ||
| .put("index.number_of_shards", resizeShardsNum) | ||
| .putNull("index.blocks.write"); | ||
|
|
||
| IllegalStateException ex = expectThrows( | ||
| IllegalStateException.class, | ||
| () -> client().admin() | ||
| .indices() | ||
| .prepareResizeIndex(TEST_INDEX, "first_split") | ||
| .setResizeType(resizeType) | ||
| .setSettings(resizeSettingsBuilder.build()) | ||
| .get() | ||
| ); | ||
| assertEquals( | ||
| ex.getMessage(), | ||
| "Index " + resizeType + " is not allowed as remote migration mode is mixed" + " and index is remote store enabled" | ||
| ); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.