Package org.elasticsearch.indices
Class ShardLimitValidator
java.lang.Object
org.elasticsearch.indices.ShardLimitValidator
public class ShardLimitValidator
extends java.lang.Object
This class contains the logic used to check the cluster-wide shard limit before shards are created and ensuring that the limit is
updated correctly on setting updates, etc.
NOTE: This is the limit applied at *shard creation time*. If you are looking for the limit applied at *allocation* time, which is
controlled by a different setting,
see
ShardsLimitAllocationDecider
.-
Field Summary
Fields Modifier and Type Field Description static Setting<java.lang.Integer>
SETTING_CLUSTER_MAX_SHARDS_PER_NODE
protected java.util.concurrent.atomic.AtomicInteger
shardLimitPerNode
-
Constructor Summary
Constructors Constructor Description ShardLimitValidator(Settings settings, ClusterService clusterService)
-
Method Summary
Modifier and Type Method Description java.util.Optional<java.lang.String>
checkShardLimit(int newShards, ClusterState state)
Checks to see if an operation can be performed without taking the cluster over the cluster-wide shard limit.int
getShardLimitPerNode()
Gets the currently configured value of theSETTING_CLUSTER_MAX_SHARDS_PER_NODE
setting.void
validateShardLimit(ClusterState currentState, Index[] indicesToOpen)
Validates whether a list of indices can be opened without going over the cluster shard limit.void
validateShardLimit(Settings settings, ClusterState state)
Checks whether an index can be created without going over the cluster shard limit.
-
Field Details
-
SETTING_CLUSTER_MAX_SHARDS_PER_NODE
-
shardLimitPerNode
protected final java.util.concurrent.atomic.AtomicInteger shardLimitPerNode
-
-
Constructor Details
-
Method Details
-
getShardLimitPerNode
public int getShardLimitPerNode()Gets the currently configured value of theSETTING_CLUSTER_MAX_SHARDS_PER_NODE
setting.- Returns:
- the current value of the setting
-
validateShardLimit
Checks whether an index can be created without going over the cluster shard limit.- Parameters:
settings
- the settings of the index to be createdstate
- the current cluster state- Throws:
ValidationException
- if creating this index would put the cluster over the cluster shard limit
-
validateShardLimit
Validates whether a list of indices can be opened without going over the cluster shard limit. Only counts indices which are currently closed and will be opened, ignores indices which are already open.- Parameters:
currentState
- The current cluster state.indicesToOpen
- The indices which are to be opened.- Throws:
ValidationException
- If this operation would take the cluster over the limit and enforcement is enabled.
-
checkShardLimit
Checks to see if an operation can be performed without taking the cluster over the cluster-wide shard limit. Returns an error message if appropriate, or an emptyOptional
otherwise.- Parameters:
newShards
- The number of shards to be added by this operationstate
- The current cluster state- Returns:
- If present, an error message to be given as the reason for failing an operation. If empty, a sign that the operation is valid.
-