Skip to content

Commit c8ced34

Browse files
Fix get index settings API doesn't show number_of_routing_shards when it was explicitly set on index creation (#16294)
* Fix get index settings API doesn't show number_of_routing_shards when it was explicitly set on index creation Signed-off-by: Gao Binlong <[email protected]> * Update skip version in rest yaml test file Signed-off-by: Gao Binlong <[email protected]> * Fix test failure Signed-off-by: Gao Binlong <[email protected]> --------- Signed-off-by: Gao Binlong <[email protected]> (cherry picked from commit 5941a7e) Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent b771f78 commit c8ced34

File tree

5 files changed

+82
-7
lines changed

5 files changed

+82
-7
lines changed

Diff for: CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
8686
- Streaming bulk request hangs ([#16158](https://github.com/opensearch-project/OpenSearch/pull/16158))
8787
- Fix warnings from SLF4J on startup when repository-s3 is installed ([#16194](https://github.com/opensearch-project/OpenSearch/pull/16194))
8888
- Fix protobuf-java leak through client library dependencies ([#16254](https://github.com/opensearch-project/OpenSearch/pull/16254))
89+
- Fix get index settings API doesn't show `number_of_routing_shards` setting when it was explicitly set ([#16294](https://github.com/opensearch-project/OpenSearch/pull/16294))
8990
- Fix multi-search with template doesn't return status code ([#16265](https://github.com/opensearch-project/OpenSearch/pull/16265))
9091
- [Streaming Indexing] Fix intermittent 'The bulk request must be terminated by a newline [\n]' failures [#16337](https://github.com/opensearch-project/OpenSearch/pull/16337))
9192
- 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))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
---
2+
setup:
3+
- do:
4+
indices.create:
5+
body:
6+
settings:
7+
index:
8+
number_of_routing_shards: 4
9+
number_of_shards: 2
10+
number_of_replicas: 1
11+
index: test-index
12+
13+
- do:
14+
indices.create:
15+
body:
16+
settings:
17+
index:
18+
number_of_shards: 2
19+
number_of_replicas: 1
20+
index: test-index1
21+
22+
---
23+
Test retrieval of number_routing_shards settings:
24+
- skip:
25+
version: " - 2.99.99"
26+
reason: "introduced in 3.0.0" # TODO: change it to 2.18.0 after backport to 2.x branch
27+
- do:
28+
indices.get_settings:
29+
flat_settings: true
30+
index: test-index
31+
# show `index.number_of_routing_shards` if it was explicitly set when creating
32+
- match:
33+
test-index.settings.index\.number_of_routing_shards: "4"
34+
35+
- do:
36+
indices.get_settings:
37+
flat_settings: true
38+
index: test-index1
39+
# do not show `index.number_of_routing_shards` if it was not explicitly set when creating
40+
- match:
41+
test-index1.settings.index\.number_of_routing_shards: null

Diff for: server/src/main/java/org/opensearch/cluster/metadata/IndexMetadata.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,8 @@ public Iterator<Setting<?>> settings() {
299299
}
300300

301301
},
302-
Property.IndexScope
302+
Property.IndexScope,
303+
Property.NotCopyableOnResize
303304
);
304305

305306
/**

Diff for: server/src/main/java/org/opensearch/cluster/metadata/MetadataCreateIndexService.java

+1-6
Original file line numberDiff line numberDiff line change
@@ -627,14 +627,9 @@ IndexMetadata buildAndValidateTemporaryIndexMetadata(
627627
final boolean isHiddenAfterTemplates = IndexMetadata.INDEX_HIDDEN_SETTING.get(aggregatedIndexSettings);
628628
final boolean isSystem = validateDotIndex(request.index(), isHiddenAfterTemplates);
629629

630-
// remove the setting it's temporary and is only relevant once we create the index
631-
final Settings.Builder settingsBuilder = Settings.builder().put(aggregatedIndexSettings);
632-
settingsBuilder.remove(IndexMetadata.INDEX_NUMBER_OF_ROUTING_SHARDS_SETTING.getKey());
633-
final Settings indexSettings = settingsBuilder.build();
634-
635630
final IndexMetadata.Builder tmpImdBuilder = IndexMetadata.builder(request.index());
636631
tmpImdBuilder.setRoutingNumShards(routingNumShards);
637-
tmpImdBuilder.settings(indexSettings);
632+
tmpImdBuilder.settings(aggregatedIndexSettings);
638633
tmpImdBuilder.system(isSystem);
639634
addRemoteStoreCustomMetadata(tmpImdBuilder, true);
640635

Diff for: server/src/test/java/org/opensearch/cluster/metadata/MetadataCreateIndexServiceTests.java

+37
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@
137137
import static java.util.Collections.emptyMap;
138138
import static java.util.Collections.singleton;
139139
import static java.util.Collections.singletonList;
140+
import static org.opensearch.cluster.metadata.IndexMetadata.INDEX_NUMBER_OF_REPLICAS_SETTING;
140141
import static org.opensearch.cluster.metadata.IndexMetadata.INDEX_NUMBER_OF_ROUTING_SHARDS_SETTING;
141142
import static org.opensearch.cluster.metadata.IndexMetadata.INDEX_NUMBER_OF_SHARDS_SETTING;
142143
import static org.opensearch.cluster.metadata.IndexMetadata.INDEX_READ_ONLY_BLOCK;
@@ -1830,6 +1831,42 @@ private void validateRemoteCustomData(Map<String, String> customData, String exp
18301831
assertEquals(expectedValue, customData.get(expectedKey));
18311832
}
18321833

1834+
public void testNumberOfRoutingShardsShowsInIndexSettings() {
1835+
withTemporaryClusterService(((clusterService, threadPool) -> {
1836+
MetadataCreateIndexService checkerService = new MetadataCreateIndexService(
1837+
Settings.EMPTY,
1838+
clusterService,
1839+
indicesServices,
1840+
null,
1841+
null,
1842+
createTestShardLimitService(randomIntBetween(1, 1000), false, clusterService),
1843+
null,
1844+
null,
1845+
threadPool,
1846+
null,
1847+
new SystemIndices(Collections.emptyMap()),
1848+
false,
1849+
new AwarenessReplicaBalance(Settings.EMPTY, clusterService.getClusterSettings()),
1850+
DefaultRemoteStoreSettings.INSTANCE,
1851+
repositoriesServiceSupplier
1852+
);
1853+
final int routingNumberOfShards = 4;
1854+
Settings indexSettings = Settings.builder()
1855+
.put("index.version.created", Version.CURRENT)
1856+
.put(INDEX_NUMBER_OF_SHARDS_SETTING.getKey(), 2)
1857+
.put(INDEX_NUMBER_OF_REPLICAS_SETTING.getKey(), 0)
1858+
.put(INDEX_NUMBER_OF_ROUTING_SHARDS_SETTING.getKey(), routingNumberOfShards)
1859+
.build();
1860+
CreateIndexClusterStateUpdateRequest request = new CreateIndexClusterStateUpdateRequest("create index", "test", "test");
1861+
IndexMetadata indexMetadata = checkerService.buildAndValidateTemporaryIndexMetadata(
1862+
indexSettings,
1863+
request,
1864+
routingNumberOfShards
1865+
);
1866+
assertEquals(INDEX_NUMBER_OF_ROUTING_SHARDS_SETTING.get(indexMetadata.getSettings()).intValue(), routingNumberOfShards);
1867+
}));
1868+
}
1869+
18331870
public void testGetIndexNumberOfRoutingShardsWithNullSourceIndex() {
18341871
Settings indexSettings = Settings.builder()
18351872
.put("index.version.created", Version.CURRENT)

0 commit comments

Comments
 (0)