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
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classRoutingTable.BuilderBuilder for the routing table.-
Nested classes/interfaces inherited from interface org.elasticsearch.common.io.stream.Writeable
Writeable.Reader<V>, Writeable.Writer<V>
-
-
Field Summary
Fields Modifier and Type Field Description static RoutingTableEMPTY_ROUTING_TABLE
-
Method Summary
Modifier and Type Method Description 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).GroupShardsIteratorallActiveShardsGrouped(java.lang.String[] indices, boolean includeEmpty)GroupShardsIteratorallActiveShardsGrouped(java.lang.String[] indices, boolean includeEmpty, boolean includeRelocationTargets)Return GroupShardsIterator where each active shard routing has it's own shard iterator.GroupShardsIterator<ShardIterator>allAssignedShardsGrouped(java.lang.String[] indices, boolean includeEmpty)GroupShardsIterator<ShardIterator>allAssignedShardsGrouped(java.lang.String[] indices, boolean includeEmpty, boolean includeRelocationTargets)Return GroupShardsIterator where each assigned shard routing has it's own shard iterator.java.util.List<ShardRouting>allShards()All the shards (replicas) for all indices in this routing table.java.util.List<ShardRouting>allShards(java.lang.String index)All the shards (replicas) for the provided index.ShardsIteratorallShards(java.lang.String[] indices)ShardsIteratorallShardsIncludingRelocationTargets(java.lang.String[] indices)static RoutingTable.Builderbuilder()static RoutingTable.Builderbuilder(RoutingTable routingTable)Diff<RoutingTable>diff(RoutingTable previousState)Returns serializable object representing differences between this and previousStateShardRoutinggetByAllocationId(ShardId shardId, java.lang.String allocationId)ImmutableOpenMap<java.lang.String,IndexRoutingTable>getIndicesRouting()booleanhasIndex(java.lang.String index)booleanhasIndex(Index index)IndexRoutingTableindex(java.lang.String index)IndexRoutingTableindex(Index index)ImmutableOpenMap<java.lang.String,IndexRoutingTable>indicesRouting()java.util.Iterator<IndexRoutingTable>iterator()static Diff<RoutingTable>readDiffFrom(StreamInput in)static RoutingTablereadFrom(StreamInput in)IndexShardRoutingTableshardRoutingTable(java.lang.String index, int shardId)All shards for the provided index and shard idIndexShardRoutingTableshardRoutingTable(ShardId shardId)All shards for the providedShardIdIndexShardRoutingTableshardRoutingTableOrNull(ShardId shardId)java.util.List<ShardRouting>shardsWithState(ShardRoutingState state)java.lang.StringtoString()booleanvalidate(MetaData metaData)longversion()Returns the version of theRoutingTable.voidwriteTo(StreamOutput out)Write this into the StreamOutput.
-
-
-
Field Detail
-
EMPTY_ROUTING_TABLE
public static final RoutingTable EMPTY_ROUTING_TABLE
-
-
Method Detail
-
version
public long version()
Returns the version of theRoutingTable.- Returns:
- version of the
RoutingTable
-
iterator
public java.util.Iterator<IndexRoutingTable> iterator()
- Specified by:
iteratorin interfacejava.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 existShardNotFoundException- if provided shard id is unknown
-
shardRoutingTable
public IndexShardRoutingTable shardRoutingTable(ShardId shardId)
All shards for the providedShardId- Returns:
- All the shard routing entries for the given index and shard id
- Throws:
IndexNotFoundException- if provided index does not existShardNotFoundException- if provided shard id is unknown
-
shardRoutingTableOrNull
public IndexShardRoutingTable shardRoutingTableOrNull(ShardId shardId)
-
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 allActiveShardsGrouped(java.lang.String[] indices, boolean includeEmpty)
-
allActiveShardsGrouped
public GroupShardsIterator allActiveShardsGrouped(java.lang.String[] indices, boolean includeEmpty, boolean includeRelocationTargets)
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 wellincludeRelocationTargets- if true, an extra shard iterator will be added for relocating shards. The extra iterator contains a single ShardRouting pointing at the relocating target
-
allAssignedShardsGrouped
public GroupShardsIterator<ShardIterator> allAssignedShardsGrouped(java.lang.String[] indices, boolean includeEmpty)
-
allAssignedShardsGrouped
public GroupShardsIterator<ShardIterator> allAssignedShardsGrouped(java.lang.String[] indices, boolean includeEmpty, boolean includeRelocationTargets)
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 wellincludeRelocationTargets- if true, an extra shard iterator will be added for relocating shards. The extra iterator contains a single ShardRouting pointing at the relocating target
-
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:DiffableReturns serializable object representing differences between this and previousState- Specified by:
diffin interfaceDiffable<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:WriteableWrite this into the StreamOutput.
-
builder
public static RoutingTable.Builder builder()
-
builder
public static RoutingTable.Builder builder(RoutingTable routingTable)
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-