/** * The shard id. */ public int getId() { return id(); }
public int highestPrimary() { if (highestPrimary == -1) { int maxId = -1; for (ShardRouting shard : shards) { if (shard.primary()) { maxId = Math.max(maxId, shard.id()); } } return highestPrimary = maxId; } return highestPrimary; }
IndexUpgradeStatus(String index, ShardUpgradeStatus[] shards) { this.index = index; Map<Integer, List<ShardUpgradeStatus>> tmpIndexShards = new HashMap<>(); for (ShardUpgradeStatus shard : shards) { List<ShardUpgradeStatus> lst = tmpIndexShards.get(shard.getShardRouting().id()); if (lst == null) { lst = new ArrayList<>(); tmpIndexShards.put(shard.getShardRouting().id(), lst); } lst.add(shard); } indexShards = new HashMap<>(); for (Map.Entry<Integer, List<ShardUpgradeStatus>> entry : tmpIndexShards.entrySet()) { indexShards.put(entry.getKey(), new IndexShardUpgradeStatus(entry.getValue().get(0).getShardRouting().shardId(), entry.getValue().toArray(new ShardUpgradeStatus[entry.getValue().size()]))); } }
IndexSegments(String index, ShardSegments[] shards) { this.index = index; Map<Integer, List<ShardSegments>> tmpIndexShards = new HashMap<>(); for (ShardSegments shard : shards) { List<ShardSegments> lst = tmpIndexShards.get(shard.getShardRouting().id()); if (lst == null) { lst = new ArrayList<>(); tmpIndexShards.put(shard.getShardRouting().id(), lst); } lst.add(shard); } indexShards = new HashMap<>(); for (Map.Entry<Integer, List<ShardSegments>> entry : tmpIndexShards.entrySet()) { indexShards.put(entry.getKey(), new IndexShardSegments(entry.getValue().get(0).getShardRouting().shardId(), entry.getValue().toArray(new ShardSegments[entry.getValue().size()]))); } }
public Map<Integer, IndexShardStats> getIndexShards() { if (indexShards != null) { return indexShards; } Map<Integer, List<ShardStats>> tmpIndexShards = new HashMap<>(); for (ShardStats shard : shards) { List<ShardStats> lst = tmpIndexShards.get(shard.getShardRouting().id()); if (lst == null) { lst = new ArrayList<>(); tmpIndexShards.put(shard.getShardRouting().id(), lst); } lst.add(shard); } indexShards = new HashMap<>(); for (Map.Entry<Integer, List<ShardStats>> entry : tmpIndexShards.entrySet()) { indexShards.put(entry.getKey(), new IndexShardStats(entry.getValue().get(0).getShardRouting().shardId(), entry.getValue().toArray(new ShardStats[entry.getValue().size()]))); } return indexShards; }
final Set<String> inSyncAllocationIds = indexMetaData.inSyncAllocationIds(unassignedShard.id()); final boolean snapshotRestore = unassignedShard.recoverySource().getType() == RecoverySource.Type.SNAPSHOT; final boolean enoughAllocationsFound = nodeShardsResult.orderedAllocationCandidates.size() > 0; logger.debug("[{}][{}]: found {} allocation candidates of {} based on allocation ids: [{}]", unassignedShard.index(), unassignedShard.id(), nodeShardsResult.orderedAllocationCandidates.size(), unassignedShard, inSyncAllocationIds); unassignedShard.index(), unassignedShard.id(), unassignedShard.recoverySource()); return AllocateUnassignedDecision.NOT_TAKEN; } else { unassignedShard.index(), unassignedShard.id(), nodeShardsResult.allocationsFound); return AllocateUnassignedDecision.no(AllocationStatus.NO_VALID_SHARD_COPY, explain ? buildNodeDecisions(null, shardState, inSyncAllocationIds) : null); DecidedNode decidedNode = nodesToAllocate.yesNodeShards.get(0); logger.debug("[{}][{}]: allocating [{}] to [{}] on primary allocation", unassignedShard.index(), unassignedShard.id(), unassignedShard, decidedNode.nodeShardState.getNode()); node = decidedNode.nodeShardState.getNode(); allocationId = decidedNode.nodeShardState.allocationId(); final NodeGatewayStartedShards nodeShardState = decidedNode.nodeShardState; logger.debug("[{}][{}]: allocating [{}] to [{}] on forced primary allocation", unassignedShard.index(), unassignedShard.id(), unassignedShard, nodeShardState.getNode()); node = nodeShardState.getNode(); allocationId = nodeShardState.allocationId(); } else if (nodesToAllocate.throttleNodeShards.isEmpty() == false) { logger.debug("[{}][{}]: throttling allocation [{}] to [{}] on forced primary allocation", unassignedShard.index(), unassignedShard.id(), unassignedShard, nodesToAllocate.throttleNodeShards);
@Override protected ShardSegments shardOperation(IndicesSegmentsRequest request, ShardRouting shardRouting) { IndexService indexService = indicesService.indexServiceSafe(shardRouting.index()); IndexShard indexShard = indexService.getShard(shardRouting.id()); return new ShardSegments(indexShard.routingEntry(), indexShard.segments(request.verbose())); } }
i = shard.id(); indicesAndShards.put(shard.index(), Math.max(i, shard.id())); for (final ShardRouting shardRouting : routingNode) { final HashSet<ShardRouting> shards = shardsByShardId.computeIfAbsent(new ShardId(shardRouting.index(), shardRouting.id()), k -> new HashSet<>()); shards.add(shardRouting);
"from the routing table"); final Set<String> inSyncAllocationIds = indexMetaData.inSyncAllocationIds(shardRouting.id()); if (shardRouting.active() && inSyncAllocationIds.contains(shardRouting.allocationId().getId()) == false) {
logger.trace("[{}][{}] can't move", shardRouting.index(), shardRouting.id());
public Builder addReplica() { for (IntCursor cursor : shards.keys()) { int shardNumber = cursor.value; ShardId shardId = new ShardId(index, shardNumber); // version 0, will get updated when reroute will happen ShardRouting shard = ShardRouting.newUnassigned(shardId, false, PeerRecoverySource.INSTANCE, new UnassignedInfo(UnassignedInfo.Reason.REPLICA_ADDED, null)); shards.put(shardNumber, new IndexShardRoutingTable.Builder(shards.get(shard.id())).addShard(shard).build() ); } return this; }
@Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { builder.startObject() .field("state", state()) .field("primary", primary()) .field("node", currentNodeId()) .field("relocating_node", relocatingNodeId()) .field("shard", id()) .field("index", getIndexName()); if (expectedShardSize != UNAVAILABLE_EXPECTED_SHARD_SIZE) { builder.field("expected_shard_size_in_bytes", expectedShardSize); } if (recoverySource != null) { builder.field("recovery_source", recoverySource); } if (allocationId != null) { builder.field("allocation_id"); allocationId.toXContent(builder, params); } if (unassignedInfo != null) { unassignedInfo.toXContent(builder, params); } return builder.endObject(); }
/** * Adds a new shard routing (makes a copy of it), with reference data used from the index shard routing table * if it needs to be created. */ public Builder addShard(ShardRouting shard) { IndexShardRoutingTable indexShard = shards.get(shard.id()); if (indexShard == null) { indexShard = new IndexShardRoutingTable.Builder(shard.shardId()).addShard(shard).build(); } else { indexShard = new IndexShardRoutingTable.Builder(indexShard).addShard(shard).build(); } shards.put(indexShard.shardId().id(), indexShard); return this; }
final int repId = shard.id(); final int nodeHigh = node.highestPrimary(shard.index().getName()); final int minNodeHigh = minNode.highestPrimary(shard.getIndexName());
if (decision.type() == Decision.Type.THROTTLE) { logger.debug("[{}][{}]: throttling allocation [{}] to [{}] in order to reuse its unallocated persistent store", unassignedShard.index(), unassignedShard.id(), unassignedShard, nodeWithHighestMatch.node()); unassignedShard.index(), unassignedShard.id(), unassignedShard, nodeWithHighestMatch.node());
/** * Returns the expected shard size for the given shard or the default value provided if not enough information are available * to estimate the shards size. */ public static long getExpectedShardSize(ShardRouting shard, RoutingAllocation allocation, long defaultValue) { final IndexMetaData metaData = allocation.metaData().getIndexSafe(shard.index()); final ClusterInfo info = allocation.clusterInfo(); if (metaData.getResizeSourceIndex() != null && shard.active() == false && shard.recoverySource().getType() == RecoverySource.Type.LOCAL_SHARDS) { // in the shrink index case we sum up the source index shards since we basically make a copy of the shard in // the worst case long targetShardSize = 0; final Index mergeSourceIndex = metaData.getResizeSourceIndex(); final IndexMetaData sourceIndexMeta = allocation.metaData().index(mergeSourceIndex); if (sourceIndexMeta != null) { final Set<ShardId> shardIds = IndexMetaData.selectRecoverFromShards(shard.id(), sourceIndexMeta, metaData.getNumberOfShards()); for (IndexShardRoutingTable shardRoutingTable : allocation.routingTable().index(mergeSourceIndex.getName())) { if (shardIds.contains(shardRoutingTable.shardId())) { targetShardSize += info.getShardSize(shardRoutingTable.primaryShard(), 0); } } } return targetShardSize == 0 ? defaultValue : targetShardSize; } else { return info.getShardSize(shard, defaultValue); } } }
ShardId shardId = IndexMetaData.selectSplitShard(shardRouting.id(), sourceIndexMetaData, indexMetaData.getNumberOfShards()); ShardRouting sourceShardRouting = allocation.routingNodes().activePrimary(shardId); if (sourceShardRouting == null) {
table.addCell(shard.id());
@Override protected ShardSegments shardOperation(IndicesSegmentsRequest request, ShardRouting shardRouting) { IndexService indexService = indicesService.indexServiceSafe(shardRouting.index()); IndexShard indexShard = indexService.getShard(shardRouting.id()); return new ShardSegments(indexShard.routingEntry(), indexShard.segments(request.verbose())); } }