Package org.elasticsearch.gateway
Class PrimaryShardAllocator
- java.lang.Object
-
- org.elasticsearch.gateway.BaseGatewayShardAllocator
-
- org.elasticsearch.gateway.PrimaryShardAllocator
-
public abstract class PrimaryShardAllocator extends BaseGatewayShardAllocator
The primary shard allocator allocates unassigned primary shards to nodes that hold valid copies of the unassigned primaries. It does this by iterating over all unassigned primary shards in the routing table and fetching shard metadata from each node in the cluster that holds a copy of the shard. The shard metadata from each node is compared against the set of valid allocation IDs and for all valid shard copies (if any), the primary shard allocator executes the allocation deciders to chose a copy to assign the primary shard to. Note that the PrimaryShardAllocator does *not* allocate primaries on index creation (seeBalancedShardsAllocator
), nor does it allocate primaries when a primary shard failed and there is a valid replica copy that can immediately be promoted to primary, as this takes place inRoutingNodes.failShard(org.apache.logging.log4j.Logger, org.elasticsearch.cluster.routing.ShardRouting, org.elasticsearch.cluster.routing.UnassignedInfo, org.elasticsearch.cluster.metadata.IndexMetaData, org.elasticsearch.cluster.routing.RoutingChangesObserver)
.
-
-
Field Summary
-
Fields inherited from class org.elasticsearch.gateway.BaseGatewayShardAllocator
logger
-
-
Constructor Summary
Constructors Constructor Description PrimaryShardAllocator()
-
Method Summary
Modifier and Type Method Description protected static org.elasticsearch.gateway.PrimaryShardAllocator.NodeShardsResult
buildNodeShardsResult(ShardRouting shard, boolean matchAnyShard, java.util.Set<java.lang.String> ignoreNodes, java.util.Set<java.lang.String> inSyncAllocationIds, AsyncShardFetch.FetchResult<TransportNodesListGatewayStartedShards.NodeGatewayStartedShards> shardState, org.apache.logging.log4j.Logger logger)
Builds a list of nodes.protected abstract AsyncShardFetch.FetchResult<TransportNodesListGatewayStartedShards.NodeGatewayStartedShards>
fetchData(ShardRouting shard, RoutingAllocation allocation)
AllocateUnassignedDecision
makeAllocationDecision(ShardRouting unassignedShard, RoutingAllocation allocation, org.apache.logging.log4j.Logger logger)
Make a decision on the allocation of an unassigned shard.-
Methods inherited from class org.elasticsearch.gateway.BaseGatewayShardAllocator
allocateUnassigned, buildDecisionsForAllNodes
-
-
-
-
Method Detail
-
makeAllocationDecision
public AllocateUnassignedDecision makeAllocationDecision(ShardRouting unassignedShard, RoutingAllocation allocation, org.apache.logging.log4j.Logger logger)
Description copied from class:BaseGatewayShardAllocator
Make a decision on the allocation of an unassigned shard. This method is used byBaseGatewayShardAllocator.allocateUnassigned(RoutingAllocation)
to make decisions about whether or not the shard can be allocated by this allocator and if so, to which node it will be allocated.- Specified by:
makeAllocationDecision
in classBaseGatewayShardAllocator
- Parameters:
unassignedShard
- the unassigned shard to allocateallocation
- the current routing statelogger
- the logger- Returns:
- an
AllocateUnassignedDecision
with the final decision of whether to allocate and details of the decision
-
buildNodeShardsResult
protected static org.elasticsearch.gateway.PrimaryShardAllocator.NodeShardsResult buildNodeShardsResult(ShardRouting shard, boolean matchAnyShard, java.util.Set<java.lang.String> ignoreNodes, java.util.Set<java.lang.String> inSyncAllocationIds, AsyncShardFetch.FetchResult<TransportNodesListGatewayStartedShards.NodeGatewayStartedShards> shardState, org.apache.logging.log4j.Logger logger)
Builds a list of nodes. If matchAnyShard is set to false, only nodes that have an allocation id matching inSyncAllocationIds are added to the list. Otherwise, any node that has a shard is added to the list, but entries with matching allocation id are always at the front of the list.
-
fetchData
protected abstract AsyncShardFetch.FetchResult<TransportNodesListGatewayStartedShards.NodeGatewayStartedShards> fetchData(ShardRouting shard, RoutingAllocation allocation)
-
-