java.lang.Object
org.elasticsearch.cluster.routing.allocation.allocator.BalancedShardsAllocator
All Implemented Interfaces:
ShardsAllocator

public class BalancedShardsAllocator extends Object implements 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)
The sensitivity of the algorithm is defined by cluster.routing.allocation.balance.threshold. Allocator takes into account constraints set by AllocationDeciders when allocating and balancing shards.
  • Field Details

    • SHARD_BALANCE_FACTOR_SETTING

      public static final Setting<Float> SHARD_BALANCE_FACTOR_SETTING
    • INDEX_BALANCE_FACTOR_SETTING

      public static final Setting<Float> INDEX_BALANCE_FACTOR_SETTING
    • WRITE_LOAD_BALANCE_FACTOR_SETTING

      public static final Setting<Float> WRITE_LOAD_BALANCE_FACTOR_SETTING
    • DISK_USAGE_BALANCE_FACTOR_SETTING

      public static final Setting<Float> DISK_USAGE_BALANCE_FACTOR_SETTING
    • THRESHOLD_SETTING

      public static final Setting<Float> THRESHOLD_SETTING
    • INVALID_WEIGHTS_MINIMUM_LOG_INTERVAL

      public static final Setting<TimeValue> INVALID_WEIGHTS_MINIMUM_LOG_INTERVAL
  • Constructor Details

  • Method Details

    • allocate

      public void allocate(RoutingAllocation allocation)
      Description copied from interface: ShardsAllocator
      Allocates 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:
      allocate in interface ShardsAllocator
      Parameters:
      allocation - current node allocation
    • explainShardAllocation

      public ShardAllocationDecision explainShardAllocation(ShardRouting shard, RoutingAllocation allocation)
      Description copied from interface: ShardsAllocator
      Returns the decision for where a shard should reside in the cluster. If the shard is unassigned, then the AllocateUnassignedDecision will be non-null. If the shard is not in the unassigned state, then the MoveDecision will 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 a UnsupportedOperationException.
      Specified by:
      explainShardAllocation in interface ShardsAllocator
    • explainShardAllocationFunction

      public Function<ShardRouting,ShardAllocationDecision> explainShardAllocationFunction(RoutingAllocation allocation)
      Description copied from interface: ShardsAllocator
      Similar 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:
      explainShardAllocationFunction in interface ShardsAllocator