Search in sources :

Example 1 with GridDhtPreloaderAssignments

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

the class PreloadingRestartWhileClearingPartitionTest method testPreloadingRestart.

/**
 * @throws Exception If failed.
 */
@Test
public void testPreloadingRestart() throws Exception {
    IgniteEx crd = startGrids(3);
    crd.cluster().state(ClusterState.ACTIVE);
    final int clearingPart = 0;
    final int cnt = 1_100;
    final int delta = 2_000;
    final int rmv = 1_500;
    loadDataToPartition(clearingPart, getTestIgniteInstanceName(0), DEFAULT_CACHE_NAME, cnt, 0);
    forceCheckpoint();
    stopGrid(2);
    loadDataToPartition(clearingPart, getTestIgniteInstanceName(0), DEFAULT_CACHE_NAME, delta, cnt);
    // Removal required for triggering full rebalancing.
    List<Integer> clearKeys = partitionKeys(grid(0).cache(DEFAULT_CACHE_NAME), clearingPart, rmv, cnt);
    for (Integer clearKey : clearKeys) grid(0).cache(DEFAULT_CACHE_NAME).remove(clearKey);
    CountDownLatch lock = new CountDownLatch(1);
    CountDownLatch unlock = new CountDownLatch(1);
    // Start node and delay preloading in the middle of partition clearing.
    IgniteEx g2 = startGrid(2, new DependencyResolver() {

        @Override
        public <T> T resolve(T instance) {
            if (instance instanceof GridDhtPartitionTopologyImpl) {
                GridDhtPartitionTopologyImpl top = (GridDhtPartitionTopologyImpl) instance;
                top.partitionFactory(new GridDhtPartitionTopologyImpl.PartitionFactory() {

                    @Override
                    public GridDhtLocalPartition create(GridCacheSharedContext ctx, CacheGroupContext grp, int id, boolean recovery) {
                        return id == clearingPart ? new GridDhtLocalPartitionSyncEviction(ctx, grp, id, recovery, 1, lock, unlock) : new GridDhtLocalPartition(ctx, grp, id, recovery);
                    }
                });
            }
            return instance;
        }
    });
    assertTrue(U.await(lock, GridDhtLocalPartitionSyncEviction.TIMEOUT, TimeUnit.MILLISECONDS));
    // Stop supplier for clearingPart.
    GridCacheContext<Object, Object> ctx = g2.cachex(DEFAULT_CACHE_NAME).context();
    GridDhtPartitionDemander.RebalanceFuture rebFut = (GridDhtPartitionDemander.RebalanceFuture) ctx.preloader().rebalanceFuture();
    GridDhtPreloaderAssignments assignments = U.field(rebFut, "assignments");
    ClusterNode supplier = assignments.supplier(clearingPart);
    AtomicReference<GridFutureAdapter<?>> ref = U.field(ctx.topology().localPartition(clearingPart), "finishFutRef");
    GridFutureAdapter clearFut = ref.get();
    assertFalse(clearFut.isDone());
    grid(supplier).close();
    doSleep(1000);
    unlock.countDown();
    awaitPartitionMapExchange(true, true, null);
    assertPartitionsSame(idleVerify(grid(2), DEFAULT_CACHE_NAME));
    for (Ignite grid : G.allGrids()) assertEquals(cnt + delta - rmv, grid.cache(DEFAULT_CACHE_NAME).size());
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) CountDownLatch(java.util.concurrent.CountDownLatch) GridCacheSharedContext(org.apache.ignite.internal.processors.cache.GridCacheSharedContext) GridDhtPartitionDemander(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionDemander) DependencyResolver(org.apache.ignite.internal.processors.resource.DependencyResolver) GridDhtPreloaderAssignments(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPreloaderAssignments) IgniteEx(org.apache.ignite.internal.IgniteEx) GridFutureAdapter(org.apache.ignite.internal.util.future.GridFutureAdapter) Ignite(org.apache.ignite.Ignite) CacheGroupContext(org.apache.ignite.internal.processors.cache.CacheGroupContext) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Aggregations

CountDownLatch (java.util.concurrent.CountDownLatch)1 Ignite (org.apache.ignite.Ignite)1 ClusterNode (org.apache.ignite.cluster.ClusterNode)1 IgniteEx (org.apache.ignite.internal.IgniteEx)1 CacheGroupContext (org.apache.ignite.internal.processors.cache.CacheGroupContext)1 GridCacheSharedContext (org.apache.ignite.internal.processors.cache.GridCacheSharedContext)1 GridDhtPartitionDemander (org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionDemander)1 GridDhtPreloaderAssignments (org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPreloaderAssignments)1 DependencyResolver (org.apache.ignite.internal.processors.resource.DependencyResolver)1 GridFutureAdapter (org.apache.ignite.internal.util.future.GridFutureAdapter)1 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)1 Test (org.junit.Test)1