From 3a85274e4c2609934855d394a468796db46de5d1 Mon Sep 17 00:00:00 2001 From: Sophia Date: Tue, 18 Jun 2024 22:21:06 -0500 Subject: [PATCH] Adding number of routing shards to index settings before passing into GetSettingsResponse Signed-off-by: Sophia --- CHANGELOG.md | 1 + .../40_routing_shards_returned.yml | 183 ++++++++++++++++++ .../get/TransportGetSettingsAction.java | 7 +- 3 files changed, 190 insertions(+), 1 deletion(-) create mode 100644 rest-api-spec/src/main/resources/rest-api-spec/test/indices.get_settings/40_routing_shards_returned.yml diff --git a/CHANGELOG.md b/CHANGELOG.md index 41d9c4f4f3905..6cc52a6d42045 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -39,6 +39,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), - Fix the computed max shards of cluster to avoid int overflow ([#14155](https://github.com/opensearch-project/OpenSearch/pull/14155)) - Fixed rest-high-level client searchTemplate & mtermVectors endpoints to have a leading slash ([#14465](https://github.com/opensearch-project/OpenSearch/pull/14465)) - Write shard level metadata blob when snapshotting searchable snapshot indexes ([#13190](https://github.com/opensearch-project/OpenSearch/pull/13190)) +- 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/40_routing_shards_returned.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/indices.get_settings/40_routing_shards_returned.yml new file mode 100644 index 0000000000000..e99acbd0c9122 --- /dev/null +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/indices.get_settings/40_routing_shards_returned.yml @@ -0,0 +1,183 @@ +--- +setup: + - skip: + version: " - 2.15.99" + reason: "number_of_routing_shards returned starting in 2.16.0" + - do: + indices.create: + index: test_1 + body: + settings: + number_of_shards: 5 + number_of_replicas: 1 + - do: + indices.create: + index: test_2 + body: + settings: + number_of_shards: 3 + number_of_replicas: 0 + number_of_routing_shards: 6 + +--- +"Get /_settings": + + - do: + indices.get_settings: {} + + - match: { test_1.settings.index.number_of_shards: "5"} + - match: { test_1.settings.index.number_of_replicas: "1"} + - match: { test_2.settings.index.number_of_shards: "3"} + - match: { test_2.settings.index.number_of_replicas: "0"} + - match: { test_2.settings.index.number_of_replicas: "6"} + +--- +"Get /{index}/_settings": + + - do: + indices.get_settings: + index: test_1 + + - match: { test_1.settings.index.number_of_shards: "5"} + - match: { test_1.settings.index.number_of_replicas: "1"} + - is_false: test_2 + + +--- +"Get /{index}/_settings/_all": + + - do: + indices.get_settings: + index: test_1 + name: _all + + - match: { test_1.settings.index.number_of_shards: "5"} + - match: { test_1.settings.index.number_of_replicas: "1"} + - is_false: test_2 + +--- +"Get /{index}/_settings/*": + + - do: + indices.get_settings: + index: test_1 + name: '*' + + - match: { test_1.settings.index.number_of_shards: "5"} + - match: { test_1.settings.index.number_of_replicas: "1"} + - is_false: test_2 + +--- +"Get /{index}/_settings/{name}": + + - do: + indices.get_settings: + index: test_1 + name: index.number_of_shards + + - match: { test_1.settings.index.number_of_shards: "5"} + - is_false: test_1.settings.index.number_of_replicas + - is_false: test_2 + +--- +"Get /{index}/_settings/{name,name}": + + - do: + indices.get_settings: + index: test_1 + name: index.number_of_shards,index.number_of_replicas + + - match: { test_1.settings.index.number_of_shards: "5"} + - match: { test_1.settings.index.number_of_replicas: "1"} + - is_false: test_2 + +--- +"Get /{index}/_settings/{name*}": + + - do: + indices.get_settings: + index: test_1 + name: 'index.number_of_s*' + + - match: { test_1.settings.index.number_of_shards: "5"} + - is_false: test_1.settings.index.number_of_replicas + - is_false: test_2 + +--- +"Get /_settings/{name}": + + - do: + indices.get_settings: + name: index.number_of_shards + + - match: { test_1.settings.index.number_of_shards: "5"} + - match: { test_2.settings.index.number_of_shards: "3"} + - is_false: test_1.settings.index.number_of_replicas + - is_false: test_2.settings.index.number_of_replicas + - is_false: test_2.settings.index.number_of_routing_shards + +--- +"Get /_all/_settings/{name}": + + - do: + indices.get_settings: + index: _all + name: index.number_of_shards + + - match: { test_1.settings.index.number_of_shards: "5"} + - match: { test_2.settings.index.number_of_shards: "3"} + - is_false: test_1.settings.index.number_of_replicas + - is_false: test_2.settings.index.number_of_replicas + - is_false: test_2.settings.index.number_of_routing_shards + + +--- +"Get /*/_settings/{name}": + + - do: + indices.get_settings: + index: '*' + name: index.number_of_shards + + - match: { test_1.settings.index.number_of_shards: "5"} + - match: { test_2.settings.index.number_of_shards: "3"} + - is_false: test_1.settings.index.number_of_replicas + - is_false: test_2.settings.index.number_of_replicas + - is_false: test_2.settings.index.number_of_routing_shards + +--- +"Get /index,index/_settings/{name}": + + - do: + indices.get_settings: + index: test_1,test_2 + name: index.number_of_shards + + - match: { test_1.settings.index.number_of_shards: "5"} + - match: { test_2.settings.index.number_of_shards: "3"} + - is_false: test_1.settings.index.number_of_replicas + - is_false: test_2.settings.index.number_of_replicas + - is_false: test_2.settings.index.number_of_routing_shards + +--- +"Get /index*/_settings/{name}": + + - do: + indices.get_settings: + index: '*2' + name: index.number_of_shards + + - match: { test_2.settings.index.number_of_shards: "3"} + - is_false: test_1 + - is_false: test_2.settings.index.number_of_replicas + - is_false: test_2.settings.index.number_of_routing_shards + +--- +"Get /_settings with local flag": + + - do: + indices.get_settings: + local: true + + - is_true: test_1 + - is_true: test_2 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); }