Skip to content

Commit

Permalink
Use default value when index.number_of_replicas is null
Browse files Browse the repository at this point in the history
Signed-off-by: Liyun Xiu <xiliyun@amazon.com>
  • Loading branch information
chishui committed Jul 18, 2024
1 parent b3b743d commit e675065
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -946,7 +946,8 @@ static Settings aggregateIndexSettings(
if (INDEX_NUMBER_OF_SHARDS_SETTING.exists(indexSettingsBuilder) == false) {
indexSettingsBuilder.put(SETTING_NUMBER_OF_SHARDS, INDEX_NUMBER_OF_SHARDS_SETTING.get(settings));
}
if (INDEX_NUMBER_OF_REPLICAS_SETTING.exists(indexSettingsBuilder) == false) {
if (INDEX_NUMBER_OF_REPLICAS_SETTING.exists(indexSettingsBuilder) == false
|| indexSettingsBuilder.get(SETTING_NUMBER_OF_REPLICAS) == null) {
indexSettingsBuilder.put(SETTING_NUMBER_OF_REPLICAS, DEFAULT_REPLICA_COUNT_SETTING.get(currentState.metadata().settings()));
}
if (settings.get(SETTING_AUTO_EXPAND_REPLICAS) != null && indexSettingsBuilder.get(SETTING_AUTO_EXPAND_REPLICAS) == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2151,6 +2151,33 @@ public void testAsyncDurabilityThrowsExceptionWhenRestrictSettingTrue() {
);
}

public void testAggregateIndexSettingsIndexReplicaIsSetToNull() {
// This checks that aggregateIndexSettings works for the case when the index setting `index.number_of_replicas` is set to null
request = new CreateIndexClusterStateUpdateRequest("create index", "test", "test");
request.settings(Settings.builder().putNull(SETTING_NUMBER_OF_REPLICAS).build());
Integer clusterDefaultReplicaNumber = 5;
Metadata metadata = new Metadata.Builder().persistentSettings(
Settings.builder().put("cluster.default_number_of_replicas", clusterDefaultReplicaNumber).build()
).build();
ClusterState clusterState = ClusterState.builder(org.opensearch.cluster.ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY))
.metadata(metadata)
.build();
Settings settings = Settings.builder().put(CLUSTER_REMOTE_INDEX_RESTRICT_ASYNC_DURABILITY_SETTING.getKey(), true).build();
clusterSettings = new ClusterSettings(settings, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS);
Settings aggregatedSettings = aggregateIndexSettings(
clusterState,
request,
Settings.EMPTY,
null,
Settings.EMPTY,
IndexScopedSettings.DEFAULT_SCOPED_SETTINGS,
randomShardLimitService(),
Collections.emptySet(),
clusterSettings
);
assertEquals(clusterDefaultReplicaNumber.toString(), aggregatedSettings.get(SETTING_NUMBER_OF_REPLICAS));
}

public void testRequestDurabilityWhenRestrictSettingTrue() {
// This checks that aggregateIndexSettings works for the case when the cluster setting
// cluster.remote_store.index.restrict.async-durability is false or not set, it allows all types of durability modes
Expand Down

0 comments on commit e675065

Please sign in to comment.