Package org.elasticsearch.index.shard.service

Examples of org.elasticsearch.index.shard.service.InternalIndexShard


                    }
                }
                continue;
            }

            InternalIndexShard indexShard = (InternalIndexShard) indexService.shard(shardId);
            if (indexShard != null) {
                ShardRouting currentRoutingEntry = indexShard.routingEntry();
                // if the current and global routing are initializing, but are still not the same, its a different "shard" being allocated
                // for example: a shard that recovers from one node and now needs to recover to another node,
                //              or a replica allocated and then allocating a primary because the primary failed on another node
                boolean shardHasBeenRemoved = false;
                if (currentRoutingEntry.initializing() && shardRouting.initializing() && !currentRoutingEntry.equals(shardRouting)) {
                    logger.debug("[{}][{}] removing shard (different instance of it allocated on this node, current [{}], global [{}])", shardRouting.index(), shardRouting.id(), currentRoutingEntry, shardRouting);
                    // closing the shard will also cancel any ongoing recovery.
                    indexService.removeShard(shardRouting.id(), "removing shard (different instance of it allocated on this node)");
                    shardHasBeenRemoved = true;
                } else if (isPeerRecovery(shardRouting)) {
                    // check if there is an existing recovery going, and if so, and the source node is not the same, cancel the recovery to restart it
                    RecoveryState recoveryState = recoveryTarget.recoveryState(indexShard);
                    if (recoveryState != null && recoveryState.getStage() != RecoveryState.Stage.DONE) {
                        // we have an ongoing recovery, find the source based on current routing and compare them
                        DiscoveryNode sourceNode = findSourceNodeForPeerRecovery(routingTable, nodes, shardRouting);
                        if (!recoveryState.getSourceNode().equals(sourceNode)) {
                            logger.debug("[{}][{}] removing shard (recovery source changed), current [{}], global [{}])", shardRouting.index(), shardRouting.id(), currentRoutingEntry, shardRouting);
                            // closing the shard will also cancel any ongoing recovery.
                            indexService.removeShard(shardRouting.id(), "removing shard (recovery source node changed)");
                            shardHasBeenRemoved = true;
                        }
                    }
                }
                if (shardHasBeenRemoved == false && !shardRouting.equals(indexShard.routingEntry())) {
                    // if we happen to remove the shardRouting by id above we don't need to jump in here!
                    indexShard.routingEntry(shardRouting);
                    indexService.shardInjectorSafe(shardId).getInstance(IndexShardGatewayService.class).routingStateChanged();
                }
            }

            if (shardRouting.initializing()) {
View Full Code Here


            }
            try {
                if (logger.isDebugEnabled()) {
                    logger.debug("[{}][{}] creating shard", shardRouting.index(), shardId);
                }
                InternalIndexShard indexShard = (InternalIndexShard) indexService.createShard(shardId);
                indexShard.routingEntry(shardRouting);
                indexShard.engine().addFailedEngineListener(failedEngineHandler);
            } catch (IndexShardAlreadyExistsException e) {
                // ignore this, the method call can happen several times
            } catch (Throwable e) {
                logger.warn("[{}][{}] failed to create shard", e, shardRouting.index(), shardRouting.id());
                try {
                    indexService.removeShard(shardId, "failed to create [" + ExceptionsHelper.detailedMessage(e) + "]");
                } catch (IndexShardMissingException e1) {
                    // ignore
                } catch (Throwable e1) {
                    logger.warn("[{}][{}] failed to remove shard after failed creation", e1, shardRouting.index(), shardRouting.id());
                }
                failedShards.put(shardRouting.shardId(), new FailedShard(shardRouting.version()));
                if (nodes.masterNode() != null) {
                    shardStateAction.shardFailed(shardRouting, indexMetaData.getUUID(), "Failed to create shard, message [" + detailedMessage(e) + "]",
                            nodes.masterNode()
                    );
                } else {
                    logger.debug("can't send shard failed for {} as there is no current master", shardRouting.shardId());
                }
                return;
            }
        }
        final InternalIndexShard indexShard = (InternalIndexShard) indexService.shardSafe(shardId);

        if (indexShard.ignoreRecoveryAttempt()) {
            // we are already recovering (we can get to this state since the cluster event can happen several
            // times while we recover)
            logger.trace("ignoring recovery instruction for shard {} (shard state: [{}])", indexShard.shardId(), indexShard.state());
            return;
        }

        if (isPeerRecovery(shardRouting)) {
            try {

                assert sourceNode != null : "peer recovery started but sourceNode is null";

                // we don't mark this one as relocated at the end.
                // For primaries: requests in any case are routed to both when its relocating and that way we handle
                //    the edge case where its mark as relocated, and we might need to roll it back...
                // For replicas: we are recovering a backup from a primary
                RecoveryState.Type type = shardRouting.primary() ? RecoveryState.Type.RELOCATION : RecoveryState.Type.REPLICA;
                recoveryTarget.startRecovery(indexShard, type, sourceNode, new PeerRecoveryListener(shardRouting, indexService, indexMetaData));
            } catch (Throwable e) {
                indexShard.engine().failEngine("corrupted preexisting index", e);
                handleRecoveryFailure(indexService, indexMetaData, shardRouting, true, e);
            }
        } else {
            // we are the first primary, recover from the gateway
            // if its post api allocation, the index should exists
View Full Code Here

    }

    @Override
    protected ShardReconstructIndexResponse shardOperation(ShardReconstructIndexRequest request) throws ElasticsearchException {
        IndexService indexService = indicesService.indexService(request.index());
        InternalIndexShard indexShard = (InternalIndexShard) indexService.shardSafe(request.shardId());
        Engine.Searcher searcher = indexShard.engine().acquireSearcher("transport_reconstruct");
        IndexReader reader = searcher.reader();
        DocumentReconstructor dr = new DocumentReconstructor(reader);
        try {
            return new ShardReconstructIndexResponse(true, dr.reconstruct(request.shardId()));
        } catch (IOException e) {
View Full Code Here

    @Override
    protected ShardSkywalkerResponse shardOperation(ShardSkywalkerRequest request) throws ElasticsearchException {
        synchronized (mutex) {
            IndexService indexService = indicesService.indexServiceSafe(request.index());
            InternalIndexShard indexShard = (InternalIndexShard) indexService.shardSafe(request.shardId());
            MapperService mapperService = indexService.mapperService();
            Engine.Searcher searcher = indexShard.acquireSearcher("skywalker_action");
            try {
                IndexReader reader = searcher.reader();

                Skywalker skywalker = new Skywalker(reader);

                Map<String, Object> response = new HashMap();

                Directory directory = indexShard.store().directory();
                List indexFiles = new ArrayList();
                for (String f : skywalker.getIndexFiles(directory)) {
                    Map indexFile = new HashMap();
                    indexFile.put("name", f);
                    indexFile.put("function", skywalker.getFileFunction(f));
                    indexFiles.add(indexFile);
                }
                response.put("indexFiles", indexFiles);

                skywalker.getStoreMetadata(response, indexShard.store().getMetadata());

                response.put("indexVersion", skywalker.getVersion());
                response.put("directoryImpl", skywalker.getDirImpl());
                response.put("numDocs", reader.numDocs());
                response.put("maxDoc", reader.maxDoc());
                response.put("hasDeletions", reader.hasDeletions());
                response.put("numDeletedDocs", reader.numDeletedDocs());

                Set<FieldTermCount> ftc = skywalker.getFieldTermCounts();
                response.put("numTerms", skywalker.getNumTerms());

                Map indexFormatInfo = new HashMap();
                FormatDetails details = skywalker.getFormatDetails();
                indexFormatInfo.put("version", details.getVersion());
                indexFormatInfo.put("genericName", details.getGenericName());
                indexFormatInfo.put("capabilities", details.getCapabilities());
                response.put("indexFormat", indexFormatInfo);

                List commits = new ArrayList();
                Iterator<Segment> it = indexShard.engine().segments().iterator();
                while (it.hasNext()) {
                    Segment segment = it.next();
                    Map m = new HashMap();
                    m.put("segment", segment.getName());
                    m.put("count", segment.getNumDocs());
View Full Code Here

TOP

Related Classes of org.elasticsearch.index.shard.service.InternalIndexShard

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.