private static boolean clusterHas5xNodes(ClusterState state) { return state.nodes().getMinNodeVersion().before(Version.V_6_0_0_alpha1); }
@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; }
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()); }
/** * Returns <code>true</code> iff the local node is the mater node of the cluster. */ public boolean localNodeMaster() { return state.nodes().isLocalNodeElectedMaster(); }
/** * 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)); }
/** * 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(); }
@Override protected void doExecute(ClearScrollRequest request, final ActionListener<ClearScrollResponse> listener) { Runnable runnable = new ClearScrollController(request, listener, clusterService.state().nodes(), logger, searchTransportService); runnable.run(); }
/** * 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; } }
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())); }
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); }
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); }
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); }
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()); } }
@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); } }
@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 + "]")); } }
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; }
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); }
@Override public void clusterChanged(ClusterChangedEvent event) { long currentNanoTime = currentNanoTime(); if (event.state().nodes().isLocalNodeElectedMaster()) { scheduleIfNeeded(currentNanoTime, event.state()); } }
protected String[] resolveNodes(TasksRequest request, ClusterState clusterState) { if (request.getTaskId().isSet()) { return new String[]{request.getTaskId().getNodeId()}; } else { return clusterState.nodes().resolveNodes(request.getNodes()); } }
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"); } }