org.elasticsearch.cluster.node.DiscoveryNodes.get()方法的使用及代码示例

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

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

DiscoveryNodes.get介绍

[英]Get a node by its id
[中]通过其id获取节点

代码示例

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

private static List<ShardRouting> collectAttributeShards(AttributesKey key, DiscoveryNodes nodes, ArrayList<ShardRouting> from) {
  final ArrayList<ShardRouting> to = new ArrayList<>();
  for (final String attribute : key.attributes) {
    final String localAttributeValue = nodes.getLocalNode().getAttributes().get(attribute);
    if (localAttributeValue != null) {
      for (Iterator<ShardRouting> iterator = from.iterator(); iterator.hasNext(); ) {
        ShardRouting fromShard = iterator.next();
        final DiscoveryNode discoveryNode = nodes.get(fromShard.currentNodeId());
        if (discoveryNode == null) {
          iterator.remove(); // node is not present anymore - ignore shard
        } else if (localAttributeValue.equals(discoveryNode.getAttributes().get(attribute))) {
          iterator.remove();
          to.add(fromShard);
        }
      }
    }
  }
  return Collections.unmodifiableList(to);
}

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

/**
 * This method collects nodes from the remote clusters asynchronously if any of the scroll IDs references a remote cluster.
 * Otherwise the action listener will be invoked immediately with a function based on the given discovery nodes.
 */
static void collectNodesAndRun(final Iterable<ScrollIdForNode> scrollIds, DiscoveryNodes nodes,
                SearchTransportService searchTransportService,
                ActionListener<BiFunction<String, String, DiscoveryNode>> listener) {
  Set<String> clusters = new HashSet<>();
  for (ScrollIdForNode target : scrollIds) {
    if (target.getClusterAlias() != null) {
      clusters.add(target.getClusterAlias());
    }
  }
  if (clusters.isEmpty()) { // no remote clusters
    listener.onResponse((cluster, node) -> nodes.get(node));
  } else {
    RemoteClusterService remoteClusterService = searchTransportService.getRemoteClusterService();
    remoteClusterService.collectNodes(clusters, ActionListener.wrap(nodeFunction -> {
      final BiFunction<String, String, DiscoveryNode> clusterNodeLookup = (clusterAlias, node) -> {
        if (clusterAlias == null) {
          return nodes.get(node);
        } else {
          return nodeFunction.apply(clusterAlias, node);
        }
      };
      listener.onResponse(clusterNodeLookup);
    }, listener::onFailure));
  }
}

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

this.nodesToShards.put(nodeId, new RoutingNode(nodeId, clusterState.nodes().get(nodeId), entry.getValue()));

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

.filter(shr -> nodes.get(shr.currentNodeId()).getVersion().before(Version.V_6_0_0_alpha1))
.map(ShardRouting::allocationId)
.map(AllocationId::getId)

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

private Table buildTable(RestRequest request, ClusterStateResponse state) {
    Table table = getTableWithHeader(request);
    DiscoveryNodes nodes = state.getState().nodes();

    table.startRow();
    DiscoveryNode master = nodes.get(nodes.getMasterNodeId());
    if (master == null) {
      table.addCell("-");
      table.addCell("-");
      table.addCell("-");
      table.addCell("-");
    } else {
      table.addCell(master.getId());
      table.addCell(master.getHostName());
      table.addCell(master.getHostAddress());
      table.addCell(master.getName());
    }
    table.endRow();

    return table;
  }
}

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

NodeEntry<T> nodeEntry = entry.getValue();
DiscoveryNode node = nodes.get(nodeId);
if (node != null) {
  if (nodeEntry.isFailed()) {

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

/**
 * Finds the store for the assigned shard in the fetched data, returns null if none is found.
 */
private TransportNodesListShardStoreMetaData.StoreFilesMetaData findStore(ShardRouting shard, RoutingAllocation allocation,
                                     AsyncShardFetch.FetchResult<NodeStoreFilesMetaData> data) {
  assert shard.currentNodeId() != null;
  DiscoveryNode primaryNode = allocation.nodes().get(shard.currentNodeId());
  if (primaryNode == null) {
    return null;
  }
  NodeStoreFilesMetaData primaryNodeFilesStore = data.getData().get(primaryNode);
  if (primaryNodeFilesStore == null) {
    return null;
  }
  return primaryNodeFilesStore.storeFilesMetaData();
}

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

/**
 * Finds the routing source node for peer recovery, return null if its not found. Note, this method expects the shard
 * routing to *require* peer recovery, use {@link ShardRouting#recoverySource()} to check if its needed or not.
 */
private static DiscoveryNode findSourceNodeForPeerRecovery(Logger logger, RoutingTable routingTable, DiscoveryNodes nodes,
                              ShardRouting shardRouting) {
  DiscoveryNode sourceNode = null;
  if (!shardRouting.primary()) {
    ShardRouting primary = routingTable.shardRoutingTable(shardRouting.shardId()).primaryShard();
    // only recover from started primary, if we can't find one, we will do it next round
    if (primary.active()) {
      sourceNode = nodes.get(primary.currentNodeId());
      if (sourceNode == null) {
        logger.trace("can't find replica source node because primary shard {} is assigned to an unknown node.", primary);
      }
    } else {
      logger.trace("can't find replica source node because primary shard {} is not active.", primary);
    }
  } else if (shardRouting.relocatingNodeId() != null) {
    sourceNode = nodes.get(shardRouting.relocatingNodeId());
    if (sourceNode == null) {
      logger.trace("can't find relocation source node for shard {} because it is assigned to an unknown node [{}].",
        shardRouting.shardId(), shardRouting.relocatingNodeId());
    }
  } else {
    throw new IllegalStateException("trying to find source node for peer recovery when routing state means no peer recovery: " +
      shardRouting);
  }
  return sourceNode;
}

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

builder.startObject("nodes");
for (Map.Entry<String, List<TaskInfo>> entry : getPerNodeTasks().entrySet()) {
  DiscoveryNode node = discoveryNodes.get(entry.getKey());
  builder.startObject(entry.getKey());
  if (node != null) {

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

final int numDocsOnPrimary = numDocsOnPrimary(shards, preSyncResponses);
for (final ShardRouting shard : shards) {
  final DiscoveryNode node = state.nodes().get(shard.currentNodeId());
  if (node == null) {
    logger.trace("{} is assigned to an unknown node. skipping for sync id [{}]. shard routing {}", shardId, syncId, shard);

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

try {
  final ShardRouting primaryShard = shardRoutingTable.primaryShard();
  final DiscoveryNode primaryNode = state.nodes().get(primaryShard.currentNodeId());
  if (primaryNode == null) {
    logger.trace("{} failed to resolve node for primary shard {}, skipping sync", shardId, primaryShard);

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

for (final ShardRouting shard : shards) {
  logger.trace("{} sending pre-synced flush request to {}", shardId, shard);
  final DiscoveryNode node = state.nodes().get(shard.currentNodeId());
  if (node == null) {
    logger.trace("{} shard routing {} refers to an unknown node. skipping.", shardId, shard);

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

private void deleteShardIfExistElseWhere(ClusterState state, IndexShardRoutingTable indexShardRoutingTable) {
  List<Tuple<DiscoveryNode, ShardActiveRequest>> requests = new ArrayList<>(indexShardRoutingTable.size());
  String indexUUID = indexShardRoutingTable.shardId().getIndex().getUUID();
  ClusterName clusterName = state.getClusterName();
  for (ShardRouting shardRouting : indexShardRoutingTable) {
    assert shardRouting.started() : "expected started shard but was " + shardRouting;
    DiscoveryNode currentNode = state.nodes().get(shardRouting.currentNodeId());
    requests.add(new Tuple<>(currentNode,
      new ShardActiveRequest(clusterName, indexUUID, shardRouting.shardId(), deleteShardTimeout)));
  }
  ShardActiveResponseHandler responseHandler = new ShardActiveResponseHandler(indexShardRoutingTable.shardId(), state.getVersion(),
    requests.size());
  for (Tuple<DiscoveryNode, ShardActiveRequest> request : requests) {
    logger.trace("{} sending shard active check to {}", request.v2().shardId, request.v1());
    transportService.sendRequest(request.v1(), ACTION_SHARD_EXISTS, request.v2(), responseHandler);
  }
}

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

public static ClusterAllocationExplanation explainShard(ShardRouting shardRouting, RoutingAllocation allocation,
                            ClusterInfo clusterInfo, boolean includeYesDecisions,
                            GatewayAllocator gatewayAllocator, ShardsAllocator shardAllocator) {
  allocation.setDebugMode(includeYesDecisions ? DebugMode.ON : DebugMode.EXCLUDE_YES_DECISIONS);
  ShardAllocationDecision shardDecision;
  if (shardRouting.initializing() || shardRouting.relocating()) {
    shardDecision = ShardAllocationDecision.NOT_TAKEN;
  } else {
    AllocateUnassignedDecision allocateDecision = shardRouting.unassigned() ?
      gatewayAllocator.decideUnassignedShardAllocation(shardRouting, allocation) : AllocateUnassignedDecision.NOT_TAKEN;
    if (allocateDecision.isDecisionTaken() == false) {
      shardDecision = shardAllocator.decideShardAllocation(shardRouting, allocation);
    } else {
      shardDecision = new ShardAllocationDecision(allocateDecision, MoveDecision.NOT_TAKEN);
    }
  }
  return new ClusterAllocationExplanation(shardRouting,
    shardRouting.currentNodeId() != null ? allocation.nodes().get(shardRouting.currentNodeId()) : null,
    shardRouting.relocatingNodeId() != null ? allocation.nodes().get(shardRouting.relocatingNodeId()) : null,
    clusterInfo, shardDecision);
}

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

DiscoveryNode currentNode = allocation.nodes().get(shard.currentNodeId());
DiscoveryNode nodeWithHighestMatch = matchingNodes.getNodeWithHighestMatch();

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

int currentNode = 0;
for (String nodeId : nodeIds) {
  nodes[currentNode++] = clusterState.getNodes().get(nodeId);

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

final DiscoveryNode discoveryNode = clusterName == null ? nodes.get(nodeId) : remoteConnections.apply(clusterName, nodeId);
if (discoveryNode == null) {
  throw new IllegalStateException("no node found for id: " + nodeId);

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

private void buildRow(Table table, boolean fullId, boolean detailed, DiscoveryNodes discoveryNodes, TaskInfo taskInfo) {
  table.startRow();
  String nodeId = taskInfo.getTaskId().getNodeId();
  DiscoveryNode node = discoveryNodes.get(nodeId);
  table.addCell(taskInfo.getId());
  table.addCell(taskInfo.getAction());
  table.addCell(taskInfo.getTaskId().toString());
  if (taskInfo.getParentTaskId().isSet()) {
    table.addCell(taskInfo.getParentTaskId().toString());
  } else {
    table.addCell("-");
  }
  table.addCell(taskInfo.getType());
  table.addCell(taskInfo.getStartTime());
  table.addCell(FORMATTER.format(Instant.ofEpochMilli(taskInfo.getStartTime())));
  table.addCell(taskInfo.getRunningTimeNanos());
  table.addCell(TimeValue.timeValueNanos(taskInfo.getRunningTimeNanos()).toString());
  // Node information. Note that the node may be null because it has left the cluster between when we got this response and now.
  table.addCell(fullId ? nodeId : Strings.substring(nodeId, 0, 4));
  table.addCell(node == null ? "-" : node.getHostAddress());
  table.addCell(node.getAddress().address().getPort());
  table.addCell(node == null ? "-" : node.getName());
  table.addCell(node == null ? "-" : node.getVersion().toString());
  if (detailed) {
    table.addCell(taskInfo.getDescription());
  }
  table.endRow();
}

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

table.addCell(shardSegment.getShardRouting().getId());
table.addCell(shardSegment.getShardRouting().primary() ? "p" : "r");
table.addCell(nodes.get(shardSegment.getShardRouting().currentNodeId()).getHostAddress());
table.addCell(shardSegment.getShardRouting().currentNodeId());
table.addCell(segment.getName());

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

builder.withTimeout(request.getTimeout());
DiscoveryNode node = clusterService.state().nodes().get(request.getTaskId().getNodeId());
if (node == null) {

相关文章

微信公众号

最新文章

更多