public final class ShardRouting extends java.lang.Object implements Writeable, ToXContent
ShardRouting
immutably encapsulates information about shard
routings like id, state, version, etc.Writeable.Reader<V>, Writeable.Writer<V>
ToXContent.DelegatingMapParams, ToXContent.MapParams, ToXContent.Params
Modifier and Type | Field and Description |
---|---|
static long |
UNAVAILABLE_EXPECTED_SHARD_SIZE
Used if shard size is not available
|
EMPTY_PARAMS
Constructor and Description |
---|
ShardRouting(ShardId shardId,
StreamInput in) |
ShardRouting(StreamInput in) |
Modifier and Type | Method and Description |
---|---|
boolean |
active()
|
AllocationId |
allocationId()
An id that uniquely identifies an allocation.
|
boolean |
assignedToNode()
Returns
true iff this shard is assigned to a node ie. |
ShardRouting |
cancelRelocation()
Cancel relocation of a shard.
|
java.lang.String |
currentNodeId()
The current node id the shard is allocated on.
|
boolean |
equals(java.lang.Object o) |
boolean |
equalsIgnoringMetaData(ShardRouting other)
returns true if the current routing is identical to the other routing in all but meta fields, i.e., unassigned info
|
long |
getExpectedShardSize()
Returns the expected shard size for
ShardRoutingState.RELOCATING and ShardRoutingState.INITIALIZING
shards. |
int |
getId()
The shard id.
|
java.lang.String |
getIndexName()
The index name.
|
ShardRouting |
getTargetRelocatingShard()
Returns a shard routing representing the target shard.
|
int |
hashCode() |
int |
id()
The shard id.
|
Index |
index() |
ShardRouting |
initialize(java.lang.String nodeId,
java.lang.String existingAllocationId,
long expectedShardSize)
Initializes an unassigned shard on a node.
|
boolean |
initializing()
The shard is initializing (usually recovering either from peer shard
or from gateway).
|
boolean |
isRelocationSourceOf(ShardRouting other)
returns true if the routing is the relocation source for the given routing
|
boolean |
isRelocationTarget()
Returns
true if this shard is a relocation target for another shard (i.e., was created with initializeTargetRelocatingShard() |
boolean |
isRelocationTargetOf(ShardRouting other)
returns true if the routing is the relocation target of the given routing
|
boolean |
isSameAllocation(ShardRouting other)
returns true if this routing has the same allocation ID as another.
|
ShardRouting |
moveActiveReplicaToPrimary()
Make the active shard primary unless it's not primary
|
ShardRouting |
moveToStarted()
Set the shards state to
STARTED . |
ShardRouting |
moveToUnassigned(UnassignedInfo unassignedInfo)
Moves the shard to unassigned state.
|
ShardRouting |
moveUnassignedFromPrimary()
Set the unassigned primary shard to non-primary
|
static ShardRouting |
newUnassigned(ShardId shardId,
boolean primary,
RecoverySource recoverySource,
UnassignedInfo unassignedInfo)
Creates a new unassigned shard.
|
boolean |
primary()
Returns
true iff this shard is a primary. |
RecoverySource |
recoverySource()
Returns recovery source for the given shard.
|
ShardRouting |
reinitializePrimaryShard()
Moves the primary shard from started to initializing
|
ShardRouting |
reinitializeReplicaShard()
Reinitializes a replica shard, giving it a fresh allocation id
|
ShardRouting |
relocate(java.lang.String relocatingNodeId,
long expectedShardSize)
Relocate the shard to another node.
|
boolean |
relocating()
Returns
true iff the this shard is currently relocating to
another node. |
java.lang.String |
relocatingNodeId()
The relocating node id the shard is either relocating to or relocating from.
|
ShardRouting |
removeRelocationSource()
Removes relocation source of a non-primary shard.
|
ShardId |
shardId()
The shard id.
|
ShardIterator |
shardsIt()
A shard iterator with just this shard in it.
|
java.lang.String |
shortSummary()
A short description of the shard.
|
boolean |
started()
The shard is in started mode.
|
ShardRoutingState |
state()
The shard state.
|
java.lang.String |
toString() |
XContentBuilder |
toXContent(XContentBuilder builder,
ToXContent.Params params) |
boolean |
unassigned()
The shard is unassigned (not allocated to any node).
|
UnassignedInfo |
unassignedInfo()
Additional metadata on why the shard is/was unassigned.
|
ShardRouting |
updateUnassigned(UnassignedInfo unassignedInfo,
RecoverySource recoverySource) |
void |
writeTo(StreamOutput out)
Write this into the StreamOutput.
|
void |
writeToThin(StreamOutput out)
Writes shard information to
StreamOutput without writing index name and shard id |
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
isFragment
public static final long UNAVAILABLE_EXPECTED_SHARD_SIZE
public ShardRouting(ShardId shardId, StreamInput in) throws java.io.IOException
java.io.IOException
public ShardRouting(StreamInput in) throws java.io.IOException
java.io.IOException
public static ShardRouting newUnassigned(ShardId shardId, boolean primary, RecoverySource recoverySource, UnassignedInfo unassignedInfo)
public Index index()
public java.lang.String getIndexName()
public int id()
public int getId()
public boolean unassigned()
public boolean initializing()
public boolean active()
public boolean started()
public boolean relocating()
true
iff the this shard is currently relocating to
another node. Otherwise false
ShardRoutingState.RELOCATING
public boolean assignedToNode()
public java.lang.String currentNodeId()
public java.lang.String relocatingNodeId()
public ShardRouting getTargetRelocatingShard()
@Nullable public UnassignedInfo unassignedInfo()
@Nullable public AllocationId allocationId()
public boolean primary()
true
iff this shard is a primary.public ShardRoutingState state()
public ShardId shardId()
public ShardIterator shardsIt()
public void writeToThin(StreamOutput out) throws java.io.IOException
StreamOutput
without writing index name and shard idout
- StreamOutput
to write shard information tojava.io.IOException
- if something happens during writepublic void writeTo(StreamOutput out) throws java.io.IOException
Writeable
public ShardRouting updateUnassigned(UnassignedInfo unassignedInfo, RecoverySource recoverySource)
public ShardRouting moveToUnassigned(UnassignedInfo unassignedInfo)
public ShardRouting initialize(java.lang.String nodeId, @Nullable java.lang.String existingAllocationId, long expectedShardSize)
existingAllocationId
- allocation id to use. If null, a fresh allocation id is generated.public ShardRouting relocate(java.lang.String relocatingNodeId, long expectedShardSize)
relocatingNodeId
- id of the node to relocate the shardpublic ShardRouting cancelRelocation()
RELOCATING
.public ShardRouting removeRelocationSource()
INITIALIZING
.
This allows the non-primary shard to continue recovery from the primary even though its non-primary
relocation source has failed.public ShardRouting reinitializePrimaryShard()
public ShardRouting reinitializeReplicaShard()
public ShardRouting moveToStarted()
STARTED
. The shards state must be
INITIALIZING
or RELOCATING
. Any relocation will be
canceled.public ShardRouting moveActiveReplicaToPrimary()
IllegalShardRoutingStateException
- if shard is already a primarypublic ShardRouting moveUnassignedFromPrimary()
IllegalShardRoutingStateException
- if shard is already a replicapublic boolean isSameAllocation(ShardRouting other)
Note: if both shard routing has a null as their allocationId()
, this method returns false as the routing describe
no allocation at all..
public boolean isRelocationTarget()
true
if this shard is a relocation target for another shard (i.e., was created with initializeTargetRelocatingShard()
public boolean isRelocationTargetOf(ShardRouting other)
public boolean isRelocationSourceOf(ShardRouting other)
public boolean equalsIgnoringMetaData(ShardRouting other)
public boolean equals(java.lang.Object o)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
public java.lang.String toString()
toString
in class java.lang.Object
public java.lang.String shortSummary()
public XContentBuilder toXContent(XContentBuilder builder, ToXContent.Params params) throws java.io.IOException
toXContent
in interface ToXContent
java.io.IOException
public long getExpectedShardSize()
ShardRoutingState.RELOCATING
and ShardRoutingState.INITIALIZING
shards. If it's size is not available -1L will be returned.@Nullable public RecoverySource recoverySource()
RecoverySource.PeerRecoverySource
.active()