Package org.elasticsearch.cluster.routing

Examples of org.elasticsearch.cluster.routing.ShardRouting


        // the index operations will not be routed to it properly
        RoutingNode node = clusterService.state().readOnlyRoutingNodes().node(request.targetNode().id());
        if (node == null) {
            throw new DelayRecoveryException("source node does not have the node [" + request.targetNode() + "] in its state yet..");
        }
        ShardRouting targetShardRouting = null;
        for (ShardRouting shardRouting : node) {
            if (shardRouting.shardId().equals(request.shardId())) {
                targetShardRouting = shardRouting;
                break;
            }
        }
        if (targetShardRouting == null) {
            throw new DelayRecoveryException("source node does not have the shard listed in its state as allocated on the node");
        }
        if (!targetShardRouting.initializing()) {
            throw new DelayRecoveryException("source node has the state of the target shard to be [" + targetShardRouting.state() + "], expecting to be [initializing]");
        }

        logger.trace("[{}][{}] starting recovery to {}, mark_as_relocated {}", request.shardId().index().name(), request.shardId().id(), request.targetNode(), request.markAsRelocated());
        final RecoveryResponse response = new RecoveryResponse();
View Full Code Here


            DocsStats docsStats = mock(DocsStats.class);
            when(indexShard.docStats()).thenReturn(docsStats).thenThrow(IllegalIndexShardStateException.class);
            when(docsStats.getCount()).thenReturn(654321L);

            ShardRouting shardRouting = mock(ShardRouting.class);
            when(indexShard.routingEntry()).thenReturn(shardRouting);
            when(shardRouting.primary()).thenReturn(true);
            when(shardRouting.relocatingNodeId()).thenReturn("node_X");

            TransportPutIndexTemplateAction transportPutIndexTemplateAction = mock(TransportPutIndexTemplateAction.class);
            bind(TransportPutIndexTemplateAction.class).toInstance(transportPutIndexTemplateAction);

            when(indexShard.state()).thenReturn(IndexShardState.STARTED);
View Full Code Here

     */
    public String getRedirectAddress(String index, String digest) throws MissingHTTPEndpointException {
        ShardIterator shards = clusterService.operationRouting().getShards(
                clusterService.state(), index, null, null, digest, "_local");

        ShardRouting shard;
        Set<String> nodeIds = new HashSet<>();

        // check if one of the shards is on the current node;
        while ((shard = shards.nextOrNull()) != null) {
            if (!shard.active()) {
                continue;
            }
            if (shard.currentNodeId().equals(clusterService.localNode().getId())) {
                return null;
            }
            nodeIds.add(shard.currentNodeId());
        }

        DiscoveryNode node;
        DiscoveryNodes nodes = clusterService.state().getNodes();
        for (String nodeId : nodeIds) {
View Full Code Here

        ClusterState clusterState = clusterService.state();
        String[] concreteIndices = clusterState.metaData().concreteIndices(request.indicesOptions(), request.indices());
        Map<String, Set<String>> routingMap = clusterState.metaData().resolveSearchRouting(request.routing(), request.indices());
        Set<String> nodeIds = newHashSet();
        GroupShardsIterator groupShardsIterator = clusterService.operationRouting().searchShards(clusterState, request.indices(), concreteIndices, routingMap, request.preference());
        ShardRouting shard;
        ClusterSearchShardsGroup[] groupResponses = new ClusterSearchShardsGroup[groupShardsIterator.size()];
        int currentGroup = 0;
        for (ShardIterator shardIt : groupShardsIterator) {
            String index = shardIt.shardId().getIndex();
            int shardId = shardIt.shardId().getId();
            ShardRouting[] shardRoutings = new ShardRouting[shardIt.size()];
            int currentShard = 0;
            shardIt.reset();
            while ((shard = shardIt.nextOrNull()) != null) {
                shardRoutings[currentShard++] = shard;
                nodeIds.add(shard.currentNodeId());
            }
            groupResponses[currentGroup++] = new ClusterSearchShardsGroup(index, shardId, shardRoutings);
        }
        DiscoveryNode[] nodes = new DiscoveryNode[nodeIds.size()];
        int currentNode = 0;
View Full Code Here

    private RoutingNode[] sortedNodesLeastToHigh(RoutingAllocation allocation) {
        // create count per node id, taking into account relocations
        final ObjectIntOpenHashMap<String> nodeCounts = new ObjectIntOpenHashMap<>();
        for (RoutingNode node : allocation.routingNodes()) {
            for (int i = 0; i < node.size(); i++) {
                ShardRouting shardRouting = node.get(i);
                String nodeId = shardRouting.relocating() ? shardRouting.relocatingNodeId() : shardRouting.currentNodeId();
                nodeCounts.addTo(nodeId, 1);
            }
        }
        RoutingNode[] nodes = allocation.routingNodes().toArray();
        Arrays.sort(nodes, new Comparator<RoutingNode>() {
View Full Code Here

                List<ShardRouting> shardRoutingsToBeApplied = new ArrayList<>(shardRoutingEntries.size());
                for (int i = 0; i < shardRoutingEntries.size(); i++) {
                    ShardRoutingEntry shardRoutingEntry = shardRoutingEntries.get(i);
                    shardRoutingEntry.processed = true;
                    ShardRouting shardRouting = shardRoutingEntry.shardRouting;
                    IndexMetaData indexMetaData = metaData.index(shardRouting.index());
                    // if there is no metadata or the current index is not of the right uuid, the index has been deleted while it was being allocated
                    // which is fine, we should just ignore this
                    if (indexMetaData == null) {
                        continue;
                    }
                    if (!indexMetaData.isSameUUID(shardRoutingEntry.indexUUID)) {
                        logger.debug("{} ignoring shard failed, different index uuid, current {}, got {}", shardRouting.shardId(), indexMetaData.getUUID(), shardRoutingEntry);
                        continue;
                    }

                    logger.debug("{} will apply shard failed {}", shardRouting.shardId(), shardRoutingEntry);
                    shardRoutingsToBeApplied.add(shardRouting);
                }

                RoutingAllocation.Result routingResult = allocationService.applyFailedShards(currentState, shardRoutingsToBeApplied);
                if (!routingResult.changed()) {
View Full Code Here

                        List<ShardRouting> shardRoutingToBeApplied = new ArrayList<>(shardRoutingEntries.size());

                        for (int i = 0; i < shardRoutingEntries.size(); i++) {
                            ShardRoutingEntry shardRoutingEntry = shardRoutingEntries.get(i);
                            shardRoutingEntry.processed = true;
                            ShardRouting shardRouting = shardRoutingEntry.shardRouting;
                            try {
                                IndexMetaData indexMetaData = metaData.index(shardRouting.index());
                                IndexRoutingTable indexRoutingTable = routingTable.index(shardRouting.index());
                                // if there is no metadata, no routing table or the current index is not of the right uuid, the index has been deleted while it was being allocated
                                // which is fine, we should just ignore this
                                if (indexMetaData == null) {
                                    continue;
                                }
                                if (indexRoutingTable == null) {
                                    continue;
                                }

                                if (!indexMetaData.isSameUUID(shardRoutingEntry.indexUUID)) {
                                    logger.debug("{} ignoring shard started, different index uuid, current {}, got {}", shardRouting.shardId(), indexMetaData.getUUID(), shardRoutingEntry);
                                    continue;
                                }

                                // find the one that maps to us, if its already started, no need to do anything...
                                // the shard might already be started since the nodes that is starting the shards might get cluster events
                                // with the shard still initializing, and it will try and start it again (until the verification comes)

                                IndexShardRoutingTable indexShardRoutingTable = indexRoutingTable.shard(shardRouting.id());

                                boolean applyShardEvent = true;

                                for (ShardRouting entry : indexShardRoutingTable) {
                                    if (shardRouting.currentNodeId().equals(entry.currentNodeId())) {
                                        // we found the same shard that exists on the same node id
                                        if (!entry.initializing()) {
                                            // shard is in initialized state, skipping event (probable already started)
                                            logger.debug("{} ignoring shard started event for {}, current state: {}", shardRouting.shardId(), shardRoutingEntry, entry.state());
                                            applyShardEvent = false;
                                        }
                                    }
                                }

                                if (applyShardEvent) {
                                    shardRoutingToBeApplied.add(shardRouting);
                                    logger.debug("{} will apply shard started {}", shardRouting.shardId(), shardRoutingEntry);
                                }

                            } catch (Throwable t) {
                                logger.error("{} unexpected failure while processing shard started [{}]", t, shardRouting.shardId(), shardRouting);
                            }
                        }

                        if (shardRoutingToBeApplied.isEmpty()) {
                            return currentState;
View Full Code Here

                if (entry.state() == State.STARTED && !entry.waitingIndices().isEmpty()) {
                    for (String index : entry.waitingIndices().keySet()) {
                        if (event.indexRoutingTableChanged(index)) {
                            IndexRoutingTable indexShardRoutingTable = event.state().getRoutingTable().index(index);
                            for (ShardId shardId : entry.waitingIndices().get(index)) {
                                ShardRouting shardRouting = indexShardRoutingTable.shard(shardId.id()).primaryShard();
                                if (shardRouting != null && (shardRouting.started() || shardRouting.unassigned())) {
                                    return true;
                                }
                            }
                        }
                    }
View Full Code Here

            IndexMetaData indexMetaData = metaData.index(index);
            IndexRoutingTable indexRoutingTable = clusterState.getRoutingTable().index(index);
            for (int i = 0; i < indexMetaData.numberOfShards(); i++) {
                ShardId shardId = new ShardId(index, i);
                if (indexRoutingTable != null) {
                    ShardRouting primary = indexRoutingTable.shard(i).primaryShard();
                    if (primary == null || !primary.assignedToNode()) {
                        builder.put(shardId, new SnapshotMetaData.ShardSnapshotStatus(null, State.MISSING, "primary shard is not allocated"));
                    } else if (clusterState.getNodes().smallestVersion().onOrAfter(Version.V_1_2_0) && (primary.relocating() || primary.initializing())) {
                        // The WAITING state was introduced in V1.2.0 - don't use it if there are nodes with older version in the cluster
                        builder.put(shardId, new SnapshotMetaData.ShardSnapshotStatus(primary.currentNodeId(), State.WAITING));
                    } else if (!primary.started()) {
                        builder.put(shardId, new SnapshotMetaData.ShardSnapshotStatus(primary.currentNodeId(), State.MISSING, "primary shard hasn't been started yet"));
                    } else {
                        builder.put(shardId, new SnapshotMetaData.ShardSnapshotStatus(primary.currentNodeId()));
                    }
                } else {
                    builder.put(shardId, new SnapshotMetaData.ShardSnapshotStatus(null, State.MISSING, "missing routing table"));
                }
            }
View Full Code Here

            }
            request.beforeStart();
            int shardIndex = -1;
            for (final ShardIterator shardIt : shardsIts) {
                shardIndex++;
                final ShardRouting shard = shardIt.nextOrNull();
                if (shard != null) {
                    performFirstPhase(shardIndex, shardIt, shard);
                } else {
                    // really, no shards active in this group
                    onFirstPhaseResult(shardIndex, null, null, shardIt, new NoShardAvailableActionException(shardIt.shardId()));
View Full Code Here

TOP

Related Classes of org.elasticsearch.cluster.routing.ShardRouting

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.