Skip to content

Commit

Permalink
Fix get index settings API doesn't show setting when it was explicitl…
Browse files Browse the repository at this point in the history
…y set

Signed-off-by: Gao Binlong <gbinlong@amazon.com>
  • Loading branch information
gaobinlong committed Oct 12, 2024
1 parent 20536ee commit f85959d
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- Streaming bulk request hangs ([#16158](https://github.com/opensearch-project/OpenSearch/pull/16158))
- 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 get index settings API doesn't show `number_of_routing_shards` setting when it was explicitly set

### Security

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
---
setup:
- do:
indices.create:
body:
settings:
index:
number_of_routing_shards: 4
number_of_shards: 2
number_of_replicas: 1
index: test-index

- do:
indices.create:
body:
settings:
index:
number_of_shards: 2
number_of_replicas: 1
index: test-index1

---
Test retrieval of number_routing_shards settings:
- skip:
version: " - 2.17.99"
reason: "introduced in 2.18.0"
- do:
indices.get_settings:
flat_settings: true
index: test-index
# show `index.number_of_routing_shards` if it was explicitly set when creating
- match:
test-index.settings.index\.number_of_routing_shards: "4"

- do:
indices.get_settings:
flat_settings: true
index: test-index1
# do not show `index.number_of_routing_shards` if it was not explicitly set when creating
- match:
test-index1.settings.index\.number_of_routing_shards: null
Original file line number Diff line number Diff line change
Expand Up @@ -626,14 +626,9 @@ IndexMetadata buildAndValidateTemporaryIndexMetadata(
final boolean isHiddenAfterTemplates = IndexMetadata.INDEX_HIDDEN_SETTING.get(aggregatedIndexSettings);
final boolean isSystem = validateDotIndex(request.index(), isHiddenAfterTemplates);

// remove the setting it's temporary and is only relevant once we create the index
final Settings.Builder settingsBuilder = Settings.builder().put(aggregatedIndexSettings);
settingsBuilder.remove(IndexMetadata.INDEX_NUMBER_OF_ROUTING_SHARDS_SETTING.getKey());
final Settings indexSettings = settingsBuilder.build();

final IndexMetadata.Builder tmpImdBuilder = IndexMetadata.builder(request.index());
tmpImdBuilder.setRoutingNumShards(routingNumShards);
tmpImdBuilder.settings(indexSettings);
tmpImdBuilder.settings(aggregatedIndexSettings);
tmpImdBuilder.system(isSystem);
addRemoteStoreCustomMetadata(tmpImdBuilder, true);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@
import static java.util.Collections.emptyMap;
import static java.util.Collections.singleton;
import static java.util.Collections.singletonList;
import static org.opensearch.cluster.metadata.IndexMetadata.INDEX_NUMBER_OF_REPLICAS_SETTING;
import static org.opensearch.cluster.metadata.IndexMetadata.INDEX_NUMBER_OF_ROUTING_SHARDS_SETTING;
import static org.opensearch.cluster.metadata.IndexMetadata.INDEX_NUMBER_OF_SHARDS_SETTING;
import static org.opensearch.cluster.metadata.IndexMetadata.INDEX_READ_ONLY_BLOCK;
Expand Down Expand Up @@ -1821,6 +1822,42 @@ private void validateRemoteCustomData(Map<String, String> customData, String exp
assertEquals(expectedValue, customData.get(expectedKey));
}

public void testNumberOfRoutingShardsShowsInIndexSettings() {
withTemporaryClusterService(((clusterService, threadPool) -> {
MetadataCreateIndexService checkerService = new MetadataCreateIndexService(
Settings.EMPTY,
clusterService,
indicesServices,
null,
null,
createTestShardLimitService(randomIntBetween(1, 1000), false, clusterService),
null,
null,
threadPool,
null,
new SystemIndices(Collections.emptyMap()),
false,
new AwarenessReplicaBalance(Settings.EMPTY, clusterService.getClusterSettings()),
DefaultRemoteStoreSettings.INSTANCE,
repositoriesServiceSupplier
);
final int routingNumberOfShards = 4;
Settings indexSettings = Settings.builder()
.put("index.version.created", Version.CURRENT)
.put(INDEX_NUMBER_OF_SHARDS_SETTING.getKey(), 2)
.put(INDEX_NUMBER_OF_REPLICAS_SETTING.getKey(), 0)
.put(INDEX_NUMBER_OF_ROUTING_SHARDS_SETTING.getKey(), routingNumberOfShards)
.build();
CreateIndexClusterStateUpdateRequest request = new CreateIndexClusterStateUpdateRequest("create index", "test", "test");
IndexMetadata indexMetadata = checkerService.buildAndValidateTemporaryIndexMetadata(
indexSettings,
request,
routingNumberOfShards
);
assertEquals(INDEX_NUMBER_OF_ROUTING_SHARDS_SETTING.get(indexMetadata.getSettings()).intValue(), routingNumberOfShards);
}));
}

public void testGetIndexNumberOfRoutingShardsWithNullSourceIndex() {
Settings indexSettings = Settings.builder()
.put("index.version.created", Version.CURRENT)
Expand Down

0 comments on commit f85959d

Please sign in to comment.