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 wrong default value when setting index.number_of_routing_shards to null on index creation #16331

Merged
merged 2 commits into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -80,6 +80,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- Fix warnings from SLF4J on startup when repository-s3 is installed ([#16194](https://github.com/opensearch-project/OpenSearch/pull/16194))
- Fix protobuf-java leak through client library dependencies ([#16254](https://github.com/opensearch-project/OpenSearch/pull/16254))
- Fix multi-search with template doesn't return status code ([#16265](https://github.com/opensearch-project/OpenSearch/pull/16265))
- Fix wrong default value when setting `index.number_of_routing_shards` to null on index creation ([#16331](https://github.com/opensearch-project/OpenSearch/pull/16331))

### Security

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,33 @@
properties:
"":
type: keyword

---
"Create index with setting index.number_of_routing_shards to null":
- skip:
version: " - 2.99.99"
reason: "fixed in 3.0.0"
- do:
indices.create:
index: test_index
body:
settings:
number_of_routing_shards: null
- do:
cluster.state:
metric: [ metadata ]
index: test_index
- match : { metadata.indices.test_index.routing_num_shards: 1024 }

- do:
indices.create:
index: test_index1
body:
settings:
number_of_routing_shards: null
number_of_shards: 3
- do:
cluster.state:
metric: [ metadata ]
index: test_index1
- match : { metadata.indices.test_index1.routing_num_shards: 768 }
Original file line number Diff line number Diff line change
Expand Up @@ -1210,7 +1210,7 @@ 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)) {
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 @@ -1857,6 +1857,24 @@ public void testGetIndexNumberOfRoutingShardsYieldsSourceNumberOfShards() {
assertThat(targetRoutingNumberOfShards, is(6));
}

public void testGetIndexNumberOfRoutingShardsWhenExplicitlySetToNull() {
String nullValue = null;
Settings indexSettings = Settings.builder()
.put("index.version.created", Version.CURRENT)
.put(INDEX_NUMBER_OF_ROUTING_SHARDS_SETTING.getKey(), nullValue)
.build();
int targetRoutingNumberOfShards = getIndexNumberOfRoutingShards(indexSettings, null);
assertThat(targetRoutingNumberOfShards, is(1024));

indexSettings = Settings.builder()
.put("index.version.created", Version.CURRENT)
.put(INDEX_NUMBER_OF_SHARDS_SETTING.getKey(), 3)
.put(INDEX_NUMBER_OF_ROUTING_SHARDS_SETTING.getKey(), nullValue)
.build();
targetRoutingNumberOfShards = getIndexNumberOfRoutingShards(indexSettings, null);
assertThat(targetRoutingNumberOfShards, is(768));
}

public void testSoftDeletesDisabledIsRejected() {
final IllegalArgumentException error = expectThrows(IllegalArgumentException.class, () -> {
request = new CreateIndexClusterStateUpdateRequest("create index", "test", "test");
Expand Down
Loading