Java Code Examples for org.elasticsearch.cluster.node.DiscoveryNode#equals()

The following examples show how to use org.elasticsearch.cluster.node.DiscoveryNode#equals() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
@Override
protected void handleTransportDisconnect(DiscoveryNode node) {
    synchronized (masterNodeMutex) {
        if (!node.equals(this.masterNode)) {
            return;
        }
        if (connectOnNetworkDisconnect) {
            try {
                transportService.connectToNode(node);
                // if all is well, make sure we restart the pinger
                if (masterPinger != null) {
                    masterPinger.stop();
                }
                this.masterPinger = new MasterPinger();
                // 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, masterPinger);
            } catch (Exception e) {
                logger.trace("[master] [{}] transport disconnected (with verified connect)", masterNode);
                notifyMasterFailure(masterNode, "transport disconnected (with verified connect)");
            }
        } else {
            logger.trace("[master] [{}] transport disconnected", node);
            notifyMasterFailure(node, "transport disconnected");
        }
    }
}
 
Example 2
/**
 * 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.id())) {
            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);
        }
    }
}
 
Example 3
@Override
public void onNodeAck(DiscoveryNode node, @Nullable Throwable t) {
    if (!ackedTaskListener.mustAck(node)) {
        //we always wait for the master ack anyway
        if (!node.equals(nodes.masterNode())) {
            return;
        }
    }
    if (t == null) {
        logger.trace("ack received from node [{}], cluster_state update (version: {})", node, clusterStateVersion);
    } else {
        this.lastFailure = t;
        logger.debug("ack received from node [{}], cluster_state update (version: {})", t, node, clusterStateVersion);
    }

    if (countDown.countDown()) {
        logger.trace("all expected nodes acknowledged cluster_state update (version: {})", clusterStateVersion);
        FutureUtils.cancel(ackTimeoutCallback);
        ackedTaskListener.onAllNodesAcked(lastFailure);
    }
}
 
Example 4
Source Project: crate   File: MasterService.java    License: Apache License 2.0 6 votes vote down vote up
AckCountDownListener(AckedClusterStateTaskListener ackedTaskListener, long clusterStateVersion, DiscoveryNodes nodes,
                     ThreadPool threadPool) {
    this.ackedTaskListener = ackedTaskListener;
    this.clusterStateVersion = clusterStateVersion;
    this.threadPool = threadPool;
    this.masterNode = nodes.getMasterNode();
    int countDown = 0;
    for (DiscoveryNode node : nodes) {
        //we always wait for at least the master node
        if (node.equals(masterNode) || ackedTaskListener.mustAck(node)) {
            countDown++;
        }
    }
    LOGGER.trace("expecting {} acknowledgements for cluster_state update (version: {})", countDown, clusterStateVersion);
    this.countDown = new CountDown(countDown + 1); // we also wait for onCommit to be called
}
 
Example 5
Source Project: crate   File: MasterService.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void onNodeAck(DiscoveryNode node, @Nullable Exception e) {
    if (node.equals(masterNode) == false && ackedTaskListener.mustAck(node) == false) {
        return;
    }
    if (e == null) {
        LOGGER.trace("ack received from node [{}], cluster_state update (version: {})", node, clusterStateVersion);
    } else {
        this.lastFailure = e;
        LOGGER.debug(() -> new ParameterizedMessage(
                "ack received from node [{}], cluster_state update (version: {})", node, clusterStateVersion), e);
    }

    if (countDown.countDown()) {
        finish();
    }
}
 
Example 6
public void publish(ClusterChangedEvent clusterChangedEvent, final Discovery.AckListener ackListener) {
    Set<DiscoveryNode> nodesToPublishTo = new HashSet<>(clusterChangedEvent.state().nodes().size());
    DiscoveryNode localNode = nodesProvider.nodes().localNode();
    for (final DiscoveryNode node : clusterChangedEvent.state().nodes()) {
        if (node.equals(localNode)) {
            continue;
        }
        nodesToPublishTo.add(node);
    }
    publish(clusterChangedEvent, nodesToPublishTo, new AckClusterStatePublishResponseHandler(nodesToPublishTo, ackListener));
}
 
Example 7
Source Project: crate   File: TransportService.java    License: Apache License 2.0 5 votes vote down vote up
public CheckedBiConsumer<Transport.Connection, ConnectionProfile, IOException> connectionValidator(DiscoveryNode node) {
    return (newConnection, actualProfile) -> {
        // We don't validate cluster names to allow for CCS connections.
        final DiscoveryNode remote = handshake(newConnection, actualProfile.getHandshakeTimeout().millis(), cn -> true).discoveryNode;
        if (node.equals(remote) == false) {
            throw new ConnectTransportException(node, "handshake failed. unexpected remote node " + remote);
        }
    };

}
 
Example 8
private static void buildDiffAndSerializeStates(ClusterState clusterState, ClusterState previousState, DiscoveryNodes discoveryNodes,
                                                boolean sendFullVersion, Map<Version, BytesReference> serializedStates,
                                                Map<Version, BytesReference> serializedDiffs) {
    Diff<ClusterState> diff = null;
    for (DiscoveryNode node : discoveryNodes) {
        if (node.equals(discoveryNodes.getLocalNode())) {
            // ignore, see newPublicationContext
            continue;
        }
        try {
            if (sendFullVersion || !previousState.nodes().nodeExists(node)) {
                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);
        }
    }
}
 
Example 9
Source Project: Elasticsearch   File: TransportService.java    License: Apache License 2.0 4 votes vote down vote up
public boolean nodeConnected(DiscoveryNode node) {
    return node.equals(localNode) || transport.nodeConnected(node);
}
 
Example 10
Source Project: Elasticsearch   File: TransportService.java    License: Apache License 2.0 4 votes vote down vote up
public void connectToNode(DiscoveryNode node) throws ConnectTransportException {
    if (node.equals(localNode)) {
        return;
    }
    transport.connectToNode(node);
}
 
Example 11
Source Project: Elasticsearch   File: TransportService.java    License: Apache License 2.0 4 votes vote down vote up
public void connectToNodeLight(DiscoveryNode node) throws ConnectTransportException {
    if (node.equals(localNode)) {
        return;
    }
    transport.connectToNodeLight(node);
}
 
Example 12
Source Project: Elasticsearch   File: TransportService.java    License: Apache License 2.0 4 votes vote down vote up
public void disconnectFromNode(DiscoveryNode node) {
    if (node.equals(localNode)) {
        return;
    }
    transport.disconnectFromNode(node);
}
 
Example 13
Source Project: crate   File: Coordinator.java    License: Apache License 2.0 4 votes vote down vote up
CoordinatorPublication(PublishRequest publishRequest, PublicationTransportHandler.PublicationContext publicationContext,
                       ListenableFuture<Void> localNodeAckEvent, AckListener ackListener, ActionListener<Void> publishListener) {
    super(publishRequest,
        new AckListener() {
            @Override
            public void onCommit(TimeValue commitTime) {
                ackListener.onCommit(commitTime);
            }

            @Override
            public void onNodeAck(DiscoveryNode node, Exception e) {
                // acking and cluster state application for local node is handled specially
                if (node.equals(getLocalNode())) {
                    synchronized (mutex) {
                        if (e == null) {
                            localNodeAckEvent.onResponse(null);
                        } else {
                            localNodeAckEvent.onFailure(e);
                        }
                    }
                } else {
                    ackListener.onNodeAck(node, e);
                    if (e == null) {
                        lagDetector.setAppliedVersion(node, publishRequest.getAcceptedState().version());
                    }
                }
            }
        },
        transportService.getThreadPool()::relativeTimeInMillis);
    this.publishRequest = publishRequest;
    this.publicationContext = publicationContext;
    this.localNodeAckEvent = localNodeAckEvent;
    this.ackListener = ackListener;
    this.publishListener = publishListener;
    this.scheduledCancellable = transportService.getThreadPool().schedule(new Runnable() {
        @Override
        public void run() {
            synchronized (mutex) {
                cancel("timed out after " + publishTimeout);
            }
        }

        @Override
        public String toString() {
            return "scheduled timeout for " + this;
        }
    }, publishTimeout, Names.GENERIC);
}
 
Example 14
Source Project: crate   File: LeaderChecker.java    License: Apache License 2.0 4 votes vote down vote up
void handleDisconnectedNode(DiscoveryNode discoveryNode) {
    if (discoveryNode.equals(leader)) {
        leaderFailed();
    }
}
 
Example 15
Source Project: crate   File: NodeJoinTests.java    License: Apache License 2.0 4 votes vote down vote up
private boolean clusterStateHasNode(DiscoveryNode node) {
    return node.equals(MasterServiceTests.discoveryState(masterService).nodes().get(node.getId()));
}