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

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

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

MetaData.getIndexSafe介绍

[英]Returns the IndexMetaData for this index.
[中]返回此索引的IndexMetaData。

代码示例

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

@Override
  protected Settings getIndexSettings(Index index) {
    IndexMetaData indexMetaData = allocation.metaData().getIndexSafe(index);
    return indexMetaData.getSettings();
  }
};

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

/**
 * Returns <code>true</code> iff all replicas are active for the given shard routing. Otherwise <code>false</code>
 */
public boolean allReplicasActive(ShardId shardId, MetaData metaData) {
  final List<ShardRouting> shards = assignedShards(shardId);
  if (shards.isEmpty() || shards.size() < metaData.getIndexSafe(shardId.getIndex()).getNumberOfReplicas() + 1) {
    return false; // if we are empty nothing is active if we have less than total at least one is unassigned
  }
  for (ShardRouting shard : shards) {
    if (!shard.active()) {
      return false;
    }
  }
  return true;
}

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

for (Map.Entry<Index, List<Map.Entry<ShardId, Updates>>> indexChanges : changesGroupedByIndex.entrySet()) {
  Index index = indexChanges.getKey();
  final IndexMetaData oldIndexMetaData = oldMetaData.getIndexSafe(index);
  IndexMetaData.Builder indexMetaDataBuilder = null;
  for (Map.Entry<ShardId, Updates> shardEntry : indexChanges.getValue()) {

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

private Decision shouldFilter(ShardRouting shardRouting, RoutingNode node, RoutingAllocation allocation) {
  Decision decision = shouldClusterFilter(node, allocation);
  if (decision != null) return decision;
  decision = shouldIndexFilter(allocation.metaData().getIndexSafe(shardRouting.index()), node, allocation);
  if (decision != null) return decision;
  return allocation.decision(Decision.YES, NAME, "node passes include/exclude/require filters");
}

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

List<GatewayMetaState.IndexMetaWriteInfo> indicesToWrite = new ArrayList<>();
for (Index index : potentiallyUnwrittenIndices) {
  IndexMetaData newIndexMetaData = newMetaData.getIndexSafe(index);
  IndexMetaData previousIndexMetaData = previousMetaData == null ? null : previousMetaData.index(index);
  String writeReason = null;

代码示例来源: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

@Override
  public void onFailure(Exception e) {
    logger.trace("{}: got failure from {}", actionName, shardId);
    int totalNumCopies = clusterState.getMetaData().getIndexSafe(shardId.getIndex()).getNumberOfReplicas() + 1;
    ShardResponse shardResponse = newShardResponse();
    ReplicationResponse.ShardInfo.Failure[] failures;
    if (TransportActions.isShardNotAvailableException(e)) {
      failures = new ReplicationResponse.ShardInfo.Failure[0];
    } else {
      ReplicationResponse.ShardInfo.Failure failure = new ReplicationResponse.ShardInfo.Failure(shardId, null, e,
        ExceptionsHelper.status(e), true);
      failures = new ReplicationResponse.ShardInfo.Failure[totalNumCopies];
      Arrays.fill(failures, failure);
    }
    shardResponse.setShardInfo(new ReplicationResponse.ShardInfo(totalNumCopies, 0, failures));
    shardsResponses.add(shardResponse);
    if (responsesCountDown.countDown()) {
      finishAndNotifyListener(listener, shardsResponses);
    }
  }
};

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

@Override
public ClusterTasksResult<PutMappingClusterStateUpdateRequest>
execute(ClusterState currentState, List<PutMappingClusterStateUpdateRequest> tasks) throws Exception {
  Map<Index, MapperService> indexMapperServices = new HashMap<>();
  ClusterTasksResult.Builder<PutMappingClusterStateUpdateRequest> builder = ClusterTasksResult.builder();
  try {
    for (PutMappingClusterStateUpdateRequest request : tasks) {
      try {
        for (Index index : request.indices()) {
          final IndexMetaData indexMetaData = currentState.metaData().getIndexSafe(index);
          if (indexMapperServices.containsKey(indexMetaData.getIndex()) == false) {
            MapperService mapperService = indicesService.createIndexMapperService(indexMetaData);
            indexMapperServices.put(index, mapperService);
            // add mappings for all types, we need them for cross-type validation
            mapperService.merge(indexMetaData, MergeReason.MAPPING_RECOVERY, request.updateAllTypes());
          }
        }
        currentState = applyRequest(currentState, request, indexMapperServices);
        builder.success(request);
      } catch (Exception e) {
        builder.failure(request, e);
      }
    }
    return builder.build(currentState);
  } finally {
    IOUtils.close(indexMapperServices.values());
  }
}

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

private void deassociateDeadNodes(RoutingAllocation allocation) {
  for (Iterator<RoutingNode> it = allocation.routingNodes().mutableIterator(); it.hasNext(); ) {
    RoutingNode node = it.next();
    if (allocation.nodes().getDataNodes().containsKey(node.nodeId())) {
      // its a live node, continue
      continue;
    }
    // now, go over all the shards routing on the node, and fail them
    for (ShardRouting shardRouting : node.copyShards()) {
      final IndexMetaData indexMetaData = allocation.metaData().getIndexSafe(shardRouting.index());
      boolean delayed = INDEX_DELAYED_NODE_LEFT_TIMEOUT_SETTING.get(indexMetaData.getSettings()).nanos() > 0;
      UnassignedInfo unassignedInfo = new UnassignedInfo(UnassignedInfo.Reason.NODE_LEFT, "node_left[" + node.nodeId() + "]",
        null, 0, allocation.getCurrentNanoTime(), System.currentTimeMillis(), delayed, AllocationStatus.NO_ATTEMPT);
      allocation.routingNodes().failShard(logger, shardRouting, unassignedInfo, indexMetaData, allocation.changes());
    }
    // its a dead node, remove it, note, its important to remove it *after* we apply failed shard
    // since it relies on the fact that the RoutingNode exists in the list of nodes
    it.remove();
  }
}

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

private boolean addFailureIfIndexIsUnavailable(DocWriteRequest request, int idx, final ConcreteIndices concreteIndices,
    final MetaData metaData) {
  IndexNotFoundException cannotCreate = indicesThatCannotBeCreated.get(request.index());
  if (cannotCreate != null) {
    addFailure(request, idx, cannotCreate);
    return true;
  }
  Index concreteIndex = concreteIndices.getConcreteIndex(request.index());
  if (concreteIndex == null) {
    try {
      concreteIndex = concreteIndices.resolveIfAbsent(request);
    } catch (IndexClosedException | IndexNotFoundException ex) {
      addFailure(request, idx, ex);
      return true;
    }
  }
  IndexMetaData indexMetaData = metaData.getIndexSafe(concreteIndex);
  if (indexMetaData.getState() == IndexMetaData.State.CLOSE) {
    addFailure(request, idx, new IndexClosedException(concreteIndex));
    return true;
  }
  return false;
}

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

@Override
public Decision canAllocate(ShardRouting shardRouting, RoutingNode node, RoutingAllocation allocation) {
  if (shardRouting.unassigned()) {
    // only for unassigned - we filter allocation right after the index creation ie. for shard shrinking etc. to ensure
    // that once it has been allocated post API the replicas can be allocated elsewhere without user interaction
    // this is a setting that can only be set within the system!
    IndexMetaData indexMd = allocation.metaData().getIndexSafe(shardRouting.index());
    DiscoveryNodeFilters initialRecoveryFilters = indexMd.getInitialRecoveryFilters();
    if (initialRecoveryFilters != null  &&
      INITIAL_RECOVERY_TYPES.contains(shardRouting.recoverySource().getType()) &&
      initialRecoveryFilters.match(node.node()) == false) {
      String explanation = (shardRouting.recoverySource().getType() == RecoverySource.Type.LOCAL_SHARDS) ?
        "initial allocation of the shrunken index is only allowed on nodes [%s] that hold a copy of every shard in the index" :
        "initial allocation of the index is only allowed on nodes [%s]";
      return allocation.decision(Decision.NO, NAME, explanation, initialRecoveryFilters);
    }
  }
  return shouldFilter(shardRouting, node, allocation);
}

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

private Decision doDecide(ShardRouting shardRouting, RoutingNode node, RoutingAllocation allocation,
             BiPredicate<Integer, Integer> decider) {
  IndexMetaData indexMd = allocation.metaData().getIndexSafe(shardRouting.index());
  final int indexShardLimit = INDEX_TOTAL_SHARDS_PER_NODE_SETTING.get(indexMd.getSettings(), settings);

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

@Override
public Decision canAllocate(ShardRouting shardRouting, RoutingAllocation allocation) {
  final UnassignedInfo unassignedInfo = shardRouting.unassignedInfo();
  final Decision decision;
  if (unassignedInfo != null && unassignedInfo.getNumFailedAllocations() > 0) {
    final IndexMetaData indexMetaData = allocation.metaData().getIndexSafe(shardRouting.index());
    final int maxRetry = SETTING_ALLOCATION_MAX_RETRY.get(indexMetaData.getSettings());
    if (unassignedInfo.getNumFailedAllocations() >= maxRetry) {
      decision = allocation.decision(Decision.NO, NAME, "shard has exceeded the maximum number of retries [%d] on " +
        "failed allocation attempts - manually call [/_cluster/reroute?retry_failed=true] to retry, [%s]",
        maxRetry, unassignedInfo.toString());
    } else {
      decision = allocation.decision(Decision.YES, NAME, "shard has failed allocating [%d] times but [%d] retries are allowed",
        unassignedInfo.getNumFailedAllocations(), maxRetry);
    }
  } else {
    decision = allocation.decision(Decision.YES, NAME, "shard has no previous failures");
  }
  return decision;
}

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

public ClusterState closeIndices(ClusterState currentState, final Index[] indices, String indicesAsString) {
  Set<IndexMetaData> indicesToClose = new HashSet<>();
  for (Index index : indices) {
    final IndexMetaData indexMetaData = currentState.metaData().getIndexSafe(index);
    if (indexMetaData.getState() != IndexMetaData.State.CLOSE) {
      indicesToClose.add(indexMetaData);

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

List<IndexMetaData> indicesToOpen = new ArrayList<>();
for (Index index : request.indices()) {
  final IndexMetaData indexMetaData = currentState.metaData().getIndexSafe(index);
  if (indexMetaData.getState() != IndexMetaData.State.OPEN) {
    indicesToOpen.add(indexMetaData);
  rtBuilder.addAsFromCloseToOpen(updatedState.metaData().getIndexSafe(index.getIndex()));

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

Settings indexSettings = allocation.metaData().getIndexSafe(shardRouting.index()).getSettings();
final Rebalance enable;
final boolean usedIndexSetting;

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

/**
   * Returns the expected shard size for the given shard or the default value provided if not enough information are available
   * to estimate the shards size.
   */
  public static long getExpectedShardSize(ShardRouting shard, RoutingAllocation allocation, long defaultValue) {
    final IndexMetaData metaData = allocation.metaData().getIndexSafe(shard.index());
    final ClusterInfo info = allocation.clusterInfo();
    if (metaData.getResizeSourceIndex() != null && shard.active() == false &&
      shard.recoverySource().getType() == RecoverySource.Type.LOCAL_SHARDS) {
      // in the shrink index case we sum up the source index shards since we basically make a copy of the shard in
      // the worst case
      long targetShardSize = 0;
      final Index mergeSourceIndex = metaData.getResizeSourceIndex();
      final IndexMetaData sourceIndexMeta = allocation.metaData().index(mergeSourceIndex);
      if (sourceIndexMeta != null) {
        final Set<ShardId> shardIds = IndexMetaData.selectRecoverFromShards(shard.id(),
          sourceIndexMeta, metaData.getNumberOfShards());
        for (IndexShardRoutingTable shardRoutingTable : allocation.routingTable().index(mergeSourceIndex.getName())) {
          if (shardIds.contains(shardRoutingTable.shardId())) {
            targetShardSize += info.getShardSize(shardRoutingTable.primaryShard(), 0);
          }
        }
      }
      return targetShardSize == 0 ? defaultValue : targetShardSize;
    } else {
      return info.getShardSize(shard, defaultValue);
    }

  }
}

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

if (unassignedInfo != null && shardRouting.recoverySource().getType() == RecoverySource.Type.LOCAL_SHARDS) {
  final IndexMetaData indexMetaData = allocation.metaData().getIndexSafe(shardRouting.index());
  Index resizeSourceIndex = indexMetaData.getResizeSourceIndex();
  assert resizeSourceIndex != null;
    return allocation.decision(Decision.NO, NAME, "resize source index [%s] doesn't exists", resizeSourceIndex.toString());
  IndexMetaData sourceIndexMetaData = allocation.metaData().getIndexSafe(resizeSourceIndex);
  if (indexMetaData.getNumberOfShards() < sourceIndexMetaData.getNumberOfShards()) {

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

final IndexMetaData indexMetaData = allocation.metaData().getIndexSafe(shardRouting.index());
final Allocation enable;
final boolean usedIndexSetting;

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

/**
 * Removes delay markers from unassigned shards based on current time stamp.
 */
private void removeDelayMarkers(RoutingAllocation allocation) {
  final RoutingNodes.UnassignedShards.UnassignedIterator unassignedIterator = allocation.routingNodes().unassigned().iterator();
  final MetaData metaData = allocation.metaData();
  while (unassignedIterator.hasNext()) {
    ShardRouting shardRouting = unassignedIterator.next();
    UnassignedInfo unassignedInfo = shardRouting.unassignedInfo();
    if (unassignedInfo.isDelayed()) {
      final long newComputedLeftDelayNanos = unassignedInfo.getRemainingDelay(allocation.getCurrentNanoTime(),
        metaData.getIndexSafe(shardRouting.index()).getSettings());
      if (newComputedLeftDelayNanos == 0) {
        unassignedIterator.updateUnassigned(new UnassignedInfo(unassignedInfo.getReason(), unassignedInfo.getMessage(),
          unassignedInfo.getFailure(), unassignedInfo.getNumFailedAllocations(), unassignedInfo.getUnassignedTimeInNanos(),
          unassignedInfo.getUnassignedTimeInMillis(), false, unassignedInfo.getLastAllocationStatus()),
          shardRouting.recoverySource(), allocation.changes());
      }
    }
  }
}

相关文章

微信公众号

最新文章

更多