public class RoutingNodes extends java.lang.Object implements java.lang.Iterable<RoutingNode>
RoutingNodes
represents a copy the routing information contained in the cluster state
.
It can be either initialized as mutable or immutable (see RoutingNodes(ClusterState, boolean)
), allowing
or disallowing changes to its elements.
The main methods used to update routing entries are:
initializeShard(org.elasticsearch.cluster.routing.ShardRouting, java.lang.String, java.lang.String, long, org.elasticsearch.cluster.routing.RoutingChangesObserver)
initializes an unassigned shard.
startShard(org.apache.logging.log4j.Logger, org.elasticsearch.cluster.routing.ShardRouting, org.elasticsearch.cluster.routing.RoutingChangesObserver)
starts an initializing shard / completes relocation of a shard.
relocateShard(org.elasticsearch.cluster.routing.ShardRouting, java.lang.String, long, org.elasticsearch.cluster.routing.RoutingChangesObserver)
starts relocation of a started shard.
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)
fails/cancels an assigned shard.
Modifier and Type | Class and Description |
---|---|
static class |
RoutingNodes.UnassignedShards |
Constructor and Description |
---|
RoutingNodes(ClusterState clusterState) |
RoutingNodes(ClusterState clusterState,
boolean readOnly) |
Modifier and Type | Method and Description |
---|---|
ShardRouting |
activePrimary(ShardId shardId)
Returns the active primary shard for the given shard id or
null if
no primary is found or the primary is not active. |
ShardRouting |
activeReplicaWithHighestVersion(ShardId shardId)
Returns one active replica shard for the given shard id or
null if
no active replica is found. |
boolean |
allReplicasActive(ShardId shardId,
MetaData metaData)
Returns
true iff all replicas are active for the given shard routing. |
static boolean |
assertShardStats(RoutingNodes routingNodes)
Calculates RoutingNodes statistics by iterating over all
ShardRouting s
in the cluster to ensure the book-keeping is correct. |
java.util.List<ShardRouting> |
assignedShards(ShardId shardId)
Returns all shards that are not in the state UNASSIGNED with the same shard
ID as the given shard.
|
void |
failShard(org.apache.logging.log4j.Logger logger,
ShardRouting failedShard,
UnassignedInfo unassignedInfo,
IndexMetaData indexMetaData,
RoutingChangesObserver routingChangesObserver)
Applies the relevant logic to handle a cancelled or failed shard.
|
ShardRouting |
getByAllocationId(ShardId shardId,
java.lang.String allocationId) |
int |
getIncomingRecoveries(java.lang.String nodeId) |
int |
getOutgoingRecoveries(java.lang.String nodeId) |
int |
getRelocatingShardCount() |
boolean |
hasInactivePrimaries() |
boolean |
hasInactiveShards() |
boolean |
hasUnassignedPrimaries()
Returns
true iff this RoutingNodes instance has any unassigned primaries even if the
primaries are marked as temporarily ignored. |
boolean |
hasUnassignedShards()
Returns
true iff this RoutingNodes instance has any unassigned shards even if the
shards are marked as temporarily ignored. |
ShardRouting |
initializeShard(ShardRouting unassignedShard,
java.lang.String nodeId,
java.lang.String existingAllocationId,
long expectedSize,
RoutingChangesObserver routingChangesObserver)
Moves a shard from unassigned to initialize state
|
java.util.Iterator<RoutingNode> |
iterator() |
java.util.Iterator<RoutingNode> |
mutableIterator() |
RoutingNode |
node(java.lang.String nodeId) |
java.util.Iterator<ShardRouting> |
nodeInterleavedShardIterator()
Creates an iterator over shards interleaving between nodes: The iterator returns the first shard from
the first node, then the first shard of the second node, etc.
|
com.carrotsearch.hppc.ObjectIntHashMap<java.lang.String> |
nodesPerAttributesCounts(java.lang.String attributeName) |
Tuple<ShardRouting,ShardRouting> |
relocateShard(ShardRouting startedShard,
java.lang.String nodeId,
long expectedShardSize,
RoutingChangesObserver changes)
Relocate a shard to another node, adding the target initializing
shard as well as assigning it.
|
java.util.List<ShardRouting> |
shards(java.util.function.Predicate<ShardRouting> predicate) |
java.util.List<ShardRouting> |
shardsWithState(ShardRoutingState... state) |
java.util.List<ShardRouting> |
shardsWithState(java.lang.String index,
ShardRoutingState... state) |
int |
size()
Returns the number of routing nodes
|
ShardRouting |
startShard(org.apache.logging.log4j.Logger logger,
ShardRouting initializingShard,
RoutingChangesObserver routingChangesObserver)
Applies the relevant logic to start an initializing shard.
|
java.lang.String |
toString() |
RoutingNodes.UnassignedShards |
unassigned() |
public RoutingNodes(ClusterState clusterState)
public RoutingNodes(ClusterState clusterState, boolean readOnly)
public int getIncomingRecoveries(java.lang.String nodeId)
public int getOutgoingRecoveries(java.lang.String nodeId)
public java.util.Iterator<RoutingNode> iterator()
iterator
in interface java.lang.Iterable<RoutingNode>
public java.util.Iterator<RoutingNode> mutableIterator()
public RoutingNodes.UnassignedShards unassigned()
public RoutingNode node(java.lang.String nodeId)
public com.carrotsearch.hppc.ObjectIntHashMap<java.lang.String> nodesPerAttributesCounts(java.lang.String attributeName)
public boolean hasUnassignedPrimaries()
true
iff this RoutingNodes
instance has any unassigned primaries even if the
primaries are marked as temporarily ignored.public boolean hasUnassignedShards()
true
iff this RoutingNodes
instance has any unassigned shards even if the
shards are marked as temporarily ignored.public boolean hasInactivePrimaries()
public boolean hasInactiveShards()
public int getRelocatingShardCount()
public java.util.List<ShardRouting> assignedShards(ShardId shardId)
@Nullable public ShardRouting getByAllocationId(ShardId shardId, java.lang.String allocationId)
public ShardRouting activePrimary(ShardId shardId)
null
if
no primary is found or the primary is not active.public ShardRouting activeReplicaWithHighestVersion(ShardId shardId)
null
if
no active replica is found.
Since replicas could possibly be on nodes with a older version of ES than
the primary is, this will return replicas on the highest version of ES.public boolean allReplicasActive(ShardId shardId, MetaData metaData)
true
iff all replicas are active for the given shard routing. Otherwise false
public java.util.List<ShardRouting> shards(java.util.function.Predicate<ShardRouting> predicate)
public java.util.List<ShardRouting> shardsWithState(ShardRoutingState... state)
public java.util.List<ShardRouting> shardsWithState(java.lang.String index, ShardRoutingState... state)
public java.lang.String toString()
toString
in class java.lang.Object
public ShardRouting initializeShard(ShardRouting unassignedShard, java.lang.String nodeId, @Nullable java.lang.String existingAllocationId, long expectedSize, RoutingChangesObserver routingChangesObserver)
existingAllocationId
- allocation id to use. If null, a fresh allocation id is generated.public Tuple<ShardRouting,ShardRouting> relocateShard(ShardRouting startedShard, java.lang.String nodeId, long expectedShardSize, RoutingChangesObserver changes)
public ShardRouting startShard(org.apache.logging.log4j.Logger logger, ShardRouting initializingShard, RoutingChangesObserver routingChangesObserver)
public void failShard(org.apache.logging.log4j.Logger logger, ShardRouting failedShard, UnassignedInfo unassignedInfo, IndexMetaData indexMetaData, RoutingChangesObserver routingChangesObserver)
public int size()
public static boolean assertShardStats(RoutingNodes routingNodes)
ShardRouting
s
in the cluster to ensure the book-keeping is correct.
For performance reasons, this should only be called from assertstrue
or throws an assertion error. If assertion are not enabled
this method does nothing.public java.util.Iterator<ShardRouting> nodeInterleavedShardIterator()