/** * Get the id of the master node * * @return id of the master */ public String getMasterNodeId() { return masterNodeId(); }
@Override public boolean apply(ClusterState previousState, ClusterState.ClusterStateStatus previousStatus, ClusterState newState, ClusterState.ClusterStateStatus newStatus) { // The condition !newState.nodes().masterNodeId().equals(previousState.nodes().masterNodeId()) is not sufficient as the same master node might get reelected after a disruption. return newState.nodes().masterNodeId() != null && newState != previousState; }
if (!Objects.equals(stateToProcess.clusterState.nodes().masterNodeId(), potentialState.clusterState.nodes().masterNodeId())) { break;
public Builder(DiscoveryNodes nodes) { this.masterNodeId = nodes.masterNodeId(); this.localNodeId = nodes.localNodeId(); this.nodes = ImmutableOpenMap.builder(nodes.nodes()); }
@Override public ClusterState execute(ClusterState currentState) { if (!masterNode.id().equals(currentState.nodes().masterNodeId())) { // master got switched on us, no need to send anything return currentState; } DiscoveryNodes discoveryNodes = DiscoveryNodes.builder(currentState.nodes()) // make sure the old master node, which has failed, is not part of the nodes we publish .remove(masterNode.id()) .masterNodeId(null).build(); // flush any pending cluster states from old master, so it will not be set as master again ArrayList<ProcessClusterState> pendingNewClusterStates = new ArrayList<>(); processNewClusterStates.drainTo(pendingNewClusterStates); logger.trace("removed [{}] pending cluster states", pendingNewClusterStates.size()); return rejoin(ClusterState.builder(currentState).nodes(discoveryNodes).build(), "master left (reason = " + reason + ")"); }
/** * In the case we follow an elected master the new cluster state needs to have the same elected master and * the new cluster state version needs to be equal or higher than our cluster state version. * If the first condition fails we reject the cluster state and throw an error. * If the second condition fails we ignore the cluster state. */ static boolean shouldIgnoreOrRejectNewClusterState(ESLogger logger, ClusterState currentState, ClusterState newClusterState) { if (currentState.nodes().masterNodeId() == null) { return false; } if (!currentState.nodes().masterNodeId().equals(newClusterState.nodes().masterNodeId())) { logger.warn("received a cluster state from a different master then the current one, rejecting (received {}, current {})", newClusterState.nodes().masterNode(), currentState.nodes().masterNode()); throw new IllegalStateException("cluster state from a different master than the current one, rejecting (received " + newClusterState.nodes().masterNode() + ", current " + currentState.nodes().masterNode() + ")"); } else if (newClusterState.version() < currentState.version()) { // if the new state has a smaller version, and it has the same master node, then no need to process it logger.debug("received a cluster state that has a lower version than the current one, ignoring (received {}, current {})", newClusterState.version(), currentState.version()); return true; } else { return false; } }
@Override public void clusterChanged(ClusterChangedEvent event) { try { SnapshotsInProgress prev = event.previousState().custom(SnapshotsInProgress.TYPE); SnapshotsInProgress curr = event.state().custom(SnapshotsInProgress.TYPE); if (prev == null) { if (curr != null) { processIndexShardSnapshots(event); } } else if (prev.equals(curr) == false) { processIndexShardSnapshots(event); } String masterNodeId = event.state().nodes().masterNodeId(); if (masterNodeId != null && masterNodeId.equals(event.previousState().nodes().masterNodeId()) == false) { syncShardStatsOnNewMaster(event); } } catch (Throwable t) { logger.warn("Failed to update snapshot state ", t); } }
@Override public ClusterState execute(ClusterState currentState) { if (nodeSpecificClusterState.version() < currentState.version() && Objects.equals(nodeSpecificClusterState.nodes().masterNodeId(), currentState.nodes().masterNodeId())) { return currentState; } if (currentState.blocks().hasGlobalBlock(discoverySettings.getNoMasterBlock())) { // its a fresh update from the master as we transition from a start of not having a master to having one logger.debug("got first state from fresh master [{}]", nodeSpecificClusterState.nodes().masterNodeId()); return nodeSpecificClusterState; } ClusterState.Builder builder = ClusterState.builder(nodeSpecificClusterState); // if the routing table did not change, use the original one if (nodeSpecificClusterState.routingTable().version() == currentState.routingTable().version()) { builder.routingTable(currentState.routingTable()); } if (nodeSpecificClusterState.metaData().version() == currentState.metaData().version()) { builder.metaData(currentState.metaData()); } return builder.build(); }
if (!Objects.equal(stateToProcess.clusterState.nodes().masterNodeId(), potentialState.clusterState.nodes().masterNodeId())) { break; if (updatedState.version() < currentState.version() && Objects.equal(updatedState.nodes().masterNodeId(), currentState.nodes().masterNodeId())) { return currentState;
if (!Objects.equal(stateToProcess.clusterState.nodes().masterNodeId(), potentialState.clusterState.nodes().masterNodeId())) { break; if (updatedState.version() < currentState.version() && Objects.equal(updatedState.nodes().masterNodeId(), currentState.nodes().masterNodeId())) { return currentState;
if (!Objects.equal(stateToProcess.clusterState.nodes().masterNodeId(), potentialState.clusterState.nodes().masterNodeId())) { break; if (updatedState.version() < currentState.version() && Objects.equal(updatedState.nodes().masterNodeId(), currentState.nodes().masterNodeId())) { return currentState;
String masterNodeId = state.getState().nodes().masterNodeId(); String localNodeId = state.getState().nodes().getLocalNodeId(); if (localNodeId == null || !localNodeId.equals(masterNodeId)) {
String masterNodeId = masterNodeId(); if (masterNodeId != null) { resolvedNodesIds.add(masterNodeId);
@Override public ClusterState execute(ClusterState currentState) { // Rebuild state ClusterState.Builder stateBuilder = newClusterStateBuilder().state(currentState); // Rebuild nodes DiscoveryNodes.Builder nodesBuilder = newNodesBuilder() .localNodeId(localNode.id()) .masterNodeId(singleton.master().get().node().id()) .put(singleton.master().get().node); for (ESNode node : JavaConversions$.MODULE$.asJavaCollection(singleton.slaves())) { nodesBuilder.put(node.node()); } latestDiscoNodes = nodesBuilder.build(); stateBuilder.nodes(latestDiscoNodes); for (DiscoveryNode node : latestDiscoNodes) { if (!currentState.nodes().nodeExists(node.id())) { transportService.connectToNode(node); } } // update the fact that we are the master... if (!localNode().id().equals(currentState.nodes().masterNodeId())) { ClusterBlocks clusterBlocks = ClusterBlocks.builder().blocks(currentState.blocks()).removeGlobalBlock(NO_MASTER_BLOCK).build(); stateBuilder.blocks(clusterBlocks); } return stateBuilder.build(); }
private Table buildTable(RestRequest request, ClusterStateResponse state) { Table table = getTableWithHeader(request); DiscoveryNodes nodes = state.getState().nodes(); table.startRow(); DiscoveryNode master = nodes.get(nodes.masterNodeId()); 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; } }
@Override public ClusterState execute(ClusterState currentState) { // Rebuild state ClusterState.Builder stateBuilder = ClusterState.builder(currentState); // Rebuild nodes DiscoveryNodes.Builder nodesBuilder = DiscoveryNodes.builder() .localNodeId(localNode.id()) .masterNodeId(singleton.master().getNode().id()) .put(singleton.master().getNode()); for (ESNode node : singleton.slaves()) { nodesBuilder.put(node.getNode()); } latestDiscoNodes = nodesBuilder.build(); stateBuilder.nodes(latestDiscoNodes); for (DiscoveryNode node : latestDiscoNodes) { if (!currentState.nodes().nodeExists(node.id())) { transportService.connectToNode(node); } } // update the fact that we are the master... if (!localNode().id().equals(currentState.nodes().masterNodeId())) { ClusterBlocks clusterBlocks = ClusterBlocks.builder().blocks(currentState.blocks()).removeGlobalBlock(NO_MASTER_BLOCK).build(); stateBuilder.blocks(clusterBlocks); } return stateBuilder.build(); }
@Override public ClusterState execute(ClusterState currentState) { // Rebuild state ClusterState.Builder stateBuilder = ClusterState.builder(currentState); // Rebuild nodes DiscoveryNodes.Builder nodesBuilder = DiscoveryNodes.builder() .localNodeId(localNode.id()) .masterNodeId(singleton.master().getNode().id()) .put(singleton.master().getNode()); for (ESNode node : singleton.slaves()) { nodesBuilder.put(node.getNode()); } latestDiscoNodes = nodesBuilder.build(); stateBuilder.nodes(latestDiscoNodes); for (DiscoveryNode node : latestDiscoNodes) { if (!currentState.nodes().nodeExists(node.id())) { transportService.connectToNode(node); } } // update the fact that we are the master... if (!localNode().id().equals(currentState.nodes().masterNodeId())) { ClusterBlocks clusterBlocks = ClusterBlocks.builder().blocks(currentState.blocks()).removeGlobalBlock(NO_MASTER_BLOCK).build(); stateBuilder.blocks(clusterBlocks); } return stateBuilder.build(); }
@Override public ClusterState execute(ClusterState currentState) { // Rebuild state ClusterState.Builder stateBuilder = ClusterState.builder(currentState); // Rebuild nodes DiscoveryNodes.Builder nodesBuilder = DiscoveryNodes.builder() .localNodeId(localNode.id()) .masterNodeId(singleton.master().getNode().id()) .put(singleton.master().getNode()); for (ESNode node : singleton.slaves()) { nodesBuilder.put(node.getNode()); } latestDiscoNodes = nodesBuilder.build(); stateBuilder.nodes(latestDiscoNodes); for (DiscoveryNode node : latestDiscoNodes) { if (!currentState.nodes().nodeExists(node.id())) { transportService.connectToNode(node); } } // update the fact that we are the master... if (!localNode().id().equals(currentState.nodes().masterNodeId())) { ClusterBlocks clusterBlocks = ClusterBlocks.builder().blocks(currentState.blocks()).removeGlobalBlock(NO_MASTER_BLOCK).build(); stateBuilder.blocks(clusterBlocks); } return stateBuilder.build(); }
logger.debug("got first state from fresh master [{}]", updatedState.nodes().masterNodeId()); long count = clusterJoinsCounter.incrementAndGet(); logger.trace("updated cluster join cluster to [{}]", count);
String masterId = nodes.masterNodeId(); Table table = getTableWithHeader(req);