Class RoutingTable

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

public class RoutingTable
extends java.lang.Object
implements java.lang.Iterable<IndexRoutingTable>, Diffable<RoutingTable>
Represents a global cluster-wide routing table for all indices including the version of the current routing state.
See Also:
IndexRoutingTable
  • Field Details

    • EMPTY_ROUTING_TABLE

      public static final RoutingTable EMPTY_ROUTING_TABLE
  • Method Details

    • shardRoutingTable

      public static IndexShardRoutingTable shardRoutingTable​(IndexRoutingTable indexRouting, int shardId)
      Get's the IndexShardRoutingTable for the given shard id from the given IndexRoutingTable or throws a ShardNotFoundException if no shard by the given id is found in the IndexRoutingTable.
      Parameters:
      indexRouting - IndexRoutingTable
      shardId - ShardId
      Returns:
      IndexShardRoutingTable
    • version

      public long version()
      Returns the version of the RoutingTable.
      Returns:
      version of the RoutingTable
    • iterator

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

      public boolean hasIndex​(java.lang.String index)
    • hasIndex

      public boolean hasIndex​(Index index)
    • index

      public IndexRoutingTable index​(java.lang.String index)
    • index

      public IndexRoutingTable index​(Index index)
    • indicesRouting

      public ImmutableOpenMap<java.lang.String,​IndexRoutingTable> indicesRouting()
    • getIndicesRouting

      public ImmutableOpenMap<java.lang.String,​IndexRoutingTable> getIndicesRouting()
    • shardRoutingTable

      public IndexShardRoutingTable shardRoutingTable​(java.lang.String index, int shardId)
      All shards for the provided index and shard id
      Returns:
      All the shard routing entries for the given index and shard id
      Throws:
      IndexNotFoundException - if provided index does not exist
      ShardNotFoundException - if provided shard id is unknown
    • shardRoutingTable

      public IndexShardRoutingTable shardRoutingTable​(ShardId shardId)
      All shards for the provided ShardId
      Returns:
      All the shard routing entries for the given index and shard id
      Throws:
      IndexNotFoundException - if provided index does not exist
      ShardNotFoundException - if provided shard id is unknown
    • getByAllocationId

      @Nullable public ShardRouting getByAllocationId​(ShardId shardId, java.lang.String allocationId)
    • validate

      public boolean validate​(Metadata metadata)
    • shardsWithState

      public java.util.List<ShardRouting> shardsWithState​(ShardRoutingState state)
    • allShards

      public java.util.List<ShardRouting> allShards()
      All the shards (replicas) for all indices in this routing table.
      Returns:
      All the shards
    • allShards

      public java.util.List<ShardRouting> allShards​(java.lang.String index)
      All the shards (replicas) for the provided index.
      Parameters:
      index - The index to return all the shards (replicas).
      Returns:
      All the shards matching the specific index
      Throws:
      IndexNotFoundException - If the index passed does not exists
    • allActiveShardsGrouped

      public GroupShardsIterator<ShardIterator> allActiveShardsGrouped​(java.lang.String[] indices, boolean includeEmpty)
      Return GroupShardsIterator where each active shard routing has it's own shard iterator.
      Parameters:
      includeEmpty - if true, a shard iterator will be added for non-assigned shards as well
    • allAssignedShardsGrouped

      public GroupShardsIterator<ShardIterator> allAssignedShardsGrouped​(java.lang.String[] indices, boolean includeEmpty)
      Return GroupShardsIterator where each assigned shard routing has it's own shard iterator.
      Parameters:
      includeEmpty - if true, a shard iterator will be added for non-assigned shards as well
    • allShards

      public ShardsIterator allShards​(java.lang.String[] indices)
    • allShardsIncludingRelocationTargets

      public ShardsIterator allShardsIncludingRelocationTargets​(java.lang.String[] indices)
    • activePrimaryShardsGrouped

      public GroupShardsIterator<ShardIterator> activePrimaryShardsGrouped​(java.lang.String[] indices, boolean includeEmpty)
      All the *active* primary shards for the provided indices grouped (each group is a single element, consisting of the primary shard). This is handy for components that expect to get group iterators, but still want in some cases to iterate over all primary shards (and not just one shard in replication group).
      Parameters:
      indices - The indices to return all the shards (replicas)
      Returns:
      All the primary shards grouped into a single shard element group each
      Throws:
      IndexNotFoundException - If an index passed does not exists
    • diff

      public Diff<RoutingTable> diff​(RoutingTable previousState)
      Description copied from interface: Diffable
      Returns serializable object representing differences between this and previousState
      Specified by:
      diff in interface Diffable<RoutingTable>
    • readDiffFrom

      public static Diff<RoutingTable> readDiffFrom​(StreamInput in) throws java.io.IOException
      Throws:
      java.io.IOException
    • readFrom

      public static RoutingTable readFrom​(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 RoutingTable.Builder builder()
    • builder

      public static RoutingTable.Builder builder​(RoutingTable routingTable)
    • toString

      public java.lang.String toString()
      Overrides:
      toString in class java.lang.Object