-
Notifications
You must be signed in to change notification settings - Fork 25k
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
Adding a deprecation info API check for too many shards #85967
Merged
masseyke
merged 3 commits into
elastic:master
from
masseyke:feature/deprecation-info-shard-check
May 6, 2022
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
...precation/src/main/java/org/elasticsearch/xpack/deprecation/ClusterDeprecationChecks.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
package org.elasticsearch.xpack.deprecation; | ||
|
||
import org.elasticsearch.cluster.ClusterState; | ||
import org.elasticsearch.indices.ShardLimitValidator; | ||
import org.elasticsearch.xpack.core.deprecation.DeprecationIssue; | ||
|
||
public class ClusterDeprecationChecks { | ||
static DeprecationIssue checkShards(ClusterState clusterState) { | ||
// Make sure we have room to add a small non-frozen index if needed | ||
if (ShardLimitValidator.canAddShardsToCluster(5, 1, clusterState, false)) { | ||
return null; | ||
} else { | ||
return new DeprecationIssue( | ||
DeprecationIssue.Level.WARNING, | ||
"The cluster has too many shards to be able to upgrade", | ||
"https://ela.st/es-deprecation-7-shard-limit", | ||
"Delete indices to clear up space", | ||
false, | ||
null | ||
); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
...tion/src/test/java/org/elasticsearch/xpack/deprecation/ClusterDeprecationChecksTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
package org.elasticsearch.xpack.deprecation; | ||
|
||
import org.elasticsearch.Version; | ||
import org.elasticsearch.cluster.ClusterName; | ||
import org.elasticsearch.cluster.ClusterState; | ||
import org.elasticsearch.cluster.metadata.IndexMetadata; | ||
import org.elasticsearch.cluster.metadata.Metadata; | ||
import org.elasticsearch.cluster.node.DiscoveryNode; | ||
import org.elasticsearch.cluster.node.DiscoveryNodes; | ||
import org.elasticsearch.cluster.routing.allocation.DataTier; | ||
import org.elasticsearch.common.settings.Settings; | ||
import org.elasticsearch.indices.ShardLimitValidator; | ||
import org.elasticsearch.test.ESTestCase; | ||
import org.elasticsearch.xpack.core.deprecation.DeprecationIssue; | ||
|
||
import java.util.List; | ||
import java.util.UUID; | ||
|
||
import static java.util.Collections.singletonList; | ||
import static org.elasticsearch.xpack.deprecation.DeprecationChecks.CLUSTER_SETTINGS_CHECKS; | ||
import static org.hamcrest.Matchers.equalTo; | ||
|
||
public class ClusterDeprecationChecksTests extends ESTestCase { | ||
public void testCheckShards() { | ||
/* | ||
* This test sets the number of allowed shards per node to 5 and creates 2 nodes. So we have room for 10 shards, which is the | ||
* number of shards that checkShards() is making sure we can add. The first time there are no indices, so the check passes. The | ||
* next time there is an index with one shard and one replica, leaving room for 8 shards. So the check fails. | ||
*/ | ||
final ClusterState state = ClusterState.builder(new ClusterName(randomAlphaOfLength(5))) | ||
.metadata( | ||
Metadata.builder() | ||
.persistentSettings(Settings.builder().put(ShardLimitValidator.SETTING_CLUSTER_MAX_SHARDS_PER_NODE.getKey(), 5).build()) | ||
.build() | ||
) | ||
.nodes( | ||
DiscoveryNodes.builder() | ||
.add(new DiscoveryNode(UUID.randomUUID().toString(), buildNewFakeTransportAddress(), Version.CURRENT)) | ||
.add(new DiscoveryNode(UUID.randomUUID().toString(), buildNewFakeTransportAddress(), Version.CURRENT)) | ||
) | ||
.build(); | ||
List<DeprecationIssue> issues = DeprecationChecks.filterChecks(CLUSTER_SETTINGS_CHECKS, c -> c.apply(state)); | ||
assertThat(0, equalTo(issues.size())); | ||
|
||
final ClusterState stateWithProblems = ClusterState.builder(new ClusterName(randomAlphaOfLength(5))) | ||
.metadata( | ||
Metadata.builder() | ||
.persistentSettings(Settings.builder().put(ShardLimitValidator.SETTING_CLUSTER_MAX_SHARDS_PER_NODE.getKey(), 4).build()) | ||
.put( | ||
IndexMetadata.builder(randomAlphaOfLength(10)) | ||
.settings(settings(Version.CURRENT).put(DataTier.TIER_PREFERENCE_SETTING.getKey(), " ")) | ||
.numberOfShards(1) | ||
.numberOfReplicas(1) | ||
.build(), | ||
false | ||
) | ||
.build() | ||
) | ||
.nodes( | ||
DiscoveryNodes.builder() | ||
.add(new DiscoveryNode(UUID.randomUUID().toString(), buildNewFakeTransportAddress(), Version.CURRENT)) | ||
.add(new DiscoveryNode(UUID.randomUUID().toString(), buildNewFakeTransportAddress(), Version.CURRENT)) | ||
) | ||
.build(); | ||
|
||
issues = DeprecationChecks.filterChecks(CLUSTER_SETTINGS_CHECKS, c -> c.apply(stateWithProblems)); | ||
|
||
DeprecationIssue expected = new DeprecationIssue( | ||
DeprecationIssue.Level.WARNING, | ||
"The cluster has too many shards to be able to upgrade", | ||
"https://ela.st/es-deprecation-7-shard-limit", | ||
"Delete indices to clear up space", | ||
false, | ||
null | ||
); | ||
assertEquals(singletonList(expected), issues); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this message from another deprecation error? Otherwise maybe we can be more specific and say something like "there is not enough room for N more shards, increase the
cluster.max_shards_per_node
orcluster.max_shards_per_node.frozen
settings or remove indices to clear up resources."(using "space" is hard here, because it makes it sound like it's disk-related, when really it's just our arbitrary limits)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be used in another error message, but in this case I think it was just me trying to walk the line between being too technical and not technical enough to be useful. I'll reword it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I intentionally didn't include
cluster.max_shards_per_node.frozen
in the reworded version because we're not checking that setting (the assumption is that the new small index would not be a frozen index).