Search in sources :

Example 21 with GridDhtPartitionsFullMessage

use of org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsFullMessage in project ignite by apache.

the class TxOnCachesStopTest method testOptimisticTxMappedOnPMETopology.

/**
 * @throws Exception If failed.
 */
@Test
public void testOptimisticTxMappedOnPMETopology() throws Exception {
    Assume.assumeFalse(MvccFeatureChecker.forcedMvcc());
    startGridsMultiThreaded(1);
    Ignite client = startClientGrid("client");
    client.cluster().active(true);
    awaitPartitionMapExchange(true, true, null);
    final IgniteCache<Integer, byte[]> cache = client.getOrCreateCache(destroyCacheCfg);
    final IgniteCache<Integer, byte[]> cache2 = client.getOrCreateCache(surviveCacheCfg);
    final TestRecordingCommunicationSpi srvSpi = TestRecordingCommunicationSpi.spi(grid(0));
    CountDownLatch destroyLatch = new CountDownLatch(1);
    srvSpi.blockMessages((node, msg) -> (msg instanceof GridDhtPartitionsFullMessage));
    try (Transaction tx = client.transactions().txStart(OPTIMISTIC, SERIALIZABLE)) {
        cache2.put(100, new byte[1024]);
        cache.put(100, new byte[1024]);
        GridTestUtils.runAsync(() -> {
            grid(0).destroyCache(destroyCacheCfg.getName());
            destroyLatch.countDown();
        });
        destroyLatch.await();
        IgniteFuture commitFut = tx.commitAsync();
        srvSpi.stopBlock();
        commitFut.get(10_000);
        fail("Transaction should be rolled back.");
    } catch (IgniteFutureTimeoutException fte) {
        srvSpi.stopBlock();
        fail("Partition map exchange hangs [err=" + fte + ']');
    } catch (IgniteException e) {
        srvSpi.stopBlock();
        assertTrue(X.hasCause(e, CacheInvalidStateException.class) || X.hasCause(e, IgniteException.class));
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IgniteFutureTimeoutException(org.apache.ignite.lang.IgniteFutureTimeoutException) TestRecordingCommunicationSpi(org.apache.ignite.internal.TestRecordingCommunicationSpi) GridDhtPartitionsFullMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsFullMessage) Transaction(org.apache.ignite.transactions.Transaction) IgniteException(org.apache.ignite.IgniteException) IgniteFuture(org.apache.ignite.lang.IgniteFuture) Ignite(org.apache.ignite.Ignite) CountDownLatch(java.util.concurrent.CountDownLatch) CacheInvalidStateException(org.apache.ignite.internal.processors.cache.CacheInvalidStateException) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 22 with GridDhtPartitionsFullMessage

use of org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsFullMessage in project ignite by apache.

the class IgniteClientCacheStartFailoverTest method testRebalanceState.

/**
 * @throws Exception If failed.
 */
@Test
public void testRebalanceState() throws Exception {
    final int SRVS = 3;
    startGrids(SRVS);
    List<String> cacheNames = startCaches(ignite(0), 100);
    Ignite c = startClientGrid(SRVS);
    assertTrue(c.configuration().isClientMode());
    awaitPartitionMapExchange();
    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);
    // Will switch to ideal topology but some partitions are not evicted yet.
    for (int i = 0; i < SRVS + 1; i++) {
        AffinityTopologyVersion topVer = new AffinityTopologyVersion(SRVS + 2, 1);
        IgniteKernal node = (IgniteKernal) ignite(i);
        for (String cacheName : cacheNames) {
            GridDhtPartitionTopology top = node.cachex(cacheName).context().topology();
            waitForReadyTopology(top, topVer);
            assertEquals(topVer, top.readyTopologyVersion());
        }
    }
    TestRecordingCommunicationSpi.spi(ignite(0)).stopBlock();
    // Trigger eviction.
    awaitPartitionMapExchange();
    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.cachex(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.topology.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) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Aggregations

GridDhtPartitionsFullMessage (org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsFullMessage)22 TestRecordingCommunicationSpi (org.apache.ignite.internal.TestRecordingCommunicationSpi)12 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)12 ClusterNode (org.apache.ignite.cluster.ClusterNode)11 Message (org.apache.ignite.plugin.extensions.communication.Message)8 Ignite (org.apache.ignite.Ignite)7 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)7 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)5 IgniteEx (org.apache.ignite.internal.IgniteEx)5 CountDownLatch (java.util.concurrent.CountDownLatch)4 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4 GridDhtPartitionsAbstractMessage (org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsAbstractMessage)4 Transaction (org.apache.ignite.transactions.Transaction)4 Test (org.junit.Test)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 IgniteFutureTimeoutCheckedException (org.apache.ignite.internal.IgniteFutureTimeoutCheckedException)3 ClusterTopologyCheckedException (org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)3 GridAffinityAssignmentCache (org.apache.ignite.internal.processors.affinity.GridAffinityAssignmentCache)3 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)3