Class ShardRouting
- java.lang.Object
-
- org.elasticsearch.cluster.routing.ShardRouting
-
- All Implemented Interfaces:
Writeable
,ToXContent
,ToXContentObject
public final class ShardRouting extends java.lang.Object implements Writeable, ToXContentObject
ShardRouting
immutably encapsulates information about shard indexRoutings like id, state, version, etc.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.elasticsearch.common.xcontent.ToXContent
ToXContent.DelegatingMapParams, ToXContent.MapParams, ToXContent.Params
-
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 long
UNAVAILABLE_EXPECTED_SHARD_SIZE
Used if shard size is not available-
Fields inherited from interface org.elasticsearch.common.xcontent.ToXContent
EMPTY_PARAMS
-
-
Constructor Summary
Constructors Constructor Description ShardRouting(StreamInput in)
ShardRouting(ShardId shardId, StreamInput in)
-
Method Summary
Modifier and Type Method Description boolean
active()
AllocationId
allocationId()
An id that uniquely identifies an allocation.boolean
assignedToNode()
Returnstrue
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 infolong
getExpectedShardSize()
Returns the expected shard size forShardRoutingState.RELOCATING
andShardRoutingState.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 routingboolean
isRelocationTarget()
Returnstrue
if this shard is a relocation target for another shard (i.e., was created withinitializeTargetRelocatingShard()
boolean
isRelocationTargetOf(ShardRouting other)
returns true if the routing is the relocation target of the given routingboolean
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 primaryShardRouting
moveToStarted()
Set the shards state toSTARTED
.ShardRouting
moveToUnassigned(UnassignedInfo unassignedInfo)
Moves the shard to unassigned state.ShardRouting
moveUnassignedFromPrimary()
Set the unassigned primary shard to non-primarystatic ShardRouting
newUnassigned(ShardId shardId, boolean primary, RecoverySource recoverySource, UnassignedInfo unassignedInfo)
Creates a new unassigned shard.boolean
primary()
Returnstrue
iff this shard is a primary.RecoverySource
recoverySource()
Returns recovery source for the given shard.ShardRouting
reinitializeReplicaShard()
Reinitializes a replica shard, giving it a fresh allocation idShardRouting
relocate(java.lang.String relocatingNodeId, long expectedShardSize)
Relocate the shard to another node.boolean
relocating()
Returnstrue
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 toStreamOutput
without writing index name and shard id-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.elasticsearch.common.xcontent.ToXContentObject
isFragment
-
-
-
-
Field Detail
-
UNAVAILABLE_EXPECTED_SHARD_SIZE
public static final long UNAVAILABLE_EXPECTED_SHARD_SIZE
Used if shard size is not available- See Also:
- Constant Field Values
-
-
Constructor Detail
-
ShardRouting
public ShardRouting(ShardId shardId, StreamInput in) throws java.io.IOException
- Throws:
java.io.IOException
-
ShardRouting
public ShardRouting(StreamInput in) throws java.io.IOException
- Throws:
java.io.IOException
-
-
Method Detail
-
newUnassigned
public static ShardRouting newUnassigned(ShardId shardId, boolean primary, RecoverySource recoverySource, UnassignedInfo unassignedInfo)
Creates a new unassigned shard.
-
index
public Index index()
-
getIndexName
public java.lang.String getIndexName()
The index name.
-
id
public int id()
The shard id.
-
getId
public int getId()
The shard id.
-
unassigned
public boolean unassigned()
The shard is unassigned (not allocated to any node).
-
initializing
public boolean initializing()
The shard is initializing (usually recovering either from peer shard or from gateway).
-
active
public boolean active()
-
started
public boolean started()
The shard is in started mode.
-
relocating
public boolean relocating()
Returnstrue
iff the this shard is currently relocating to another node. Otherwisefalse
- See Also:
ShardRoutingState.RELOCATING
-
assignedToNode
public boolean assignedToNode()
-
currentNodeId
public java.lang.String currentNodeId()
The current node id the shard is allocated on.
-
relocatingNodeId
public java.lang.String relocatingNodeId()
The relocating node id the shard is either relocating to or relocating from.
-
getTargetRelocatingShard
public ShardRouting getTargetRelocatingShard()
Returns a shard routing representing the target shard. The target shard routing will be the INITIALIZING state and have relocatingNodeId set to the source node.
-
unassignedInfo
@Nullable public UnassignedInfo unassignedInfo()
Additional metadata on why the shard is/was unassigned. The metadata is kept around until the shard moves to STARTED.
-
allocationId
@Nullable public AllocationId allocationId()
An id that uniquely identifies an allocation.
-
primary
public boolean primary()
Returnstrue
iff this shard is a primary.
-
state
public ShardRoutingState state()
The shard state.
-
shardId
public ShardId shardId()
The shard id.
-
shardsIt
public ShardIterator shardsIt()
A shard iterator with just this shard in it.
-
writeToThin
public void writeToThin(StreamOutput out) throws java.io.IOException
Writes shard information toStreamOutput
without writing index name and shard id- Parameters:
out
-StreamOutput
to write shard information to- Throws:
java.io.IOException
- if something happens during write
-
writeTo
public void writeTo(StreamOutput out) throws java.io.IOException
Description copied from interface:Writeable
Write this into the StreamOutput.
-
updateUnassigned
public ShardRouting updateUnassigned(UnassignedInfo unassignedInfo, RecoverySource recoverySource)
-
moveToUnassigned
public ShardRouting moveToUnassigned(UnassignedInfo unassignedInfo)
Moves the shard to unassigned state.
-
initialize
public ShardRouting initialize(java.lang.String nodeId, @Nullable java.lang.String existingAllocationId, long expectedShardSize)
Initializes an unassigned shard on a node.- Parameters:
existingAllocationId
- allocation id to use. If null, a fresh allocation id is generated.
-
relocate
public ShardRouting relocate(java.lang.String relocatingNodeId, long expectedShardSize)
Relocate the shard to another node.- Parameters:
relocatingNodeId
- id of the node to relocate the shard
-
cancelRelocation
public ShardRouting cancelRelocation()
Cancel relocation of a shard. The shards state must be set toRELOCATING
.
-
removeRelocationSource
public ShardRouting removeRelocationSource()
Removes relocation source of a non-primary shard. The shard state must beINITIALIZING
. This allows the non-primary shard to continue recovery from the primary even though its non-primary relocation source has failed.
-
reinitializeReplicaShard
public ShardRouting reinitializeReplicaShard()
Reinitializes a replica shard, giving it a fresh allocation id
-
moveToStarted
public ShardRouting moveToStarted()
Set the shards state toSTARTED
. The shards state must beINITIALIZING
orRELOCATING
. Any relocation will be canceled.
-
moveActiveReplicaToPrimary
public ShardRouting moveActiveReplicaToPrimary()
Make the active shard primary unless it's not primary- Throws:
IllegalShardRoutingStateException
- if shard is already a primary
-
moveUnassignedFromPrimary
public ShardRouting moveUnassignedFromPrimary()
Set the unassigned primary shard to non-primary- Throws:
IllegalShardRoutingStateException
- if shard is already a replica
-
isSameAllocation
public boolean isSameAllocation(ShardRouting other)
returns true if this routing has the same allocation ID as another.Note: if both shard routing has a null as their
allocationId()
, this method returns false as the routing describe no allocation at all..
-
isRelocationTarget
public boolean isRelocationTarget()
Returnstrue
if this shard is a relocation target for another shard (i.e., was created withinitializeTargetRelocatingShard()
-
isRelocationTargetOf
public boolean isRelocationTargetOf(ShardRouting other)
returns true if the routing is the relocation target of the given routing
-
isRelocationSourceOf
public boolean isRelocationSourceOf(ShardRouting other)
returns true if the routing is the relocation source for the given routing
-
equalsIgnoringMetaData
public 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
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
shortSummary
public java.lang.String shortSummary()
A short description of the shard.
-
toXContent
public XContentBuilder toXContent(XContentBuilder builder, ToXContent.Params params) throws java.io.IOException
- Specified by:
toXContent
in interfaceToXContent
- Throws:
java.io.IOException
-
getExpectedShardSize
public long getExpectedShardSize()
Returns the expected shard size forShardRoutingState.RELOCATING
andShardRoutingState.INITIALIZING
shards. If it's size is not available -1L will be returned.
-
recoverySource
@Nullable public RecoverySource recoverySource()
Returns recovery source for the given shard. Replica shards always recover from the primaryRecoverySource.PeerRecoverySource
.- Returns:
- recovery source or null if shard is
active()
-
-