org.elasticsearch.indices.IndicesService.indexServiceSafe()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(11.5k)|赞(0)|评价(0)|浏览(70)

本文整理了Java中org.elasticsearch.indices.IndicesService.indexServiceSafe()方法的一些代码示例,展示了IndicesService.indexServiceSafe()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。IndicesService.indexServiceSafe()方法的具体详情如下:
包路径:org.elasticsearch.indices.IndicesService
类名称:IndicesService
方法名:indexServiceSafe

IndicesService.indexServiceSafe介绍

[英]Returns an IndexService for the specified index if exists otherwise a IndexNotFoundException is thrown.
[中]如果存在,则返回指定索引的IndexService,否则将引发IndexNotFoundException。

代码示例

代码示例来源:origin: org.elasticsearch/elasticsearch

@Override
public void doRun() {
  final IndexShard indexShard = indicesService.indexServiceSafe(shardId.getIndex()).getShardOrNull(shardId.id());
  assert indexId != null;
  snapshot(indexShard, snapshot, indexId, shardEntry.getValue());
}

代码示例来源:origin: org.elasticsearch/elasticsearch

protected IndexShard getIndexShard(final ShardId shardId) {
  IndexService indexService = indicesService.indexServiceSafe(shardId.getIndex());
  return indexService.getShard(shardId.id());
}

代码示例来源:origin: org.elasticsearch/elasticsearch

@Override
  protected String getExecutor(GetRequest request, ShardId shardId) {
    IndexService indexService = indicesService.indexServiceSafe(shardId.getIndex());
    return indexService.getIndexSettings().isSearchThrottled() ? ThreadPool.Names.SEARCH_THROTTLED : super.getExecutor(request,
      shardId);
  }
}

代码示例来源:origin: org.elasticsearch/elasticsearch

@Override
  protected String getExecutor(MultiTermVectorsShardRequest request, ShardId shardId) {
    IndexService indexService = indicesService.indexServiceSafe(shardId.getIndex());
    return indexService.getIndexSettings().isSearchThrottled() ? ThreadPool.Names.SEARCH_THROTTLED : super.getExecutor(request,
      shardId);
  }
}

代码示例来源:origin: org.elasticsearch/elasticsearch

@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);
}

代码示例来源:origin: org.elasticsearch/elasticsearch

@Override
  protected String getExecutor(TermVectorsRequest request, ShardId shardId) {
    IndexService indexService = indicesService.indexServiceSafe(shardId.getIndex());
    return indexService.getIndexSettings().isSearchThrottled() ? ThreadPool.Names.SEARCH_THROTTLED : super.getExecutor(request,
      shardId);
  }
}

代码示例来源:origin: org.elasticsearch/elasticsearch

@Override
  protected String getExecutor(MultiGetShardRequest request, ShardId shardId) {
    IndexService indexService = indicesService.indexServiceSafe(shardId.getIndex());
    return indexService.getIndexSettings().isSearchThrottled() ? ThreadPool.Names.SEARCH_THROTTLED : super.getExecutor(request,
      shardId);
  }
}

代码示例来源:origin: org.elasticsearch/elasticsearch

@Override
  protected String getExecutor(ExplainRequest request, ShardId shardId) {
    IndexService indexService = searchService.getIndicesService().indexServiceSafe(shardId.getIndex());
    return indexService.getIndexSettings().isSearchThrottled() ? ThreadPool.Names.SEARCH_THROTTLED : super.getExecutor(request,
      shardId);
  }
}

代码示例来源:origin: org.elasticsearch/elasticsearch

@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();
}

代码示例来源:origin: org.elasticsearch/elasticsearch

@Override
protected EmptyResult shardOperation(ForceMergeRequest request, ShardRouting shardRouting) throws IOException {
  IndexShard indexShard = indicesService.indexServiceSafe(shardRouting.shardId().getIndex()).getShard(shardRouting.shardId().id());
  indexShard.forceMerge(request);
  return EmptyResult.INSTANCE;
}

代码示例来源:origin: org.elasticsearch/elasticsearch

@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()));
  }
}

代码示例来源:origin: org.elasticsearch/elasticsearch

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();
  return new InFlightOpsResponse(opCount);
}

代码示例来源:origin: org.elasticsearch/elasticsearch

private void rewriteShardRequest(ShardSearchRequest request, ActionListener<ShardSearchRequest> listener) {
  IndexShard shard = indicesService.indexServiceSafe(request.shardId().getIndex()).getShard(request.shardId().id());
  Executor executor = getExecutor(shard);
  // we also do rewrite on the coordinating node (TransportSearchService) but we also need to do it here for BWC as well as
  // AliasFilters that might need to be rewritten. These are edge-cases but we are every efficient doing the rewrite here so it's not
  // adding a lot of overhead
  Rewriteable.rewriteAndFetch(request.getRewriteable(), indicesService.getRewriteContext(request::nowInMillis),
    ActionListener.wrap(r ->
        executor.execute(new AbstractRunnable() {
          @Override
          public void onFailure(Exception e) {
            listener.onFailure(e);
          }
          @Override
          protected void doRun() {
            listener.onResponse(request);
          }
        }), listener::onFailure));
}

代码示例来源:origin: org.elasticsearch/elasticsearch

private PreSyncedFlushResponse performPreSyncedFlush(PreShardSyncedFlushRequest request) {
  IndexShard indexShard = indicesService.indexServiceSafe(request.shardId().getIndex()).getShard(request.shardId().id());
  FlushRequest flushRequest = new FlushRequest().force(false).waitIfOngoing(true);
  logger.trace("{} performing pre sync flush", request.shardId());
  indexShard.flush(flushRequest);
  final CommitStats commitStats = indexShard.commitStats();
  final Engine.CommitId commitId = commitStats.getRawCommitId();
  logger.trace("{} pre sync flush done. commit id {}, num docs {}", request.shardId(), commitId, commitStats.getNumDocs());
  return new PreSyncedFlushResponse(commitId, commitStats.getNumDocs(), commitStats.syncId());
}

代码示例来源:origin: org.elasticsearch/elasticsearch

@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);
}

代码示例来源:origin: org.elasticsearch/elasticsearch

@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);
  }
}

代码示例来源:origin: org.elasticsearch/elasticsearch

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 + "]");
  }
}

代码示例来源:origin: org.elasticsearch/elasticsearch

@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 (RuntimeException e) {
      if (TransportActions.isShardNotAvailableException(e)) {
        throw e;
      } else {
        logger.debug(() -> new ParameterizedMessage("{} failed to execute multi term vectors for [{}]/[{}]",
          shardId, termVectorsRequest.type(), termVectorsRequest.id()), e);
        response.add(request.locations.get(i),
            new MultiTermVectorsResponse.Failure(request.index(), termVectorsRequest.type(), termVectorsRequest.id(), e));
      }
    }
  }
  return response;
}

代码示例来源:origin: org.elasticsearch/elasticsearch

private RecoveryResponse recover(final StartRecoveryRequest request) throws IOException {
  final IndexService indexService = indicesService.indexServiceSafe(request.shardId().getIndex());
  final IndexShard shard = indexService.getShard(request.shardId().id());
  final ShardRouting routingEntry = shard.routingEntry();
  if (routingEntry.primary() == false || routingEntry.active() == false) {
    throw new DelayRecoveryException("source shard [" + routingEntry + "] is not an active primary");
  }
  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() + "]");
  }
  RecoverySourceHandler handler = ongoingRecoveries.addNewRecovery(request, shard);
  logger.trace("[{}][{}] starting recovery to {}", request.shardId().getIndex().getName(), request.shardId().id(),
    request.targetNode());
  try {
    return handler.recoverToTarget();
  } finally {
    ongoingRecoveries.remove(shard, handler);
  }
}

代码示例来源:origin: org.elasticsearch/elasticsearch

@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);
}

相关文章

微信公众号

最新文章

更多