Search in sources :

Example 26 with Message

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

the class CacheLateAffinityAssignmentTest method testJoinExchangeBecomeCoordinator.

/**
 * @throws Exception If failed.
 */
public void testJoinExchangeBecomeCoordinator() throws Exception {
    long topVer = 0;
    final int NODES = 3;
    for (int i = 0; i < NODES; i++) startServer(i, ++topVer);
    checkAffinity(NODES, topVer(topVer, 1), true);
    for (int i = 0; i < NODES; i++) {
        TestRecordingCommunicationSpi spi = (TestRecordingCommunicationSpi) ignite(i).configuration().getCommunicationSpi();
        spi.blockMessages(new IgniteBiPredicate<ClusterNode, Message>() {

            @Override
            public boolean apply(ClusterNode node, Message msg) {
                return msg.getClass().equals(GridDhtPartitionsSingleMessage.class) || msg.getClass().equals(GridDhtPartitionsFullMessage.class);
            }
        });
    }
    final CountDownLatch latch = new CountDownLatch(1);
    IgniteInternalFuture<?> stopFut = GridTestUtils.runAsync(new Callable<Void>() {

        @Override
        public Void call() throws Exception {
            latch.await();
            U.sleep(5000);
            for (int i = 0; i < NODES; i++) stopGrid(getTestIgniteInstanceName(i), false, false);
            return null;
        }
    }, "stop-thread");
    latch.countDown();
    Ignite node = startGrid(NODES);
    assertEquals(NODES + 1, node.cluster().localNode().order());
    stopFut.get();
    for (int i = 0; i < NODES + 1; i++) calculateAffinity(++topVer);
    checkAffinity(1, topVer(topVer, 0), true);
    for (int i = 0; i < NODES; i++) startServer(i, ++topVer);
    checkAffinity(NODES + 1, topVer(topVer, 1), true);
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) GridDhtPartitionSupplyMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionSupplyMessage) DiscoverySpiCustomMessage(org.apache.ignite.spi.discovery.DiscoverySpiCustomMessage) Message(org.apache.ignite.plugin.extensions.communication.Message) DiscoveryCustomMessage(org.apache.ignite.internal.managers.discovery.DiscoveryCustomMessage) GridDhtPartitionsSingleMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsSingleMessage) GridDhtPartitionsFullMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsFullMessage) CacheAffinityChangeMessage(org.apache.ignite.internal.processors.cache.CacheAffinityChangeMessage) CountDownLatch(java.util.concurrent.CountDownLatch) IgniteException(org.apache.ignite.IgniteException) ClusterTopologyServerNotFoundException(org.apache.ignite.internal.cluster.ClusterTopologyServerNotFoundException) TestRecordingCommunicationSpi(org.apache.ignite.internal.TestRecordingCommunicationSpi) Ignite(org.apache.ignite.Ignite)

Example 27 with Message

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

the class CacheLateAffinityAssignmentTest method testNoForceKeysRequests.

/**
 * @throws Exception If failed.
 */
public void testNoForceKeysRequests() throws Exception {
    fail("https://issues.apache.org/jira/browse/IGNITE-5510");
    cacheC = new IgniteClosure<String, CacheConfiguration[]>() {

        @Override
        public CacheConfiguration[] apply(String s) {
            return null;
        }
    };
    final AtomicBoolean fail = new AtomicBoolean();
    spiC = new IgniteClosure<String, TestRecordingCommunicationSpi>() {

        @Override
        public TestRecordingCommunicationSpi apply(String s) {
            TestRecordingCommunicationSpi spi = new TestRecordingCommunicationSpi();
            spi.blockMessages(new IgniteBiPredicate<ClusterNode, Message>() {

                @Override
                public boolean apply(ClusterNode node, Message msg) {
                    if (msg instanceof GridDhtForceKeysRequest || msg instanceof GridDhtForceKeysResponse) {
                        fail.set(true);
                        U.dumpStack(log, "Unexpected message: " + msg);
                    }
                    return false;
                }
            });
            return spi;
        }
    };
    final int SRVS = 3;
    for (int i = 0; i < SRVS; i++) startGrid(i);
    client = true;
    startGrid(SRVS);
    client = false;
    final List<CacheConfiguration> ccfgs = new ArrayList<>();
    ccfgs.add(cacheConfiguration("tc1", TRANSACTIONAL, 0));
    ccfgs.add(cacheConfiguration("tc2", TRANSACTIONAL, 1));
    ccfgs.add(cacheConfiguration("tc3", TRANSACTIONAL, 2));
    for (CacheConfiguration ccfg : ccfgs) ignite(0).createCache(ccfg);
    final int NODES = SRVS + 1;
    final AtomicInteger nodeIdx = new AtomicInteger();
    final long stopTime = System.currentTimeMillis() + 60_000;
    IgniteInternalFuture<?> updateFut = GridTestUtils.runMultiThreadedAsync(new Callable<Void>() {

        @Override
        public Void call() throws Exception {
            int idx = nodeIdx.getAndIncrement();
            Ignite node = grid(idx);
            List<IgniteCache<Object, Object>> caches = new ArrayList<>();
            for (CacheConfiguration ccfg : ccfgs) caches.add(node.cache(ccfg.getName()));
            while (!fail.get() && System.currentTimeMillis() < stopTime) {
                for (IgniteCache<Object, Object> cache : caches) cacheOperations(cache);
            }
            return null;
        }
    }, NODES, "update-thread");
    IgniteInternalFuture<?> srvRestartFut = GridTestUtils.runAsync(new Callable<Void>() {

        @Override
        public Void call() throws Exception {
            while (!fail.get() && System.currentTimeMillis() < stopTime) {
                Ignite node = startGrid(NODES);
                List<IgniteCache<Object, Object>> caches = new ArrayList<>();
                for (CacheConfiguration ccfg : ccfgs) caches.add(node.cache(ccfg.getName()));
                for (int i = 0; i < 2; i++) {
                    for (IgniteCache<Object, Object> cache : caches) cacheOperations(cache);
                }
                U.sleep(500);
                stopGrid(NODES);
                U.sleep(500);
            }
            return null;
        }
    }, "srv-restart");
    srvRestartFut.get();
    updateFut.get();
    assertFalse("Unexpected messages.", fail.get());
}
Also used : GridDhtForceKeysResponse(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtForceKeysResponse) GridDhtPartitionSupplyMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionSupplyMessage) DiscoverySpiCustomMessage(org.apache.ignite.spi.discovery.DiscoverySpiCustomMessage) Message(org.apache.ignite.plugin.extensions.communication.Message) DiscoveryCustomMessage(org.apache.ignite.internal.managers.discovery.DiscoveryCustomMessage) GridDhtPartitionsSingleMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsSingleMessage) GridDhtPartitionsFullMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsFullMessage) CacheAffinityChangeMessage(org.apache.ignite.internal.processors.cache.CacheAffinityChangeMessage) ArrayList(java.util.ArrayList) GridDhtForceKeysRequest(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtForceKeysRequest) Ignite(org.apache.ignite.Ignite) List(java.util.List) ArrayList(java.util.ArrayList) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) ClusterNode(org.apache.ignite.cluster.ClusterNode) IgniteBiPredicate(org.apache.ignite.lang.IgniteBiPredicate) IgniteCache(org.apache.ignite.IgniteCache) IgniteException(org.apache.ignite.IgniteException) ClusterTopologyServerNotFoundException(org.apache.ignite.internal.cluster.ClusterTopologyServerNotFoundException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) TestRecordingCommunicationSpi(org.apache.ignite.internal.TestRecordingCommunicationSpi) AtomicInteger(java.util.concurrent.atomic.AtomicInteger)

Example 28 with Message

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

the class IgniteClientCacheStartFailoverTest method testRebalanceState.

/**
 * @throws Exception If failed.
 */
public void testRebalanceState() throws Exception {
    final int SRVS = 3;
    startGrids(SRVS);
    List<String> cacheNames = startCaches(ignite(0), 100);
    client = true;
    Ignite c = startGrid(SRVS);
    assertTrue(c.configuration().isClientMode());
    awaitPartitionMapExchange();
    client = false;
    TestRecordingCommunicationSpi.spi(ignite(0)).blockMessages(new IgniteBiPredicate<ClusterNode, Message>() {

        @Override
        public boolean apply(ClusterNode clusterNode, Message msg) {
            return msg instanceof GridDhtPartitionsFullMessage && ((GridDhtPartitionsFullMessage) msg).exchangeId() == null;
        }
    });
    startGrid(SRVS + 1);
    for (String cacheName : cacheNames) c.cache(cacheName);
    U.sleep(1000);
    for (int i = 0; i < SRVS + 1; i++) {
        AffinityTopologyVersion topVer = new AffinityTopologyVersion(SRVS + 2);
        IgniteKernal node = (IgniteKernal) ignite(i);
        for (String cacheName : cacheNames) {
            GridDhtPartitionTopology top = node.context().cache().internalCache(cacheName).context().topology();
            waitForReadyTopology(top, topVer);
            assertEquals(topVer, top.readyTopologyVersion());
            assertFalse(top.rebalanceFinished(topVer));
        }
    }
    TestRecordingCommunicationSpi.spi(ignite(0)).stopBlock();
    for (int i = 0; i < SRVS + 1; i++) {
        final AffinityTopologyVersion topVer = new AffinityTopologyVersion(SRVS + 2, 1);
        final IgniteKernal node = (IgniteKernal) ignite(i);
        for (String cacheName : cacheNames) {
            final GridDhtPartitionTopology top = node.context().cache().internalCache(cacheName).context().topology();
            GridTestUtils.waitForCondition(new GridAbsPredicate() {

                @Override
                public boolean apply() {
                    return top.rebalanceFinished(topVer);
                }
            }, 5000);
            assertTrue(top.rebalanceFinished(topVer));
        }
    }
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) IgniteKernal(org.apache.ignite.internal.IgniteKernal) GridDhtPartitionsFullMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsFullMessage) Message(org.apache.ignite.plugin.extensions.communication.Message) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) GridDhtPartitionTopology(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtPartitionTopology) GridAbsPredicate(org.apache.ignite.internal.util.lang.GridAbsPredicate) GridDhtPartitionsFullMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsFullMessage) Ignite(org.apache.ignite.Ignite)

Example 29 with Message

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

the class IgniteOnePhaseCommitInvokeTest method onePhaseInvoke.

/**
 * @param withOldVal If {@code true}
 * @param setVal Flag whether set value from entry processor.
 * @param retPrev Flag whether entry processor should return previous value.
 * @throws Exception If failed.
 */
private void onePhaseInvoke(final boolean withOldVal, final boolean setVal, final boolean retPrev) throws Exception {
    log.info("Test onePhaseInvoke [withOldVal=" + withOldVal + ", setVal=" + setVal + ", retPrev=" + retPrev + ']');
    Ignite srv0 = startGrid(0);
    if (withOldVal)
        srv0.cache(CACHE_NAME).put(1, 1);
    client = true;
    final Ignite clientNode = startGrid(1);
    final int grpId = groupIdForCache(srv0, CACHE_NAME);
    TestRecordingCommunicationSpi.spi(srv0).blockMessages(new IgniteBiPredicate<ClusterNode, Message>() {

        @Override
        public boolean apply(ClusterNode node, Message msg) {
            return msg instanceof GridDhtPartitionSupplyMessage && ((GridDhtPartitionSupplyMessage) msg).groupId() == grpId;
        }
    });
    client = false;
    Ignite srv1 = startGrid(2);
    TestRecordingCommunicationSpi.spi(srv1).blockMessages(GridDhtTxPrepareResponse.class, srv0.name());
    IgniteInternalFuture<?> fut = GridTestUtils.runAsync(new Callable<Void>() {

        @Override
        public Void call() throws Exception {
            Object res = clientNode.cache(CACHE_NAME).invoke(1, new TestEntryProcessor(setVal, retPrev));
            Object expRes;
            if (retPrev)
                expRes = withOldVal ? 1 : null;
            else
                expRes = null;
            assertEquals(expRes, res);
            return null;
        }
    });
    U.sleep(1000);
    stopGrid(0);
    fut.get();
    if (!setVal)
        checkCacheData(F.asMap(1, null), CACHE_NAME);
    else {
        Object expVal;
        if (setVal)
            expVal = 2;
        else
            expVal = withOldVal ? 1 : null;
        checkCacheData(F.asMap(1, expVal), CACHE_NAME);
    }
    checkOnePhaseCommitReturnValuesCleaned(-1);
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) GridDhtPartitionSupplyMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionSupplyMessage) Message(org.apache.ignite.plugin.extensions.communication.Message) GridDhtPartitionSupplyMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionSupplyMessage) Ignite(org.apache.ignite.Ignite)

Example 30 with Message

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

the class IgniteTxOriginatingNodeFailureAbstractSelfTest method getConfiguration.

/**
 * {@inheritDoc}
 */
@Override
protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
    IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
    cfg.setCommunicationSpi(new TcpCommunicationSpi() {

        @Override
        public void sendMessage(ClusterNode node, Message msg, IgniteInClosure<IgniteException> ackClosure) throws IgniteSpiException {
            if (!F.eq(ignoreMsgNodeId, node.id()) || !ignoredMessage((GridIoMessage) msg))
                super.sendMessage(node, msg, ackClosure);
        }
    });
    cfg.getTransactionConfiguration().setDefaultTxConcurrency(OPTIMISTIC);
    return cfg;
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) GridIoMessage(org.apache.ignite.internal.managers.communication.GridIoMessage) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) GridIoMessage(org.apache.ignite.internal.managers.communication.GridIoMessage) Message(org.apache.ignite.plugin.extensions.communication.Message) IgniteException(org.apache.ignite.IgniteException) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException) TcpCommunicationSpi(org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi)

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