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

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

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

ClusterState.nodes介绍

暂无

代码示例

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

private static boolean clusterHas5xNodes(ClusterState state) {
  return state.nodes().getMinNodeVersion().before(Version.V_6_0_0_alpha1);
}

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

@Override
public void clusterChanged(ClusterChangedEvent event) {
  if(has5xNodes == null || event.nodesChanged()) {
    has5xNodes = Boolean.valueOf(clusterHas5xNodes(event.state()));
    if(log.isTraceEnabled()) {
      log.trace("has5xNodes: {}", has5xNodes);
    }
  }
  
  final List<String> indicesCreated = event.indicesCreated();
  final List<Index> indicesDeleted = event.indicesDeleted();
  if(has5xIndices == null || !indicesCreated.isEmpty() || !indicesDeleted.isEmpty()) {
    has5xIndices = Boolean.valueOf(clusterHas5xIndices(event.state()));
    if(log.isTraceEnabled()) {
      log.trace("has5xIndices: {}", has5xIndices);
    }
  }
  
  if(nodes == null || event.nodesChanged()) {
    nodes = event.state().nodes();
    if(log.isDebugEnabled()) {
      log.debug("Cluster Info Holder now initialized for 'nodes'");
    }
  }
  
  isLocalNodeElectedMaster = event.localNodeMaster()?Boolean.TRUE:Boolean.FALSE;
}

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

public ClusterChangedEvent(String source, ClusterState state, ClusterState previousState) {
  Objects.requireNonNull(source, "source must not be null");
  Objects.requireNonNull(state, "state must not be null");
  Objects.requireNonNull(previousState, "previousState must not be null");
  this.source = source;
  this.state = state;
  this.previousState = previousState;
  this.nodesDelta = state.nodes().delta(previousState.nodes());
}

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

/**
 * Returns <code>true</code> iff the local node is the mater node of the cluster.
 */
public boolean localNodeMaster() {
  return state.nodes().isLocalNodeElectedMaster();
}

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

/**
 * resolve node ids to concrete nodes of the incoming request
 **/
protected void resolveRequest(NodesRequest request, ClusterState clusterState) {
  assert request.concreteNodes() == null : "request concreteNodes shouldn't be set";
  String[] nodesIds = clusterState.nodes().resolveNodes(request.nodesIds());
  request.setConcreteNodes(Arrays.stream(nodesIds).map(clusterState.nodes()::get).toArray(DiscoveryNode[]::new));
}

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

/**
 * a cluster state supersedes another state if they are from the same master and the version of this state is higher than that of the
 * other state.
 * <p>
 * In essence that means that all the changes from the other cluster state are also reflected by the current one
 */
public boolean supersedes(ClusterState other) {
  return this.nodes().getMasterNodeId() != null && this.nodes().getMasterNodeId().equals(other.nodes().getMasterNodeId())
    && this.version() > other.version();
}

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

@Override
protected void doExecute(ClearScrollRequest request, final ActionListener<ClearScrollResponse> listener) {
  Runnable runnable = new ClearScrollController(request, listener, clusterService.state().nodes(), logger, searchTransportService);
  runnable.run();
}

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

/**
   * returns true if stored state is older then given state or they are from a different master, meaning they can't be compared
   * */
  public boolean isOlderOrDifferentMaster(ClusterState clusterState) {
    return version < clusterState.version() || Objects.equals(masterNodeId, clusterState.nodes().getMasterNodeId()) == false;
  }
}

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

public Discovery.AckListener createAckListener(ThreadPool threadPool, ClusterState newClusterState) {
  return new DelegatingAckListener(nonFailedTasks.stream()
    .filter(task -> task.listener instanceof AckedClusterStateTaskListener)
    .map(task -> new AckCountDownListener((AckedClusterStateTaskListener) task.listener, newClusterState.version(),
      newClusterState.nodes(), threadPool))
    .collect(Collectors.toList()));
}

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

public ShardIterator getShards(ClusterState clusterState, String index, int shardId, @Nullable String preference) {
  final IndexShardRoutingTable indexShard = clusterState.getRoutingTable().shardRoutingTable(index, shardId);
  return preferenceActiveShardIterator(indexShard, clusterState.nodes().getLocalNodeId(), clusterState.nodes(),
    preference, null, null);
}

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

public ShardIterator getShards(ClusterState clusterState, String index, String id, @Nullable String routing,
                @Nullable String preference) {
  return preferenceActiveShardIterator(shards(clusterState, index, id, routing), clusterState.nodes().getLocalNodeId(),
    clusterState.nodes(), preference, null, null);
}

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

SearchScrollQueryAndFetchAsyncAction(Logger logger, ClusterService clusterService, SearchTransportService searchTransportService,
                   SearchPhaseController searchPhaseController, SearchScrollRequest request, SearchTask task,
                   ParsedScrollId scrollId, ActionListener<SearchResponse> listener) {
  super(scrollId, logger, clusterService.state().nodes(), listener, searchPhaseController, request, searchTransportService);
  this.task = task;
  this.queryFetchResults = new AtomicArray<>(scrollId.getContext().length);
}

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

public void logMinimumMasterNodesWarningIfNecessary(ClusterState oldState, ClusterState newState) {
  // check if min_master_nodes setting is too low and log warning
  if (hasTooManyMasterNodes(oldState.nodes()) == false && hasTooManyMasterNodes(newState.nodes())) {
    logger.warn("value for setting \"{}\" is too low. This can result in data loss! Please set it to at least a quorum of master-" +
        "eligible nodes (current value: [{}], total number of master-eligible nodes used for publishing in this round: [{}])",
      ElectMasterService.DISCOVERY_ZEN_MINIMUM_MASTER_NODES_SETTING.getKey(), minimumMasterNodes(),
      newState.getNodes().getMasterNodes().size());
  }
}

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

@Override
  public void messageReceived(VerifyNodeRepositoryRequest request, TransportChannel channel) throws Exception {
    DiscoveryNode localNode = clusterService.state().nodes().getLocalNode();
    try {
      doVerify(request.repository, request.verificationToken, localNode);
    } catch (Exception ex) {
      logger.warn(() -> new ParameterizedMessage("[{}] failed to verify repository", request.repository), ex);
      throw ex;
    }
    channel.sendResponse(TransportResponse.Empty.INSTANCE);
  }
}

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

@Override
public void clusterStateProcessed(String source, ClusterState oldState, ClusterState newState) {
  if (newState.nodes().isLocalNodeElectedMaster()) {
    ElectionContext.this.onElectedAsMaster(newState);
  } else {
    onFailure(source, new NotMasterException("election stopped [" + source + "]"));
  }
}

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

public static Set<Index> getRelevantIndices(ClusterState state, ClusterState previousState, Set<Index> previouslyWrittenIndices) {
  Set<Index> relevantIndices;
  if (isDataOnlyNode(state)) {
    relevantIndices = getRelevantIndicesOnDataOnlyNode(state, previousState, previouslyWrittenIndices);
  } else if (state.nodes().getLocalNode().isMasterNode()) {
    relevantIndices = getRelevantIndicesForMasterEligibleNode(state);
  } else {
    relevantIndices = Collections.emptySet();
  }
  return relevantIndices;
}

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

SearchScrollQueryThenFetchAsyncAction(Logger logger, ClusterService clusterService, SearchTransportService searchTransportService,
                   SearchPhaseController searchPhaseController, SearchScrollRequest request, SearchTask task,
                   ParsedScrollId scrollId, ActionListener<SearchResponse> listener) {
  super(scrollId, logger, clusterService.state().nodes(), listener, searchPhaseController, request,
    searchTransportService);
  this.task = task;
  this.fetchResults = new AtomicArray<>(scrollId.getContext().length);
  this.queryResults = new AtomicArray<>(scrollId.getContext().length);
}

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

@Override
public void clusterChanged(ClusterChangedEvent event) {
  long currentNanoTime = currentNanoTime();
  if (event.state().nodes().isLocalNodeElectedMaster()) {
    scheduleIfNeeded(currentNanoTime, event.state());
  }
}

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

protected String[] resolveNodes(TasksRequest request, ClusterState clusterState) {
  if (request.getTaskId().isSet()) {
    return new String[]{request.getTaskId().getNodeId()};
  } else {
    return clusterState.nodes().resolveNodes(request.getNodes());
  }
}

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

private void handleLeaveRequest(final DiscoveryNode node) {
  if (lifecycleState() != Lifecycle.State.STARTED) {
    // not started, ignore a node failure
    return;
  }
  if (localNodeMaster()) {
    removeNode(node, "zen-disco-node-left", "left");
  } else if (node.equals(clusterState().nodes().getMasterNode())) {
    handleMasterGone(node, null, "shut_down");
  }
}

相关文章