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>
The IndexRoutingTable 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 one primary and 1 or more replicas. In other words, each instance of a shard is considered a replica while only one replica per shard is a primary replica. The primary 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.

  • Method Details

    • getIndex

      public Index getIndex()
      Return the index id
      Returns:
      id of the index
    • iterator

      public java.util.Iterator<IndexShardRoutingTable> iterator()
      Specified by:
      iterator in interface java.lang.Iterable<IndexShardRoutingTable>
    • numberOfNodesShardsAreAllocatedOn

      public int numberOfNodesShardsAreAllocatedOn​(java.lang.String... excludedNodes)
      Calculates the number of nodes that hold one or more shards of this index IndexRoutingTable excluding the nodes with the node ids give as the excludedNodes 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

    • getShards

    • shard

      public IndexShardRoutingTable shard​(int shardId)
    • allPrimaryShardsActive

      public boolean allPrimaryShardsActive()
      Returns true if all shards are primary and active. Otherwise false.
    • 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()
      Returns true if all primary shards are in ShardRoutingState.UNASSIGNED state. Otherwise false.
    • primaryShardsUnassigned

      public int primaryShardsUnassigned()
      Calculates the number of primary shards in the routing tables that are in ShardRoutingState.UNASSIGNED state.
    • shardsWithState

      public java.util.List<ShardRouting> shardsWithState​(ShardRoutingState state)
      Returns a List of shards that match one of the states listed in states
      Parameters:
      state - ShardRoutingState to retrieve
      Returns:
      a List of shards that match one of the given states
    • 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 class java.lang.Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class java.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.
      Specified by:
      writeTo in interface Writeable
      Throws:
      java.io.IOException
    • builder

      public static IndexRoutingTable.Builder builder​(Index index)
    • prettyPrint

      public java.lang.String prettyPrint()