/** * Returns <code>true</code> iff the this shard is currently * {@link ShardRoutingState#STARTED started} or * {@link ShardRoutingState#RELOCATING relocating} to another node. * Otherwise <code>false</code> */ public boolean active() { return started() || relocating(); }
@Override public void replicaPromoted(ShardRouting replicaShard) { assert replicaShard.started() && replicaShard.primary() == false : "expected started replica shard " + replicaShard; setChanged(); }
@Override public void shardStarted(ShardRouting initializingShard, ShardRouting startedShard) { assert initializingShard.initializing() : "expected initializing shard " + initializingShard; assert startedShard.started() : "expected started shard " + startedShard; setChanged(); }
@Override public void relocationStarted(ShardRouting startedShard, ShardRouting targetRelocatingShard) { assert startedShard.started() : "expected started shard " + startedShard; assert targetRelocatingShard.isRelocationTarget() : "expected relocation target shard " + targetRelocatingShard; setChanged(); }
private void promoteReplicaToPrimary(ShardRouting activeReplica, IndexMetaData indexMetaData, RoutingChangesObserver routingChangesObserver) { // if the activeReplica was relocating before this call to failShard, its relocation was cancelled earlier when we // failed initializing replica shards (and moved replica relocation source back to started) assert activeReplica.started() : "replica relocation should have been cancelled: " + activeReplica; ShardRouting primarySwappedCandidate = promoteActiveReplicaShardToPrimary(activeReplica); routingChangesObserver.replicaPromoted(activeReplica); }
static boolean shardCanBeDeleted(String localNodeId, IndexShardRoutingTable indexShardRoutingTable) { // a shard can be deleted if all its copies are active, and its not allocated on this node if (indexShardRoutingTable.size() == 0) { // should not really happen, there should always be at least 1 (primary) shard in a // shard replication group, in any case, protected from deleting something by mistake return false; } for (ShardRouting shardRouting : indexShardRoutingTable) { // be conservative here, check on started, not even active if (shardRouting.started() == false) { return false; } // check if shard is active on the current node if (localNodeId.equals(shardRouting.currentNodeId())) { return false; } } return true; }
if (minShard.started()) { String minNodeId = minShard.currentNodeId(); Optional<ResponseCollectorService.ComputedNodeStats> maybeMinStats = nodeStats.get(minNodeId);
@Override public void startedPrimaryReinitialized(ShardRouting startedPrimaryShard, ShardRouting initializedShard) { assert startedPrimaryShard.primary() && startedPrimaryShard.started() : "expected started primary shard " + startedPrimaryShard; assert initializedShard.primary() && initializedShard.initializing(): "expected initializing primary shard " + initializedShard; setChanged(); }
private void deleteShardIfExistElseWhere(ClusterState state, IndexShardRoutingTable indexShardRoutingTable) { List<Tuple<DiscoveryNode, ShardActiveRequest>> requests = new ArrayList<>(indexShardRoutingTable.size()); String indexUUID = indexShardRoutingTable.shardId().getIndex().getUUID(); ClusterName clusterName = state.getClusterName(); for (ShardRouting shardRouting : indexShardRoutingTable) { assert shardRouting.started() : "expected started shard but was " + shardRouting; DiscoveryNode currentNode = state.nodes().get(shardRouting.currentNodeId()); requests.add(new Tuple<>(currentNode, new ShardActiveRequest(clusterName, indexUUID, shardRouting.shardId(), deleteShardTimeout))); } ShardActiveResponseHandler responseHandler = new ShardActiveResponseHandler(indexShardRoutingTable.shardId(), state.getVersion(), requests.size()); for (Tuple<DiscoveryNode, ShardActiveRequest> request : requests) { logger.trace("{} sending shard active check to {}", request.v2().shardId, request.v1()); transportService.sendRequest(request.v1(), ACTION_SHARD_EXISTS, request.v2(), responseHandler); } }
foundShard = replica; break; } else if (replica.started() && (foundShard.initializing() || foundShard.relocating())) {
if (!shardRouting.started()) { if (explain) { return new RerouteExplanation(this, allocation.decision(Decision.NO, "move_allocation_command",
if (shardRouting.started() == false) {
if (shard.started() == false) {
if (assignedShard.started() || assignedShard.initializing()) {
IndexShardRoutingTable shardRouting = indexShardRoutingTable.shard(shardId.id()); if (shardRouting != null && shardRouting.primaryShard() != null) { if (shardRouting.primaryShard().started()) {
.getTargetRelocatingShard(); } else { assert shardRouting.started(); initializingShard = shardRouting.relocate(currentNodeId, ShardRouting.UNAVAILABLE_EXPECTED_SHARD_SIZE) .getTargetRelocatingShard();
private boolean waitingShardsStartedOrUnassigned(ClusterChangedEvent event) { SnapshotsInProgress curr = event.state().custom(SnapshotsInProgress.TYPE); if (curr != null) { for (SnapshotsInProgress.Entry entry : curr.entries()) { if (entry.state() == State.STARTED && !entry.waitingIndices().isEmpty()) { for (ObjectCursor<String> index : entry.waitingIndices().keys()) { if (event.indexRoutingTableChanged(index.value)) { IndexRoutingTable indexShardRoutingTable = event.state().getRoutingTable().index(index.value); for (ShardId shardId : entry.waitingIndices().get(index.value)) { ShardRouting shardRouting = indexShardRoutingTable.shard(shardId.id()).primaryShard(); if (shardRouting != null && (shardRouting.started() || shardRouting.unassigned())) { return true; } } } } } } } return false; }
final AllocationDeciders deciders = allocation.deciders(); for (ShardRouting shard : index) { if (shard.started()) {
this.shardRouting.started() == false || // note that we use started and not active to avoid relocating shards this.indexShardOperationPermits.isBlocked() || // if permits are blocked, we are still transitioning this.replicationTracker.isPrimaryMode()
} else if (!primary.started()) { builder.put(shardId, new SnapshotsInProgress.ShardSnapshotStatus(primary.currentNodeId(), State.MISSING, "primary shard hasn't been started yet")); } else {