Skip to content

Commit 5941a7e

Browse files
authoredOct 23, 2024
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 <gbinlong@amazon.com> * Update skip version in rest yaml test file Signed-off-by: Gao Binlong <gbinlong@amazon.com> * Fix test failure Signed-off-by: Gao Binlong <gbinlong@amazon.com> --------- Signed-off-by: Gao Binlong <gbinlong@amazon.com>
1 parent 15607b1 commit 5941a7e

File tree

5 files changed

+82
-7
lines changed

5 files changed

+82
-7
lines changed
 

‎CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
8585
- Streaming bulk request hangs ([#16158](https://github.com/opensearch-project/OpenSearch/pull/16158))
8686
- Fix warnings from SLF4J on startup when repository-s3 is installed ([#16194](https://github.com/opensearch-project/OpenSearch/pull/16194))
8787
- Fix protobuf-java leak through client library dependencies ([#16254](https://github.com/opensearch-project/OpenSearch/pull/16254))
88+
- 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))
8889
- Fix multi-search with template doesn't return status code ([#16265](https://github.com/opensearch-project/OpenSearch/pull/16265))
8990
- [Streaming Indexing] Fix intermittent 'The bulk request must be terminated by a newline [\n]' failures [#16337](https://github.com/opensearch-project/OpenSearch/pull/16337))
9091
- 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

‎server/src/main/java/org/opensearch/cluster/metadata/IndexMetadata.java

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

302302
},
303-
Property.IndexScope
303+
Property.IndexScope,
304+
Property.NotCopyableOnResize
304305
);
305306

306307
/**

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

+1-6
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

+37
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)
Please sign in to comment.