@Override public final XContentBuilder toXContent(XContentBuilder builder, ToXContent.Params params) throws IOException { builder.startObject(); builder.field("type", getType()); addAdditionalFields(builder, params); return builder.endObject(); }
/** returns true if the current routing is identical to the other routing in all but meta fields, i.e., unassigned info */ public boolean equalsIgnoringMetaData(ShardRouting other) { if (primary != other.primary) { return false; } if (shardId != null ? !shardId.equals(other.shardId) : other.shardId != null) { return false; } if (currentNodeId != null ? !currentNodeId.equals(other.currentNodeId) : other.currentNodeId != null) { return false; } if (relocatingNodeId != null ? !relocatingNodeId.equals(other.relocatingNodeId) : other.relocatingNodeId != null) { return false; } if (allocationId != null ? !allocationId.equals(other.allocationId) : other.allocationId != null) { return false; } if (state != other.state) { return false; } if (recoverySource != null ? !recoverySource.equals(other.recoverySource) : other.recoverySource != null) { return false; } return true; }
@Override public int hashCode() { int h = hashCode; if (h == 0) { h = shardId.hashCode(); h = 31 * h + (currentNodeId != null ? currentNodeId.hashCode() : 0); h = 31 * h + (relocatingNodeId != null ? relocatingNodeId.hashCode() : 0); h = 31 * h + (primary ? 1 : 0); h = 31 * h + (state != null ? state.hashCode() : 0); h = 31 * h + (recoverySource != null ? recoverySource.hashCode() : 0); h = 31 * h + (allocationId != null ? allocationId.hashCode() : 0); h = 31 * h + (unassignedInfo != null ? unassignedInfo.hashCode() : 0); hashCode = h; } return h; }
@Override public final void writeTo(StreamOutput out) throws IOException { out.writeByte((byte) getType().ordinal()); writeAdditionalFields(out); }
@Override public void writeTo(StreamOutput out) throws IOException { timer.writeTo(out); out.writeByte(stage.id()); shardId.writeTo(out); recoverySource.writeTo(out); targetNode.writeTo(out); out.writeOptionalWriteable(sourceNode); index.writeTo(out); translog.writeTo(out); verifyIndex.writeTo(out); out.writeBoolean(primary); }
public ShardRouting(ShardId shardId, StreamInput in) throws IOException { this.shardId = shardId; currentNodeId = in.readOptionalString(); relocatingNodeId = in.readOptionalString(); primary = in.readBoolean(); state = ShardRoutingState.fromValue(in.readByte()); if (state == ShardRoutingState.UNASSIGNED || state == ShardRoutingState.INITIALIZING) { recoverySource = RecoverySource.readFrom(in); } else { recoverySource = null; } unassignedInfo = in.readOptionalWriteable(UnassignedInfo::new); allocationId = in.readOptionalWriteable(AllocationId::new); final long shardSize; if (state == ShardRoutingState.RELOCATING || state == ShardRoutingState.INITIALIZING) { shardSize = in.readLong(); } else { shardSize = UNAVAILABLE_EXPECTED_SHARD_SIZE; } expectedShardSize = shardSize; asList = Collections.singletonList(this); targetRelocatingShard = initializeTargetRelocatingShard(); }
final boolean indexShouldExists = recoveryState.getRecoverySource().getType() != RecoverySource.Type.EMPTY_STORE; indexShard.prepareForIndexRecovery(); long version = -1; if (recoveryState.getRecoverySource().getType() == RecoverySource.Type.LOCAL_SHARDS) { assert indexShouldExists; store.bootstrapNewHistory(); store.associateIndexWithNewTranslog(translogUUID); } else if (indexShouldExists) { if (recoveryState.getRecoverySource().shouldBootstrapNewHistoryUUID()) { store.bootstrapNewHistory();
@Override public int hashCode() { return getType().hashCode(); }
@Override public final void writeTo(StreamOutput out) throws IOException { out.writeByte((byte) getType().ordinal()); writeAdditionalFields(out); }
/** * Writes shard information to {@link StreamOutput} without writing index name and shard id * * @param out {@link StreamOutput} to write shard information to * @throws IOException if something happens during write */ public void writeToThin(StreamOutput out) throws IOException { out.writeOptionalString(currentNodeId); out.writeOptionalString(relocatingNodeId); out.writeBoolean(primary); out.writeByte(state.value()); if (state == ShardRoutingState.UNASSIGNED || state == ShardRoutingState.INITIALIZING) { recoverySource.writeTo(out); } out.writeOptionalWriteable(unassignedInfo); out.writeOptionalWriteable(allocationId); if (state == ShardRoutingState.RELOCATING || state == ShardRoutingState.INITIALIZING) { out.writeLong(expectedShardSize); } }
@Override public synchronized void readFrom(StreamInput in) throws IOException { timer.readFrom(in); stage = Stage.fromId(in.readByte()); shardId = ShardId.readShardId(in); recoverySource = RecoverySource.readFrom(in); targetNode = new DiscoveryNode(in); sourceNode = in.readOptionalWriteable(DiscoveryNode::new); index.readFrom(in); translog.readFrom(in); verifyIndex.readFrom(in); primary = in.readBoolean(); }
final boolean indexShouldExists = recoveryState.getRecoverySource().getType() != RecoverySource.Type.EMPTY_STORE; indexShard.prepareForIndexRecovery(); long version = -1; if (recoveryState.getRecoverySource().getType() == RecoverySource.Type.LOCAL_SHARDS) { assert indexShouldExists; store.bootstrapNewHistory(); store.associateIndexWithNewTranslog(translogUUID); } else if (indexShouldExists) { if (recoveryState.getRecoverySource().shouldBootstrapNewHistoryUUID()) { store.bootstrapNewHistory();
/** * Helper method that creates update entry for the given recovery source's restore uuid * if such an entry does not exist yet. */ private Updates changes(RecoverySource recoverySource) { assert recoverySource.getType() == RecoverySource.Type.SNAPSHOT; return shardChanges.computeIfAbsent(((SnapshotRecoverySource) recoverySource).restoreUUID(), k -> new Updates()); }
builder.field(Fields.TYPE, recoverySource.getType()); builder.field(Fields.STAGE, stage.toString()); builder.field(Fields.PRIMARY, primary); if (recoverySource.getType() == RecoverySource.Type.PEER) { builder.startObject(Fields.SOURCE); builder.field(Fields.ID, sourceNode.getId()); } else { builder.startObject(Fields.SOURCE); recoverySource.addAdditionalFields(builder, params); builder.endObject();
@Override public final void writeTo(StreamOutput out) throws IOException { out.writeByte((byte) getType().ordinal()); writeAdditionalFields(out); }
/** * Writes shard information to {@link StreamOutput} without writing index name and shard id * * @param out {@link StreamOutput} to write shard information to * @throws IOException if something happens during write */ public void writeToThin(StreamOutput out) throws IOException { out.writeOptionalString(currentNodeId); out.writeOptionalString(relocatingNodeId); out.writeBoolean(primary); out.writeByte(state.value()); if (state == ShardRoutingState.UNASSIGNED || state == ShardRoutingState.INITIALIZING) { recoverySource.writeTo(out); } out.writeOptionalWriteable(unassignedInfo); out.writeOptionalWriteable(allocationId); if (state == ShardRoutingState.RELOCATING || state == ShardRoutingState.INITIALIZING) { out.writeLong(expectedShardSize); } }