Class AllocationService


public class AllocationService extends Object
This service manages the node allocation of a cluster. For this reason the AllocationService keeps AllocationDeciders to choose nodes for shard allocation. This class also manages new nodes joining the cluster and rerouting of shards.
  • Constructor Details

  • Method Details

    • setExistingShardsAllocators

      public void setExistingShardsAllocators(Map<String,ExistingShardsAllocator> existingShardsAllocators)
      Inject the ExistingShardsAllocators to use. May only be called once.
    • applyStartedShards

      public ClusterState applyStartedShards(ClusterState clusterState, List<ShardRouting> startedShards)
      Applies the started shards. Note, only initializing ShardRouting instances that exist in the routing table should be provided as parameter and no duplicates should be contained.

      If the same instance of the ClusterState is returned, then no change has been made.

    • applyFailedShard

      public ClusterState applyFailedShard(ClusterState clusterState, ShardRouting failedShard, boolean markAsStale)
    • applyFailedShards

      public ClusterState applyFailedShards(ClusterState clusterState, List<FailedShard> failedShards)
    • applyFailedShards

      public ClusterState applyFailedShards(ClusterState clusterState, List<FailedShard> failedShards, List<StaleShard> staleShards)
      Applies the failed shards. Note, only assigned ShardRouting instances that exist in the routing table should be provided as parameter. Also applies a list of allocation ids to remove from the in-sync set for shard copies for which there are no routing entries in the routing table.

      If the same instance of ClusterState is returned, then no change has been made.

    • disassociateDeadNodes

      public ClusterState disassociateDeadNodes(ClusterState clusterState, boolean reroute, String reason)
      unassigned an shards that are associated with nodes that are no longer part of the cluster, potentially promoting replicas if needed.
    • adaptAutoExpandReplicas

      public ClusterState adaptAutoExpandReplicas(ClusterState clusterState)
      Checks if there are replicas with the auto-expand feature that need to be adapted. Returns an updated cluster state if changes were necessary, or the identical cluster if no changes were required.
    • firstListElementsToCommaDelimitedString

      public static <T> String firstListElementsToCommaDelimitedString(List<T> elements, Function<T,String> formatter, boolean isDebugEnabled)
      Internal helper to cap the number of elements in a potentially long list for logging.
      Type Parameters:
      T - The list element type.
      elements - The elements to log. May be any non-null list. Must not be null.
      formatter - A function that can convert list elements to a String. Must not be null.
      A comma-separated string of the first few elements.
    • reroute

      public AllocationService.CommandsResult reroute(ClusterState clusterState, AllocationCommands commands, boolean explain, boolean retryFailed)
    • reroute

      public ClusterState reroute(ClusterState clusterState, String reason)
      Computes the next step towards a fully allocated and balanced cluster and records this step in the routing table of the returned state. Should be called after every change to the cluster that affects the routing table and/or the balance of shards.

      This method is expensive in larger clusters. Wherever possible you should invoke this method asynchronously using RerouteService.reroute(java.lang.String, org.elasticsearch.common.Priority, org.elasticsearch.action.ActionListener<org.elasticsearch.cluster.ClusterState>) to batch up invocations rather than calling the method directly. The node's reroute service is typically obtained from ClusterService.getRerouteService().

      an updated cluster state, or the same instance that was passed as an argument if no changes were made.
    • currentNanoTime

      protected long currentNanoTime()
      override this to control time based decisions during allocation
    • cleanCaches

      public void cleanCaches()
    • getNumberOfInFlightFetches

      public int getNumberOfInFlightFetches()
    • explainShardAllocation

      public ShardAllocationDecision explainShardAllocation(ShardRouting shardRouting, RoutingAllocation allocation)