Class AllocationService
java.lang.Object
org.elasticsearch.cluster.routing.allocation.AllocationService
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.-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
this class is used to describe results of applying a set ofAllocationCommand
-
Constructor Summary
ConstructorDescriptionAllocationService(AllocationDeciders allocationDeciders, ShardsAllocator shardsAllocator, ClusterInfoService clusterInfoService, SnapshotsInfoService snapshotsInfoService)
AllocationService(AllocationDeciders allocationDeciders, GatewayAllocator gatewayAllocator, ShardsAllocator shardsAllocator, ClusterInfoService clusterInfoService, SnapshotsInfoService snapshotsInfoService)
-
Method Summary
Modifier and TypeMethodDescriptionadaptAutoExpandReplicas(ClusterState clusterState)
Checks if there are replicas with the auto-expand feature that need to be adapted.applyFailedShard(ClusterState clusterState, ShardRouting failedShard, boolean markAsStale)
applyFailedShards(ClusterState clusterState, List<FailedShard> failedShards)
applyFailedShards(ClusterState clusterState, List<FailedShard> failedShards, List<StaleShard> staleShards)
Applies the failed shards.applyStartedShards(ClusterState clusterState, List<ShardRouting> startedShards)
Applies the started shards.void
protected long
override this to control time based decisions during allocationdisassociateDeadNodes(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.explainShardAllocation(ShardRouting shardRouting, RoutingAllocation allocation)
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.int
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.reroute(ClusterState clusterState, AllocationCommands commands, boolean explain, boolean retryFailed)
void
setExistingShardsAllocators(Map<String,ExistingShardsAllocator> existingShardsAllocators)
Inject theExistingShardsAllocator
s to use.
-
Constructor Details
-
AllocationService
public AllocationService(AllocationDeciders allocationDeciders, GatewayAllocator gatewayAllocator, ShardsAllocator shardsAllocator, ClusterInfoService clusterInfoService, SnapshotsInfoService snapshotsInfoService) -
AllocationService
public AllocationService(AllocationDeciders allocationDeciders, ShardsAllocator shardsAllocator, ClusterInfoService clusterInfoService, SnapshotsInfoService snapshotsInfoService)
-
-
Method Details
-
setExistingShardsAllocators
public void setExistingShardsAllocators(Map<String,ExistingShardsAllocator> existingShardsAllocators)Inject theExistingShardsAllocator
s to use. May only be called once. -
applyStartedShards
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
-
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
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.- Parameters:
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.- Returns:
- A comma-separated string of the first few elements.
-
reroute
public AllocationService.CommandsResult reroute(ClusterState clusterState, AllocationCommands commands, boolean explain, boolean retryFailed) -
reroute
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 fromClusterService.getRerouteService()
.- Returns:
- 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)
-