当前位置: 首页>>代码示例>>Java>>正文


Java IndexService.getShard方法代码示例

本文整理汇总了Java中org.elasticsearch.index.IndexService.getShard方法的典型用法代码示例。如果您正苦于以下问题:Java IndexService.getShard方法的具体用法?Java IndexService.getShard怎么用?Java IndexService.getShard使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.elasticsearch.index.IndexService的用法示例。


在下文中一共展示了IndexService.getShard方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: performSyncedFlush

import org.elasticsearch.index.IndexService; //导入方法依赖的package包/类
private ShardSyncedFlushResponse performSyncedFlush(ShardSyncedFlushRequest request) {
    IndexService indexService = indicesService.indexServiceSafe(request.shardId().getIndex());
    IndexShard indexShard = indexService.getShard(request.shardId().id());
    logger.trace("{} performing sync flush. sync id [{}], expected commit id {}", request.shardId(), request.syncId(), request.expectedCommitId());
    Engine.SyncedFlushResult result = indexShard.syncFlush(request.syncId(), request.expectedCommitId());
    logger.trace("{} sync flush done. sync id [{}], result [{}]", request.shardId(), request.syncId(), result);
    switch (result) {
        case SUCCESS:
            return new ShardSyncedFlushResponse();
        case COMMIT_MISMATCH:
            return new ShardSyncedFlushResponse("commit has changed");
        case PENDING_OPERATIONS:
            return new ShardSyncedFlushResponse("pending operations");
        default:
            throw new ElasticsearchException("unknown synced flush result [" + result + "]");
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:18,代码来源:SyncedFlushService.java

示例2: shardOperation

import org.elasticsearch.index.IndexService; //导入方法依赖的package包/类
@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);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:23,代码来源:TransportUpgradeStatusAction.java

示例3: shardOperation

import org.elasticsearch.index.IndexService; //导入方法依赖的package包/类
@Override
protected MultiTermVectorsShardResponse shardOperation(MultiTermVectorsShardRequest request, ShardId shardId) {
    final MultiTermVectorsShardResponse response = new MultiTermVectorsShardResponse();
    final IndexService indexService = indicesService.indexServiceSafe(shardId.getIndex());
    final IndexShard indexShard = indexService.getShard(shardId.id());
    for (int i = 0; i < request.locations.size(); i++) {
        TermVectorsRequest termVectorsRequest = request.requests.get(i);
        try {
            TermVectorsResponse termVectorsResponse = TermVectorsService.getTermVectors(indexShard, termVectorsRequest);
            response.add(request.locations.get(i), termVectorsResponse);
        } catch (Exception t) {
            if (TransportActions.isShardNotAvailableException(t)) {
                throw (ElasticsearchException) t;
            } else {
                logger.debug((Supplier<?>) () -> new ParameterizedMessage("{} failed to execute multi term vectors for [{}]/[{}]", shardId, termVectorsRequest.type(), termVectorsRequest.id()), t);
                response.add(request.locations.get(i),
                        new MultiTermVectorsResponse.Failure(request.index(), termVectorsRequest.type(), termVectorsRequest.id(), t));
            }
        }
    }

    return response;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:24,代码来源:TransportShardMultiTermsVectorAction.java

示例4: testCloseSearchContextOnRewriteException

import org.elasticsearch.index.IndexService; //导入方法依赖的package包/类
public void testCloseSearchContextOnRewriteException() {
    createIndex("index");
    client().prepareIndex("index", "type", "1").setSource("field", "value").setRefreshPolicy(IMMEDIATE).get();

    SearchService service = getInstanceFromNode(SearchService.class);
    IndicesService indicesService = getInstanceFromNode(IndicesService.class);
    IndexService indexService = indicesService.indexServiceSafe(resolveIndex("index"));
    IndexShard indexShard = indexService.getShard(0);

    final int activeContexts = service.getActiveContexts();
    final int activeRefs = indexShard.store().refCount();
    expectThrows(SearchPhaseExecutionException.class, () ->
            client().prepareSearch("index").setQuery(new FailOnRewriteQueryBuilder()).get());
    assertEquals(activeContexts, service.getActiveContexts());
    assertEquals(activeRefs, indexShard.store().refCount());
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:17,代码来源:SearchServiceTests.java

示例5: performInFlightOps

import org.elasticsearch.index.IndexService; //导入方法依赖的package包/类
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);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:11,代码来源:SyncedFlushService.java

示例6: recover

import org.elasticsearch.index.IndexService; //导入方法依赖的package包/类
private RecoveryResponse recover(final StartRecoveryRequest request) throws IOException {
    final IndexService indexService = indicesService.indexServiceSafe(request.shardId().getIndex());
    final IndexShard shard = indexService.getShard(request.shardId().id());

    // starting recovery from that our (the source) shard state is marking the shard to be in recovery mode as well, otherwise
    // the index operations will not be routed to it properly
    RoutingNode node = clusterService.state().getRoutingNodes().node(request.targetNode().getId());
    if (node == null) {
        logger.debug("delaying recovery of {} as source node {} is unknown", request.shardId(), request.targetNode());
        throw new DelayRecoveryException("source node does not have the node [" + request.targetNode() + "] in its state yet..");
    }

    ShardRouting routingEntry = shard.routingEntry();
    if (request.isPrimaryRelocation() && (routingEntry.relocating() == false || routingEntry.relocatingNodeId().equals(request.targetNode().getId()) == false)) {
        logger.debug("delaying recovery of {} as source shard is not marked yet as relocating to {}", request.shardId(), request.targetNode());
        throw new DelayRecoveryException("source shard is not marked yet as relocating to [" + request.targetNode() + "]");
    }

    ShardRouting targetShardRouting = node.getByShardId(request.shardId());
    if (targetShardRouting == null) {
        logger.debug("delaying recovery of {} as it is not listed as assigned to target node {}", request.shardId(), request.targetNode());
        throw new DelayRecoveryException("source node does not have the shard listed in its state as allocated on the node");
    }
    if (!targetShardRouting.initializing()) {
        logger.debug("delaying recovery of {} as it is not listed as initializing on the target node {}. known shards state is [{}]",
            request.shardId(), request.targetNode(), targetShardRouting.state());
        throw new DelayRecoveryException("source node has the state of the target shard to be [" + targetShardRouting.state() + "], expecting to be [initializing]");
    }

    RecoverySourceHandler handler = ongoingRecoveries.addNewRecovery(request, targetShardRouting.allocationId().getId(), shard);
    logger.trace("[{}][{}] starting recovery to {}", request.shardId().getIndex().getName(), request.shardId().id(), request.targetNode());
    try {
        return handler.recoverToTarget();
    } finally {
        ongoingRecoveries.remove(shard, handler);
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:38,代码来源:PeerRecoverySourceService.java

示例7: shardOperation

import org.elasticsearch.index.IndexService; //导入方法依赖的package包/类
@Override
protected MultiGetShardResponse shardOperation(MultiGetShardRequest request, ShardId shardId) {
    IndexService indexService = indicesService.indexServiceSafe(shardId.getIndex());
    IndexShard indexShard = indexService.getShard(shardId.id());

    if (request.refresh() && !request.realtime()) {
        indexShard.refresh("refresh_flag_mget");
    }

    MultiGetShardResponse response = new MultiGetShardResponse();
    for (int i = 0; i < request.locations.size(); i++) {
        MultiGetRequest.Item item = request.items.get(i);
        try {
            GetResult getResult = indexShard.getService().get(item.type(), item.id(), item.storedFields(), request.realtime(), item.version(),
                item.versionType(), item.fetchSourceContext());
            response.add(request.locations.get(i), new GetResponse(getResult));
        } catch (Exception e) {
            if (TransportActions.isShardNotAvailableException(e)) {
                throw (ElasticsearchException) e;
            } else {
                logger.debug((Supplier<?>) () -> new ParameterizedMessage("{} failed to execute multi_get for [{}]/[{}]", shardId,
                    item.type(), item.id()), e);
                response.add(request.locations.get(i), new MultiGetResponse.Failure(request.index(), item.type(), item.id(), e));
            }
        }
    }

    return response;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:30,代码来源:TransportShardMultiGetAction.java

示例8: shardOperation

import org.elasticsearch.index.IndexService; //导入方法依赖的package包/类
@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);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:14,代码来源:TransportGetAction.java

示例9: testShardAdditionAndRemoval

import org.elasticsearch.index.IndexService; //导入方法依赖的package包/类
public void testShardAdditionAndRemoval() {
    createIndex("test", Settings.builder().put("index.number_of_shards", 3).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", "4mb").build());
    IndexShard shard0 = test.getShard(0);
    controller.simulateIndexing(shard0);
    controller.assertBuffer(shard0, 1);

    // add another shard
    IndexShard shard1 = test.getShard(1);
    controller.simulateIndexing(shard1);
    controller.assertBuffer(shard0, 1);
    controller.assertBuffer(shard1, 1);

    // remove first shard
    controller.deleteShard(shard0);
    controller.forceCheck();
    controller.assertBuffer(shard1, 1);

    // remove second shard
    controller.deleteShard(shard1);
    controller.forceCheck();

    // add a new one
    IndexShard shard2 = test.getShard(2);
    controller.simulateIndexing(shard2);
    controller.assertBuffer(shard2, 1);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:32,代码来源:IndexingMemoryControllerTests.java

示例10: testActiveInactive

import org.elasticsearch.index.IndexService; //导入方法依赖的package包/类
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);
    }
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:39,代码来源:IndexingMemoryControllerTests.java

示例11: testTimeout

import org.elasticsearch.index.IndexService; //导入方法依赖的package包/类
public void testTimeout() throws IOException {
    createIndex("index");
    final SearchService service = getInstanceFromNode(SearchService.class);
    final IndicesService indicesService = getInstanceFromNode(IndicesService.class);
    final IndexService indexService = indicesService.indexServiceSafe(resolveIndex("index"));
    final IndexShard indexShard = indexService.getShard(0);
    final SearchContext contextWithDefaultTimeout = service.createContext(
        new ShardSearchLocalRequest(
            indexShard.shardId(),
            1,
            SearchType.DEFAULT,
            new SearchSourceBuilder(),
            new String[0],
            false,
            new AliasFilter(null, Strings.EMPTY_ARRAY),
            1.0f),
        null);
    // the search context should inherit the default timeout
    assertThat(contextWithDefaultTimeout.timeout(), equalTo(TimeValue.timeValueSeconds(5)));

    final long seconds = randomIntBetween(6, 10);
    final SearchContext context = service.createContext(
        new ShardSearchLocalRequest(
            indexShard.shardId(),
            1,
            SearchType.DEFAULT,
            new SearchSourceBuilder().timeout(TimeValue.timeValueSeconds(seconds)),
            new String[0],
            false,
            new AliasFilter(null, Strings.EMPTY_ARRAY),
            1.0f),
        null);
    // the search context should inherit the query timeout
    assertThat(context.timeout(), equalTo(TimeValue.timeValueSeconds(seconds)));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:36,代码来源:SearchServiceTests.java

示例12: shardOperation

import org.elasticsearch.index.IndexService; //导入方法依赖的package包/类
@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());
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:74,代码来源:TransportIndicesStatsAction.java

示例13: shardOperation

import org.elasticsearch.index.IndexService; //导入方法依赖的package包/类
@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()));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:7,代码来源:TransportIndicesSegmentsAction.java

示例14: shardOperation

import org.elasticsearch.index.IndexService; //导入方法依赖的package包/类
@Override
protected RecoveryState shardOperation(RecoveryRequest request, ShardRouting shardRouting) {
    IndexService indexService = indicesService.indexServiceSafe(shardRouting.shardId().getIndex());
    IndexShard indexShard = indexService.getShard(shardRouting.shardId().id());
    return indexShard.recoveryState();
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:7,代码来源:TransportRecoveryAction.java

示例15: getIndexShard

import org.elasticsearch.index.IndexService; //导入方法依赖的package包/类
private IndexShard getIndexShard(ShardId shardId) {
    IndexService indexService = indicesService.indexServiceSafe(shardId.getIndex());
    return indexService.getShard(shardId.id());
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:5,代码来源:TransportReplicationAction.java


注:本文中的org.elasticsearch.index.IndexService.getShard方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。