/** * Creates a new unassigned shard. */ public static ShardRouting newUnassigned(ShardId shardId, boolean primary, RecoverySource recoverySource, UnassignedInfo unassignedInfo) { return new ShardRouting(shardId, null, null, primary, ShardRoutingState.UNASSIGNED, recoverySource, unassignedInfo, null, UNAVAILABLE_EXPECTED_SHARD_SIZE); }
public IllegalShardRoutingStateException(StreamInput in) throws IOException { super(in); shard = new ShardRouting(in); }
/** * Relocate the shard to another node. * * @param relocatingNodeId id of the node to relocate the shard */ public ShardRouting relocate(String relocatingNodeId, long expectedShardSize) { assert state == ShardRoutingState.STARTED : "current shard has to be started in order to be relocated " + this; return new ShardRouting(shardId, currentNodeId, relocatingNodeId, primary, ShardRoutingState.RELOCATING, recoverySource, null, AllocationId.newRelocation(allocationId), expectedShardSize); }
/** * Set the unassigned primary shard to non-primary * * @throws IllegalShardRoutingStateException if shard is already a replica */ public ShardRouting moveUnassignedFromPrimary() { assert state == ShardRoutingState.UNASSIGNED : "expected an unassigned shard " + this; if (!primary) { throw new IllegalShardRoutingStateException(this, "Not primary, can't move to replica"); } return new ShardRouting(shardId, currentNodeId, relocatingNodeId, false, state, PeerRecoverySource.INSTANCE, unassignedInfo, allocationId, expectedShardSize); }
@Override public void readFrom(StreamInput in) throws IOException { shardRouting = new ShardRouting(in); int size = in.readVInt(); if (size == 0) { segments = Collections.emptyList(); } else { segments = new ArrayList<>(size); for (int i = 0; i < size; i++) { segments.add(Segment.readSegment(in)); } } }
public ShardRouting updateUnassigned(UnassignedInfo unassignedInfo, RecoverySource recoverySource) { assert this.unassignedInfo != null : "can only update unassign info if they are already set"; assert this.unassignedInfo.isDelayed() || (unassignedInfo.isDelayed() == false) : "cannot transition from non-delayed to delayed"; return new ShardRouting(shardId, currentNodeId, relocatingNodeId, primary, state, recoverySource, unassignedInfo, allocationId, expectedShardSize); }
@Override public void readFrom(StreamInput in) throws IOException { shardId = ShardId.readShardId(in); shards = new ShardRouting[in.readVInt()]; for (int i = 0; i < shards.length; i++) { shards[i] = new ShardRouting(shardId, in); } }
/** * Cancel relocation of a shard. The shards state must be set * to <code>RELOCATING</code>. */ public ShardRouting cancelRelocation() { assert state == ShardRoutingState.RELOCATING : this; assert assignedToNode() : this; assert relocatingNodeId != null : this; return new ShardRouting(shardId, currentNodeId, null, primary, ShardRoutingState.STARTED, recoverySource, null, AllocationId.cancelRelocation(allocationId), UNAVAILABLE_EXPECTED_SHARD_SIZE); }
@Nullable private ShardRouting initializeTargetRelocatingShard() { if (state == ShardRoutingState.RELOCATING) { return new ShardRouting(shardId, relocatingNodeId, currentNodeId, primary, ShardRoutingState.INITIALIZING, PeerRecoverySource.INSTANCE, unassignedInfo, AllocationId.newTargetRelocation(allocationId), expectedShardSize); } else { return null; } }
/** * Reinitializes a replica shard, giving it a fresh allocation id */ public ShardRouting reinitializeReplicaShard() { assert state == ShardRoutingState.INITIALIZING : this; assert primary == false : this; assert isRelocationTarget() == false : this; return new ShardRouting(shardId, currentNodeId, null, primary, ShardRoutingState.INITIALIZING, recoverySource, unassignedInfo, AllocationId.newInitializing(), expectedShardSize); }
/** * Removes relocation source of a non-primary shard. The shard state must be <code>INITIALIZING</code>. * This allows the non-primary shard to continue recovery from the primary even though its non-primary * relocation source has failed. */ public ShardRouting removeRelocationSource() { assert primary == false : this; assert state == ShardRoutingState.INITIALIZING : this; assert assignedToNode() : this; assert relocatingNodeId != null : this; return new ShardRouting(shardId, currentNodeId, null, primary, state, recoverySource, unassignedInfo, AllocationId.finishRelocation(allocationId), expectedShardSize); }
/** * Make the active shard primary unless it's not primary * * @throws IllegalShardRoutingStateException if shard is already a primary */ public ShardRouting moveActiveReplicaToPrimary() { assert active(): "expected an active shard " + this; if (primary) { throw new IllegalShardRoutingStateException(this, "Already primary, can't move to primary"); } return new ShardRouting(shardId, currentNodeId, relocatingNodeId, true, state, recoverySource, unassignedInfo, allocationId, expectedShardSize); }
/** * Set the shards state to <code>STARTED</code>. The shards state must be * <code>INITIALIZING</code> or <code>RELOCATING</code>. Any relocation will be * canceled. */ public ShardRouting moveToStarted() { assert state == ShardRoutingState.INITIALIZING : "expected an initializing shard " + this; AllocationId allocationId = this.allocationId; if (allocationId.getRelocationId() != null) { // relocation target allocationId = AllocationId.finishRelocation(allocationId); } return new ShardRouting(shardId, currentNodeId, null, primary, ShardRoutingState.STARTED, null, null, allocationId, UNAVAILABLE_EXPECTED_SHARD_SIZE); }
/** * Moves the shard to unassigned state. */ public ShardRouting moveToUnassigned(UnassignedInfo unassignedInfo) { assert state != ShardRoutingState.UNASSIGNED : this; final RecoverySource recoverySource; if (active()) { if (primary()) { recoverySource = ExistingStoreRecoverySource.INSTANCE; } else { recoverySource = PeerRecoverySource.INSTANCE; } } else { recoverySource = recoverySource(); } return new ShardRouting(shardId, null, null, primary, ShardRoutingState.UNASSIGNED, recoverySource, unassignedInfo, null, UNAVAILABLE_EXPECTED_SHARD_SIZE); }
/** * Initializes an unassigned shard on a node. * * @param existingAllocationId allocation id to use. If null, a fresh allocation id is generated. */ public ShardRouting initialize(String nodeId, @Nullable String existingAllocationId, long expectedShardSize) { assert state == ShardRoutingState.UNASSIGNED : this; assert relocatingNodeId == null : this; final AllocationId allocationId; if (existingAllocationId == null) { allocationId = AllocationId.newInitializing(); } else { allocationId = AllocationId.newInitializing(existingAllocationId); } return new ShardRouting(shardId, nodeId, null, primary, ShardRoutingState.INITIALIZING, recoverySource, unassignedInfo, allocationId, expectedShardSize); }
@Override public void readFrom(StreamInput in) throws IOException { super.readFrom(in); shardRouting = new ShardRouting(in); totalBytes = in.readLong(); toUpgradeBytes = in.readLong(); toUpgradeBytesAncient = in.readLong(); }
public ClusterAllocationExplanation(StreamInput in) throws IOException { this.shardRouting = new ShardRouting(in); this.currentNode = in.readOptionalWriteable(DiscoveryNode::new); this.relocationTargetNode = in.readOptionalWriteable(DiscoveryNode::new); this.clusterInfo = in.readOptionalWriteable(ClusterInfo::new); this.shardAllocationDecision = new ShardAllocationDecision(in); }
@Override public void readFrom(StreamInput in) throws IOException { failureReason = in.readOptionalString(); int numResponses = in.readInt(); shardResponses = new HashMap<>(); for (int i = 0; i < numResponses; i++) { ShardRouting shardRouting = new ShardRouting(in); SyncedFlushService.ShardSyncedFlushResponse response = SyncedFlushService.ShardSyncedFlushResponse.readSyncedFlushResponse(in); shardResponses.put(shardRouting, response); } syncId = in.readOptionalString(); shardId = ShardId.readShardId(in); totalShards = in.readInt(); }
public static IndexShardRoutingTable readFromThin(StreamInput in, Index index) throws IOException { int iShardId = in.readVInt(); ShardId shardId = new ShardId(index, iShardId); Builder builder = new Builder(shardId); int size = in.readVInt(); for (int i = 0; i < size; i++) { ShardRouting shard = new ShardRouting(shardId, in); builder.addShard(shard); } return builder.build(); }
@Override public void readFrom(StreamInput in) throws IOException { shardRouting = new ShardRouting(in); commonStats = new CommonStats(in); commitStats = CommitStats.readOptionalCommitStatsFrom(in); statePath = in.readString(); dataPath = in.readString(); isCustomDataPath = in.readBoolean(); if (in.getVersion().onOrAfter(Version.V_6_0_0_alpha1)) { seqNoStats = in.readOptionalWriteable(SeqNoStats::new); } }