Search in sources :

Example 36 with IndexShard

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

the class TransportClusterStatsAction method nodeOperation.

@Override
protected ClusterStatsNodeResponse nodeOperation(ClusterStatsNodeRequest nodeRequest) {
    NodeInfo nodeInfo = nodeService.info(true, true, false, true, false, true, false, true, false, false);
    NodeStats nodeStats = nodeService.stats(CommonStatsFlags.NONE, true, true, true, false, true, false, false, false, false, false, false);
    List<ShardStats> shardsStats = new ArrayList<>();
    for (IndexService indexService : indicesService) {
        for (IndexShard indexShard : indexService) {
            if (indexShard.routingEntry() != null && indexShard.routingEntry().active()) {
                // only report on fully started shards
                shardsStats.add(new ShardStats(indexShard.routingEntry(), indexShard.shardPath(), new CommonStats(indicesService.getIndicesQueryCache(), indexShard, SHARD_STATS_FLAGS), indexShard.commitStats(), indexShard.seqNoStats()));
            }
        }
    }
    ClusterHealthStatus clusterStatus = null;
    if (clusterService.state().nodes().isLocalNodeElectedMaster()) {
        clusterStatus = new ClusterStateHealth(clusterService.state()).getStatus();
    }
    return new ClusterStatsNodeResponse(nodeInfo.getNode(), clusterStatus, nodeInfo, nodeStats, shardsStats.toArray(new ShardStats[shardsStats.size()]));
}
Also used : ShardStats(org.elasticsearch.action.admin.indices.stats.ShardStats) ClusterHealthStatus(org.elasticsearch.cluster.health.ClusterHealthStatus) NodeStats(org.elasticsearch.action.admin.cluster.node.stats.NodeStats) ClusterStateHealth(org.elasticsearch.cluster.health.ClusterStateHealth) CommonStats(org.elasticsearch.action.admin.indices.stats.CommonStats) IndexService(org.elasticsearch.index.IndexService) NodeInfo(org.elasticsearch.action.admin.cluster.node.info.NodeInfo) IndexShard(org.elasticsearch.index.shard.IndexShard) ArrayList(java.util.ArrayList)

Example 37 with IndexShard

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

the class TransportIndicesStatsAction method shardOperation.

@Override
protected ShardStats shardOperation(IndicesStatsRequest request, ShardRouting shardRouting) {
    IndexService indexService = indicesService.indexServiceSafe(shardRouting.shardId().getIndex());
    IndexShard indexShard = indexService.getShard(shardRouting.shardId().id());
    // if we don't have the routing entry yet, we need it stats wise, we treat it as if the shard is not ready yet
    if (indexShard.routingEntry() == null) {
        throw new ShardNotFoundException(indexShard.shardId());
    }
    CommonStatsFlags flags = new CommonStatsFlags().clear();
    if (request.docs()) {
        flags.set(CommonStatsFlags.Flag.Docs);
    }
    if (request.store()) {
        flags.set(CommonStatsFlags.Flag.Store);
    }
    if (request.indexing()) {
        flags.set(CommonStatsFlags.Flag.Indexing);
        flags.types(request.types());
    }
    if (request.get()) {
        flags.set(CommonStatsFlags.Flag.Get);
    }
    if (request.search()) {
        flags.set(CommonStatsFlags.Flag.Search);
        flags.groups(request.groups());
    }
    if (request.merge()) {
        flags.set(CommonStatsFlags.Flag.Merge);
    }
    if (request.refresh()) {
        flags.set(CommonStatsFlags.Flag.Refresh);
    }
    if (request.flush()) {
        flags.set(CommonStatsFlags.Flag.Flush);
    }
    if (request.warmer()) {
        flags.set(CommonStatsFlags.Flag.Warmer);
    }
    if (request.queryCache()) {
        flags.set(CommonStatsFlags.Flag.QueryCache);
    }
    if (request.fieldData()) {
        flags.set(CommonStatsFlags.Flag.FieldData);
        flags.fieldDataFields(request.fieldDataFields());
    }
    if (request.segments()) {
        flags.set(CommonStatsFlags.Flag.Segments);
        flags.includeSegmentFileSizes(request.includeSegmentFileSizes());
    }
    if (request.completion()) {
        flags.set(CommonStatsFlags.Flag.Completion);
        flags.completionDataFields(request.completionFields());
    }
    if (request.translog()) {
        flags.set(CommonStatsFlags.Flag.Translog);
    }
    if (request.suggest()) {
        flags.set(CommonStatsFlags.Flag.Suggest);
    }
    if (request.requestCache()) {
        flags.set(CommonStatsFlags.Flag.RequestCache);
    }
    if (request.recovery()) {
        flags.set(CommonStatsFlags.Flag.Recovery);
    }
    return new ShardStats(indexShard.routingEntry(), indexShard.shardPath(), new CommonStats(indicesService.getIndicesQueryCache(), indexShard, flags), indexShard.commitStats(), indexShard.seqNoStats());
}
Also used : ShardNotFoundException(org.elasticsearch.index.shard.ShardNotFoundException) IndexService(org.elasticsearch.index.IndexService) IndexShard(org.elasticsearch.index.shard.IndexShard)

Example 38 with IndexShard

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

the class TransportIndicesSegmentsAction method shardOperation.

@Override
protected ShardSegments shardOperation(IndicesSegmentsRequest request, ShardRouting shardRouting) {
    IndexService indexService = indicesService.indexServiceSafe(shardRouting.index());
    IndexShard indexShard = indexService.getShard(shardRouting.id());
    return new ShardSegments(indexShard.routingEntry(), indexShard.segments(request.verbose()));
}
Also used : IndexService(org.elasticsearch.index.IndexService) IndexShard(org.elasticsearch.index.shard.IndexShard)

Example 39 with IndexShard

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

the class TransportFieldStatsAction method shardOperation.

@Override
protected FieldStatsShardResponse shardOperation(FieldStatsShardRequest request) {
    ShardId shardId = request.shardId();
    Map<String, FieldStats<?>> fieldStats = new HashMap<>();
    IndexService indexServices = indicesService.indexServiceSafe(shardId.getIndex());
    IndexShard shard = indexServices.getShard(shardId.id());
    try (Engine.Searcher searcher = shard.acquireSearcher("fieldstats")) {
        // Resolve patterns and deduplicate
        Set<String> fieldNames = new HashSet<>();
        for (String field : request.getFields()) {
            fieldNames.addAll(shard.mapperService().simpleMatchToIndexNames(field));
        }
        for (String field : fieldNames) {
            FieldStats<?> stats = indicesService.getFieldStats(shard, searcher, field, request.shouldUseCache());
            if (stats != null) {
                fieldStats.put(field, stats);
            }
        }
    } catch (Exception e) {
        throw ExceptionsHelper.convertToElastic(e);
    }
    return new FieldStatsShardResponse(shardId, fieldStats);
}
Also used : HashMap(java.util.HashMap) IndexService(org.elasticsearch.index.IndexService) IndexShard(org.elasticsearch.index.shard.IndexShard) ClusterBlockException(org.elasticsearch.cluster.block.ClusterBlockException) BroadcastShardOperationFailedException(org.elasticsearch.action.support.broadcast.BroadcastShardOperationFailedException) ShardOperationFailedException(org.elasticsearch.action.ShardOperationFailedException) DefaultShardOperationFailedException(org.elasticsearch.action.support.DefaultShardOperationFailedException) ShardId(org.elasticsearch.index.shard.ShardId) Engine(org.elasticsearch.index.engine.Engine) HashSet(java.util.HashSet)

Example 40 with IndexShard

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

the class TransportGetAction method shardOperation.

@Override
protected GetResponse shardOperation(GetRequest request, ShardId shardId) {
    IndexService indexService = indicesService.indexServiceSafe(shardId.getIndex());
    IndexShard indexShard = indexService.getShard(shardId.id());
    if (request.refresh() && !request.realtime()) {
        indexShard.refresh("refresh_flag_get");
    }
    GetResult result = indexShard.getService().get(request.type(), request.id(), request.storedFields(), request.realtime(), request.version(), request.versionType(), request.fetchSourceContext());
    return new GetResponse(result);
}
Also used : GetResult(org.elasticsearch.index.get.GetResult) IndexService(org.elasticsearch.index.IndexService) IndexShard(org.elasticsearch.index.shard.IndexShard)

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