Search in sources :

Example 1 with TcpDiscoveryAbstractMessage

use of org.apache.ignite.spi.discovery.tcp.messages.TcpDiscoveryAbstractMessage 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 2 with TcpDiscoveryAbstractMessage

use of org.apache.ignite.spi.discovery.tcp.messages.TcpDiscoveryAbstractMessage in project ignite by apache.

the class TcpClientDiscoverySpiSelfTest method testTimeoutWaitingNodeAddedMessage.

/**
     * @throws Exception If any error occurs.
     */
public void testTimeoutWaitingNodeAddedMessage() throws Exception {
    longSockTimeouts = true;
    startServerNodes(2);
    final CountDownLatch cnt = new CountDownLatch(1);
    ((TcpDiscoverySpi) G.ignite("server-1").configuration().getDiscoverySpi()).addSendMessageListener(new IgniteInClosure<TcpDiscoveryAbstractMessage>() {

        @Override
        public void apply(TcpDiscoveryAbstractMessage msg) {
            try {
                cnt.await(10, MINUTES);
            } catch (InterruptedException e) {
                Thread.currentThread().interrupt();
                throw new IgniteInterruptedException(e);
            }
        }
    });
    try {
        netTimeout = 500;
        startGrid("client-0");
        assert false;
    } catch (IgniteCheckedException e) {
        cnt.countDown();
        IgniteSpiException spiEx = e.getCause(IgniteSpiException.class);
        assert spiEx != null : e;
        assert spiEx.getMessage().contains("Join process timed out") : spiEx.getMessage();
    }
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) TcpDiscoveryAbstractMessage(org.apache.ignite.spi.discovery.tcp.messages.TcpDiscoveryAbstractMessage) IgniteInterruptedException(org.apache.ignite.IgniteInterruptedException) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException) CountDownLatch(java.util.concurrent.CountDownLatch) IgniteInterruptedException(org.apache.ignite.IgniteInterruptedException)

Example 3 with TcpDiscoveryAbstractMessage

use of org.apache.ignite.spi.discovery.tcp.messages.TcpDiscoveryAbstractMessage in project ignite by apache.

the class TcpClientDiscoverySpiSelfTest method missedAddFinishedMessage.

/**
     * @param singleSrv If {@code true} starts one server node two otherwise.
     * @throws Exception If failed.
     */
private void missedAddFinishedMessage(boolean singleSrv) throws Exception {
    int srvs = singleSrv ? 1 : 2;
    startServerNodes(srvs);
    afterWrite = new CIX2<TcpDiscoveryAbstractMessage, Socket>() {

        private boolean first = true;

        @Override
        public void applyx(TcpDiscoveryAbstractMessage msg, Socket sock) throws IgniteCheckedException {
            if (first && (msg instanceof TcpDiscoveryJoinRequestMessage)) {
                first = false;
                log.info("Close socket after message write [msg=" + msg + "]");
                try {
                    sock.close();
                } catch (IOException e) {
                    throw new IgniteCheckedException(e);
                }
                log.info("Delay after message write [msg=" + msg + "]");
                // Wait when server process join request.
                U.sleep(5000);
            }
        }
    };
    Ignite srv = singleSrv ? G.ignite("server-0") : G.ignite("server-1");
    TcpDiscoveryNode srvNode = (TcpDiscoveryNode) srv.cluster().localNode();
    assertEquals(singleSrv ? 1 : 2, srvNode.order());
    clientIpFinder = new TcpDiscoveryVmIpFinder();
    clientIpFinder.setAddresses(Collections.singleton("localhost:" + srvNode.discoveryPort()));
    startClientNodes(1);
    TcpDiscoveryNode clientNode = (TcpDiscoveryNode) G.ignite("client-0").cluster().localNode();
    assertEquals(srvNode.id(), clientNode.clientRouterNodeId());
    checkNodes(srvs, 1);
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) TcpDiscoveryAbstractMessage(org.apache.ignite.spi.discovery.tcp.messages.TcpDiscoveryAbstractMessage) TcpDiscoveryVmIpFinder(org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder) Ignite(org.apache.ignite.Ignite) IOException(java.io.IOException) Socket(java.net.Socket) TcpDiscoveryNode(org.apache.ignite.spi.discovery.tcp.internal.TcpDiscoveryNode) TcpDiscoveryJoinRequestMessage(org.apache.ignite.spi.discovery.tcp.messages.TcpDiscoveryJoinRequestMessage)

Example 4 with TcpDiscoveryAbstractMessage

use of org.apache.ignite.spi.discovery.tcp.messages.TcpDiscoveryAbstractMessage in project ignite by apache.

the class TcpClientDiscoverySpiSelfTest method testClientAndRouterFail.

/**
     * @throws Exception If failed.
     */
public void testClientAndRouterFail() throws Exception {
    startServerNodes(2);
    startClientNodes(2);
    checkNodes(2, 2);
    srvFailedLatch = new CountDownLatch(2);
    clientFailedLatch = new CountDownLatch(2);
    attachListeners(1, 1);
    ((TcpDiscoverySpi) G.ignite("server-1").configuration().getDiscoverySpi()).addSendMessageListener(new IgniteInClosure<TcpDiscoveryAbstractMessage>() {

        @Override
        public void apply(TcpDiscoveryAbstractMessage msg) {
            try {
                Thread.sleep(1000000);
            } catch (InterruptedException ignored) {
                Thread.interrupted();
            }
        }
    });
    failClient(1);
    failServer(1);
    awaitClient(srvFailedLatch);
    awaitClient(clientFailedLatch);
    checkNodes(1, 1);
}
Also used : TcpDiscoveryAbstractMessage(org.apache.ignite.spi.discovery.tcp.messages.TcpDiscoveryAbstractMessage) CountDownLatch(java.util.concurrent.CountDownLatch) IgniteInterruptedException(org.apache.ignite.IgniteInterruptedException)

Example 5 with TcpDiscoveryAbstractMessage

use of org.apache.ignite.spi.discovery.tcp.messages.TcpDiscoveryAbstractMessage in project ignite by apache.

the class CacheDiscoveryDataConcurrentJoinTest method getConfiguration.

/** {@inheritDoc} */
@Override
protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
    IgniteConfiguration cfg = super.getConfiguration(gridName);
    TcpDiscoverySpi testSpi = new TcpDiscoverySpi() {

        /** */
        private boolean delay = true;

        @Override
        protected void startMessageProcess(TcpDiscoveryAbstractMessage msg) {
            if (getTestIgniteInstanceName(0).equals(ignite.name())) {
                if (msg instanceof TcpDiscoveryJoinRequestMessage) {
                    TcpDiscoveryJoinRequestMessage msg0 = (TcpDiscoveryJoinRequestMessage) msg;
                    if (delay) {
                        log.info("Delay join processing: " + msg0);
                        delay = false;
                        doSleep(5000);
                    }
                }
            }
            super.startMessageProcess(msg);
        }
    };
    testSpi.setIpFinder(ipFinder);
    testSpi.setJoinTimeout(60_000);
    cfg.setDiscoverySpi(testSpi);
    cfg.setClientMode(client);
    Integer caches = staticCaches.get();
    if (caches != null) {
        cfg.setCacheConfiguration(cacheConfigurations(caches).toArray(new CacheConfiguration[caches]));
        staticCaches.remove();
    }
    return cfg;
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) GridAtomicInteger(org.apache.ignite.internal.util.GridAtomicInteger) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) TcpDiscoveryAbstractMessage(org.apache.ignite.spi.discovery.tcp.messages.TcpDiscoveryAbstractMessage) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) TcpDiscoverySpi(org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi) TcpDiscoveryJoinRequestMessage(org.apache.ignite.spi.discovery.tcp.messages.TcpDiscoveryJoinRequestMessage)

Aggregations

TcpDiscoveryAbstractMessage (org.apache.ignite.spi.discovery.tcp.messages.TcpDiscoveryAbstractMessage)10 TcpDiscoveryJoinRequestMessage (org.apache.ignite.spi.discovery.tcp.messages.TcpDiscoveryJoinRequestMessage)5 CountDownLatch (java.util.concurrent.CountDownLatch)4 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)4 IOException (java.io.IOException)3 Socket (java.net.Socket)3 Ignite (org.apache.ignite.Ignite)3 IgniteSpiException (org.apache.ignite.spi.IgniteSpiException)3 TcpDiscoveryNode (org.apache.ignite.spi.discovery.tcp.internal.TcpDiscoveryNode)3 StreamCorruptedException (java.io.StreamCorruptedException)2 SocketTimeoutException (java.net.SocketTimeoutException)2 ArrayList (java.util.ArrayList)2 SSLException (javax.net.ssl.SSLException)2 IgniteInterruptedException (org.apache.ignite.IgniteInterruptedException)2 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)2 DiscoveryEvent (org.apache.ignite.events.DiscoveryEvent)2 Event (org.apache.ignite.events.Event)2 IgniteSpiOperationTimeoutHelper (org.apache.ignite.spi.IgniteSpiOperationTimeoutHelper)2 TcpDiscoverySpi (org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi)2 DiscoveryDataPacket (org.apache.ignite.spi.discovery.tcp.internal.DiscoveryDataPacket)2