org.elasticsearch.cluster.metadata.MetaData.hasIndex()方法的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(12.9k)|赞(0)|评价(0)|浏览(101)

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

MetaData.hasIndex介绍

[英]Returns true iff existing index has the same IndexMetaData instance
[中]如果现有索引具有相同的IndexMetaData实例,则返回true

代码示例

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

/**
 * Returns the indices created in this event
 */
public List<String> indicesCreated() {
  if (!metaDataChanged()) {
    return Collections.emptyList();
  }
  List<String> created = null;
  for (ObjectCursor<String> cursor : state.metaData().indices().keys()) {
    String index = cursor.value;
    if (!previousState.metaData().hasIndex(index)) {
      if (created == null) {
        created = new ArrayList<>();
      }
      created.add(index);
    }
  }
  return created == null ? Collections.<String>emptyList() : created;
}

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

final IndexGraveyard graveyard = metaData.indexGraveyard();
for (IndexMetaData indexMetaData : indexMetaDataList) {
  if (metaData.hasIndex(indexMetaData.getIndex().getName())) {
    logger.warn("[{}] can not be imported as a dangling index, as index with same name already exists in cluster metadata",
      indexMetaData.getIndex());

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

/**
 * Returns list of indices with missing shards, and list of indices that are closed
 *
 * @param shards list of shard statuses
 * @return list of failed and closed indices
 */
private Tuple<Set<String>, Set<String>> indicesWithMissingShards(ImmutableOpenMap<ShardId, SnapshotsInProgress.ShardSnapshotStatus> shards, MetaData metaData) {
  Set<String> missing = new HashSet<>();
  Set<String> closed = new HashSet<>();
  for (ObjectObjectCursor<ShardId, SnapshotsInProgress.ShardSnapshotStatus> entry : shards) {
    if (entry.value.state() == State.MISSING) {
      if (metaData.hasIndex(entry.key.getIndex().getName()) && metaData.getIndexSafe(entry.key.getIndex()).getState() == IndexMetaData.State.CLOSE) {
        closed.add(entry.key.getIndex().getName());
      } else {
        missing.add(entry.key.getIndex().getName());
      }
    }
  }
  return new Tuple<>(missing, closed);
}

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

static IndexMetaData validateResize(ClusterState state, String sourceIndex,
                    Set<String> targetIndexMappingsTypes, String targetIndexName,
                    Settings targetIndexSettings) {
  if (state.metaData().hasIndex(targetIndexName)) {
    throw new ResourceAlreadyExistsException(state.metaData().index(targetIndexName).getIndex());
  }
  final IndexMetaData sourceMetaData = state.metaData().index(sourceIndex);
  if (sourceMetaData == null) {
    throw new IndexNotFoundException(sourceIndex);
  }
  // ensure index is read-only
  if (state.blocks().indexBlocked(ClusterBlockLevel.WRITE, sourceIndex) == false) {
    throw new IllegalStateException("index " + sourceIndex + " must be read-only to resize index. use \"index.blocks.write=true\"");
  }
  if ((targetIndexMappingsTypes.size() > 1 ||
    (targetIndexMappingsTypes.isEmpty() || targetIndexMappingsTypes.contains(MapperService.DEFAULT_MAPPING)) == false)) {
    throw new IllegalArgumentException("mappings are not allowed when resizing indices" +
      ", all mappings are copied from the source index");
  }
  if (IndexMetaData.INDEX_NUMBER_OF_SHARDS_SETTING.exists(targetIndexSettings)) {
    // this method applies all necessary checks ie. if the target shards are less than the source shards
    // of if the source shards are divisible by the number of target shards
    IndexMetaData.getRoutingFactor(sourceMetaData.getNumberOfShards(),
      IndexMetaData.INDEX_NUMBER_OF_SHARDS_SETTING.get(targetIndexSettings));
  }
  return sourceMetaData;
}

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

/**
 * Deletes an index that is not assigned to this node. This method cleans up all disk folders relating to the index
 * but does not deal with in-memory structures. For those call {@link #removeIndex(Index, IndexRemovalReason, String)}
 */
@Override
public void deleteUnassignedIndex(String reason, IndexMetaData metaData, ClusterState clusterState) {
  if (nodeEnv.hasNodeFile()) {
    String indexName = metaData.getIndex().getName();
    try {
      if (clusterState.metaData().hasIndex(indexName)) {
        final IndexMetaData index = clusterState.metaData().index(indexName);
        throw new IllegalStateException("Can't delete unassigned index store for [" + indexName + "] - it's still part of " +
                        "the cluster state [" + index.getIndexUUID() + "] [" + metaData.getIndexUUID() + "]");
      }
      deleteIndexStore(reason, metaData, clusterState);
    } catch (Exception e) {
      logger.warn(() -> new ParameterizedMessage("[{}] failed to delete unassigned index (reason [{}])",
        metaData.getIndex(), reason), e);
    }
  }
}

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

boolean validate(MetaData metaData) {
  if (!metaData.hasIndex(index.getName())) {
    throw new IllegalStateException(index + " exists in routing does not exists in metadata");

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

/**
 * Validate the name for an index against some static rules and a cluster state.
 */
public static void validateIndexName(String index, ClusterState state) {
  validateIndexOrAliasName(index, InvalidIndexNameException::new);
  if (!index.toLowerCase(Locale.ROOT).equals(index)) {
    throw new InvalidIndexNameException(index, "must be lowercase");
  }
  if (state.routingTable().hasIndex(index)) {
    throw new ResourceAlreadyExistsException(state.routingTable().index(index).getIndex());
  }
  if (state.metaData().hasIndex(index)) {
    throw new ResourceAlreadyExistsException(state.metaData().index(index).getIndex());
  }
  if (state.metaData().hasAlias(index)) {
    throw new InvalidIndexNameException(index, "already exists as alias");
  }
}

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

continue;
if (currentState.metaData().hasIndex(indexMetaData.getIndex().getName())) {
  continue;

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

indexSettings = indexService.getIndexSettings();
  indicesService.removeIndex(index, DELETED, "index no longer part of the metadata");
} else if (previousState.metaData().hasIndex(index.getName())) {

代码示例来源: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: harbby/presto-connectors

/**
 * Cleans dangling indices if they are already allocated on the provided meta data.
 */
void cleanupAllocatedDangledIndices(MetaData metaData) {
  for (String danglingIndex : danglingIndices.keySet()) {
    if (metaData.hasIndex(danglingIndex)) {
      logger.debug("[{}] no longer dangling (created), removing from dangling list", danglingIndex);
      danglingIndices.remove(danglingIndex);
    }
  }
}

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

/**
 * Returns the indices created in this event
 */
public List<String> indicesCreated() {
  if (!metaDataChanged()) {
    return Collections.emptyList();
  }
  List<String> created = null;
  for (ObjectCursor<String> cursor : state.metaData().indices().keys()) {
    String index = cursor.value;
    if (!previousState.metaData().hasIndex(index)) {
      if (created == null) {
        created = new ArrayList<>();
      }
      created.add(index);
    }
  }
  return created == null ? Collections.<String>emptyList() : created;
}

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

private void validateAlias(String alias, String index, String indexRouting, MetaData metaData) {
  validateAliasStandalone(alias, indexRouting);
  if (!Strings.hasText(index)) {
    throw new IllegalArgumentException("index name is required");
  }
  assert metaData != null;
  if (metaData.hasIndex(alias)) {
    throw new InvalidAliasNameException(new Index(index), alias, "an index exists with the same name as the alias");
  }
}

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

protected NumShards getNumShards(String index) {
  MetaData metaData = client().admin().cluster().prepareState().get().getState().metaData();
  assertThat(metaData.hasIndex(index), equalTo(true));
  int numShards = Integer.valueOf(metaData.index(index).getSettings().get(SETTING_NUMBER_OF_SHARDS));
  int numReplicas = Integer.valueOf(metaData.index(index).getSettings().get(SETTING_NUMBER_OF_REPLICAS));
  return new NumShards(numShards, numReplicas);
}

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

public void validate(RoutingTableValidation validation, MetaData metaData) {
  if (!metaData.hasIndex(index())) {
    validation.addIndexFailure(index(), "Exists in routing does not exists in metadata");
    return;
  }
  IndexMetaData indexMetaData = metaData.index(index());
  for (String failure : validate(indexMetaData)) {
    validation.addIndexFailure(index, failure);
  }
}

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

public void deleteClosedIndex(String reason, IndexMetaData metaData, ClusterState clusterState) {
  if (nodeEnv.hasNodeFile()) {
    String indexName = metaData.getIndex();
    try {
      if (clusterState.metaData().hasIndex(indexName)) {
        final IndexMetaData index = clusterState.metaData().index(indexName);
        throw new IllegalStateException("Can't delete closed index store for [" + indexName + "] - it's still part of the cluster state [" + index.getIndexUUID() + "] [" + metaData.getIndexUUID() + "]");
      }
      deleteIndexStore(reason, metaData, clusterState, true);
    } catch (IOException e) {
      logger.warn("[{}] failed to delete closed index", e, metaData.getIndex());
    }
  }
}

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

/**
 * Validate the name for an index against some static rules and a cluster state.
 */
public static void validateIndexName(String index, ClusterState state) {
  validateIndexOrAliasName(index, InvalidIndexNameException::new);
  if (!index.toLowerCase(Locale.ROOT).equals(index)) {
    throw new InvalidIndexNameException(index, "must be lowercase");
  }
  if (state.routingTable().hasIndex(index)) {
    throw new ResourceAlreadyExistsException(state.routingTable().index(index).getIndex());
  }
  if (state.metaData().hasIndex(index)) {
    throw new ResourceAlreadyExistsException(state.metaData().index(index).getIndex());
  }
  if (state.metaData().hasAlias(index)) {
    throw new InvalidIndexNameException(index, "already exists as alias");
  }
}

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

/**
 * Validate the name for an index against some static rules and a cluster state.
 */
public static void validateIndexName(String index, ClusterState state) {
  validateIndexOrAliasName(index, InvalidIndexNameException::new);
  if (!index.toLowerCase(Locale.ROOT).equals(index)) {
    throw new InvalidIndexNameException(index, "must be lowercase");
  }
  if (state.routingTable().hasIndex(index)) {
    throw new ResourceAlreadyExistsException(state.routingTable().index(index).getIndex());
  }
  if (state.metaData().hasIndex(index)) {
    throw new ResourceAlreadyExistsException(state.metaData().index(index).getIndex());
  }
  if (state.metaData().hasAlias(index)) {
    throw new InvalidIndexNameException(index, "already exists as alias");
  }
}

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

@Override
protected void resolveRequest(MetaData metaData, String concreteIndex, IndexRequest request) {
  MappingMetaData mappingMd = null;
  if (metaData.hasIndex(concreteIndex)) {
    mappingMd = metaData.index(concreteIndex).mappingOrDefault(request.type());
  }
  request.process(metaData, mappingMd, allowIdGeneration, concreteIndex);
  ShardId shardId = clusterService.operationRouting().shardId(clusterService.state(), concreteIndex, request.type(), request.id(), request.routing());
  request.setShardId(shardId);
}

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

public static void resolveAndValidateRouting(final MetaData metaData, String concreteIndex, DeleteRequest request) {
  request.routing(metaData.resolveIndexRouting(request.routing(), request.index()));
  if (metaData.hasIndex(concreteIndex)) {
    // check if routing is required, if so, throw error if routing wasn't specified
    MappingMetaData mappingMd = metaData.index(concreteIndex).mappingOrDefault(request.type());
    if (mappingMd != null && mappingMd.routing().required()) {
      if (request.routing() == null) {
        if (request.versionType() != VersionType.INTERNAL) {
          // TODO: implement this feature
          throw new IllegalArgumentException("routing value is required for deleting documents of type [" + request.type()
            + "] while using version_type [" + request.versionType() + "]");
        }
        throw new RoutingMissingException(concreteIndex, request.type(), request.id());
      }
    }
  }
}

相关文章

微信公众号

最新文章

更多