Search in sources :

Example 21 with IndexShard

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

the class IndexingMemoryControllerTests method testActiveInactive.

public void testActiveInactive() {
    createIndex("test", Settings.builder().put("index.number_of_shards", 2).put("index.number_of_replicas", 0).build());
    IndicesService indicesService = getInstanceFromNode(IndicesService.class);
    IndexService test = indicesService.indexService(resolveIndex("test"));
    MockController controller = new MockController(Settings.builder().put("indices.memory.index_buffer_size", "5mb").build());
    IndexShard shard0 = test.getShard(0);
    controller.simulateIndexing(shard0);
    IndexShard shard1 = test.getShard(1);
    controller.simulateIndexing(shard1);
    controller.assertBuffer(shard0, 1);
    controller.assertBuffer(shard1, 1);
    controller.simulateIndexing(shard0);
    controller.simulateIndexing(shard1);
    controller.assertBuffer(shard0, 2);
    controller.assertBuffer(shard1, 2);
    // index into one shard only, crosses the 5mb limit, so shard1 is refreshed
    controller.simulateIndexing(shard0);
    controller.simulateIndexing(shard0);
    controller.assertBuffer(shard0, 0);
    controller.assertBuffer(shard1, 2);
    controller.simulateIndexing(shard1);
    controller.simulateIndexing(shard1);
    controller.assertBuffer(shard1, 4);
    controller.simulateIndexing(shard1);
    controller.simulateIndexing(shard1);
    // shard1 crossed 5 mb and is now cleared:
    controller.assertBuffer(shard1, 0);
}
Also used : IndexService(org.elasticsearch.index.IndexService) IndexShard(org.elasticsearch.index.shard.IndexShard)

Example 22 with IndexShard

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

the class TransportTermVectorsAction method shardOperation.

@Override
protected TermVectorsResponse shardOperation(TermVectorsRequest request, ShardId shardId) {
    IndexService indexService = indicesService.indexServiceSafe(shardId.getIndex());
    IndexShard indexShard = indexService.getShard(shardId.id());
    return TermVectorsService.getTermVectors(indexShard, request);
}
Also used : IndexService(org.elasticsearch.index.IndexService) IndexShard(org.elasticsearch.index.shard.IndexShard)

Example 23 with IndexShard

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

the class SyncedFlushService method performInFlightOps.

private InFlightOpsResponse performInFlightOps(InFlightOpsRequest request) {
    IndexService indexService = indicesService.indexServiceSafe(request.shardId().getIndex());
    IndexShard indexShard = indexService.getShard(request.shardId().id());
    if (indexShard.routingEntry().primary() == false) {
        throw new IllegalStateException("[" + request.shardId() + "] expected a primary shard");
    }
    int opCount = indexShard.getActiveOperationsCount();
    logger.trace("{} in flight operations sampled at [{}]", request.shardId(), opCount);
    return new InFlightOpsResponse(opCount);
}
Also used : IndexService(org.elasticsearch.index.IndexService) IndexShard(org.elasticsearch.index.shard.IndexShard)

Example 24 with IndexShard

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

the class RecoveryTarget method finalizeRecovery.

@Override
public void finalizeRecovery(final long globalCheckpoint) {
    indexShard().updateGlobalCheckpointOnReplica(globalCheckpoint);
    final IndexShard indexShard = indexShard();
    indexShard.finalizeRecovery();
}
Also used : IndexShard(org.elasticsearch.index.shard.IndexShard)

Example 25 with IndexShard

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

the class TransportNodesListShardStoreMetaData method listStoreMetaData.

private StoreFilesMetaData listStoreMetaData(ShardId shardId) throws IOException {
    logger.trace("listing store meta data for {}", shardId);
    long startTimeNS = System.nanoTime();
    boolean exists = false;
    try {
        IndexService indexService = indicesService.indexService(shardId.getIndex());
        if (indexService != null) {
            IndexShard indexShard = indexService.getShardOrNull(shardId.id());
            if (indexShard != null) {
                exists = true;
                return new StoreFilesMetaData(shardId, indexShard.snapshotStoreMetadata());
            }
        }
        // try and see if we an list unallocated
        IndexMetaData metaData = clusterService.state().metaData().index(shardId.getIndex());
        if (metaData == null) {
            // we may send this requests while processing the cluster state that recovered the index
            // sometimes the request comes in before the local node processed that cluster state
            // in such cases we can load it from disk
            metaData = IndexMetaData.FORMAT.loadLatestState(logger, NamedXContentRegistry.EMPTY, nodeEnv.indexPaths(shardId.getIndex()));
        }
        if (metaData == null) {
            logger.trace("{} node doesn't have meta data for the requests index, responding with empty", shardId);
            return new StoreFilesMetaData(shardId, Store.MetadataSnapshot.EMPTY);
        }
        final IndexSettings indexSettings = indexService != null ? indexService.getIndexSettings() : new IndexSettings(metaData, settings);
        final ShardPath shardPath = ShardPath.loadShardPath(logger, nodeEnv, shardId, indexSettings);
        if (shardPath == null) {
            return new StoreFilesMetaData(shardId, Store.MetadataSnapshot.EMPTY);
        }
        //    reuse local resources.
        return new StoreFilesMetaData(shardId, Store.readMetadataSnapshot(shardPath.resolveIndex(), shardId, nodeEnv::shardLock, logger));
    } finally {
        TimeValue took = new TimeValue(System.nanoTime() - startTimeNS, TimeUnit.NANOSECONDS);
        if (exists) {
            logger.debug("{} loaded store meta data (took [{}])", shardId, took);
        } else {
            logger.trace("{} didn't find any store meta data to load (took [{}])", shardId, took);
        }
    }
}
Also used : IndexService(org.elasticsearch.index.IndexService) ShardPath(org.elasticsearch.index.shard.ShardPath) IndexShard(org.elasticsearch.index.shard.IndexShard) IndexSettings(org.elasticsearch.index.IndexSettings) TimeValue(org.elasticsearch.common.unit.TimeValue) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData)

Aggregations

IndexShard (org.elasticsearch.index.shard.IndexShard)94 IndexService (org.elasticsearch.index.IndexService)51 IndicesService (org.elasticsearch.indices.IndicesService)20 ShardRouting (org.elasticsearch.cluster.routing.ShardRouting)19 ShardId (org.elasticsearch.index.shard.ShardId)19 IOException (java.io.IOException)16 Engine (org.elasticsearch.index.engine.Engine)16 ElasticsearchException (org.elasticsearch.ElasticsearchException)13 IndexMetaData (org.elasticsearch.cluster.metadata.IndexMetaData)13 Settings (org.elasticsearch.common.settings.Settings)11 Translog (org.elasticsearch.index.translog.Translog)10 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)9 HashMap (java.util.HashMap)8 IndexRequest (org.elasticsearch.action.index.IndexRequest)8 DiscoveryNode (org.elasticsearch.cluster.node.DiscoveryNode)8 ClusterState (org.elasticsearch.cluster.ClusterState)7 Releasable (org.elasticsearch.common.lease.Releasable)7 ClusterService (org.elasticsearch.cluster.service.ClusterService)6 Path (java.nio.file.Path)5 ArrayList (java.util.ArrayList)5