Skip to content

Commit 7eaef9c

Browse files
committed
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]>
1 parent 20536ee commit 7eaef9c

File tree

4 files changed

+80
-6
lines changed

4 files changed

+80
-6
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
7373
- Streaming bulk request hangs ([#16158](https://github.com/opensearch-project/OpenSearch/pull/16158))
7474
- Fix warnings from SLF4J on startup when repository-s3 is installed ([#16194](https://github.com/opensearch-project/OpenSearch/pull/16194))
7575
- Fix protobuf-java leak through client library dependencies ([#16254](https://github.com/opensearch-project/OpenSearch/pull/16254))
76+
- Fix get index settings API doesn't show `number_of_routing_shards` setting when it was explicitly set
7677

7778
### Security
7879

Lines changed: 41 additions & 0 deletions
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.17.99"
26+
reason: "introduced in 2.18.0"
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

server/src/main/java/org/opensearch/cluster/metadata/MetadataCreateIndexService.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -626,14 +626,9 @@ IndexMetadata buildAndValidateTemporaryIndexMetadata(
626626
final boolean isHiddenAfterTemplates = IndexMetadata.INDEX_HIDDEN_SETTING.get(aggregatedIndexSettings);
627627
final boolean isSystem = validateDotIndex(request.index(), isHiddenAfterTemplates);
628628

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

server/src/test/java/org/opensearch/cluster/metadata/MetadataCreateIndexServiceTests.java

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@
136136
import static java.util.Collections.emptyMap;
137137
import static java.util.Collections.singleton;
138138
import static java.util.Collections.singletonList;
139+
import static org.opensearch.cluster.metadata.IndexMetadata.INDEX_NUMBER_OF_REPLICAS_SETTING;
139140
import static org.opensearch.cluster.metadata.IndexMetadata.INDEX_NUMBER_OF_ROUTING_SHARDS_SETTING;
140141
import static org.opensearch.cluster.metadata.IndexMetadata.INDEX_NUMBER_OF_SHARDS_SETTING;
141142
import static org.opensearch.cluster.metadata.IndexMetadata.INDEX_READ_ONLY_BLOCK;
@@ -1821,6 +1822,42 @@ private void validateRemoteCustomData(Map<String, String> customData, String exp
18211822
assertEquals(expectedValue, customData.get(expectedKey));
18221823
}
18231824

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

0 commit comments

Comments
 (0)