/** * Returns the current {@link ShardRoutingState} of the shard. */ public ShardRoutingState getShardState() { return shardRouting.state(); }
/** * The number of shards on this node that will not be eventually relocated. */ public int numberOfOwningShards() { int count = 0; for (ShardRouting shardEntry : this) { if (shardEntry.state() != ShardRoutingState.RELOCATING) { count++; } } return count; }
/** * Determine the number of shards with a specific state * @param states set of states which should be counted * @return number of shards */ public int numberOfShardsWithState(ShardRoutingState... states) { int count = 0; for (ShardRouting shardEntry : this) { for (ShardRoutingState state : states) { if (shardEntry.state() == state) { count++; } } } return count; }
public List<ShardRouting> shardsWithState(ShardRoutingState state) { if (state == ShardRoutingState.INITIALIZING) { return allInitializingShards; } List<ShardRouting> shards = new ArrayList<>(); for (ShardRouting shardEntry : this) { if (shardEntry.state() == state) { shards.add(shardEntry); } } return shards; }
public List<ShardRouting> replicaShardsWithState(ShardRoutingState... states) { List<ShardRouting> shards = new ArrayList<>(); for (ShardRouting shardEntry : replicas) { for (ShardRoutingState state : states) { if (shardEntry.state() == state) { shards.add(shardEntry); } } } return shards; }
/** * Determine the shards with a specific state * @param states set of states which should be listed * @return List of shards */ public List<ShardRouting> shardsWithState(ShardRoutingState... states) { List<ShardRouting> shards = new ArrayList<>(); for (ShardRouting shardEntry : this) { for (ShardRoutingState state : states) { if (shardEntry.state() == state) { shards.add(shardEntry); } } } return shards; }
/** * Determine the shards of an index with a specific state * @param index id of the index * @param states set of states which should be listed * @return a list of shards */ public List<ShardRouting> shardsWithState(String index, ShardRoutingState... states) { List<ShardRouting> shards = new ArrayList<>(); for (ShardRouting shardEntry : this) { if (!shardEntry.getIndexName().equals(index)) { continue; } for (ShardRoutingState state : states) { if (shardEntry.state() == state) { shards.add(shardEntry); } } } return shards; }
allAllocationIds.add(shard.allocationId().getId()); if (shard.state() != ShardRoutingState.STARTED) { allShardsStarted = false;
/** * Builds the internal model from all shards in the given * {@link Iterable}. All shards in the {@link Iterable} must be assigned * to a node. This method will skip shards in the state * {@link ShardRoutingState#RELOCATING} since each relocating shard has * a shadow shard in the state {@link ShardRoutingState#INITIALIZING} * on the target node which we respect during the allocation / balancing * process. In short, this method recreates the status-quo in the cluster. */ private Map<String, ModelNode> buildModelFromAssigned() { Map<String, ModelNode> nodes = new HashMap<>(); for (RoutingNode rn : routingNodes) { ModelNode node = new ModelNode(rn); nodes.put(rn.nodeId(), node); for (ShardRouting shard : rn) { assert rn.nodeId().equals(shard.currentNodeId()); /* we skip relocating shards here since we expect an initializing shard with the same id coming in */ if (shard.state() != RELOCATING) { node.addShard(shard); if (logger.isTraceEnabled()) { logger.trace("Assigned shard [{}] to node [{}]", shard, node.getNodeId()); } } } } return nodes; }
@Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { builder.startObject(Fields.ROUTING) .field(Fields.STATE, shardRouting.state()) .field(Fields.PRIMARY, shardRouting.primary()) .field(Fields.NODE, shardRouting.currentNodeId()) .field(Fields.RELOCATING_NODE, shardRouting.relocatingNodeId()) .endObject(); commonStats.toXContent(builder, params); if (commitStats != null) { commitStats.toXContent(builder, params); } if (seqNoStats != null) { seqNoStats.toXContent(builder, params); } builder.startObject(Fields.SHARD_PATH); builder.field(Fields.STATE_PATH, statePath); builder.field(Fields.DATA_PATH, dataPath); builder.field(Fields.IS_CUSTOM_DATA_PATH, isCustomDataPath); builder.endObject(); return builder; }
builder.field("shard", shardRouting.getId()); builder.field("primary", shardRouting.primary()); builder.field("current_state", shardRouting.state().toString().toLowerCase(Locale.ROOT)); if (shardRouting.unassignedInfo() != null) { unassignedInfoToXContent(shardRouting.unassignedInfo(), builder); } else { String explanation; if (shardRouting.state() == ShardRoutingState.RELOCATING) { explanation = "the shard is in the process of relocating from node [" + currentNode.getName() + "] " + "to node [" + relocationTargetNode.getName() + "], wait until relocation has completed"; } else { assert shardRouting.state() == ShardRoutingState.INITIALIZING; explanation = "the shard is in the process of initializing on node [" + currentNode.getName() + "], " + "wait until initialization has completed";
/** * Returns the current {@link ShardRoutingState} of the shard. */ public ShardRoutingState getShardState() { return shardRouting.state(); }
/** * Returns the current {@link ShardRoutingState} of the shard. */ public ShardRoutingState getShardState() { return shardRouting.state(); }
builder.field(Fields.STATE, shardUpgradeStatus.getShardRouting().state()); builder.field(Fields.PRIMARY, shardUpgradeStatus.getShardRouting().primary()); builder.field(Fields.NODE, shardUpgradeStatus.getShardRouting().currentNodeId());
return new RerouteExplanation(this, allocation.decision(Decision.NO, "cancel_allocation_command", "can't cancel " + shardId + " on node " + discoNode + ", shard is primary and " + shardRouting.state().name().toLowerCase(Locale.ROOT))); discoNode + ", shard is primary and " + shardRouting.state().name().toLowerCase(Locale.ROOT));
@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(); }
builder.field(Fields.STATE, shardSegments.getShardRouting().state()); builder.field(Fields.PRIMARY, shardSegments.getShardRouting().primary()); builder.field(Fields.NODE, shardSegments.getShardRouting().currentNodeId());
", shard is not started (state = " + shardRouting.state() + "]");
"a primary relocation is completed by the master, but primary mode is not active " + currentRouting; changeState(IndexShardState.STARTED, "global state is [" + newRouting.state() + "]"); } else if (currentRouting.primary() && currentRouting.relocating() && replicationTracker.isRelocated() && (newRouting.relocating() == false || newRouting.equalsIgnoringMetaData(currentRouting) == false)) { newRouting.state());
table.addCell("r"); table.addCell(shard.state()); table.addCell(getOrNull(commonStats, CommonStats::getDocs, DocsStats::getCount)); table.addCell(getOrNull(commonStats, CommonStats::getStore, StoreStats::getSize));