From 02bd80286124256f87aee8e582cbe783d4c716da Mon Sep 17 00:00:00 2001 From: Sophia Date: Mon, 24 Jun 2024 21:43:57 -0500 Subject: [PATCH] Adding number of routing shards to index settings before passing into GetSettingsResponse Signed-off-by: Sophia --- CHANGELOG.md | 1 + .../test/indices.get_settings/10_basic.yml | 39 +++++++++++++++++++ .../get/TransportGetSettingsAction.java | 7 +++- .../settings/get/GetSettingsActionTests.java | 10 +++++ 4 files changed, 56 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cafe9c20e7ff4..50cb18787147d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -45,6 +45,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), - Fix fs info reporting negative available size ([#11573](https://github.com/opensearch-project/OpenSearch/pull/11573)) - Add ListPitInfo::getKeepAlive() getter ([#14495](https://github.com/opensearch-project/OpenSearch/pull/14495)) - Fix FuzzyQuery in keyword field will use IndexOrDocValuesQuery when both of index and doc_value are true ([#14378](https://github.com/opensearch-project/OpenSearch/pull/14378)) +- Updated GET {index}/_settings to return `number_of_routing_shards` ([#14446](https://github.com/opensearch-project/OpenSearch/pull/14446)) ### Security diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/indices.get_settings/10_basic.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/indices.get_settings/10_basic.yml index a50be32e82c6a..845989edc93b7 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/indices.get_settings/10_basic.yml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/indices.get_settings/10_basic.yml @@ -171,3 +171,42 @@ setup: - is_true: test_1 - is_true: test_2 + +--- +"Test number of routing shards returned": + - skip: + version: " - 2.99.99" + reason: "introduced in 3.0.0" + + - do: + indices.create: + index: test_3 + body: + settings: + number_of_shards: 3 + number_of_replicas: 0 + number_of_routing_shards: 6 + + - do: + indices.get_settings: {} + + - match: { test_3.settings.index.number_of_shards: "3"} + - match: { test_3.settings.index.number_of_replicas: "0"} + - match: { test_3.settings.index.number_of_routing_shards: "6"} + + - do: + indices.get_settings: + index: test_3 + + - match: { test_3.settings.index.number_of_shards: "3"} + - match: { test_3.settings.index.number_of_replicas: "0"} + - match: { test_3.settings.index.number_of_routing_shards: "6"} + + - do: + indices.get_settings: + index: test_3 + name: _all + + - match: { test_3.settings.index.number_of_shards: "3"} + - match: { test_3.settings.index.number_of_replicas: "0"} + - match: { test_3.settings.index.number_of_routing_shards: "6"} diff --git a/server/src/main/java/org/opensearch/action/admin/indices/settings/get/TransportGetSettingsAction.java b/server/src/main/java/org/opensearch/action/admin/indices/settings/get/TransportGetSettingsAction.java index d8f2180208b18..4b16301a1762f 100644 --- a/server/src/main/java/org/opensearch/action/admin/indices/settings/get/TransportGetSettingsAction.java +++ b/server/src/main/java/org/opensearch/action/admin/indices/settings/get/TransportGetSettingsAction.java @@ -121,7 +121,12 @@ protected void clusterManagerOperation(GetSettingsRequest request, ClusterState continue; } - Settings indexSettings = settingsFilter.filter(indexMetadata.getSettings()); + Settings indexSettingsWithRoutingShards = Settings.builder() + .put(indexMetadata.getSettings()) + .put(IndexMetadata.INDEX_NUMBER_OF_ROUTING_SHARDS_SETTING.getKey(), indexMetadata.getRoutingNumShards()) + .build(); + + Settings indexSettings = settingsFilter.filter(indexSettingsWithRoutingShards); if (request.humanReadable()) { indexSettings = IndexMetadata.addHumanReadableSettings(indexSettings); } diff --git a/server/src/test/java/org/opensearch/action/admin/indices/settings/get/GetSettingsActionTests.java b/server/src/test/java/org/opensearch/action/admin/indices/settings/get/GetSettingsActionTests.java index f2b6688716e70..e11c31d93a442 100644 --- a/server/src/test/java/org/opensearch/action/admin/indices/settings/get/GetSettingsActionTests.java +++ b/server/src/test/java/org/opensearch/action/admin/indices/settings/get/GetSettingsActionTests.java @@ -165,6 +165,16 @@ public void testIncludeDefaultsWithFiltering() { }, exception -> { throw new AssertionError(exception); })); } + public void testShouldReturnNumberOfRoutingShards() { + GetSettingsRequest noDefaultsRequest = new GetSettingsRequest().indices(indexName); + getSettingsAction.execute(null, noDefaultsRequest, ActionListener.wrap(noDefaultsResponse -> { + assertNotNull( + "index.number_of_routing_shards should be set", + noDefaultsResponse.getSetting(indexName, "index.number_of_routing_shards") + ); + }, exception -> { throw new AssertionError(exception); })); + } + static class Resolver extends IndexNameExpressionResolver { Resolver() { super(new ThreadContext(Settings.EMPTY));