Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

limit the max value of cluster.max_shards_per_node to avoid int overflow #14155

Merged
merged 2 commits into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- 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))
- Java high-level REST client bulk() is not respecting the bulkRequest.requireAlias(true) method call ([#14146](https://github.com/opensearch-project/OpenSearch/pull/14146))
- Fix the computed max shards of cluster to avoid int overflow ([#14155](https://github.com/opensearch-project/OpenSearch/pull/14155))

### Security

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,14 +261,15 @@ static Optional<String> checkShardLimit(
return Optional.empty();
}

int computedMaxShards = (int) Math.min(Integer.MAX_VALUE, (long) maxShardsPerNodeSetting * nodeCount);
int maxShardsInCluster = maxShardsPerClusterSetting;
if (maxShardsInCluster == -1) {
maxShardsInCluster = maxShardsPerNodeSetting * nodeCount;
maxShardsInCluster = computedMaxShards;
} else {
maxShardsInCluster = Math.min(maxShardsInCluster, maxShardsPerNodeSetting * nodeCount);
maxShardsInCluster = Math.min(maxShardsInCluster, computedMaxShards);
}

int currentOpenShards = state.getMetadata().getTotalOpenIndexShards();
long currentOpenShards = state.getMetadata().getTotalOpenIndexShards();
shwetathareja marked this conversation as resolved.
Show resolved Hide resolved
if ((currentOpenShards + newShards) > maxShardsInCluster) {
String errorMessage = "this action would add ["
+ newShards
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,25 @@ public void testNonSystemIndexCreationFailsWithMaxShardLimitOnCluster() {
);
}

public void testComputedMaxShardsOfClusterIntOverFlow() {
final int maxShardLimitPerNode = 500_000_000;
ClusterState state = createClusterForShardLimitTest(15, 1, 1);
Optional<String> errorMessage = ShardLimitValidator.checkShardLimit(2, state, maxShardLimitPerNode, -1);
assertFalse(errorMessage.isPresent());

errorMessage = ShardLimitValidator.checkShardLimit(Integer.MAX_VALUE - 1, state, maxShardLimitPerNode, -1);
assertEquals(
kkewwei marked this conversation as resolved.
Show resolved Hide resolved
"this action would add ["
+ (Integer.MAX_VALUE - 1)
+ "] total shards, but this cluster currently has ["
+ 2
+ "]/["
+ Integer.MAX_VALUE
+ "] maximum shards open",
errorMessage.get()
);
}

public void testNonSystemIndexCreationPassesWithMaxShardLimitOnCluster() {
final int maxShardLimitOnCluster = 5;
Settings limitOnlySettings = Settings.builder()
Expand Down
Loading