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 null value usage for index.number_of_routing_shards setting. #76069

Merged
merged 3 commits into from
Aug 5, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -819,7 +819,9 @@ static int getIndexNumberOfRoutingShards(Settings indexSettings, @Nullable Index
// in this case we either have no index to recover from or
// we have a source index with 1 shard and without an explicit split factor
// or one that is valid in that case we can split into whatever and auto-generate a new factor.
if (IndexMetadata.INDEX_NUMBER_OF_ROUTING_SHARDS_SETTING.exists(indexSettings)) {
// (Don't use IndexMetadata.INDEX_NUMBER_OF_ROUTING_SHARDS_SETTING.get(indexSettings) here, otherwise
// we get the default value when `null` has been provided as value)
if (indexSettings.get(IndexMetadata.INDEX_NUMBER_OF_ROUTING_SHARDS_SETTING.getKey()) != null) {
routingNumShards = IndexMetadata.INDEX_NUMBER_OF_ROUTING_SHARDS_SETTING.get(indexSettings);
} else {
routingNumShards = calculateNumRoutingShards(numTargetShards, indexVersionCreated);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -900,6 +900,15 @@ public void testGetIndexNumberOfRoutingShardsWhenExplicitlyConfigured() {
assertThat(targetRoutingNumberOfShards, is(9));
}

public void testGetIndexNumberOfRoutingShardsWhenNullConfigured() {
joegallo marked this conversation as resolved.
Show resolved Hide resolved
Settings indexSettings = settings(Version.CURRENT)
.put(INDEX_NUMBER_OF_ROUTING_SHARDS_SETTING.getKey(), (String) null)
.put(INDEX_NUMBER_OF_SHARDS_SETTING.getKey(), 2)
.build();
int targetRoutingNumberOfShards = getIndexNumberOfRoutingShards(indexSettings, null);
assertThat(targetRoutingNumberOfShards, is(1024));
}

public void testGetIndexNumberOfRoutingShardsYieldsSourceNumberOfShards() {
Settings indexSettings = Settings.builder()
.put(INDEX_NUMBER_OF_SHARDS_SETTING.getKey(), 3)
Expand Down