Class IndexRoutingTable
- java.lang.Object
-
- org.elasticsearch.cluster.AbstractDiffable<IndexRoutingTable>
-
- org.elasticsearch.cluster.routing.IndexRoutingTable
-
- All Implemented Interfaces:
java.lang.Iterable<IndexShardRoutingTable>
,Diffable<IndexRoutingTable>
,Writeable
public class IndexRoutingTable extends AbstractDiffable<IndexRoutingTable> implements java.lang.Iterable<IndexShardRoutingTable>
TheIndexRoutingTable
represents routing information for a single index. The routing table maintains a list of all shards in the index. A single shard in this context has one more instances namely exactly oneprimary
and 1 or more replicas. In other words, each instance of a shard is considered a replica while only one replica per shard is aprimary
replica. Theprimary
replica can be seen as the "leader" of the shard acting as the primary entry point for operations on a specific shard.Note: The term replica is not directly reflected in the routing table or in related classes, replicas are represented as
ShardRouting
.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
IndexRoutingTable.Builder
-
Nested classes/interfaces inherited from interface org.elasticsearch.common.io.stream.Writeable
Writeable.Reader<V>, Writeable.Writer<V>
-
-
Method Summary
Modifier and Type Method Description boolean
allPrimaryShardsActive()
Returnstrue
if all shards are primary and active.boolean
allPrimaryShardsUnassigned()
Returnstrue
if all primary shards are inShardRoutingState.UNASSIGNED
state.static IndexRoutingTable.Builder
builder(Index index)
boolean
equals(java.lang.Object o)
Index
getIndex()
Return the index idImmutableOpenIntMap<IndexShardRoutingTable>
getShards()
int
hashCode()
java.util.Iterator<IndexShardRoutingTable>
iterator()
int
numberOfNodesShardsAreAllocatedOn(java.lang.String... excludedNodes)
Calculates the number of nodes that hold one or more shards of this indexIndexRoutingTable
excluding the nodes with the node ids give as theexcludedNodes
parameter.java.lang.String
prettyPrint()
int
primaryShardsActive()
Calculates the number of primary shards in active state in routing tableint
primaryShardsUnassigned()
Calculates the number of primary shards in the routing table the are inShardRoutingState.UNASSIGNED
state.ShardsIterator
randomAllActiveShardsIt()
Returns an unordered iterator over all active shards (including replicas).static Diff<IndexRoutingTable>
readDiffFrom(StreamInput in)
static IndexRoutingTable
readFrom(StreamInput in)
IndexShardRoutingTable
shard(int shardId)
ImmutableOpenIntMap<IndexShardRoutingTable>
shards()
java.util.List<ShardRouting>
shardsWithState(ShardRoutingState state)
Returns aList
of shards that match one of the states listed instates
void
writeTo(StreamOutput out)
Write this into the StreamOutput.-
Methods inherited from class org.elasticsearch.cluster.AbstractDiffable
diff, get, readDiffFrom
-
-
-
-
Method Detail
-
getIndex
public Index getIndex()
Return the index id- Returns:
- id of the index
-
iterator
public java.util.Iterator<IndexShardRoutingTable> iterator()
- Specified by:
iterator
in interfacejava.lang.Iterable<IndexShardRoutingTable>
-
numberOfNodesShardsAreAllocatedOn
public int numberOfNodesShardsAreAllocatedOn(java.lang.String... excludedNodes)
Calculates the number of nodes that hold one or more shards of this indexIndexRoutingTable
excluding the nodes with the node ids give as theexcludedNodes
parameter.- Parameters:
excludedNodes
- id of nodes that will be excluded- Returns:
- number of distinct nodes this index has at least one shard allocated on
-
shards
public ImmutableOpenIntMap<IndexShardRoutingTable> shards()
-
getShards
public ImmutableOpenIntMap<IndexShardRoutingTable> getShards()
-
shard
public IndexShardRoutingTable shard(int shardId)
-
allPrimaryShardsActive
public boolean allPrimaryShardsActive()
Returnstrue
if all shards are primary and active. Otherwisefalse
.
-
primaryShardsActive
public int primaryShardsActive()
Calculates the number of primary shards in active state in routing table- Returns:
- number of active primary shards
-
allPrimaryShardsUnassigned
public boolean allPrimaryShardsUnassigned()
-
primaryShardsUnassigned
public int primaryShardsUnassigned()
Calculates the number of primary shards in the routing table the are inShardRoutingState.UNASSIGNED
state.
-
shardsWithState
public java.util.List<ShardRouting> shardsWithState(ShardRoutingState state)
Returns aList
of shards that match one of the states listed instates
- Parameters:
state
-ShardRoutingState
to retrieve- Returns:
- a
List
of shards that match one of the givenstates
-
randomAllActiveShardsIt
public ShardsIterator randomAllActiveShardsIt()
Returns an unordered iterator over all active shards (including replicas).
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
readFrom
public static IndexRoutingTable readFrom(StreamInput in) throws java.io.IOException
- Throws:
java.io.IOException
-
readDiffFrom
public static Diff<IndexRoutingTable> readDiffFrom(StreamInput in) throws java.io.IOException
- Throws:
java.io.IOException
-
writeTo
public void writeTo(StreamOutput out) throws java.io.IOException
Description copied from interface:Writeable
Write this into the StreamOutput.
-
builder
public static IndexRoutingTable.Builder builder(Index index)
-
prettyPrint
public java.lang.String prettyPrint()
-
-