Search in sources :

Example 16 with Message

use of org.apache.ignite.plugin.extensions.communication.Message in project ignite by apache.

the class CacheExchangeMergeTest method blockExchangeFinish.

/**
 * @param crd Exchange coordinator.
 * @param topVer Exchange topology version.
 */
private void blockExchangeFinish(Ignite crd, long topVer) {
    final AffinityTopologyVersion topVer0 = new AffinityTopologyVersion(topVer);
    TestRecordingCommunicationSpi.spi(crd).blockMessages(new IgniteBiPredicate<ClusterNode, Message>() {

        @Override
        public boolean apply(ClusterNode node, Message msg) {
            if (msg instanceof GridDhtPartitionsFullMessage) {
                GridDhtPartitionsFullMessage msg0 = (GridDhtPartitionsFullMessage) msg;
                return msg0.exchangeId() != null && msg0.exchangeId().topologyVersion().equals(topVer0);
            }
            return false;
        }
    });
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) GridDhtPartitionsFullMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsFullMessage) GridDhtPartitionsAbstractMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsAbstractMessage) GridIoMessage(org.apache.ignite.internal.managers.communication.GridIoMessage) Message(org.apache.ignite.plugin.extensions.communication.Message) GridDhtPartitionsFullMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsFullMessage) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)

Example 17 with Message

use of org.apache.ignite.plugin.extensions.communication.Message in project ignite by apache.

the class CacheExchangeMergeTest method blockExchangeFinish.

/**
 * @param crd Exchange coordinator.
 * @param topVer Exchange topology version.
 * @param blockNodes Nodes which do not receive messages.
 * @param waitMsgNodes Nodes which should receive messages.
 * @return Awaited state latch.
 */
private CountDownLatch blockExchangeFinish(Ignite crd, long topVer, final List<Integer> blockNodes, final List<Integer> waitMsgNodes) {
    log.info("blockExchangeFinish [crd=" + crd.cluster().localNode().id() + ", block=" + blockNodes + ", wait=" + waitMsgNodes + ']');
    final AffinityTopologyVersion topVer0 = new AffinityTopologyVersion(topVer);
    final CountDownLatch latch = new CountDownLatch(waitMsgNodes.size());
    TestRecordingCommunicationSpi.spi(crd).blockMessages(new IgniteBiPredicate<ClusterNode, Message>() {

        @Override
        public boolean apply(ClusterNode node, Message msg) {
            if (msg instanceof GridDhtPartitionsFullMessage) {
                GridDhtPartitionsFullMessage msg0 = (GridDhtPartitionsFullMessage) msg;
                if (msg0.exchangeId() == null || msg0.exchangeId().topologyVersion().compareTo(topVer0) < 0)
                    return false;
                String name = node.attribute(IgniteNodeAttributes.ATTR_IGNITE_INSTANCE_NAME);
                assert name != null : node;
                for (Integer idx : blockNodes) {
                    if (name.equals(getTestIgniteInstanceName(idx)))
                        return true;
                }
                for (Integer idx : waitMsgNodes) {
                    if (name.equals(getTestIgniteInstanceName(idx))) {
                        log.info("Coordinators sends awaited message [node=" + node.id() + ']');
                        latch.countDown();
                    }
                }
            }
            return false;
        }
    });
    return latch;
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) GridDhtPartitionsFullMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsFullMessage) GridDhtPartitionsAbstractMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsAbstractMessage) GridIoMessage(org.apache.ignite.internal.managers.communication.GridIoMessage) Message(org.apache.ignite.plugin.extensions.communication.Message) GridDhtPartitionsFullMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsFullMessage) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 18 with Message

use of org.apache.ignite.plugin.extensions.communication.Message in project ignite by apache.

the class GridIoManagerBenchmark0 method testLatency.

/**
 * @throws Exception If failed.
 */
@SuppressWarnings("deprecation")
public void testLatency() throws Exception {
    final IgniteKernal sndKernal = (IgniteKernal) grid(0);
    final IgniteKernal rcvKernal = (IgniteKernal) grid(1);
    final ClusterNode sndNode = sndKernal.localNode();
    final ClusterNode rcvNode = rcvKernal.localNode();
    final GridIoManager snd = sndKernal.context().io();
    final GridIoManager rcv = rcvKernal.context().io();
    final LongAdder msgCntr = new LongAdder();
    final Integer topic = 1;
    final Map<IgniteUuid, CountDownLatch> map = new ConcurrentHashMap<>();
    rcv.addMessageListener(topic, new GridMessageListener() {

        @Override
        public void onMessage(UUID nodeId, Object msg, byte plc) {
            try {
                rcv.sendToCustomTopic(sndNode, topic, (Message) msg, PUBLIC_POOL);
            } catch (IgniteCheckedException e) {
                error("Failed to send message.", e);
            }
        }
    });
    snd.addMessageListener(topic, new GridMessageListener() {

        @Override
        public void onMessage(UUID nodeId, Object msg, byte plc) {
            map.get(((GridTestMessage) msg).id()).countDown();
        }
    });
    Timer t = new Timer("results-reporter");
    t.schedule(new TimerTask() {

        private long ts = System.currentTimeMillis();

        @Override
        public void run() {
            long newTs = System.currentTimeMillis();
            long qrys = msgCntr.sumThenReset();
            long time = newTs - ts;
            X.println("Communication benchmark [qps=" + qrys * 1000 / time + ", executed=" + qrys + ", time=" + time + ']');
            ts = newTs;
        }
    }, 10000, 10000);
    final AtomicBoolean finish = new AtomicBoolean();
    IgniteInternalFuture<?> f = GridTestUtils.runMultiThreadedAsync(new Callable<Object>() {

        @Override
        public Object call() throws Exception {
            try {
                IgniteUuid msgId = IgniteUuid.randomUuid();
                while (!finish.get()) {
                    CountDownLatch latch = new CountDownLatch(1);
                    map.put(msgId, latch);
                    snd.sendToCustomTopic(rcvNode, topic, new GridTestMessage(msgId, (String) null), PUBLIC_POOL);
                    latch.await();
                    msgCntr.increment();
                }
            } catch (IgniteCheckedException e) {
                X.println("Message send failed", e);
            } catch (InterruptedException ignored) {
            // No-op.
            }
            return null;
        }
    }, 1, "send-thread");
    Thread.sleep(TEST_TIMEOUT);
    finish.set(true);
    t.cancel();
    f.get();
}
Also used : Message(org.apache.ignite.plugin.extensions.communication.Message) GridMessageListener(org.apache.ignite.internal.managers.communication.GridMessageListener) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) TimerTask(java.util.TimerTask) IgniteUuid(org.apache.ignite.lang.IgniteUuid) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) UUID(java.util.UUID) ClusterNode(org.apache.ignite.cluster.ClusterNode) IgniteKernal(org.apache.ignite.internal.IgniteKernal) CountDownLatch(java.util.concurrent.CountDownLatch) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) LongAdder(java.util.concurrent.atomic.LongAdder) Timer(java.util.Timer) GridIoManager(org.apache.ignite.internal.managers.communication.GridIoManager)

Example 19 with Message

use of org.apache.ignite.plugin.extensions.communication.Message in project ignite by apache.

the class GridTcpCommunicationSpiConcurrentConnectSelfTest method startSpis.

/**
 * @param lsnr Message listener.
 * @throws Exception If failed.
 */
private void startSpis(MessageListener lsnr) throws Exception {
    spis.clear();
    nodes.clear();
    spiRsrcs.clear();
    Map<ClusterNode, GridSpiTestContext> ctxs = new HashMap<>();
    timeoutProcessor = new GridTimeoutProcessor(new GridTestKernalContext(log));
    timeoutProcessor.start();
    timeoutProcessor.onKernalStart(true);
    for (int i = 0; i < SPI_CNT; i++) {
        CommunicationSpi<Message> spi = createSpi();
        IgniteTestResources rsrcs = new IgniteTestResources();
        GridTestNode node = new GridTestNode(rsrcs.getNodeId());
        node.setAttribute(IgniteNodeAttributes.ATTR_CLIENT_MODE, false);
        node.order(i + 1);
        GridSpiTestContext ctx = initSpiContext();
        ctx.setLocalNode(node);
        ctx.timeoutProcessor(timeoutProcessor);
        info(">>> Initialized context: nodeId=" + ctx.localNode().id());
        spiRsrcs.add(rsrcs);
        rsrcs.inject(spi);
        GridTestUtils.setFieldValue(spi, IgniteSpiAdapter.class, "igniteInstanceName", "grid-" + i);
        if (useSsl) {
            IgniteMock ignite = GridTestUtils.getFieldValue(spi, IgniteSpiAdapter.class, "ignite");
            IgniteConfiguration cfg = ignite.configuration().setSslContextFactory(GridTestUtils.sslFactory());
            ignite.setStaticCfg(cfg);
        }
        spi.setListener(lsnr);
        node.setAttributes(spi.getNodeAttributes());
        nodes.add(node);
        spi.spiStart(getTestIgniteInstanceName() + (i + 1));
        spis.add(spi);
        spi.onContextInitialized(ctx);
        ctxs.put(node, ctx);
    }
    // For each context set remote nodes.
    for (Map.Entry<ClusterNode, GridSpiTestContext> e : ctxs.entrySet()) {
        for (ClusterNode n : nodes) {
            if (!n.equals(e.getKey()))
                e.getValue().remoteNodes().add(n);
        }
    }
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) GridSpiTestContext(org.apache.ignite.testframework.GridSpiTestContext) GridTimeoutProcessor(org.apache.ignite.internal.processors.timeout.GridTimeoutProcessor) GridTestMessage(org.apache.ignite.spi.communication.GridTestMessage) Message(org.apache.ignite.plugin.extensions.communication.Message) HashMap(java.util.HashMap) GridTestKernalContext(org.apache.ignite.testframework.junits.GridTestKernalContext) GridTestNode(org.apache.ignite.testframework.GridTestNode) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) IgniteTestResources(org.apache.ignite.testframework.junits.IgniteTestResources) IgniteMock(org.apache.ignite.testframework.junits.IgniteMock) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) Map(java.util.Map)

Example 20 with Message

use of org.apache.ignite.plugin.extensions.communication.Message in project ignite by apache.

the class GridTcpCommunicationSpiMultithreadedSelfTest method testFlowSend.

/**
 * @throws Exception If failed.
 */
public void testFlowSend() throws Exception {
    reject = true;
    final CyclicBarrier barrier = new CyclicBarrier(THREAD_CNT);
    final Random rnd = new Random();
    final ClusterNode from = randomNode(rnd);
    ClusterNode tmp;
    do {
        tmp = randomNode(rnd);
    } while (tmp.id().equals(from.id()));
    final ClusterNode to = tmp;
    final int iterationCnt = 1000;
    final AtomicInteger threadId = new AtomicInteger();
    final int interval = 50;
    IgniteInternalFuture<?> fut = multithreadedAsync(new Runnable() {

        /**
         * {@inheritDoc}
         */
        @Override
        public void run() {
            try {
                // Only first thread will print messages.
                int id = threadId.getAndIncrement();
                for (int i = 0; i < iterationCnt; i++) {
                    if (id == 0 && (i % 50) == 0)
                        info(">>> Running iteration " + i);
                    try {
                        for (ClusterNode node : nodes) {
                            Message msg = new GridTestMessage(from.id(), msgId.getAndIncrement(), 0);
                            spis.get(from.id()).sendMessage(node, msg);
                        }
                    } catch (IgniteException e) {
                        log.warning(">>> Oops, unable to send message (safe to ignore).", e);
                    }
                    barrier.await();
                }
            } catch (InterruptedException ignored) {
                Thread.currentThread().interrupt();
            } catch (BrokenBarrierException e) {
                info("Wait on barrier failed: " + e);
                Thread.currentThread().interrupt();
            }
        }
    }, THREAD_CNT, "message-sender");
    final AtomicBoolean run = new AtomicBoolean(true);
    IgniteInternalFuture<?> fut2 = multithreadedAsync(new Runnable() {

        @Override
        public void run() {
            try {
                while (run.get() && !Thread.currentThread().isInterrupted()) {
                    U.sleep(interval * 3 / 2);
                    ((TcpCommunicationSpi) spis.get(from.id())).onNodeLeft(to.id());
                }
            } catch (IgniteInterruptedCheckedException ignored) {
                Thread.currentThread().interrupt();
            }
        }
    }, 1);
    fut.get();
    run.set(false);
    fut2.get();
    // Wait when all messages are acknowledged to do not break next tests' logic.
    for (CommunicationSpi<Message> spi : spis.values()) {
        GridNioServer srv = U.field(spi, "nioSrvr");
        Collection<? extends GridNioSession> sessions = GridTestUtils.getFieldValue(srv, "sessions");
        for (GridNioSession ses : sessions) {
            final GridNioRecoveryDescriptor snd = ses.outRecoveryDescriptor();
            if (snd != null) {
                GridTestUtils.waitForCondition(new GridAbsPredicate() {

                    @Override
                    public boolean apply() {
                        return snd.messagesRequests().isEmpty();
                    }
                }, 10_000);
                assertEquals("Unexpected messages: " + snd.messagesRequests(), 0, snd.messagesRequests().size());
            }
        }
    }
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) GridTestMessage(org.apache.ignite.spi.communication.GridTestMessage) BrokenBarrierException(java.util.concurrent.BrokenBarrierException) GridTestMessage(org.apache.ignite.spi.communication.GridTestMessage) Message(org.apache.ignite.plugin.extensions.communication.Message) GridNioSession(org.apache.ignite.internal.util.nio.GridNioSession) GridAbsPredicate(org.apache.ignite.internal.util.lang.GridAbsPredicate) GridNioServer(org.apache.ignite.internal.util.nio.GridNioServer) CyclicBarrier(java.util.concurrent.CyclicBarrier) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) Random(java.util.Random) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IgniteException(org.apache.ignite.IgniteException) IgniteRunnable(org.apache.ignite.lang.IgniteRunnable) GridNioRecoveryDescriptor(org.apache.ignite.internal.util.nio.GridNioRecoveryDescriptor)

Aggregations

Message (org.apache.ignite.plugin.extensions.communication.Message)56 ClusterNode (org.apache.ignite.cluster.ClusterNode)30 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)15 Ignite (org.apache.ignite.Ignite)14 IgniteException (org.apache.ignite.IgniteException)11 UUID (java.util.UUID)9 TestRecordingCommunicationSpi (org.apache.ignite.internal.TestRecordingCommunicationSpi)9 GridTestMessage (org.apache.ignite.spi.communication.GridTestMessage)9 GridDhtPartitionsFullMessage (org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsFullMessage)8 IgniteTestResources (org.apache.ignite.testframework.junits.IgniteTestResources)8 ArrayList (java.util.ArrayList)7 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)7 GridIoMessage (org.apache.ignite.internal.managers.communication.GridIoMessage)7 GridDhtPartitionSupplyMessage (org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionSupplyMessage)7 HashMap (java.util.HashMap)6 IgniteSpiException (org.apache.ignite.spi.IgniteSpiException)6 Collection (java.util.Collection)5 CountDownLatch (java.util.concurrent.CountDownLatch)5 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)5 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)5