Skip to content
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

Fix Clone Index setting override for replication type #16076

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- Fix search_as_you_type not supporting multi-fields ([#15988](https://github.com/opensearch-project/OpenSearch/pull/15988))
- Avoid infinite loop when `flat_object` field contains invalid token ([#15985](https://github.com/opensearch-project/OpenSearch/pull/15985))
- Fix infinite loop in nested agg ([#15931](https://github.com/opensearch-project/OpenSearch/pull/15931))
- Fix Clone Index setting override for replication type ([#16076](https://github.com/opensearch-project/OpenSearch/pull/16076))

### Security

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
index.number_of_replicas: 0
index.number_of_shards: 1
index.merge.scheduler.max_merge_count: 4
index.replication.type: SEGMENT

# make it read-only
- do:
Expand Down Expand Up @@ -61,3 +62,22 @@
- match: { copy-settings-target.settings.index.merge.scheduler.max_merge_count: "4" }
- match: { copy-settings-target.settings.index.merge.scheduler.max_thread_count: "2" }
- match: { copy-settings-target.settings.index.blocks.write: "true" }
- match: { copy-settings-target.settings.index.replication.type: "SEGMENT" }

- do:
catch: /illegal_argument_exception/
allowed_warnings:
- "Parameter [master_timeout] is deprecated and will be removed in 3.0. To support inclusive language, please use [cluster_manager_timeout] instead."
indices.clone:
index: "source"
target: "explicit-illegal-settings-target"
wait_for_active_shards: 1
master_timeout: 10s
body:
settings:
index.number_of_replicas: 0
index.number_of_shards: 1
index.replication.type: DOCUMENT

- match: { error.type: illegal_argument_exception }
- match: { error.reason: "cannot provide [index.replication.type] setting on resize" }
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
index.number_of_shards: 2
index.number_of_replicas: 0
index.merge.scheduler.max_merge_count: 4
index.replication.type: SEGMENT

# make it read-only
- do:
Expand Down Expand Up @@ -62,6 +63,7 @@
- match: { copy-settings-target.settings.index.merge.scheduler.max_thread_count: "2" }
- match: { copy-settings-target.settings.index.blocks.write: "true" }
- match: { copy-settings-target.settings.index.routing.allocation.include._id: $node_id }
- match: { copy-settings-target.settings.index.replication.type: "SEGMENT" }

# now we do a actual shrink and copy settings (by default)
- do:
Expand Down Expand Up @@ -90,6 +92,7 @@
- match: { default-copy-settings-target.settings.index.merge.scheduler.max_thread_count: "2" }
- match: { default-copy-settings-target.settings.index.blocks.write: "true" }
- match: { default-copy-settings-target.settings.index.routing.allocation.include._id: $node_id }
- match: { default-copy-settings-target.settings.index.replication.type: "SEGMENT" }

# now we do a actual shrink and try to set no copy settings
- do:
Expand All @@ -105,3 +108,21 @@
body:
settings:
index.number_of_replicas: 0

- do:
catch: /illegal_argument_exception/
allowed_warnings:
- "Parameter [master_timeout] is deprecated and will be removed in 3.0. To support inclusive language, please use [cluster_manager_timeout] instead."
indices.shrink:
index: "source"
target: "explicit-illegal-settings-target"
wait_for_active_shards: 1
master_timeout: 10s
body:
settings:
index.number_of_replicas: 0
index.number_of_shards: 1
index.replication.type: DOCUMENT

- match: { error.type: illegal_argument_exception }
- match: { error.reason: "cannot provide [index.replication.type] setting on resize" }
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
index.number_of_shards: 1
index.number_of_routing_shards: 4
index.merge.scheduler.max_merge_count: 4
index.replication.type: SEGMENT

# make it read-only
- do:
Expand Down Expand Up @@ -64,6 +65,7 @@
- match: { copy-settings-target.settings.index.merge.scheduler.max_thread_count: "2" }
- match: { copy-settings-target.settings.index.blocks.write: "true" }
- match: { copy-settings-target.settings.index.routing.allocation.include._id: $node_id }
- match: { copy-settings-target.settings.index.replication.type: "SEGMENT" }
gaobinlong marked this conversation as resolved.
Show resolved Hide resolved

# now we do a actual shrink and copy settings (by default)
- do:
Expand Down Expand Up @@ -93,6 +95,7 @@
- match: { default-copy-settings-target.settings.index.merge.scheduler.max_thread_count: "2" }
- match: { default-copy-settings-target.settings.index.blocks.write: "true" }
- match: { default-copy-settings-target.settings.index.routing.allocation.include._id: $node_id }
- match: { default-copy-settings-target.settings.index.replication.type: "SEGMENT" }

- do:
catch: /illegal_argument_exception/
Expand All @@ -107,3 +110,21 @@
body:
settings:
index.number_of_replicas: 0

- do:
catch: /illegal_argument_exception/
allowed_warnings:
- "Parameter [master_timeout] is deprecated and will be removed in 3.0. To support inclusive language, please use [cluster_manager_timeout] instead."
indices.split:
index: "source"
target: "explicit-illegal-settings-target"
wait_for_active_shards: 1
master_timeout: 10s
body:
settings:
index.number_of_replicas: 0
index.number_of_shards: 1
index.replication.type: DOCUMENT

- match: { error.type: illegal_argument_exception }
- match: { error.reason: "cannot provide [index.replication.type] setting on resize" }
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
import java.util.Set;
import java.util.function.IntFunction;

import static org.opensearch.cluster.metadata.IndexMetadata.INDEX_REPLICATION_TYPE_SETTING;
import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_NUMBER_OF_REPLICAS;
import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_REMOTE_STORE_ENABLED;

Expand Down Expand Up @@ -311,6 +312,9 @@ static CreateIndexClusterStateUpdateRequest prepareCreateIndexRequest(
&& IndexSettings.INDEX_SOFT_DELETES_SETTING.get(targetIndexSettings) == false) {
throw new IllegalArgumentException("Can't disable [index.soft_deletes.enabled] setting on resize");
}
if (IndexMetadata.INDEX_REPLICATION_TYPE_SETTING.exists(targetIndexSettings)) {
throw new IllegalArgumentException("cannot provide [index.replication.type] setting on resize");
}
String cause = resizeRequest.getResizeType().name().toLowerCase(Locale.ROOT) + "_index";
targetIndex.cause(cause);
Settings.Builder settingsBuilder = Settings.builder().put(targetIndexSettings);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1708,7 +1708,8 @@ static void prepareResizeIndexSettings(
.put(builder.build())
.put(IndexMetadata.SETTING_ROUTING_PARTITION_SIZE, sourceMetadata.getRoutingPartitionSize())
.put(IndexMetadata.INDEX_RESIZE_SOURCE_NAME.getKey(), resizeSourceIndex.getName())
.put(IndexMetadata.INDEX_RESIZE_SOURCE_UUID.getKey(), resizeSourceIndex.getUUID());
.put(IndexMetadata.INDEX_RESIZE_SOURCE_UUID.getKey(), resizeSourceIndex.getUUID())
.put(INDEX_REPLICATION_TYPE_SETTING.getKey(), INDEX_REPLICATION_TYPE_SETTING.get(sourceMetadata.getSettings()));
gaobinlong marked this conversation as resolved.
Show resolved Hide resolved
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,27 @@ public void testErrorCondition() {
});
assertThat(softDeletesError.getMessage(), equalTo("Can't disable [index.soft_deletes.enabled] setting on resize"));

IllegalArgumentException resizeError = expectThrows(IllegalArgumentException.class, () -> {
ResizeRequest req = new ResizeRequest("target", "source");
req.getTargetIndexRequest().settings(Settings.builder().put("index.replication.type", "SEGMENT"));
ClusterState clusterState = createClusterState(
"source",
8,
1,
Settings.builder().put("index.blocks.write", true).build()
);
TransportResizeAction.prepareCreateIndexRequest(
req,
clusterState,
(i) -> new DocsStats(between(10, 1000), between(1, 10), between(1, 10000)),
new StoreStats(between(1, 10000), between(1, 10000)),
clusterSettings,
"source",
"target"
);
});
assertThat(resizeError.getMessage(), equalTo("cannot provide [index.replication.type] setting on resize"));

// create one that won't fail
ClusterState clusterState = ClusterState.builder(
createClusterState("source", randomIntBetween(2, 10), 0, Settings.builder().put("index.blocks.write", true).build())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,20 @@ public void testPrepareResizeIndexSettingsCopySettings() {
);
}

public void testPrepareResizeIndexSettingsReplicationType() {
gaobinlong marked this conversation as resolved.
Show resolved Hide resolved
runPrepareResizeIndexSettingsTest(
Settings.builder().put(SETTING_REPLICATION_TYPE, ReplicationType.SEGMENT.toString()).build(),
Settings.builder().put(SETTING_REPLICATION_TYPE, ReplicationType.DOCUMENT.toString()).build(),
emptyList(),
true,
settings -> assertThat(
"Segment Replication must be equal to source type",
settings.get(SETTING_REPLICATION_TYPE),
equalTo(ReplicationType.SEGMENT.toString())
)
);
}

public void testPrepareResizeIndexSettingsAnalysisSettings() {
// analysis settings from the request are not overwritten
runPrepareResizeIndexSettingsTest(
Expand Down
Loading