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());
}
Aggregations