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..a6a10228193f5 100644 --- a/server/src/test/java/org/opensearch/indices/ShardLimitValidatorTests.java +++ b/server/src/test/java/org/opensearch/indices/ShardLimitValidatorTests.java @@ -214,6 +214,20 @@ 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()