org.elasticsearch.cluster.routing.ShardRouting Java Examples

The following examples show how to use org.elasticsearch.cluster.routing.ShardRouting. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SysShardsTableInfo.java    From crate with Apache License 2.0 6 votes vote down vote up
/**
 * Retrieves the routing for sys.shards
 * <p>
 * This routing contains ALL shards of ALL indices.
 * Any shards that are not yet assigned to a node will have a NEGATIVE shard id (see {@link UnassignedShard}
 */
public static Routing getRouting(ClusterState clusterState, RoutingProvider routingProvider, SessionContext sessionContext) {
    String[] concreteIndices = Arrays.stream(clusterState.metaData().getConcreteAllOpenIndices())
        .filter(index -> !IndexParts.isDangling(index))
        .toArray(String[]::new);
    User user = sessionContext != null ? sessionContext.user() : null;
    if (user != null) {
        List<String> accessibleTables = new ArrayList<>(concreteIndices.length);
        for (String indexName : concreteIndices) {
            String tableName = RelationName.fqnFromIndexName(indexName);
            if (user.hasAnyPrivilege(Privilege.Clazz.TABLE, tableName)) {
                accessibleTables.add(indexName);
            }
        }
        concreteIndices = accessibleTables.toArray(new String[0]);
    }

    Map<String, Map<String, IntIndexedContainer>> locations = new TreeMap<>();
    GroupShardsIterator<ShardIterator> groupShardsIterator =
        clusterState.getRoutingTable().allAssignedShardsGrouped(concreteIndices, true, true);
    for (final ShardIterator shardIt : groupShardsIterator) {
        final ShardRouting shardRouting = shardIt.nextOrNull();
        processShardRouting(clusterState.getNodes().getLocalNodeId(), locations, shardRouting, shardIt.shardId());
    }
    return new Routing(locations);
}
 
Example #2
Source File: SnapshotInProgressAllocationDecider.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
private Decision canMove(ShardRouting shardRouting, RoutingAllocation allocation) {
    if (!enableRelocation && shardRouting.primary()) {
        // Only primary shards are snapshotted

        SnapshotsInProgress snapshotsInProgress = allocation.routingNodes().custom(SnapshotsInProgress.TYPE);
        if (snapshotsInProgress == null) {
            // Snapshots are not running
            return allocation.decision(Decision.YES, NAME, "no snapshots are currently running");
        }

        for (SnapshotsInProgress.Entry snapshot : snapshotsInProgress.entries()) {
            SnapshotsInProgress.ShardSnapshotStatus shardSnapshotStatus = snapshot.shards().get(shardRouting.shardId());
            if (shardSnapshotStatus != null && !shardSnapshotStatus.state().completed() && shardSnapshotStatus.nodeId() != null && shardSnapshotStatus.nodeId().equals(shardRouting.currentNodeId())) {
                logger.trace("Preventing snapshotted shard [{}] to be moved from node [{}]", shardRouting.shardId(), shardSnapshotStatus.nodeId());
                return allocation.decision(Decision.NO, NAME, "snapshot for shard [%s] is currently running on node [%s]",
                        shardRouting.shardId(), shardSnapshotStatus.nodeId());
            }
        }
    }
    return allocation.decision(Decision.YES, NAME, "shard not primary or relocation disabled");
}
 
Example #3
Source File: PriorityComparator.java    From crate with Apache License 2.0 6 votes vote down vote up
@Override
public final int compare(ShardRouting o1, ShardRouting o2) {
    final String o1Index = o1.getIndexName();
    final String o2Index = o2.getIndexName();
    int cmp = 0;
    if (o1Index.equals(o2Index) == false) {
        final Settings settingsO1 = getIndexSettings(o1.index());
        final Settings settingsO2 = getIndexSettings(o2.index());
        cmp = Long.compare(priority(settingsO2), priority(settingsO1));
        if (cmp == 0) {
            cmp = Long.compare(timeCreated(settingsO2), timeCreated(settingsO1));
            if (cmp == 0) {
                cmp = o2Index.compareTo(o1Index);
            }
        }
    }
    return cmp;
}
 
Example #4
Source File: SameShardAllocationDecider.java    From crate with Apache License 2.0 6 votes vote down vote up
private Decision decideSameNode(ShardRouting shardRouting, RoutingNode node, RoutingAllocation allocation,
                                Iterable<ShardRouting> assignedShards) {
    for (ShardRouting assignedShard : assignedShards) {
        if (node.nodeId().equals(assignedShard.currentNodeId())) {
            if (assignedShard.isSameAllocation(shardRouting)) {
                return allocation.decision(Decision.NO, NAME,
                    "the shard cannot be allocated to the node on which it already exists [%s]",
                    shardRouting.toString());
            } else {
                return allocation.decision(Decision.NO, NAME,
                    "the shard cannot be allocated to the same node on which a copy of the shard already exists [%s]",
                    assignedShard.toString());
            }
        }
    }
    return allocation.decision(Decision.YES, NAME, "the shard does not exist on the same node");
}
 
Example #5
Source File: InternalClusterInfoService.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
static void buildShardLevelInfo(ESLogger logger, ShardStats[] stats, HashMap<String, Long> newShardSizes, HashMap<ShardRouting, String> newShardRoutingToDataPath, ClusterState state) {
    MetaData meta = state.getMetaData();
    for (ShardStats s : stats) {
        IndexMetaData indexMeta = meta.index(s.getShardRouting().index());
        Settings indexSettings = indexMeta == null ? null : indexMeta.getSettings();
        newShardRoutingToDataPath.put(s.getShardRouting(), s.getDataPath());
        long size = s.getStats().getStore().sizeInBytes();
        String sid = ClusterInfo.shardIdentifierFromRouting(s.getShardRouting());
        if (logger.isTraceEnabled()) {
            logger.trace("shard: {} size: {}", sid, size);
        }
        if (indexSettings != null && IndexMetaData.isIndexUsingShadowReplicas(indexSettings)) {
            // Shards on a shared filesystem should be considered of size 0
            if (logger.isTraceEnabled()) {
                logger.trace("shard: {} is using shadow replicas and will be treated as size 0", sid);
            }
            size = 0;
        }
        newShardSizes.put(sid, size);
    }
}
 
Example #6
Source File: AbstractSearchAsyncAction.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
void performFirstPhase(final int shardIndex, final ShardIterator shardIt, final ShardRouting shard) {
    if (shard == null) {
        // no more active shards... (we should not really get here, but just for safety)
        onFirstPhaseResult(shardIndex, null, null, shardIt, new NoShardAvailableActionException(shardIt.shardId()));
    } else {
        final DiscoveryNode node = nodes.get(shard.currentNodeId());
        if (node == null) {
            onFirstPhaseResult(shardIndex, shard, null, shardIt, new NoShardAvailableActionException(shardIt.shardId()));
        } else {
            String[] filteringAliases = indexNameExpressionResolver.filteringAliases(clusterState, shard.index(), request.indices());
            sendExecuteFirstPhase(node, internalSearchRequest(shard, shardsIts.size(), request, filteringAliases, startTime()), new ActionListener<FirstResult>() {
                @Override
                public void onResponse(FirstResult result) {
                    onFirstPhaseResult(shardIndex, shard, result, shardIt);
                }

                @Override
                public void onFailure(Throwable t) {
                    onFirstPhaseResult(shardIndex, shard, node.id(), shardIt, t);
                }
            });
        }
    }
}
 
Example #7
Source File: TransportUpgradeStatusAction.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
@Override
protected ShardUpgradeStatus shardOperation(UpgradeStatusRequest request, ShardRouting shardRouting) {
    IndexService indexService = indicesService.indexServiceSafe(shardRouting.shardId().getIndex());
    IndexShard indexShard = indexService.shardSafe(shardRouting.shardId().id());
    List<Segment> segments = indexShard.engine().segments(false);
    long total_bytes = 0;
    long to_upgrade_bytes = 0;
    long to_upgrade_bytes_ancient = 0;
    for (Segment seg : segments) {
        total_bytes += seg.sizeInBytes;
        if (seg.version.major != Version.CURRENT.luceneVersion.major) {
            to_upgrade_bytes_ancient += seg.sizeInBytes;
            to_upgrade_bytes += seg.sizeInBytes;
        } else if (seg.version.minor != Version.CURRENT.luceneVersion.minor) {
            // TODO: this comparison is bogus! it would cause us to upgrade even with the same format
            // instead, we should check if the codec has changed
            to_upgrade_bytes += seg.sizeInBytes;
        }
    }

    return new ShardUpgradeStatus(indexShard.routingEntry(), total_bytes, to_upgrade_bytes, to_upgrade_bytes_ancient);
}
 
Example #8
Source File: BalancedShardsAllocator.java    From crate with Apache License 2.0 6 votes vote down vote up
/**
 * Move started shards that can not be allocated to a node anymore
 *
 * For each shard to be moved this function executes a move operation
 * to the minimal eligible node with respect to the
 * weight function. If a shard is moved the shard will be set to
 * {@link ShardRoutingState#RELOCATING} and a shadow instance of this
 * shard is created with an incremented version in the state
 * {@link ShardRoutingState#INITIALIZING}.
 */
public void moveShards() {
    // Iterate over the started shards interleaving between nodes, and check if they can remain. In the presence of throttling
    // shard movements, the goal of this iteration order is to achieve a fairer movement of shards from the nodes that are
    // offloading the shards.
    for (Iterator<ShardRouting> it = allocation.routingNodes().nodeInterleavedShardIterator(); it.hasNext(); ) {
        ShardRouting shardRouting = it.next();
        final MoveDecision moveDecision = decideMove(shardRouting);
        if (moveDecision.isDecisionTaken() && moveDecision.forceMove()) {
            final ModelNode sourceNode = nodes.get(shardRouting.currentNodeId());
            final ModelNode targetNode = nodes.get(moveDecision.getTargetNode().getId());
            sourceNode.removeShard(shardRouting);
            Tuple<ShardRouting, ShardRouting> relocatingShards = routingNodes.relocateShard(shardRouting, targetNode.getNodeId(),
                allocation.clusterInfo().getShardSize(shardRouting, ShardRouting.UNAVAILABLE_EXPECTED_SHARD_SIZE), allocation.changes());
            targetNode.addShard(relocatingShards.v2());
            if (logger.isTraceEnabled()) {
                logger.trace("Moved shard [{}] to node [{}]", shardRouting, targetNode.getRoutingNode());
            }
        } else if (moveDecision.isDecisionTaken() && moveDecision.canRemain() == false) {
            logger.trace("[{}][{}] can't move", shardRouting.index(), shardRouting.id());
        }
    }
}
 
Example #9
Source File: ReplicationOperationTests.java    From crate with Apache License 2.0 6 votes vote down vote up
private void addTrackingInfo(IndexShardRoutingTable indexShardRoutingTable, ShardRouting primaryShard, Set<String> trackedShards,
                             Set<String> untrackedShards) {
    for (ShardRouting shr : indexShardRoutingTable.shards()) {
        if (shr.unassigned() == false) {
            if (shr.initializing()) {
                if (randomBoolean()) {
                    trackedShards.add(shr.allocationId().getId());
                } else {
                    untrackedShards.add(shr.allocationId().getId());
                }
            } else {
                trackedShards.add(shr.allocationId().getId());
                if (shr.relocating()) {
                    if (primaryShard == shr.getTargetRelocatingShard() || randomBoolean()) {
                        trackedShards.add(shr.getTargetRelocatingShard().allocationId().getId());
                    } else {
                        untrackedShards.add(shr.getTargetRelocatingShard().allocationId().getId());
                    }
                }
            }
        }
    }
}
 
Example #10
Source File: IndicesClusterStateService.java    From crate with Apache License 2.0 6 votes vote down vote up
private void createShard(DiscoveryNodes nodes, RoutingTable routingTable, ShardRouting shardRouting, ClusterState state) {
    assert shardRouting.initializing() : "only allow shard creation for initializing shard but was " + shardRouting;

    DiscoveryNode sourceNode = null;
    if (shardRouting.recoverySource().getType() == Type.PEER) {
        sourceNode = findSourceNodeForPeerRecovery(LOGGER, routingTable, nodes, shardRouting);
        if (sourceNode == null) {
            LOGGER.trace("ignoring initializing shard {} - no source node can be found.", shardRouting.shardId());
            return;
        }
    }

    try {
        LOGGER.debug("{} creating shard", shardRouting.shardId());
        RecoveryState recoveryState = new RecoveryState(shardRouting, nodes.getLocalNode(), sourceNode);
        indicesService.createShard(shardRouting, recoveryState, recoveryTargetService, new RecoveryListener(shardRouting),
            repositoriesService, failedShardHandler, globalCheckpointSyncer);
    } catch (Exception e) {
        failAndRemoveShard(shardRouting, true, "failed to create shard", e, state);
    }
}
 
Example #11
Source File: TransportBroadcastByNodeAction.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
private void sendNodeRequest(final DiscoveryNode node, List<ShardRouting> shards, final int nodeIndex) {
    try {
        NodeRequest nodeRequest = new NodeRequest(node.getId(), request, shards);
        if (task != null) {
            nodeRequest.setParentTask(clusterService.localNode().id(), task.getId());
            taskManager.registerChildTask(task, node.getId());
        }
        transportService.sendRequest(node, transportNodeBroadcastAction, nodeRequest, new BaseTransportResponseHandler<NodeResponse>() {
            @Override
            public NodeResponse newInstance() {
                return new NodeResponse();
            }

            @Override
            public void handleResponse(NodeResponse response) {
                onNodeResponse(node, nodeIndex, response);
            }

            @Override
            public void handleException(TransportException exp) {
                onNodeFailure(node, nodeIndex, exp);
            }

            @Override
            public String executor() {
                return ThreadPool.Names.SAME;
            }
        });
    } catch (Throwable e) {
        onNodeFailure(node, nodeIndex, e);
    }
}
 
Example #12
Source File: IndexShardStatsResponse.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
public ImmutableMap<ShardRouting, ShardStats> asMap() {
    if (shardStatsMap == null) {
        ImmutableMap.Builder<ShardRouting, ShardStats> mb = ImmutableMap.builder();
        for (ShardStats ss : shards) {
            mb.put(ss.getShardRouting(), ss);
        }

        shardStatsMap = mb.build();
    }
    return shardStatsMap;
}
 
Example #13
Source File: AbstractSearchAsyncAction.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
private String executionFailureMsg(@Nullable ShardRouting shard, final ShardIterator shardIt, SearchRequest request, boolean lastShard) {
    if (shard != null) {
        return shard.shortSummary() + ": Failed to execute [" + request + "] lastShard [" + lastShard + "]";
    } else {
        return shardIt.shardId() + ": Failed to execute [" + request + "] lastShard [" + lastShard + "]";
    }
}
 
Example #14
Source File: DiskThresholdDeciderUnitTests.java    From crate with Apache License 2.0 5 votes vote down vote up
private long getExpectedShardSize(ShardRouting shardRouting, long defaultSize, RoutingAllocation allocation) {
    return DiskThresholdDecider.getExpectedShardSize(
        shardRouting,
        defaultSize,
        allocation.clusterInfo(),
        allocation.metaData(),
        allocation.routingTable()
    );
}
 
Example #15
Source File: ShardStateAction.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
ShardRoutingEntry(ShardRouting shardRouting, String indexUUID, String message, String finderNodeId, @Nullable Throwable failure) {
    this.shardRouting = shardRouting;
    this.indexUUID = indexUUID;
    this.message = message;
    this.finderNodeId = finderNodeId;
    this.failure = failure;
}
 
Example #16
Source File: TransportBroadcastByNodeAction.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Override
public void readFrom(StreamInput in) throws IOException {
    super.readFrom(in);
    indicesLevelRequest = readRequestFrom(in);
    int size = in.readVInt();
    shards = new ArrayList<>(size);
    for (int i = 0; i < size; i++) {
        shards.add(ShardRouting.readShardRoutingEntry(in));
    }
    nodeId = in.readString();
}
 
Example #17
Source File: ShardsSyncedFlushResult.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Override
public void readFrom(StreamInput in) throws IOException {
    failureReason = in.readOptionalString();
    int numResponses = in.readInt();
    shardResponses = new HashMap<>();
    for (int i = 0; i < numResponses; i++) {
        ShardRouting shardRouting = ShardRouting.readShardRoutingEntry(in);
        SyncedFlushService.ShardSyncedFlushResponse response = SyncedFlushService.ShardSyncedFlushResponse.readSyncedFlushResponse(in);
        shardResponses.put(shardRouting, response);
    }
    syncId = in.readOptionalString();
    shardId = ShardId.readShardId(in);
    totalShards = in.readInt();
}
 
Example #18
Source File: TransportUpgradeAction.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Override
protected ShardUpgradeResult shardOperation(UpgradeRequest request, ShardRouting shardRouting) throws IOException {
    IndexShard indexShard = indicesService.indexServiceSafe(shardRouting.shardId().getIndex()).shardSafe(shardRouting.shardId().id());
    org.apache.lucene.util.Version oldestLuceneSegment = indexShard.upgrade(request);
    // We are using the current version of Elasticsearch as upgrade version since we update mapping to match the current version
    return new ShardUpgradeResult(shardRouting.shardId(), indexShard.routingEntry().primary(), Version.CURRENT, oldestLuceneSegment);
}
 
Example #19
Source File: PrimaryShardAllocator.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
private boolean isEnoughAllocationsFound(ShardRouting shard, IndexMetaData indexMetaData, NodesAndVersions nodesAndVersions) {
    // check if the counts meets the minimum set
    int requiredAllocation = 1;
    // if we restore from a repository one copy is more then enough
    if (shard.restoreSource() == null) {
        try {
            String initialShards = indexMetaData.getSettings().get(INDEX_RECOVERY_INITIAL_SHARDS, settings.get(INDEX_RECOVERY_INITIAL_SHARDS, this.initialShards));
            if ("quorum".equals(initialShards)) {
                if (indexMetaData.getNumberOfReplicas() > 1) {
                    requiredAllocation = ((1 + indexMetaData.getNumberOfReplicas()) / 2) + 1;
                }
            } else if ("quorum-1".equals(initialShards) || "half".equals(initialShards)) {
                if (indexMetaData.getNumberOfReplicas() > 2) {
                    requiredAllocation = ((1 + indexMetaData.getNumberOfReplicas()) / 2);
                }
            } else if ("one".equals(initialShards)) {
                requiredAllocation = 1;
            } else if ("full".equals(initialShards) || "all".equals(initialShards)) {
                requiredAllocation = indexMetaData.getNumberOfReplicas() + 1;
            } else if ("full-1".equals(initialShards) || "all-1".equals(initialShards)) {
                if (indexMetaData.getNumberOfReplicas() > 1) {
                    requiredAllocation = indexMetaData.getNumberOfReplicas();
                }
            } else {
                requiredAllocation = Integer.parseInt(initialShards);
            }
        } catch (Exception e) {
            logger.warn("[{}][{}] failed to derived initial_shards from value {}, ignore allocation for {}", shard.index(), shard.id(), initialShards, shard);
        }
    }

    return nodesAndVersions.allocationsFound >= requiredAllocation;
}
 
Example #20
Source File: ShardsSyncedFlushResult.java    From crate with Apache License 2.0 5 votes vote down vote up
public ShardsSyncedFlushResult(StreamInput in) throws IOException {
    failureReason = in.readOptionalString();
    int numResponses = in.readInt();
    shardResponses = new HashMap<>();
    for (int i = 0; i < numResponses; i++) {
        ShardRouting shardRouting = new ShardRouting(in);
        SyncedFlushService.ShardSyncedFlushResponse response = new SyncedFlushService.ShardSyncedFlushResponse(in);
        shardResponses.put(shardRouting, response);
    }
    syncId = in.readOptionalString();
    shardId = new ShardId(in);
    totalShards = in.readInt();
}
 
Example #21
Source File: IndexShardTestCase.java    From crate with Apache License 2.0 5 votes vote down vote up
/**
 * Takes an existing shard, closes it and starts a new initialing shard at the same location
 *
 * @param routing   the shard routing to use for the newly created shard.
 * @param listeners new listerns to use for the newly created shard
 */
protected IndexShard reinitShard(IndexShard current, ShardRouting routing, IndexingOperationListener... listeners) throws IOException {
    closeShards(current);
    return newShard(
            routing,
            current.shardPath(),
            current.indexSettings().getIndexMetaData(),
            null,
            null,
            current.engineFactory,
            current.getGlobalCheckpointSyncer(),
        EMPTY_EVENT_LISTENER, listeners);
}
 
Example #22
Source File: RemoteCollectorFactory.java    From crate with Apache License 2.0 5 votes vote down vote up
private CompletableFuture<List<Row>> retrieveRows(ShardRouting activePrimaryRouting,
                                                  RoutedCollectPhase collectPhase,
                                                  CollectTask collectTask,
                                                  ShardCollectorProviderFactory shardCollectorProviderFactory) {
    Collector<Row, ?, List<Object[]>> listCollector = Collectors.mapping(Row::materialize, Collectors.toList());
    CollectingRowConsumer<?, List<Object[]>> consumer = new CollectingRowConsumer<>(listCollector);
    String nodeId = activePrimaryRouting.currentNodeId();
    String localNodeId = clusterService.localNode().getId();
    if (localNodeId.equalsIgnoreCase(nodeId)) {
        var indexShard = indicesService.indexServiceSafe(activePrimaryRouting.index())
            .getShard(activePrimaryRouting.shardId().id());
        var collectorProvider = shardCollectorProviderFactory.create(indexShard);
        BatchIterator<Row> it;
        try {
            it = collectorProvider.getIterator(collectPhase, consumer.requiresScroll(), collectTask);
        } catch (Exception e) {
            return Exceptions.rethrowRuntimeException(e);
        }
        consumer.accept(it, null);
    } else {
        UUID childJobId = UUID.randomUUID();
        RemoteCollector remoteCollector = new RemoteCollector(
            childJobId,
            collectTask.txnCtx().sessionSettings(),
            localNodeId,
            nodeId,
            transportActionProvider.transportJobInitAction(),
            transportActionProvider.transportKillJobsNodeAction(),
            searchTp,
            tasksService,
            collectTask.getRamAccounting(),
            consumer,
            createRemoteCollectPhase(childJobId, collectPhase, activePrimaryRouting.shardId(), nodeId)
        );
        remoteCollector.doCollect();
    }
    return consumer
        .completionFuture()
        .thenApply(rows -> LazyMapList.of(rows, Buckets.arrayToSharedRow()));
}
 
Example #23
Source File: BalancedShardsAllocator.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
public int highestPrimary() {
    if (highestPrimary == -1) {
        int maxId = -1;
        for (ShardRouting shard : shards.keySet()) {
            if (shard.primary()) {
                maxId = Math.max(maxId, shard.id());
            }
        }
        return highestPrimary = maxId;
    }
    return highestPrimary;
}
 
Example #24
Source File: TransportReplicationAction.java    From crate with Apache License 2.0 5 votes vote down vote up
private boolean retryIfUnavailable(ClusterState state, ShardRouting primary) {
    if (primary == null || primary.active() == false) {
        logger.trace("primary shard [{}] is not yet active, scheduling a retry: action [{}], request [{}], "
            + "cluster state version [{}]", request.shardId(), actionName, request, state.version());
        retryBecauseUnavailable(request.shardId(), "primary shard is not active");
        return true;
    }
    if (state.nodes().nodeExists(primary.currentNodeId()) == false) {
        logger.trace("primary shard [{}] is assigned to an unknown node [{}], scheduling a retry: action [{}], request [{}], "
            + "cluster state version [{}]", request.shardId(), primary.currentNodeId(), actionName, request, state.version());
        retryBecauseUnavailable(request.shardId(), "primary shard isn't assigned to a known node.");
        return true;
    }
    return false;
}
 
Example #25
Source File: ShardStats.java    From crate with Apache License 2.0 5 votes vote down vote up
public ShardStats(ShardRouting routing, ShardPath shardPath, CommonStats commonStats, CommitStats commitStats, SeqNoStats seqNoStats) {
    this.shardRouting = routing;
    this.dataPath = shardPath.getRootDataPath().toString();
    this.statePath = shardPath.getRootStatePath().toString();
    this.isCustomDataPath = shardPath.isCustomDataPath();
    this.commitStats = commitStats;
    this.commonStats = commonStats;
    this.seqNoStats = seqNoStats;
}
 
Example #26
Source File: ShardStats.java    From crate with Apache License 2.0 5 votes vote down vote up
public ShardStats(StreamInput in) throws IOException {
    shardRouting = new ShardRouting(in);
    commonStats = new CommonStats(in);
    commitStats = in.readOptionalWriteable(CommitStats::new);
    statePath = in.readString();
    dataPath = in.readString();
    isCustomDataPath = in.readBoolean();
    seqNoStats = in.readOptionalWriteable(SeqNoStats::new);
}
 
Example #27
Source File: AllocationDeciders.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Override
public Decision canRemain(ShardRouting shardRouting, RoutingNode node, RoutingAllocation allocation) {
    if (allocation.shouldIgnoreShardForNode(shardRouting.shardId(), node.nodeId())) {
        if (logger.isTraceEnabled()) {
            logger.trace("Shard [{}] should be ignored for node [{}]", shardRouting, node.nodeId());
        }
        return Decision.NO;
    }
    Decision.Multi ret = new Decision.Multi();
    for (AllocationDecider allocationDecider : allocations) {
        Decision decision = allocationDecider.canRemain(shardRouting, node, allocation);
        // short track if a NO is returned.
        if (decision == Decision.NO) {
            if (logger.isTraceEnabled()) {
                logger.trace("Shard [{}] can not remain on node [{}] due to [{}]", shardRouting, node.nodeId(), allocationDecider.getClass().getSimpleName());
            }
            if (!allocation.debugDecision()) {
                return decision;
            } else {
                ret.add(decision);
            }
        } else if (decision != Decision.ALWAYS) {
            ret.add(decision);
        }
    }
    return ret;
}
 
Example #28
Source File: AllocationDeciders.java    From crate with Apache License 2.0 5 votes vote down vote up
@Override
public Decision canAllocate(ShardRouting shardRouting, RoutingNode node, RoutingAllocation allocation) {
    if (allocation.shouldIgnoreShardForNode(shardRouting.shardId(), node.nodeId())) {
        return Decision.NO;
    }
    Decision.Multi ret = new Decision.Multi();
    for (AllocationDecider allocationDecider : allocations) {
        Decision decision = allocationDecider.canAllocate(shardRouting, node, allocation);
        // short track if a NO is returned.
        if (decision == Decision.NO) {
            if (LOGGER.isTraceEnabled()) {
                LOGGER.trace("Can not allocate [{}] on node [{}] due to [{}]", shardRouting, node.node(), allocationDecider.getClass().getSimpleName());
            }
            // short circuit only if debugging is not enabled
            if (!allocation.debugDecision()) {
                return decision;
            } else {
                ret.add(decision);
            }
        } else if (decision != Decision.ALWAYS
                    && (allocation.getDebugMode() != EXCLUDE_YES_DECISIONS || decision.type() != Decision.Type.YES)) {
            // the assumption is that a decider that returns the static instance Decision#ALWAYS
            // does not really implements canAllocate
            ret.add(decision);
        }
    }
    return ret;
}
 
Example #29
Source File: ClusterSearchShardsGroup.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Override
public void writeTo(StreamOutput out) throws IOException {
    out.writeString(index);
    out.writeVInt(shardId);
    out.writeVInt(shards.length);
    for (ShardRouting shardRouting : shards) {
        shardRouting.writeToThin(out);
    }
}
 
Example #30
Source File: RebalanceOnlyWhenActiveAllocationDecider.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Override
public Decision canRebalance(ShardRouting shardRouting, RoutingAllocation allocation) {
    // its ok to check for active here, since in relocation, a shard is split into two in routing
    // nodes, once relocating, and one initializing
    if (!allocation.routingNodes().allReplicasActive(shardRouting)) {
        return allocation.decision(Decision.NO, NAME, "not all replicas are active in cluster");
    }
    return allocation.decision(Decision.YES, NAME, "all replicas are active in cluster");
}