Skip to content

Commit

Permalink
Fix wrong default value when setting index.number_of_routing_shards t…
Browse files Browse the repository at this point in the history
…o null on index creation (opensearch-project#16331)

* Fix wrong value when setting index.number_of_routing_shards to null on index creation

Signed-off-by: Gao Binlong <[email protected]>

* Modify change log

Signed-off-by: Gao Binlong <[email protected]>

---------

Signed-off-by: Gao Binlong <[email protected]>
  • Loading branch information
gaobinlong authored Oct 16, 2024
1 parent 23d1c7a commit a853b75
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,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

0 comments on commit a853b75

Please sign in to comment.