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 BalancedShardsAllocator.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
  • Constructor Details

    • BalancedShardsAllocator

      public BalancedShardsAllocator()
    • BalancedShardsAllocator

      public BalancedShardsAllocator(Settings settings)
    • BalancedShardsAllocator

      public BalancedShardsAllocator(ClusterSettings clusterSettings)
    • BalancedShardsAllocator

      @Inject public BalancedShardsAllocator(ClusterSettings clusterSettings, WriteLoadForecaster writeLoadForecaster)
  • 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
    • decideShardAllocation

      public ShardAllocationDecision decideShardAllocation(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. This method is primarily used by the cluster allocation explain API to provide detailed explanations for the allocation of a single shard. Implementations of the ShardsAllocator.allocate(RoutingAllocation) method may use the results of this method implementation to decide on allocating shards in the routing table to the cluster. 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:
      decideShardAllocation in interface ShardsAllocator
    • getThreshold

      public float getThreshold()
      Returns the currently configured delta threshold
    • getIndexBalance

      public float getIndexBalance()
      Returns the index related weight factor.
    • getShardBalance

      public float getShardBalance()
      Returns the shard related weight factor.