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

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

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

IndicesService.indexService介绍

[英]Returns an IndexService for the specified index if exists otherwise returns null.
[中]返回指定索引的IndexService(如果存在),否则返回null

代码示例

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

/**
 * This method returns true if the current node is allowed to delete the given index.
 * This is the case if the index is deleted in the metadata or there is no allocation
 * on the local node and the index isn't on a shared file system.
 * @param index {@code Index} to check whether deletion is allowed
 * @param indexSettings {@code IndexSettings} for the given index
 * @return true if the index can be deleted on this node
 */
public boolean canDeleteIndexContents(Index index, IndexSettings indexSettings) {
  // index contents can be deleted if its an already closed index (so all its resources have
  // already been relinquished)
  final IndexService indexService = indexService(index);
  if (indexService == null && nodeEnv.hasNodeFile()) {
    return true;
  }
  return false;
}

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

case NOOP:
  UpdateResponse update = result.action();
  IndexService indexServiceOrNull = indicesService.indexService(shardId.getIndex());
  if (indexServiceOrNull !=  null) {
    IndexShard shard = indexService.getShardOrNull(shardId.getId());

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

private IndexShard getShard(ShardActiveRequest request) {
  ClusterName thisClusterName = clusterService.getClusterName();
  if (!thisClusterName.equals(request.clusterName)) {
    logger.trace("shard exists request meant for cluster[{}], but this is cluster[{}], ignoring request",
      request.clusterName, thisClusterName);
    return null;
  }
  ShardId shardId = request.shardId;
  IndexService indexService = indicesService.indexService(shardId.getIndex());
  if (indexService != null && indexService.indexUUID().equals(request.indexUUID)) {
    return indexService.getShardOrNull(shardId.id());
  }
  return null;
}

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

IndexService indexService = indicesService.indexService(indexMetaData.getIndex());
if (indexService == null) {

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

/**
 * Clears the caches for the given shard id if the shard is still allocated on this node
 */
public void clearIndexShardCache(ShardId shardId, boolean queryCache, boolean fieldDataCache, boolean requestCache,
                 String...fields) {
  final IndexService service = indexService(shardId.getIndex());
  if (service != null) {
    IndexShard shard = service.getShardOrNull(shardId.id());
    final boolean clearedAtLeastOne = service.clearCaches(queryCache, fieldDataCache, fields);
    if ((requestCache || (clearedAtLeastOne == false && fields.length == 0)) && shard != null) {
      indicesRequestCache.clear(new IndexShardCacheEntity(shard));
    }
  }
}

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

@Override
public IndexShard createShard(ShardRouting shardRouting, RecoveryState recoveryState, PeerRecoveryTargetService recoveryTargetService,
               PeerRecoveryTargetService.RecoveryListener recoveryListener, RepositoriesService repositoriesService,
               Consumer<IndexShard.ShardFailure> onShardFailure,
               Consumer<ShardId> globalCheckpointSyncer) throws IOException {
  ensureChangesAllowed();
  IndexService indexService = indexService(shardRouting.index());
  IndexShard indexShard = indexService.createShard(shardRouting, globalCheckpointSyncer);
  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";
      client.admin().indices().preparePutMapping()
        .setConcreteIndex(shardRouting.index()) // concrete index - no name clash, it uses uuid
        .setType(type)
        .setSource(mapping.source().string(), XContentType.JSON)
        .get();
    }, this);
  return indexShard;
}

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

boolean exists = false;
try {
  IndexService indexService = indicesService.indexService(shardId.getIndex());
  if (indexService != null) {
    IndexShard indexShard = indexService.getShardOrNull(shardId.id());

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

/**
 * Returns <code>ShardDeletionCheckResult</code> signaling whether the shards content for the given shard can be deleted.
 *
 * @param shardId the shard to delete.
 * @param indexSettings the shards's relevant {@link IndexSettings}. This is required to access the indexes settings etc.
 */
public ShardDeletionCheckResult canDeleteShardContent(ShardId shardId, IndexSettings indexSettings) {
  assert shardId.getIndex().equals(indexSettings.getIndex());
  final IndexService indexService = indexService(shardId.getIndex());
  if (nodeEnv.hasNodeFile()) {
    final boolean isAllocated = indexService != null && indexService.hasShard(shardId.id());
    if (isAllocated) {
      return ShardDeletionCheckResult.STILL_ALLOCATED; // we are allocated - can't delete the shard
    } else if (indexSettings.hasCustomDataPath()) {
      // lets see if it's on a custom path (return false if the shared doesn't exist)
      // we don't need to delete anything that is not there
      return Files.exists(nodeEnv.resolveCustomLocation(indexSettings, shardId)) ?
          ShardDeletionCheckResult.FOLDER_FOUND_CAN_DELETE :
          ShardDeletionCheckResult.NO_FOLDER_FOUND;
    } else {
      // lets see if it's path is available (return false if the shared doesn't exist)
      // we don't need to delete anything that is not there
      return FileSystemUtils.exists(nodeEnv.availableShardPaths(shardId)) ?
          ShardDeletionCheckResult.FOLDER_FOUND_CAN_DELETE :
          ShardDeletionCheckResult.NO_FOLDER_FOUND;
    }
  } else {
    return ShardDeletionCheckResult.NO_LOCAL_STORAGE;
  }
}

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

final Index resizeSourceIndex = indexMetaData.getResizeSourceIndex();
final List<IndexShard> startedShards = new ArrayList<>();
final IndexService sourceIndexService = indicesService.indexService(resizeSourceIndex);
final Set<ShardId> requiredShards;
final int numShards;

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

/**
 * Deletes the index store trying to acquire all shards locks for this index.
 * This method will delete the metadata for the index even if the actual shards can't be locked.
 *
 * Package private for testing
 */
void deleteIndexStore(String reason, IndexMetaData metaData, ClusterState clusterState) throws IOException {
  if (nodeEnv.hasNodeFile()) {
    synchronized (this) {
      Index index = metaData.getIndex();
      if (hasIndex(index)) {
        String localUUid = indexService(index).indexUUID();
        throw new IllegalStateException("Can't delete index store for [" + index.getName() +
          "] - it's still part of the indices service [" + localUUid + "] [" + metaData.getIndexUUID() + "]");
      }
      if (clusterState.metaData().hasIndex(index.getName()) && (clusterState.nodes().getLocalNode().isMasterNode() == true)) {
        // we do not delete the store if it is a master eligible node and the index is still in the cluster state
        // because we want to keep the meta data for indices around even if no shards are left here
        final IndexMetaData idxMeta = clusterState.metaData().index(index.getName());
        throw new IllegalStateException("Can't delete index store for [" + index.getName() + "] - it's still part of the " +
                        "cluster state [" + idxMeta.getIndexUUID() + "] [" + metaData.getIndexUUID() + "], " +
                        "we are master eligible, so will keep the index metadata even if no shards are left.");
      }
    }
    final IndexSettings indexSettings = buildIndexSettings(metaData);
    deleteIndexStore(reason, indexSettings.getIndex(), indexSettings);
  }
}

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

ShardId shardId = indexShardRoutingTable.shardId();
if (folderNotFoundCache.contains(shardId) == false && shardCanBeDeleted(localNodeId, indexShardRoutingTable)) {
  IndexService indexService = indicesService.indexService(indexRoutingTable.getIndex());
  final IndexSettings indexSettings;
  if (indexService == null) {

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

IndexService indexService = indices.get(index.getIndex().getName());
if (indexService == null) {
  indexService = indicesService.indexService(index.getIndex());
  if (indexService == null) {

代码示例来源:origin: harbby/presto-connectors

/**
 * Returns an IndexService for the specified index if exists otherwise a {@link IndexNotFoundException} is thrown.
 */
public IndexService indexServiceSafe(String index) {
  IndexService indexService = indexService(index);
  if (indexService == null) {
    throw new IndexNotFoundException(index);
  }
  return indexService;
}

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

private IndexShard getShard(ShardActiveRequest request) {
  ClusterName thisClusterName = clusterService.getClusterName();
  if (!thisClusterName.equals(request.clusterName)) {
    logger.trace("shard exists request meant for cluster[{}], but this is cluster[{}], ignoring request", request.clusterName, thisClusterName);
    return null;
  }
  ShardId shardId = request.shardId;
  IndexService indexService = indicesService.indexService(shardId.getIndex());
  if (indexService != null && indexService.indexUUID().equals(request.indexUUID)) {
    return indexService.getShardOrNull(shardId.id());
  }
  return null;
}

代码示例来源:origin: apache/servicemix-bundles

private IndexShard getShard(ShardActiveRequest request) {
  ClusterName thisClusterName = clusterService.getClusterName();
  if (!thisClusterName.equals(request.clusterName)) {
    logger.trace("shard exists request meant for cluster[{}], but this is cluster[{}], ignoring request", request.clusterName, thisClusterName);
    return null;
  }
  ShardId shardId = request.shardId;
  IndexService indexService = indicesService.indexService(shardId.getIndex());
  if (indexService != null && indexService.indexUUID().equals(request.indexUUID)) {
    return indexService.getShardOrNull(shardId.id());
  }
  return null;
}

代码示例来源:origin: com.strapdata.elasticsearch/elasticsearch

private IndexShard getShard(ShardActiveRequest request) {
  ClusterName thisClusterName = clusterService.getClusterName();
  if (!thisClusterName.equals(request.clusterName)) {
    logger.trace("shard exists request meant for cluster[{}], but this is cluster[{}], ignoring request", request.clusterName, thisClusterName);
    return null;
  }
  ShardId shardId = request.shardId;
  IndexService indexService = indicesService.indexService(shardId.getIndex());
  if (indexService != null && indexService.indexUUID().equals(request.indexUUID)) {
    return indexService.getShardOrNull(shardId.id());
  }
  return null;
}

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

/**
 * Clears the caches for the given shard id if the shard is still allocated on this node
 */
public void clearIndexShardCache(ShardId shardId, boolean queryCache, boolean fieldDataCache, boolean requestCache,
                 String...fields) {
  final IndexService service = indexService(shardId.getIndex());
  if (service != null) {
    IndexShard shard = service.getShardOrNull(shardId.id());
    final boolean clearedAtLeastOne = service.clearCaches(queryCache, fieldDataCache, fields);
    if ((requestCache || (clearedAtLeastOne == false && fields.length == 0)) && shard != null) {
      indicesRequestCache.clear(new IndexShardCacheEntity(shard));
    }
  }
}

代码示例来源:origin: harbby/presto-connectors

private IndexShard getShard(ShardActiveRequest request) {
    ClusterName thisClusterName = clusterService.state().getClusterName();
    if (!thisClusterName.equals(request.clusterName)) {
      logger.trace("shard exists request meant for cluster[{}], but this is cluster[{}], ignoring request", request.clusterName, thisClusterName);
      return null;
    }
    ShardId shardId = request.shardId;
    IndexService indexService = indicesService.indexService(shardId.index().getName());
    if (indexService != null && indexService.indexUUID().equals(request.indexUUID)) {
      return indexService.shard(shardId.id());
    }
    return null;
  }
}

代码示例来源:origin: spinscale/elasticsearch-suggest-plugin

@Override
  public void beforeIndexShardClosed(ShardId shardId, @Nullable IndexShard indexShard) {
    IndexService indexService = indicesService.indexService(shardId.index().name());
    if (indexService != null) {
      ShardSuggestService suggestShardService = indexService.shardInjectorSafe(shardId.id()).getInstance(ShardSuggestService.class);
      suggestShardService.shutDown();
    }
  }
});

代码示例来源:origin: jprante/elasticsearch-skywalker

@Override
protected ShardReconstructIndexResponse shardOperation(ShardReconstructIndexRequest request) throws ElasticsearchException {
  IndexService indexService = indicesService.indexService(request.index());
  InternalIndexShard indexShard = (InternalIndexShard) indexService.shardSafe(request.shardId());
  Engine.Searcher searcher = indexShard.engine().acquireSearcher("transport_reconstruct");
  IndexReader reader = searcher.reader();
  DocumentReconstructor dr = new DocumentReconstructor(reader);
  try {
    return new ShardReconstructIndexResponse(true, dr.reconstruct(request.shardId()));
  } catch (IOException e) {
    throw new ElasticsearchException("failed to reconstruct index", e);
  }
}

相关文章

微信公众号

最新文章

更多