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 class
RoutingTable.Builder
Builder 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 RoutingTable
EMPTY_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).GroupShardsIterator
allActiveShardsGrouped(java.lang.String[] indices, boolean includeEmpty)
GroupShardsIterator
allActiveShardsGrouped(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.ShardsIterator
allShards(java.lang.String[] indices)
ShardsIterator
allShardsIncludingRelocationTargets(java.lang.String[] indices)
static RoutingTable.Builder
builder()
static RoutingTable.Builder
builder(RoutingTable routingTable)
Diff<RoutingTable>
diff(RoutingTable previousState)
Returns serializable object representing differences between this and previousStateShardRouting
getByAllocationId(ShardId shardId, java.lang.String allocationId)
ImmutableOpenMap<java.lang.String,IndexRoutingTable>
getIndicesRouting()
boolean
hasIndex(java.lang.String index)
boolean
hasIndex(Index index)
IndexRoutingTable
index(java.lang.String index)
IndexRoutingTable
index(Index index)
ImmutableOpenMap<java.lang.String,IndexRoutingTable>
indicesRouting()
java.util.Iterator<IndexRoutingTable>
iterator()
static Diff<RoutingTable>
readDiffFrom(StreamInput in)
static RoutingTable
readFrom(StreamInput in)
IndexShardRoutingTable
shardRoutingTable(java.lang.String index, int shardId)
All shards for the provided index and shard idIndexShardRoutingTable
shardRoutingTable(ShardId shardId)
All shards for the providedShardId
IndexShardRoutingTable
shardRoutingTableOrNull(ShardId shardId)
java.util.List<ShardRouting>
shardsWithState(ShardRoutingState state)
java.lang.String
toString()
boolean
validate(MetaData metaData)
long
version()
Returns the version of theRoutingTable
.void
writeTo(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:
iterator
in 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:Diffable
Returns serializable object representing differences between this and previousState- Specified by:
diff
in 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:Writeable
Write 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:
toString
in classjava.lang.Object
-
-