Search in sources :

Example 6 with TcpDiscoveryNode

use of org.apache.ignite.spi.discovery.tcp.internal.TcpDiscoveryNode in project ignite by apache.

the class ServerImpl method nodeAlive.

/**
     * Checks whether a node is alive or not.
     *
     * @param nodeId Node ID.
     * @return {@code True} if node is in the ring and is not being removed from.
     */
private boolean nodeAlive(UUID nodeId) {
    // Is node alive or about to be removed from the ring?
    TcpDiscoveryNode node = ring.node(nodeId);
    boolean nodeAlive = node != null && node.visible();
    if (nodeAlive) {
        synchronized (mux) {
            nodeAlive = !F.transform(failedNodes.keySet(), F.node2id()).contains(nodeId) && !F.transform(leavingNodes, F.node2id()).contains(nodeId);
        }
    }
    return nodeAlive;
}
Also used : TcpDiscoveryNode(org.apache.ignite.spi.discovery.tcp.internal.TcpDiscoveryNode)

Example 7 with TcpDiscoveryNode

use of org.apache.ignite.spi.discovery.tcp.internal.TcpDiscoveryNode in project ignite by apache.

the class ServerImpl method prepareNodeAddedMessage.

/**
     * @param msg Message to prepare.
     * @param destNodeId Destination node ID.
     * @param msgs Messages to include.
     * @param discardMsgId Discarded message ID.
     */
private void prepareNodeAddedMessage(TcpDiscoveryAbstractMessage msg, UUID destNodeId, @Nullable Collection<PendingMessage> msgs, @Nullable IgniteUuid discardMsgId, @Nullable IgniteUuid discardCustomMsgId) {
    assert destNodeId != null;
    if (msg instanceof TcpDiscoveryNodeAddedMessage) {
        TcpDiscoveryNodeAddedMessage nodeAddedMsg = (TcpDiscoveryNodeAddedMessage) msg;
        TcpDiscoveryNode node = nodeAddedMsg.node();
        if (node.id().equals(destNodeId)) {
            Collection<TcpDiscoveryNode> allNodes = ring.allNodes();
            Collection<TcpDiscoveryNode> topToSnd = new ArrayList<>(allNodes.size());
            for (TcpDiscoveryNode n0 : allNodes) {
                assert n0.internalOrder() != 0 : n0;
                // internal order.
                if (n0.internalOrder() < nodeAddedMsg.node().internalOrder())
                    topToSnd.add(n0);
            }
            nodeAddedMsg.topology(topToSnd);
            Collection<TcpDiscoveryAbstractMessage> msgs0 = null;
            if (msgs != null) {
                msgs0 = new ArrayList<>(msgs.size());
                for (PendingMessage pendingMsg : msgs) {
                    if (pendingMsg.msg != null)
                        msgs0.add(pendingMsg.msg);
                }
            }
            nodeAddedMsg.messages(msgs0, discardMsgId, discardCustomMsgId);
            Map<Long, Collection<ClusterNode>> hist;
            synchronized (mux) {
                hist = new TreeMap<>(topHist);
            }
            nodeAddedMsg.topologyHistory(hist);
        }
    }
}
Also used : TcpDiscoveryAbstractMessage(org.apache.ignite.spi.discovery.tcp.messages.TcpDiscoveryAbstractMessage) ArrayList(java.util.ArrayList) Collection(java.util.Collection) TcpDiscoveryNodeAddedMessage(org.apache.ignite.spi.discovery.tcp.messages.TcpDiscoveryNodeAddedMessage) TcpDiscoveryNode(org.apache.ignite.spi.discovery.tcp.internal.TcpDiscoveryNode)

Example 8 with TcpDiscoveryNode

use of org.apache.ignite.spi.discovery.tcp.internal.TcpDiscoveryNode in project ignite by apache.

the class ServerImpl method dumpDebugInfo.

/** {@inheritDoc} */
@Override
public void dumpDebugInfo(IgniteLogger log) {
    if (!debugMode) {
        U.quietAndWarn(log, "Failed to dump debug info (discovery SPI was not configured " + "in debug mode, consider setting 'debugMode' configuration property to 'true').");
        return;
    }
    assert log.isInfoEnabled();
    synchronized (mux) {
        StringBuilder b = new StringBuilder(U.nl());
        b.append(">>>").append(U.nl());
        b.append(">>>").append("Dumping discovery SPI debug info.").append(U.nl());
        b.append(">>>").append(U.nl());
        b.append("Local node ID: ").append(getLocalNodeId()).append(U.nl()).append(U.nl());
        b.append("Local node: ").append(locNode).append(U.nl()).append(U.nl());
        b.append("SPI state: ").append(spiState).append(U.nl()).append(U.nl());
        b.append("Internal threads: ").append(U.nl());
        b.append("    Message worker: ").append(threadStatus(msgWorker)).append(U.nl());
        b.append("    IP finder cleaner: ").append(threadStatus(ipFinderCleaner)).append(U.nl());
        b.append("    Stats printer: ").append(threadStatus(statsPrinter)).append(U.nl());
        b.append(U.nl());
        b.append("Socket readers: ").append(U.nl());
        for (SocketReader rdr : readers) b.append("    ").append(rdr).append(U.nl());
        b.append(U.nl());
        b.append("In-memory log messages: ").append(U.nl());
        for (String msg : debugLogQ) b.append("    ").append(msg).append(U.nl());
        b.append(U.nl());
        b.append("Leaving nodes: ").append(U.nl());
        for (TcpDiscoveryNode node : leavingNodes) b.append("    ").append(node.id()).append(U.nl());
        b.append(U.nl());
        b.append("Failed nodes: ").append(U.nl());
        for (TcpDiscoveryNode node : failedNodes.keySet()) b.append("    ").append(node.id()).append(U.nl());
        b.append(U.nl());
        b.append("Stats: ").append(spi.stats).append(U.nl());
        U.quietAndInfo(log, b.toString());
    }
}
Also used : TcpDiscoveryNode(org.apache.ignite.spi.discovery.tcp.internal.TcpDiscoveryNode)

Example 9 with TcpDiscoveryNode

use of org.apache.ignite.spi.discovery.tcp.internal.TcpDiscoveryNode in project ignite by apache.

the class ServerImpl method processMessageFailedNodes.

/**
     * Adds failed nodes specified in the received message to the local failed nodes list.
     *
     * @param msg Message.
     */
private void processMessageFailedNodes(TcpDiscoveryAbstractMessage msg) {
    if (msg.failedNodes() != null) {
        for (UUID nodeId : msg.failedNodes()) {
            TcpDiscoveryNode failedNode = ring.node(nodeId);
            if (failedNode != null) {
                if (!failedNode.isLocal()) {
                    boolean added = false;
                    synchronized (mux) {
                        if (!failedNodes.containsKey(failedNode)) {
                            failedNodes.put(failedNode, msg.senderNodeId() != null ? msg.senderNodeId() : getLocalNodeId());
                            added = true;
                        }
                    }
                    if (added && log.isDebugEnabled())
                        log.debug("Added node to failed nodes list [node=" + failedNode + ", msg=" + msg + ']');
                }
            }
        }
    }
}
Also used : UUID(java.util.UUID) TcpDiscoveryNode(org.apache.ignite.spi.discovery.tcp.internal.TcpDiscoveryNode)

Example 10 with TcpDiscoveryNode

use of org.apache.ignite.spi.discovery.tcp.internal.TcpDiscoveryNode in project ignite by apache.

the class GridTcpSpiForwardingSelfTest method getConfiguration.

/** {@inheritDoc} */
@SuppressWarnings({ "IfMayBeConditional", "deprecation" })
@Override
protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
    TcpDiscoveryVmIpFinder ipFinder = new TcpDiscoveryVmIpFinder();
    if (ipFinderUseLocPorts)
        ipFinder.setAddresses(Arrays.asList("127.0.0.1:" + locPort1, "127.0.0.1:" + locPort2));
    else
        ipFinder.setAddresses(Arrays.asList("127.0.0.1:" + extPort1, "127.0.0.1:" + extPort2));
    TcpDiscoverySpi spi = new TcpDiscoverySpi();
    final int locPort;
    final int commLocPort;
    if (getTestIgniteInstanceName(0).equals(igniteInstanceName)) {
        locPort = locPort1;
        commLocPort = commLocPort1;
    } else if (getTestIgniteInstanceName(1).equals(igniteInstanceName)) {
        locPort = locPort2;
        commLocPort = commLocPort2;
    } else
        throw new IllegalArgumentException("Unknown Ignite instance name");
    spi.setIpFinder(ipFinder);
    IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
    spi.setLocalPort(locPort);
    spi.setLocalPortRange(1);
    cfg.setDiscoverySpi(spi);
    cfg.setLocalHost("127.0.0.1");
    cfg.setConnectorConfiguration(null);
    TcpCommunicationSpi commSpi = new TcpCommunicationSpi() {

        @Override
        protected GridCommunicationClient createTcpClient(ClusterNode node, int connIdx) throws IgniteCheckedException {
            Map<String, Object> attrs = new HashMap<>(node.attributes());
            attrs.remove(createSpiAttributeName(ATTR_PORT));
            ((TcpDiscoveryNode) node).setAttributes(attrs);
            return super.createTcpClient(node, connIdx);
        }
    };
    commSpi.setLocalAddress("127.0.0.1");
    commSpi.setLocalPort(commLocPort);
    commSpi.setLocalPortRange(1);
    commSpi.setSharedMemoryPort(-1);
    commSpi.setConnectionsPerNode(1);
    cfg.setCommunicationSpi(commSpi);
    assert rslvr != null;
    cfg.setAddressResolver(rslvr);
    return cfg;
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) TcpDiscoveryVmIpFinder(org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder) HashMap(java.util.HashMap) TcpCommunicationSpi(org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi) TcpDiscoveryNode(org.apache.ignite.spi.discovery.tcp.internal.TcpDiscoveryNode) TcpDiscoverySpi(org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi)

Aggregations

TcpDiscoveryNode (org.apache.ignite.spi.discovery.tcp.internal.TcpDiscoveryNode)31 ClusterNode (org.apache.ignite.cluster.ClusterNode)9 Ignite (org.apache.ignite.Ignite)8 UUID (java.util.UUID)7 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)7 IOException (java.io.IOException)6 IgniteSpiException (org.apache.ignite.spi.IgniteSpiException)5 ArrayList (java.util.ArrayList)4 DiscoveryEvent (org.apache.ignite.events.DiscoveryEvent)4 TcpDiscoveryVmIpFinder (org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder)4 Nullable (org.jetbrains.annotations.Nullable)4 Socket (java.net.Socket)3 SocketTimeoutException (java.net.SocketTimeoutException)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 IgniteException (org.apache.ignite.IgniteException)3 Event (org.apache.ignite.events.Event)3 TcpDiscoveryJoinRequestMessage (org.apache.ignite.spi.discovery.tcp.messages.TcpDiscoveryJoinRequestMessage)3 StreamCorruptedException (java.io.StreamCorruptedException)2 InetSocketAddress (java.net.InetSocketAddress)2 Collection (java.util.Collection)2