Class AllocationService
java.lang.Object
org.elasticsearch.cluster.routing.allocation.AllocationService
public class AllocationService
extends java.lang.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.-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
AllocationService.CommandsResult
this class is used to describe results of applying a set ofAllocationCommand
-
Constructor Summary
Constructors Constructor Description AllocationService(AllocationDeciders allocationDeciders, ShardsAllocator shardsAllocator, ClusterInfoService clusterInfoService)
AllocationService(AllocationDeciders allocationDeciders, GatewayAllocator gatewayAllocator, ShardsAllocator shardsAllocator, ClusterInfoService clusterInfoService)
-
Method Summary
Modifier and Type Method Description ClusterState
adaptAutoExpandReplicas(ClusterState clusterState)
Checks if the are replicas with the auto-expand feature that need to be adapted.ClusterState
applyFailedShard(ClusterState clusterState, ShardRouting failedShard, boolean markAsStale)
ClusterState
applyFailedShards(ClusterState clusterState, java.util.List<FailedShard> failedShards)
ClusterState
applyFailedShards(ClusterState clusterState, java.util.List<FailedShard> failedShards, java.util.List<StaleShard> staleShards)
Applies the failed shards.ClusterState
applyStartedShards(ClusterState clusterState, java.util.List<ShardRouting> startedShards)
Applies the started shards.protected ClusterState
buildResultAndLogHealthChange(ClusterState oldState, RoutingAllocation allocation, java.lang.String reason)
void
cleanCaches()
protected long
currentNanoTime()
override this to control time based decisions during allocationClusterState
disassociateDeadNodes(ClusterState clusterState, boolean reroute, java.lang.String reason)
unassigned an shards that are associated with nodes that are no longer part of the cluster, potentially promoting replicas if needed.static <T> java.lang.String
firstListElementsToCommaDelimitedString(java.util.List<T> elements, java.util.function.Function<T,java.lang.String> formatter, boolean isDebugEnabled)
Internal helper to cap the number of elements in a potentially long list for logging.ClusterState
reroute(ClusterState clusterState, java.lang.String reason)
Reroutes the routing table based on the live nodes.AllocationService.CommandsResult
reroute(ClusterState clusterState, AllocationCommands commands, boolean explain, boolean retryFailed)
void
setGatewayAllocator(GatewayAllocator gatewayAllocator)
-
Constructor Details
-
AllocationService
public AllocationService(AllocationDeciders allocationDeciders, GatewayAllocator gatewayAllocator, ShardsAllocator shardsAllocator, ClusterInfoService clusterInfoService) -
AllocationService
public AllocationService(AllocationDeciders allocationDeciders, ShardsAllocator shardsAllocator, ClusterInfoService clusterInfoService)
-
-
Method Details
-
setGatewayAllocator
-
applyStartedShards
public ClusterState applyStartedShards(ClusterState clusterState, java.util.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. -
buildResultAndLogHealthChange
protected ClusterState buildResultAndLogHealthChange(ClusterState oldState, RoutingAllocation allocation, java.lang.String reason) -
applyFailedShard
public ClusterState applyFailedShard(ClusterState clusterState, ShardRouting failedShard, boolean markAsStale) -
applyFailedShards
public ClusterState applyFailedShards(ClusterState clusterState, java.util.List<FailedShard> failedShards) -
applyFailedShards
public ClusterState applyFailedShards(ClusterState clusterState, java.util.List<FailedShard> failedShards, java.util.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, java.lang.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 the 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> java.lang.String firstListElementsToCommaDelimitedString(java.util.List<T> elements, java.util.function.Function<T,java.lang.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
Reroutes the routing table based on the live nodes.If the same instance of ClusterState is returned, then no change has been made.
-
currentNanoTime
protected long currentNanoTime()override this to control time based decisions during allocation -
cleanCaches
public void cleanCaches()
-