Class IndexRoutingTable

java.lang.Object
org.elasticsearch.cluster.routing.IndexRoutingTable
All Implemented Interfaces:
Diffable<IndexRoutingTable>, SimpleDiffable<IndexRoutingTable>, Writeable

public class IndexRoutingTable extends Object implements SimpleDiffable<IndexRoutingTable>
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
    • numberOfNodesShardsAreAllocatedOn

      public int numberOfNodesShardsAreAllocatedOn(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
    • size

      public int size()
    • shard

      @Nullable 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 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(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • readFrom

      public static IndexRoutingTable readFrom(StreamInput in) throws IOException
      Throws:
      IOException
    • readDiffFrom

      public static Diff<IndexRoutingTable> readDiffFrom(StreamInput in) throws IOException
      Throws:
      IOException
    • writeTo

      public void writeTo(StreamOutput out) throws IOException
      Description copied from interface: Writeable
      Write this into the StreamOutput.
      Specified by:
      writeTo in interface Writeable
      Throws:
      IOException
    • builder

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

      public String prettyPrint()