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

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

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

DiscoveryNodes.nodeExists介绍

[英]Determine if a given node exists
[中]确定给定节点是否存在

代码示例

代码示例来源:origin: floragunncom/search-guard

public Boolean hasNode(DiscoveryNode node) {
  if(nodes == null) {
    if(log.isDebugEnabled()) {
      log.debug("Cluster Info Holder not initialized yet for 'nodes'");
    }
    return null;
  }
  
  return nodes.nodeExists(node)?Boolean.TRUE:Boolean.FALSE;
}

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

@Override
public ClusterState execute(ClusterState currentState) throws Exception {
  // if we are no longer master, fail...
  DiscoveryNodes nodes = currentState.nodes();
  if (!nodes.nodeExists(request.sourceNode)) {
    throw new NodeDoesNotExistOnMasterException();
  }
  return currentState;
}

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

/** Returns true if the task is not assigned or is assigned to a non-existing node */
public static boolean needsReassignment(final Assignment assignment, final DiscoveryNodes nodes) {
  return (assignment.isAssigned() == false || nodes.nodeExists(assignment.getExecutorNode()) == false);
}

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

/**
 * Returns the changes comparing this nodes to the provided nodes.
 */
public Delta delta(DiscoveryNodes other) {
  List<DiscoveryNode> removed = new ArrayList<>();
  List<DiscoveryNode> added = new ArrayList<>();
  for (DiscoveryNode node : other) {
    if (!this.nodeExists(node)) {
      removed.add(node);
    }
  }
  for (DiscoveryNode node : this) {
    if (!other.nodeExists(node)) {
      added.add(node);
    }
  }
  DiscoveryNode previousMasterNode = null;
  DiscoveryNode newMasterNode = null;
  if (masterNodeId != null) {
    if (other.masterNodeId == null || !other.masterNodeId.equals(masterNodeId)) {
      previousMasterNode = other.getMasterNode();
      newMasterNode = getMasterNode();
    }
  }
  return new Delta(previousMasterNode, newMasterNode, localNodeId, Collections.unmodifiableList(removed),
    Collections.unmodifiableList(added));
}

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

/**
 * Fills the shard fetched data with new (data) nodes and a fresh NodeEntry, and removes from
 * it nodes that are no longer part of the state.
 */
private void fillShardCacheWithDataNodes(Map<String, NodeEntry<T>> shardCache, DiscoveryNodes nodes) {
  // verify that all current data nodes are there
  for (ObjectObjectCursor<String, DiscoveryNode> cursor : nodes.getDataNodes()) {
    DiscoveryNode node = cursor.value;
    if (shardCache.containsKey(node.getId()) == false) {
      shardCache.put(node.getId(), new NodeEntry<T>(node.getId()));
    }
  }
  // remove nodes that are not longer part of the data nodes set
  shardCache.keySet().removeIf(nodeId -> !nodes.nodeExists(nodeId));
}

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

/**
 * Bans all tasks with the specified parent task from execution, cancels all tasks that are currently executing.
 * <p>
 * This method is called when a parent task that has children is cancelled.
 */
public void setBan(TaskId parentTaskId, String reason) {
  logger.trace("setting ban for the parent task {} {}", parentTaskId, reason);
  // Set the ban first, so the newly created tasks cannot be registered
  synchronized (banedParents) {
    if (lastDiscoveryNodes.nodeExists(parentTaskId.getNodeId())) {
      // Only set the ban if the node is the part of the cluster
      banedParents.put(parentTaskId, reason);
    }
  }
  // Now go through already running tasks and cancel them
  for (Map.Entry<Long, CancellableTaskHolder> taskEntry : cancellableTasks.entrySet()) {
    CancellableTaskHolder holder = taskEntry.getValue();
    if (holder.hasParent(parentTaskId)) {
      holder.cancel(reason);
    }
  }
}

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

/**
 * make sure that nodes in clusterState are pinged. Any pinging to nodes which are not
 * part of the cluster will be stopped
 */
public void updateNodesAndPing(ClusterState clusterState) {
  // remove any nodes we don't need, this will cause their FD to stop
  for (DiscoveryNode monitoredNode : nodesFD.keySet()) {
    if (!clusterState.nodes().nodeExists(monitoredNode)) {
      nodesFD.remove(monitoredNode);
    }
  }
  // add any missing nodes
  for (DiscoveryNode node : clusterState.nodes()) {
    if (node.equals(localNode)) {
      // no need to monitor the local node
      continue;
    }
    if (!nodesFD.containsKey(node)) {
      NodeFD fd = new NodeFD(node);
      // it's OK to overwrite an existing nodeFD - it will just stop and the new one will pick things up.
      nodesFD.put(node, fd);
      // we use schedule with a 0 time value to run the pinger on the pool as it will run on later
      threadPool.schedule(TimeValue.timeValueMillis(0), ThreadPool.Names.SAME, fd);
    }
  }
}

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

@Override
public void applyClusterState(ClusterChangedEvent event) {
  lastDiscoveryNodes = event.state().getNodes();
  if (event.nodesRemoved()) {
    synchronized (banedParents) {
      lastDiscoveryNodes = event.state().getNodes();
      // Remove all bans that were registered by nodes that are no longer in the cluster state
      Iterator<TaskId> banIterator = banedParents.keySet().iterator();
      while (banIterator.hasNext()) {
        TaskId taskId = banIterator.next();
        if (lastDiscoveryNodes.nodeExists(taskId.getNodeId()) == false) {
          logger.debug("Removing ban for the parent [{}] on the node [{}], reason: the parent node is gone", taskId,
            event.state().getNodes().getLocalNode());
          banIterator.remove();
        }
      }
    }
    // Cancel cancellable tasks for the nodes that are gone
    for (Map.Entry<Long, CancellableTaskHolder> taskEntry : cancellableTasks.entrySet()) {
      CancellableTaskHolder holder = taskEntry.getValue();
      CancellableTask task = holder.getTask();
      TaskId parentTaskId = task.getParentTaskId();
      if (parentTaskId.isSet() && lastDiscoveryNodes.nodeExists(parentTaskId.getNodeId()) == false) {
        if (task.cancelOnParentLeaving()) {
          holder.cancel("Coordinating node [" + parentTaskId.getNodeId() + "] left the cluster");
        }
      }
    }
  }
}

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

private void buildDiffAndSerializeStates(ClusterState clusterState, ClusterState previousState, Set<DiscoveryNode> nodesToPublishTo,
                     boolean sendFullVersion, Map<Version, BytesReference> serializedStates,
                     Map<Version, BytesReference> serializedDiffs) {
  Diff<ClusterState> diff = null;
  for (final DiscoveryNode node : nodesToPublishTo) {
    try {
      if (sendFullVersion || !previousState.nodes().nodeExists(node)) {
        // will send a full reference
        if (serializedStates.containsKey(node.getVersion()) == false) {
          serializedStates.put(node.getVersion(), serializeFullClusterState(clusterState, node.getVersion()));
        }
      } else {
        // will send a diff
        if (diff == null) {
          diff = clusterState.diff(previousState);
        }
        if (serializedDiffs.containsKey(node.getVersion()) == false) {
          serializedDiffs.put(node.getVersion(), serializeDiffClusterState(diff, node.getVersion()));
        }
      }
    } catch (IOException e) {
      throw new ElasticsearchException("failed to serialize cluster_state for publishing to node {}", e, node);
    }
  }
}

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

if (sendFullVersion || !previousState.nodes().nodeExists(node)) {
  sendFullClusterState(clusterState, serializedStates, node, publishTimeout, sendingController);
} else {

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

if (!nodes.isLocalNodeElectedMaster() || !nodes.nodeExists(request.sourceNode)) {
  logger.trace("checking ping from {} under a cluster state thread", request.sourceNode);
  masterService.submitStateUpdateTask("master ping (from: " + request.sourceNode + ")", new ClusterStateUpdateTask() {

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

resolvedNodesIds.add(masterNodeId);
} else if (nodeExists(nodeId)) {
  resolvedNodesIds.add(nodeId);
} else {

代码示例来源:origin: com.floragunn/search-guard-6

public Boolean hasNode(DiscoveryNode node) {
  if(nodes == null) {
    if(log.isDebugEnabled()) {
      log.debug("Cluster Info Holder not initialized yet for 'nodes'");
    }
    return null;
  }
  
  return nodes.nodeExists(node)?Boolean.TRUE:Boolean.FALSE;
}

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

@Override
public ClusterTasksResult<Task> execute(final ClusterState currentState, final List<Task> tasks) throws Exception {
  final DiscoveryNodes.Builder remainingNodesBuilder = DiscoveryNodes.builder(currentState.nodes());
  boolean removed = false;
  for (final Task task : tasks) {
    if (currentState.nodes().nodeExists(task.node())) {
      remainingNodesBuilder.remove(task.node());
      removed = true;
    } else {
      logger.debug("node [{}] does not exist in cluster state, ignoring", task);
    }
  }
  if (!removed) {
    // no nodes to remove, keep the current cluster state
    return ClusterTasksResult.<Task>builder().successes(tasks).build(currentState);
  }
  final ClusterState remainingNodesClusterState = remainingNodesClusterState(currentState, remainingNodesBuilder);
  final ClusterTasksResult.Builder<Task> resultBuilder = ClusterTasksResult.<Task>builder().successes(tasks);
  if (electMasterService.hasEnoughMasterNodes(remainingNodesClusterState.nodes()) == false) {
    final int masterNodes = electMasterService.countMasterNodes(remainingNodesClusterState.nodes());
    rejoin.accept(LoggerMessageFormat.format("not enough master nodes (has [{}], but needed [{}])",
                         masterNodes, electMasterService.minimumMasterNodes()));
    return resultBuilder.build(currentState);
  } else {
    return resultBuilder.build(allocationService.deassociateDeadNodes(remainingNodesClusterState, true, describeTasks(tasks)));
  }
}

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

ShardSnapshotStatus shardStatus = shardEntry.value;
if (!shardStatus.state().completed() && shardStatus.nodeId() != null) {
  if (nodes.nodeExists(shardStatus.nodeId())) {
    shards.put(shardEntry.key, shardEntry.value);
  } else {

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

if (node.equals(BECOME_MASTER_TASK) || node.equals(FINISH_ELECTION_TASK)) {
} else if (currentNodes.nodeExists(node)) {
  logger.debug("received a join request for an existing node [{}]", node);
} else {

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

@Override
public ClusterState execute(ClusterState currentState) throws Exception {
  // if we are no longer master, fail...
  DiscoveryNodes nodes = currentState.nodes();
  if (!nodes.nodeExists(request.sourceNode)) {
    throw new NodeDoesNotExistOnMasterException();
  }
  return currentState;
}

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

@Override
public ClusterState execute(ClusterState currentState) throws Exception {
  // if we are no longer master, fail...
  DiscoveryNodes nodes = currentState.nodes();
  if (!nodes.nodeExists(request.sourceNode)) {
    throw new NodeDoesNotExistOnMasterException();
  }
  return currentState;
}

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

@Override
public ClusterState execute(ClusterState currentState) throws Exception {
  // if we are no longer master, fail...
  DiscoveryNodes nodes = currentState.nodes();
  if (!nodes.nodeExists(request.sourceNode)) {
    throw new NodeDoesNotExistOnMasterException();
  }
  return currentState;
}

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

@Override
public ClusterState execute(ClusterState currentState) throws Exception {
  // if we are no longer master, fail...
  DiscoveryNodes nodes = currentState.nodes();
  if (!nodes.localNodeMaster()) {
    throw new NotMasterException("local node is not master");
  }
  if (!nodes.nodeExists(request.nodeId)) {
    throw new NodeDoesNotExistOnMasterException();
  }
  return currentState;
}

相关文章

微信公众号

最新文章

更多