Skip to content

Commit 6e563e5

Browse files
committed
More PR feedback.
Signed-off-by: Marc Handalian <marc.handalian@gmail.com>
1 parent c059bd8 commit 6e563e5

File tree

3 files changed

+14
-17
lines changed

3 files changed

+14
-17
lines changed

server/src/main/java/org/opensearch/cluster/metadata/MetadataCreateIndexService.java

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1008,22 +1008,18 @@ static Settings aggregateIndexSettings(
10081008

10091009
private static void updateSearchOnlyReplicas(Settings requestSettings, Settings.Builder builder) {
10101010
if (INDEX_NUMBER_OF_SEARCH_REPLICAS_SETTING.exists(builder) && builder.get(SETTING_NUMBER_OF_SEARCH_REPLICAS) != null) {
1011+
if (INDEX_NUMBER_OF_SEARCH_REPLICAS_SETTING.get(requestSettings) > 0
1012+
&& ReplicationType.parseString(builder.get(INDEX_REPLICATION_TYPE_SETTING.getKey())).equals(ReplicationType.DOCUMENT)) {
1013+
throw new IllegalArgumentException(
1014+
"To set "
1015+
+ SETTING_NUMBER_OF_SEARCH_REPLICAS
1016+
+ ", "
1017+
+ INDEX_REPLICATION_TYPE_SETTING.getKey()
1018+
+ " must be set to "
1019+
+ ReplicationType.SEGMENT
1020+
);
1021+
}
10111022
builder.put(SETTING_NUMBER_OF_SEARCH_REPLICAS, INDEX_NUMBER_OF_SEARCH_REPLICAS_SETTING.get(requestSettings));
1012-
} else {
1013-
// ensure we always set the default on creation to a nonnull value.
1014-
// TODO: Maybe allow a cluster wide default for search replica count when SR is default strategy
1015-
builder.put(SETTING_NUMBER_OF_SEARCH_REPLICAS, INDEX_NUMBER_OF_SEARCH_REPLICAS_SETTING.getDefault(requestSettings));
1016-
}
1017-
if (INDEX_NUMBER_OF_SEARCH_REPLICAS_SETTING.get(requestSettings) > 0
1018-
&& ReplicationType.parseString(builder.get(INDEX_REPLICATION_TYPE_SETTING.getKey())).equals(ReplicationType.DOCUMENT)) {
1019-
throw new IllegalArgumentException(
1020-
"To set "
1021-
+ SETTING_NUMBER_OF_SEARCH_REPLICAS
1022-
+ ", "
1023-
+ INDEX_REPLICATION_TYPE_SETTING.getKey()
1024-
+ " must be set to "
1025-
+ ReplicationType.SEGMENT
1026-
);
10271023
}
10281024
}
10291025

server/src/main/java/org/opensearch/cluster/metadata/MetadataUpdateSettingsService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ public ClusterState execute(ClusterState currentState) {
270270
}
271271
final int updatedNumberOfSearchReplicas = IndexMetadata.INDEX_NUMBER_OF_SEARCH_REPLICAS_SETTING.get(openSettings);
272272
if (preserveExisting == false) {
273-
// TODO: Maybe honor awareness validation to search replicas?
273+
// TODO: Honor awareness validation to search replicas.
274274

275275
// Verify that this won't take us over the cluster shard limit.
276276
int totalNewShards = Arrays.stream(request.indices())

server/src/test/java/org/opensearch/cluster/metadata/MetadataCreateIndexServiceTests.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@
128128
import static java.util.Collections.singleton;
129129
import static java.util.Collections.singletonList;
130130
import static org.opensearch.cluster.metadata.IndexMetadata.INDEX_NUMBER_OF_ROUTING_SHARDS_SETTING;
131+
import static org.opensearch.cluster.metadata.IndexMetadata.INDEX_NUMBER_OF_SEARCH_REPLICAS_SETTING;
131132
import static org.opensearch.cluster.metadata.IndexMetadata.INDEX_NUMBER_OF_SHARDS_SETTING;
132133
import static org.opensearch.cluster.metadata.IndexMetadata.INDEX_READ_ONLY_BLOCK;
133134
import static org.opensearch.cluster.metadata.IndexMetadata.INDEX_REPLICATION_TYPE_SETTING;
@@ -2250,7 +2251,7 @@ public void testDefaultSearchReplicasSetting() {
22502251
Collections.emptySet(),
22512252
clusterSettings
22522253
);
2253-
assertEquals("0", indexSettings.get(SETTING_NUMBER_OF_SEARCH_REPLICAS));
2254+
assertFalse(INDEX_NUMBER_OF_SEARCH_REPLICAS_SETTING.exists(indexSettings));
22542255
}
22552256

22562257
public void testSearchReplicasValidationWithSegmentReplication() {

0 commit comments

Comments
 (0)