org.elasticsearch.cluster.ClusterState.getRoutingNodes()方法的使用及代码示例

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

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

ClusterState.getRoutingNodes介绍

[英]Returns a built (on demand) routing nodes view of the routing table.
[中]返回路由表的内置(按需)路由节点视图。

代码示例

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

@Override
  public void clusterStatePublished(ClusterChangedEvent clusterChangedEvent) {
    int numberOfUnassignedShards = clusterChangedEvent.state().getRoutingNodes().unassigned().size();
    if (numberOfUnassignedShards > 0) {
      String reason = String.format(Locale.ROOT, "[%d] unassigned shards after failing shards", numberOfUnassignedShards);
      if (logger.isTraceEnabled()) {
        logger.trace("{}, scheduling a reroute", reason);
      }
      routingService.reroute(reason);
    }
  }
}

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

sb.append(nodes());
sb.append(routingTable());
sb.append(getRoutingNodes());
if (customs.isEmpty() == false) {
  sb.append("customs:\n");

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

/**
 * Removes shard entries from the failed shards cache that are no longer allocated to this node by the master.
 * Sends shard failures for shards that are marked as actively allocated to this node but don't actually exist on the node.
 * Resends shard failures for shards that are still marked as allocated to this node but previously failed.
 *
 * @param state new cluster state
 */
private void updateFailedShardsCache(final ClusterState state) {
  RoutingNode localRoutingNode = state.getRoutingNodes().node(state.nodes().getLocalNodeId());
  if (localRoutingNode == null) {
    failedShardsCache.clear();
    return;
  }
  DiscoveryNode masterNode = state.nodes().getMasterNode();
  // remove items from cache which are not in our routing table anymore and resend failures that have not executed on master yet
  for (Iterator<Map.Entry<ShardId, ShardRouting>> iterator = failedShardsCache.entrySet().iterator(); iterator.hasNext(); ) {
    ShardRouting failedShardRouting = iterator.next().getValue();
    ShardRouting matchedRouting = localRoutingNode.getByShardId(failedShardRouting.shardId());
    if (matchedRouting == null || matchedRouting.isSameAllocation(failedShardRouting) == false) {
      iterator.remove();
    } else {
      if (masterNode != null) { // TODO: can we remove this? Is resending shard failures the responsibility of shardStateAction?
        String message = "master " + masterNode + " has not removed previously failed shard. resending shard failure";
        logger.trace("[{}] re-sending failed shard [{}], reason [{}]", matchedRouting.shardId(), matchedRouting, message);
        shardStateAction.localShardFailed(matchedRouting, message, null, SHARD_STATE_ACTION_LISTENER, state);
      }
    }
  }
}

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

@Override
protected void masterOperation(final ClusterAllocationExplainRequest request, final ClusterState state,
                final ActionListener<ClusterAllocationExplainResponse> listener) {
  final RoutingNodes routingNodes = state.getRoutingNodes();
  final ClusterInfo clusterInfo = clusterInfoService.getClusterInfo();
  final RoutingAllocation allocation = new RoutingAllocation(allocationDeciders, routingNodes, state,
      clusterInfo, System.nanoTime());
  ShardRouting shardRouting = findShardToExplain(request, allocation);
  logger.debug("explaining the allocation for [{}], found shard [{}]", request, shardRouting);
  ClusterAllocationExplanation cae = explainShard(shardRouting, allocation,
    request.includeDiskInfo() ? clusterInfo : null, request.includeYesDecisions(), gatewayAllocator, shardAllocator);
  listener.onResponse(new ClusterAllocationExplainResponse(cae));
}

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

previousClusterState.nodes(),
  previousClusterState.routingTable(),
  previousClusterState.getRoutingNodes()),
e);

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

/**
 * Notifies master about shards that don't exist but are supposed to be active on this node.
 *
 * @param state new cluster state
 */
private void failMissingShards(final ClusterState state) {
  RoutingNode localRoutingNode = state.getRoutingNodes().node(state.nodes().getLocalNodeId());
  if (localRoutingNode == null) {
    return;
  }
  for (final ShardRouting shardRouting : localRoutingNode) {
    ShardId shardId = shardRouting.shardId();
    if (shardRouting.initializing() == false &&
      failedShardsCache.containsKey(shardId) == false &&
      indicesService.getShardOrNull(shardId) == null) {
      // the master thinks we are active, but we don't have this shard at all, mark it as failed
      sendFailShard(shardRouting, "master marked shard as active, but shard has not been created, mark shard as failed", null,
        state);
    }
  }
}

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

public static Set<Index> getRelevantIndicesOnDataOnlyNode(ClusterState state, ClusterState previousState,
                             Set<Index> previouslyWrittenIndices) {
  RoutingNode newRoutingNode = state.getRoutingNodes().node(state.nodes().getLocalNodeId());
  if (newRoutingNode == null) {
    throw new IllegalStateException("cluster state does not contain this node - cannot write index meta state");
  }
  Set<Index> indices = new HashSet<>();
  for (ShardRouting routing : newRoutingNode) {
    indices.add(routing.index());
  }
  // we have to check the meta data also: closed indices will not appear in the routing table, but we must still write the state if
  // we have it written on disk previously
  for (IndexMetaData indexMetaData : state.metaData()) {
    boolean isOrWasClosed = indexMetaData.getState().equals(IndexMetaData.State.CLOSE);
    // if the index is open we might still have to write the state if it just transitioned from closed to open
    // so we have to check for that as well.
    IndexMetaData previousMetaData = previousState.metaData().index(indexMetaData.getIndex());
    if (previousMetaData != null) {
      isOrWasClosed = isOrWasClosed || previousMetaData.getState().equals(IndexMetaData.State.CLOSE);
    }
    if (previouslyWrittenIndices.contains(indexMetaData.getIndex()) && isOrWasClosed) {
      indices.add(indexMetaData.getIndex());
    }
  }
  return indices;
}

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

RoutingNode localRoutingNode = state.getRoutingNodes().node(localNodeId);
if (localRoutingNode != null) { // null e.g. if we are not a data node
  for (ShardRouting shardRouting : localRoutingNode) {

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

@Override
protected void masterOperation(IndicesShardStoresRequest request, ClusterState state,
                ActionListener<IndicesShardStoresResponse> listener) {
  final RoutingTable routingTables = state.routingTable();
  final RoutingNodes routingNodes = state.getRoutingNodes();
  final String[] concreteIndices = indexNameExpressionResolver.concreteIndexNames(state, request);
  final Set<ShardId> shardIdsToFetch = new HashSet<>();
  logger.trace("using cluster state version [{}] to determine shards", state.version());
  // collect relevant shard ids of the requested indices for fetching store infos
  for (String index : concreteIndices) {
    IndexRoutingTable indexShardRoutingTables = routingTables.index(index);
    if (indexShardRoutingTables == null) {
      continue;
    }
    for (IndexShardRoutingTable routing : indexShardRoutingTables) {
      final int shardId = routing.shardId().id();
      ClusterShardHealth shardHealth = new ClusterShardHealth(shardId, routing);
      if (request.shardStatuses().contains(shardHealth.getStatus())) {
        shardIdsToFetch.add(routing.shardId());
      }
    }
  }
  // async fetch store infos from all the nodes
  // NOTE: instead of fetching shard store info one by one from every node (nShards * nNodes requests)
  // we could fetch all shard store info from every node once (nNodes requests)
  // we have to implement a TransportNodesAction instead of using TransportNodesListGatewayStartedShards
  // for fetching shard stores info, that operates on a list of shards instead of a single shard
  new AsyncShardStoresInfoFetches(state.nodes(), routingNodes, shardIdsToFetch, listener).start();
}

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

private void createIndices(final ClusterState state) {
  RoutingNode localRoutingNode = state.getRoutingNodes().node(state.nodes().getLocalNodeId());
  if (localRoutingNode == null) {
    return;

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

builder.startObject("routing_nodes");
builder.startArray("unassigned");
for (ShardRouting shardRouting : getRoutingNodes().unassigned()) {
  shardRouting.toXContent(builder, params);
for (RoutingNode routingNode : getRoutingNodes()) {
  builder.startArray(routingNode.nodeId() == null ? "null" : routingNode.nodeId());
  for (ShardRouting shardRouting : routingNode) {

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

if (usage.getFreeBytes() < diskThresholdSettings.getFreeBytesThresholdFloodStage().getBytes() ||
  usage.getFreeDiskAsPercentage() < diskThresholdSettings.getFreeDiskThresholdFloodStage()) {
  RoutingNode routingNode = state.getRoutingNodes().node(node);
  if (routingNode != null) { // this might happen if we haven't got the full cluster-state yet?!
    for (ShardRouting routing : routingNode) {

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

previousClusterState.nodes(),
  previousClusterState.routingTable(),
  previousClusterState.getRoutingNodes()),
e);

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

private void createOrUpdateShards(final ClusterState state) {
  RoutingNode localRoutingNode = state.getRoutingNodes().node(state.nodes().getLocalNodeId());
  if (localRoutingNode == null) {
    return;
  }
  DiscoveryNodes nodes = state.nodes();
  RoutingTable routingTable = state.routingTable();
  for (final ShardRouting shardRouting : localRoutingNode) {
    ShardId shardId = shardRouting.shardId();
    if (failedShardsCache.containsKey(shardId) == false) {
      AllocatedIndex<? extends Shard> indexService = indicesService.indexService(shardId.getIndex());
      assert indexService != null : "index " + shardId.getIndex() + " should have been created by createIndices";
      Shard shard = indexService.getShardOrNull(shardId.id());
      if (shard == null) {
        assert shardRouting.initializing() : shardRouting + " should have been removed by failMissingShards";
        createShard(nodes, routingTable, shardRouting, state);
      } else {
        updateShard(nodes, shardRouting, shard, routingTable, state);
      }
    }
  }
}

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

RoutingNode localRoutingNode = state.getRoutingNodes().node(localNodeId);
for (AllocatedIndex<? extends Shard> indexService : indicesService) {
  for (Shard shard : indexService) {

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

RoutingNode localRoutingNode = event.state().getRoutingNodes().node(localNodeId);
if (localRoutingNode != null) {
  for (ShardRouting routing : localRoutingNode) {

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

protected ClusterState applyStartedShardsUntilNoChange(ClusterState clusterState, AllocationService service) {
  ClusterState lastClusterState;
  do {
    lastClusterState = clusterState;
    logger.debug("ClusterState: {}", clusterState.getRoutingNodes());
    clusterState = service.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
  } while (lastClusterState.equals(clusterState) == false);
  return clusterState;
}

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

RoutingNode localRoutingNode = state.getRoutingNodes().node(state.nodes().getLocalNodeId());
if (localRoutingNode != null) {
  for (final ShardRouting shardRouting : localRoutingNode) {

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

protected  static ClusterState startRandomInitializingShard(ClusterState clusterState, AllocationService strategy) {
  List<ShardRouting> initializingShards = clusterState.getRoutingNodes().shardsWithState(INITIALIZING);
  if (initializingShards.isEmpty()) {
    return clusterState;
  }
  return strategy.applyStartedShards(clusterState,
    arrayAsArrayList(initializingShards.get(randomInt(initializingShards.size() - 1))));
}

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

@Override
  public void clusterStatePublished(ClusterChangedEvent clusterChangedEvent) {
    int numberOfUnassignedShards = clusterChangedEvent.state().getRoutingNodes().unassigned().size();
    if (numberOfUnassignedShards > 0) {
      String reason = String.format(Locale.ROOT, "[%d] unassigned shards after failing shards", numberOfUnassignedShards);
      if (logger.isTraceEnabled()) {
        logger.trace("{}, scheduling a reroute", reason);
      }
      routingService.reroute(reason);
    }
  }
}

相关文章