public FailedShard(ShardRouting routingEntry, String message, Exception failure, boolean markAsStale) { assert routingEntry.assignedToNode() : "only assigned shards can be failed " + routingEntry; this.routingEntry = routingEntry; this.message = message; this.failure = failure; this.markAsStale = markAsStale; }
@Override public void shardFailed(ShardRouting failedShard, UnassignedInfo unassignedInfo) { assert failedShard.assignedToNode() : "expected assigned shard " + failedShard; setChanged(); }
for (IndexShardRoutingTable shardRoutingTable : this) { for (ShardRouting shardRouting : shardRoutingTable) { if (shardRouting.assignedToNode()) { String currentNodeId = shardRouting.currentNodeId(); boolean excluded = false;
/** * 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); }
/** * 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); }
static boolean distinctNodes(List<ShardRouting> shards) { Set<String> nodes = new HashSet<>(); for (ShardRouting shard : shards) { if (shard.assignedToNode()) { if (nodes.add(shard.currentNodeId()) == false) { return false; } if (shard.relocating()) { if (nodes.add(shard.relocatingNodeId()) == false) { return false; } } } } return true; }
allAllocationIds.add(shard.getTargetRelocatingShard().allocationId().getId()); if (shard.assignedToNode()) { assignedShards.add(shard); allAllocationIds.add(shard.allocationId().getId());
private IndicesShardStoresResponse.StoreStatus.AllocationStatus getAllocationStatus(String index, int shardID, DiscoveryNode node) { for (ShardRouting shardRouting : routingNodes.node(node.getId())) { ShardId shardId = shardRouting.shardId(); if (shardId.id() == shardID && shardId.getIndexName().equals(index)) { if (shardRouting.primary()) { return IndicesShardStoresResponse.StoreStatus.AllocationStatus.PRIMARY; } else if (shardRouting.assignedToNode()) { return IndicesShardStoresResponse.StoreStatus.AllocationStatus.REPLICA; } else { return IndicesShardStoresResponse.StoreStatus.AllocationStatus.UNUSED; } } } return IndicesShardStoresResponse.StoreStatus.AllocationStatus.UNUSED; }
if (shard.assignedToNode()) { Map<ShardId, ShardRouting> entries = nodesToShards.computeIfAbsent(shard.currentNodeId(), k -> new LinkedHashMap<>()); // LinkedHashMap to preserve order
public FailedShard(ShardRouting routingEntry, String message, Exception failure, boolean markAsStale) { assert routingEntry.assignedToNode() : "only assigned shards can be failed " + routingEntry; this.routingEntry = routingEntry; this.message = message; this.failure = failure; this.markAsStale = markAsStale; }
if (!shardRouting.primary() && !shardRouting.assignedToNode()) { builder.removeShard(shardRouting); removed = true;
if (shard.assignedToNode()) {
private void updateRecoveryCounts(final ShardRouting routing, final boolean increment, @Nullable final ShardRouting primary) { final int howMany = increment ? 1 : -1; assert routing.initializing() : "routing must be initializing: " + routing; // TODO: check primary == null || primary.active() after all tests properly add ReplicaAfterPrimaryActiveAllocationDecider assert primary == null || primary.assignedToNode() : "shard is initializing but its primary is not assigned to a node"; Recoveries.getOrAdd(recoveriesPerNode, routing.currentNodeId()).addIncoming(howMany); if (routing.recoverySource().getType() == RecoverySource.Type.PEER) { // add/remove corresponding outgoing recovery on node with primary shard if (primary == null) { throw new IllegalStateException("shard is peer recovering but primary is unassigned"); } Recoveries.getOrAdd(recoveriesPerNode, primary.currentNodeId()).addOutgoing(howMany); if (increment == false && routing.primary() && routing.relocatingNodeId() != null) { // primary is done relocating, move non-primary recoveries from old primary to new primary int numRecoveringReplicas = 0; for (ShardRouting assigned : assignedShards(routing.shardId())) { if (assigned.primary() == false && assigned.initializing() && assigned.recoverySource().getType() == RecoverySource.Type.PEER) { numRecoveringReplicas++; } } recoveriesPerNode.get(routing.relocatingNodeId()).addOutgoing(-numRecoveringReplicas); recoveriesPerNode.get(routing.currentNodeId()).addOutgoing(numRecoveringReplicas); } } }
if (shardRouting.assignedToNode()) { String nodeId = shardRouting.relocating() ? shardRouting.relocatingNodeId() : shardRouting.currentNodeId(); if (!node.nodeId().equals(nodeId)) {
@Override public void shardFailed(ShardRouting failedShard, UnassignedInfo unassignedInfo) { assert failedShard.assignedToNode() : "expected assigned shard " + failedShard; setChanged(); }
@Override public void shardFailed(ShardRouting failedShard, UnassignedInfo unassignedInfo) { assert failedShard.assignedToNode() : "expected assigned shard " + failedShard; setChanged(); }
RoutingChangesObserver routingChangesObserver) { ensureMutable(); assert failedShard.assignedToNode() : "only assigned shards can be failed"; assert indexMetaData.getIndex().equals(failedShard.index()) : "shard failed for unknown index (shard entry: " + failedShard + ")";
if (indexRoutingTable != null) { ShardRouting primary = indexRoutingTable.shard(i).primaryShard(); if (primary == null || !primary.assignedToNode()) { builder.put(shardId, new SnapshotsInProgress.ShardSnapshotStatus(null, State.MISSING, "primary shard is not allocated")); } else if (primary.relocating() || primary.initializing()) {
table.addCell(getOrNull(commonStats, CommonStats::getDocs, DocsStats::getCount)); table.addCell(getOrNull(commonStats, CommonStats::getStore, StoreStats::getSize)); if (shard.assignedToNode()) { String ip = state.getState().nodes().get(shard.currentNodeId()).getHostAddress(); String nodeId = shard.currentNodeId();
String nodeId = "UNASSIGNED"; if (shard.assignedToNode()) { nodeId = shard.currentNodeId();