Search in sources :

Example 1 with GridCachePreloader

use of org.apache.ignite.internal.processors.cache.GridCachePreloader in project ignite by apache.

the class IgniteWalRebalanceTest method testRebalanceCancelOnSupplyError.

/**
 * Tests that cache rebalance is cancelled if supplyer node got exception during iteration over WAL.
 *
 * @throws Exception If failed.
 */
@Test
public void testRebalanceCancelOnSupplyError() throws Exception {
    backups = 4;
    // Prepare some data.
    IgniteEx crd = startGrids(3);
    crd.cluster().state(ACTIVE);
    final int entryCnt = PARTS_CNT * 10;
    final int preloadEntryCnt = PARTS_CNT * 11;
    {
        IgniteCache<Object, Object> cache = crd.cache(CACHE_NAME);
        for (int k = 0; k < preloadEntryCnt; k++) cache.put(k, new IndexedObject(k - 1));
    }
    forceCheckpoint();
    stopAllGrids();
    // Rewrite data to trigger further rebalance.
    IgniteEx supplierNode = startGrid(0);
    supplierNode.cluster().state(ACTIVE);
    IgniteCache<Object, Object> cache = supplierNode.cache(CACHE_NAME);
    for (int k = 0; k < entryCnt; k++) cache.put(k, new IndexedObject(k));
    forceCheckpoint();
    final int grpId = supplierNode.cachex(CACHE_NAME).context().groupId();
    // Delay rebalance process for specified group.
    blockMsgPred = (node, msg) -> {
        if (msg instanceof GridDhtPartitionDemandMessage)
            return ((GridDhtPartitionDemandMessage) msg).groupId() == grpId;
        return false;
    };
    IgniteEx demanderNode = startGrid(2);
    AffinityTopologyVersion curTopVer = demanderNode.context().discovery().topologyVersionEx();
    // Wait for rebalance process start on demander node.
    final GridCachePreloader preloader = demanderNode.cachex(CACHE_NAME).context().group().preloader();
    GridTestUtils.waitForCondition(() -> ((GridDhtPartitionDemander.RebalanceFuture) preloader.rebalanceFuture()).topologyVersion().equals(curTopVer), getTestTimeout());
    // Inject I/O factory which can throw exception during WAL read on supplier node.
    FailingIOFactory ioFactory = injectFailingIOFactory(supplierNode);
    // Resume rebalance process.
    TestRecordingCommunicationSpi spi = (TestRecordingCommunicationSpi) demanderNode.configuration().getCommunicationSpi();
    spi.stopBlock();
    // Wait till rebalance will be failed and cancelled.
    Boolean res = preloader.rebalanceFuture().get();
    Assert.assertEquals("Rebalance should be cancelled on demander node: " + preloader.rebalanceFuture(), false, res);
    // Stop blocking messages and fail WAL during read.
    blockMsgPred = null;
    ioFactory.reset();
    // Start last grid and wait for rebalance.
    startGrid(1);
    awaitPartitionMapExchange();
    // Check data consistency.
    for (Ignite ig : G.allGrids()) {
        IgniteCache<Object, Object> cache1 = ig.cache(CACHE_NAME);
        for (int k = 0; k < entryCnt; k++) assertEquals(new IndexedObject(k), cache1.get(k));
    }
}
Also used : AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) GridCachePreloader(org.apache.ignite.internal.processors.cache.GridCachePreloader) IgniteCache(org.apache.ignite.IgniteCache) TestRecordingCommunicationSpi(org.apache.ignite.internal.TestRecordingCommunicationSpi) IgniteEx(org.apache.ignite.internal.IgniteEx) Ignite(org.apache.ignite.Ignite) GridDhtPartitionDemandMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionDemandMessage) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Aggregations

Ignite (org.apache.ignite.Ignite)1 IgniteCache (org.apache.ignite.IgniteCache)1 IgniteEx (org.apache.ignite.internal.IgniteEx)1 TestRecordingCommunicationSpi (org.apache.ignite.internal.TestRecordingCommunicationSpi)1 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)1 GridCachePreloader (org.apache.ignite.internal.processors.cache.GridCachePreloader)1 GridDhtPartitionDemandMessage (org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionDemandMessage)1 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)1 Test (org.junit.Test)1