From b49cd2e175147b2c9d3092ea4021621f6f4841aa Mon Sep 17 00:00:00 2001 From: kkewwei Date: Tue, 11 Jun 2024 09:14:26 +0800 Subject: [PATCH] limit the max value of cluster.max_shards_per_node Signed-off-by: kkewwei --- CHANGELOG.md | 1 + .../org/opensearch/indices/ShardLimitValidator.java | 1 + .../indices/ShardLimitValidatorTests.java | 13 +++++++++++++ 3 files changed, 15 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c6b9822d9a8f3..24839c4c9ec81 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -72,6 +72,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), - Pass parent filter to inner hit query ([#13903](https://github.com/opensearch-project/OpenSearch/pull/13903)) - Fix NPE on restore searchable snapshot ([#13911](https://github.com/opensearch-project/OpenSearch/pull/13911)) - Fix double invocation of postCollection when MultiBucketCollector is present ([#14015](https://github.com/opensearch-project/OpenSearch/pull/14015)) +- Fix limit the max value of cluster.max_shards_per_node to avoid int overflow ([#14155](https://github.com/opensearch-project/OpenSearch/pull/14155)) ### Security diff --git a/server/src/main/java/org/opensearch/indices/ShardLimitValidator.java b/server/src/main/java/org/opensearch/indices/ShardLimitValidator.java index e345b613eebbd..15da3266f8d86 100644 --- a/server/src/main/java/org/opensearch/indices/ShardLimitValidator.java +++ b/server/src/main/java/org/opensearch/indices/ShardLimitValidator.java @@ -68,6 +68,7 @@ public class ShardLimitValidator { "cluster.max_shards_per_node", 1000, 1, + 1_500_000, new MaxShardPerNodeLimitValidator(), Setting.Property.Dynamic, Setting.Property.NodeScope diff --git a/server/src/test/java/org/opensearch/indices/ShardLimitValidatorTests.java b/server/src/test/java/org/opensearch/indices/ShardLimitValidatorTests.java index 040632ea3ed8d..b729d07be474b 100644 --- a/server/src/test/java/org/opensearch/indices/ShardLimitValidatorTests.java +++ b/server/src/test/java/org/opensearch/indices/ShardLimitValidatorTests.java @@ -214,6 +214,19 @@ public void testNonSystemIndexCreationFailsWithMaxShardLimitOnCluster() { ); } + public void testMaxValueOfMaxShardLimitOnCluster() { + final int maxShardLimitOnCluster = 2_000_000; + Settings limitOnlySettings = Settings.builder().put(SETTING_CLUSTER_MAX_SHARDS_PER_NODE.getKey(), maxShardLimitOnCluster).build(); + final IllegalArgumentException exception = expectThrows( + IllegalArgumentException.class, + () -> createTestShardLimitService(limitOnlySettings) + ); + assertEquals( + "Failed to parse value [" + maxShardLimitOnCluster + "] for setting [cluster.max_shards_per_node] must be <= 1500000", + exception.getMessage() + ); + } + public void testNonSystemIndexCreationPassesWithMaxShardLimitOnCluster() { final int maxShardLimitOnCluster = 5; Settings limitOnlySettings = Settings.builder()