Module org.elasticsearch.server
Class BalancedShardsAllocator
java.lang.Object
org.elasticsearch.cluster.routing.allocation.allocator.BalancedShardsAllocator
- All Implemented Interfaces:
ShardsAllocator
The
BalancedShardsAllocator allocates and balances shards on the cluster nodes using WeightFunction.
The balancing attempts to:
- even shard count across nodes (weighted by cluster.routing.allocation.balance.shard)
- spread shards of the same index across different nodes (weighted by cluster.routing.allocation.balance.index)
- even write load of the data streams write indices across nodes (weighted by cluster.routing.allocation.balance.write_load)
- even disk usage across nodes (weighted by cluster.routing.allocation.balance.disk_usage)
AllocationDeciders when allocating and balancing shards.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classstatic classstatic final classA NodeSorter sorts the set of nodes for a single partition using theWeightFunctionfor that partition.static final record -
Field Summary
FieldsModifier and TypeFieldDescription -
Constructor Summary
ConstructorsConstructorDescriptionBalancedShardsAllocator(BalancerSettings balancerSettings, WriteLoadForecaster writeLoadForecaster) BalancedShardsAllocator(BalancerSettings balancerSettings, WriteLoadForecaster writeLoadForecaster, BalancingWeightsFactory balancingWeightsFactory) BalancedShardsAllocator(Settings settings) -
Method Summary
Modifier and TypeMethodDescriptionvoidallocate(RoutingAllocation allocation) Allocates shards to nodes in the cluster.explainShardAllocation(ShardRouting shard, RoutingAllocation allocation) Returns the decision for where a shard should reside in the cluster.explainShardAllocationFunction(RoutingAllocation allocation) Similar to explainShardAllocation, but returns a Function that is more efficient for explaining many shards in a bulk circumstance.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.elasticsearch.cluster.routing.allocation.allocator.ShardsAllocator
allocate, execute
-
Field Details
-
SHARD_BALANCE_FACTOR_SETTING
-
INDEX_BALANCE_FACTOR_SETTING
-
WRITE_LOAD_BALANCE_FACTOR_SETTING
-
DISK_USAGE_BALANCE_FACTOR_SETTING
-
THRESHOLD_SETTING
-
INVALID_WEIGHTS_MINIMUM_LOG_INTERVAL
-
-
Constructor Details
-
BalancedShardsAllocator
public BalancedShardsAllocator() -
BalancedShardsAllocator
-
BalancedShardsAllocator
public BalancedShardsAllocator(BalancerSettings balancerSettings, WriteLoadForecaster writeLoadForecaster) -
BalancedShardsAllocator
@Inject public BalancedShardsAllocator(BalancerSettings balancerSettings, WriteLoadForecaster writeLoadForecaster, BalancingWeightsFactory balancingWeightsFactory)
-
-
Method Details
-
allocate
Description copied from interface:ShardsAllocatorAllocates shards to nodes in the cluster. An implementation of this method should: - assign unassigned shards - relocate shards that cannot stay on a node anymore - relocate shards to find a good shard balance in the cluster- Specified by:
allocatein interfaceShardsAllocator- Parameters:
allocation- current node allocation
-
explainShardAllocation
public ShardAllocationDecision explainShardAllocation(ShardRouting shard, RoutingAllocation allocation) Description copied from interface:ShardsAllocatorReturns the decision for where a shard should reside in the cluster. If the shard is unassigned, then theAllocateUnassignedDecisionwill be non-null. If the shard is not in the unassigned state, then theMoveDecisionwill be non-null. If an implementation of this interface does not support explaining decisions for a single shard through the cluster explain API, then this method should throw aUnsupportedOperationException.- Specified by:
explainShardAllocationin interfaceShardsAllocator
-
explainShardAllocationFunction
public Function<ShardRouting,ShardAllocationDecision> explainShardAllocationFunction(RoutingAllocation allocation) Description copied from interface:ShardsAllocatorSimilar to explainShardAllocation, but returns a Function that is more efficient for explaining many shards in a bulk circumstance. Internally, an allocator builds up internal data structures for simulating its balancing algorithm. In some implementations, such as the BalancedShardsAllocator (also used within the DesiredBalanceAllocator), this internal context is computationally expensive. When run over many shards, it can be Order(shards * nodes). Instead of taking a shard and explaining it, explainShardAllocationFunction returns a Function that can be called repeatedly to explain multiple shards while reusing the context in the Function's closure. This reduces the computational cost of explain.- Specified by:
explainShardAllocationFunctionin interfaceShardsAllocator
-