Search in sources :

Example 96 with IndexShard

use of org.elasticsearch.index.shard.IndexShard in project elasticsearch by elastic.

the class SearchService method executeQueryPhase.

public QuerySearchResult executeQueryPhase(QuerySearchRequest request, SearchTask task) {
    final SearchContext context = findContext(request.id());
    context.setTask(task);
    IndexShard indexShard = context.indexShard();
    SearchOperationListener operationListener = indexShard.getSearchOperationListener();
    context.incRef();
    try {
        contextProcessing(context);
        context.searcher().setAggregatedDfs(request.dfs());
        operationListener.onPreQueryPhase(context);
        long time = System.nanoTime();
        queryPhase.execute(context);
        if (context.queryResult().hasHits() == false && context.scrollContext() == null) {
            // no hits, we can release the context since there will be no fetch phase
            freeContext(context.id());
        } else {
            contextProcessedSuccessfully(context);
        }
        operationListener.onQueryPhase(context, System.nanoTime() - time);
        return context.queryResult();
    } catch (Exception e) {
        operationListener.onFailedQueryPhase(context);
        logger.trace("Query phase failed", e);
        processFailure(context, e);
        throw ExceptionsHelper.convertToRuntime(e);
    } finally {
        cleanContext(context);
    }
}
Also used : IndexShard(org.elasticsearch.index.shard.IndexShard) SearchContext(org.elasticsearch.search.internal.SearchContext) SearchOperationListener(org.elasticsearch.index.shard.SearchOperationListener) ElasticsearchException(org.elasticsearch.ElasticsearchException) AggregationInitializationException(org.elasticsearch.search.aggregations.AggregationInitializationException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException)

Example 97 with IndexShard

use of org.elasticsearch.index.shard.IndexShard in project elasticsearch by elastic.

the class TransportUpgradeStatusAction method shardOperation.

@Override
protected ShardUpgradeStatus shardOperation(UpgradeStatusRequest request, ShardRouting shardRouting) {
    IndexService indexService = indicesService.indexServiceSafe(shardRouting.shardId().getIndex());
    IndexShard indexShard = indexService.getShard(shardRouting.shardId().id());
    List<Segment> segments = indexShard.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);
}
Also used : IndexService(org.elasticsearch.index.IndexService) IndexShard(org.elasticsearch.index.shard.IndexShard) Segment(org.elasticsearch.index.engine.Segment)

Example 98 with IndexShard

use of org.elasticsearch.index.shard.IndexShard in project elasticsearch by elastic.

the class TransportUpgradeAction method shardOperation.

@Override
protected ShardUpgradeResult shardOperation(UpgradeRequest request, ShardRouting shardRouting) throws IOException {
    IndexShard indexShard = indicesService.indexServiceSafe(shardRouting.shardId().getIndex()).getShard(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);
}
Also used : IndexShard(org.elasticsearch.index.shard.IndexShard)

Example 99 with IndexShard

use of org.elasticsearch.index.shard.IndexShard in project elasticsearch by elastic.

the class IndicesService method stats.

public NodeIndicesStats stats(boolean includePrevious, CommonStatsFlags flags) {
    CommonStats oldStats = new CommonStats(flags);
    if (includePrevious) {
        Flag[] setFlags = flags.getFlags();
        for (Flag flag : setFlags) {
            switch(flag) {
                case Get:
                    oldStats.get.add(oldShardsStats.getStats);
                    break;
                case Indexing:
                    oldStats.indexing.add(oldShardsStats.indexingStats);
                    break;
                case Search:
                    oldStats.search.add(oldShardsStats.searchStats);
                    break;
                case Merge:
                    oldStats.merge.add(oldShardsStats.mergeStats);
                    break;
                case Refresh:
                    oldStats.refresh.add(oldShardsStats.refreshStats);
                    break;
                case Recovery:
                    oldStats.recoveryStats.add(oldShardsStats.recoveryStats);
                    break;
                case Flush:
                    oldStats.flush.add(oldShardsStats.flushStats);
                    break;
            }
        }
    }
    Map<Index, List<IndexShardStats>> statsByShard = new HashMap<>();
    for (IndexService indexService : this) {
        for (IndexShard indexShard : indexService) {
            try {
                if (indexShard.routingEntry() == null) {
                    continue;
                }
                IndexShardStats indexShardStats = new IndexShardStats(indexShard.shardId(), new ShardStats[] { new ShardStats(indexShard.routingEntry(), indexShard.shardPath(), new CommonStats(indicesQueryCache, indexShard, flags), indexShard.commitStats(), indexShard.seqNoStats()) });
                if (!statsByShard.containsKey(indexService.index())) {
                    statsByShard.put(indexService.index(), arrayAsArrayList(indexShardStats));
                } else {
                    statsByShard.get(indexService.index()).add(indexShardStats);
                }
            } catch (IllegalIndexShardStateException e) {
                // we can safely ignore illegal state on ones that are closing for example
                logger.trace((Supplier<?>) () -> new ParameterizedMessage("{} ignoring shard stats", indexShard.shardId()), e);
            }
        }
    }
    return new NodeIndicesStats(oldStats, statsByShard);
}
Also used : IndexShardStats(org.elasticsearch.action.admin.indices.stats.IndexShardStats) ShardStats(org.elasticsearch.action.admin.indices.stats.ShardStats) HashMap(java.util.HashMap) IndexService(org.elasticsearch.index.IndexService) IndexShard(org.elasticsearch.index.shard.IndexShard) Index(org.elasticsearch.index.Index) IndexShardStats(org.elasticsearch.action.admin.indices.stats.IndexShardStats) IllegalIndexShardStateException(org.elasticsearch.index.shard.IllegalIndexShardStateException) Flag(org.elasticsearch.action.admin.indices.stats.CommonStatsFlags.Flag) CommonStats(org.elasticsearch.action.admin.indices.stats.CommonStats) CollectionUtils.arrayAsArrayList(org.elasticsearch.common.util.CollectionUtils.arrayAsArrayList) ArrayList(java.util.ArrayList) Collections.emptyList(java.util.Collections.emptyList) List(java.util.List) Supplier(java.util.function.Supplier) ParameterizedMessage(org.apache.logging.log4j.message.ParameterizedMessage)

Example 100 with IndexShard

use of org.elasticsearch.index.shard.IndexShard in project elasticsearch by elastic.

the class IndicesService method createShard.

@Override
public IndexShard createShard(ShardRouting shardRouting, RecoveryState recoveryState, PeerRecoveryTargetService recoveryTargetService, PeerRecoveryTargetService.RecoveryListener recoveryListener, RepositoriesService repositoriesService, Callback<IndexShard.ShardFailure> onShardFailure) throws IOException {
    ensureChangesAllowed();
    IndexService indexService = indexService(shardRouting.index());
    IndexShard indexShard = indexService.createShard(shardRouting);
    indexShard.addShardFailureCallback(onShardFailure);
    indexShard.startRecovery(recoveryState, recoveryTargetService, recoveryListener, repositoriesService, (type, mapping) -> {
        assert recoveryState.getRecoverySource().getType() == RecoverySource.Type.LOCAL_SHARDS : "mapping update consumer only required by local shards recovery";
        try {
            client.admin().indices().preparePutMapping().setConcreteIndex(// concrete index - no name clash, it uses uuid
            shardRouting.index()).setType(type).setSource(mapping.source().string(), XContentType.JSON).get();
        } catch (IOException ex) {
            throw new ElasticsearchException("failed to stringify mapping source", ex);
        }
    }, this);
    return indexShard;
}
Also used : IndexService(org.elasticsearch.index.IndexService) IndexShard(org.elasticsearch.index.shard.IndexShard) IOException(java.io.IOException) ElasticsearchException(org.elasticsearch.ElasticsearchException)

Aggregations

IndexShard (org.elasticsearch.index.shard.IndexShard)173 IndexService (org.elasticsearch.index.IndexService)74 ShardId (org.elasticsearch.index.shard.ShardId)49 IndicesService (org.elasticsearch.indices.IndicesService)47 ShardRouting (org.elasticsearch.cluster.routing.ShardRouting)36 Test (org.junit.Test)35 IOException (java.io.IOException)29 Engine (org.elasticsearch.index.engine.Engine)26 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)21 ElasticsearchException (org.elasticsearch.ElasticsearchException)19 CountDownLatch (java.util.concurrent.CountDownLatch)18 DiscoveryNode (org.elasticsearch.cluster.node.DiscoveryNode)18 Settings (org.elasticsearch.common.settings.Settings)18 ArrayList (java.util.ArrayList)16 Translog (org.elasticsearch.index.translog.Translog)16 HashMap (java.util.HashMap)15 Index (org.elasticsearch.index.Index)15 IndexMetaData (org.elasticsearch.cluster.metadata.IndexMetaData)13 PlainActionFuture (org.elasticsearch.action.support.PlainActionFuture)12 List (java.util.List)11