Search in sources :

Example 46 with CacheGroupContext

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

the class LocalWalModeChangeDuringRebalancingSelfTest method testWalDisabledDuringRebalancingWithPendingTxTracker.

/**
 * @throws Exception If failed.
 */
@Test
public void testWalDisabledDuringRebalancingWithPendingTxTracker() throws Exception {
    enablePendingTxTracker = true;
    dfltCacheBackupCnt = 2;
    Ignite ignite = startGrids(3);
    ignite.cluster().baselineAutoAdjustEnabled(false);
    ignite.cluster().state(ACTIVE);
    ignite.cluster().setBaselineTopology(3);
    IgniteCache<Integer, Integer> cache = ignite.cache(DEFAULT_CACHE_NAME);
    stopGrid(2);
    awaitExchange((IgniteEx) ignite);
    // Ensure each partition has received an update.
    for (int k = 0; k < RendezvousAffinityFunction.DFLT_PARTITION_COUNT; k++) cache.put(k, k);
    IgniteEx newIgnite = startGrid(2);
    awaitExchange(newIgnite);
    CacheGroupContext grpCtx = newIgnite.cachex(DEFAULT_CACHE_NAME).context().group();
    assertFalse(grpCtx.walEnabled());
    long rebalanceStartedTs = System.currentTimeMillis();
    for (Ignite g : G.allGrids()) g.cache(DEFAULT_CACHE_NAME).rebalance();
    awaitPartitionMapExchange();
    assertTrue(grpCtx.walEnabled());
    long rebalanceFinishedTs = System.currentTimeMillis();
    CheckpointHistory cpHist = ((GridCacheDatabaseSharedManager) newIgnite.context().cache().context().database()).checkpointHistory();
    assertNotNull(cpHist);
    // Ensure there was a checkpoint on WAL re-activation.
    assertEquals(1, cpHist.checkpoints().stream().filter(ts -> rebalanceStartedTs <= ts && ts <= rebalanceFinishedTs).count());
}
Also used : CheckpointHistory(org.apache.ignite.internal.processors.cache.persistence.checkpoint.CheckpointHistory) IgniteEx(org.apache.ignite.internal.IgniteEx) 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)

Example 47 with CacheGroupContext

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

the class LocalWalModeChangeDuringRebalancingSelfTest method testLocalAndGlobalWalStateInterdependence.

/**
 * @throws Exception If failed.
 */
@Test
public void testLocalAndGlobalWalStateInterdependence() throws Exception {
    Ignite ignite = startGrids(3);
    ignite.cluster().baselineAutoAdjustEnabled(false);
    ignite.cluster().state(ACTIVE);
    IgniteCache<Integer, Integer> cache = ignite.cache(DEFAULT_CACHE_NAME);
    for (int k = 0; k < getKeysCount(); k++) cache.put(k, k);
    IgniteEx newIgnite = startGrid(3);
    newIgnite.cluster().setBaselineTopology(ignite.cluster().nodes());
    awaitExchange(newIgnite);
    CacheGroupContext grpCtx = newIgnite.cachex(DEFAULT_CACHE_NAME).context().group();
    assertFalse(grpCtx.walEnabled());
    ignite.cluster().disableWal(DEFAULT_CACHE_NAME);
    for (Ignite g : G.allGrids()) g.cache(DEFAULT_CACHE_NAME).rebalance();
    awaitPartitionMapExchange();
    // WAL is globally disabled
    assertFalse(grpCtx.walEnabled());
    ignite.cluster().enableWal(DEFAULT_CACHE_NAME);
    assertTrue(grpCtx.walEnabled());
}
Also used : IgniteEx(org.apache.ignite.internal.IgniteEx) 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)

Example 48 with CacheGroupContext

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

the class ZkCommunicationFailureContext method cachePartitionOwners.

/**
 * {@inheritDoc}
 */
@Override
public List<List<ClusterNode>> cachePartitionOwners(String cacheName) {
    if (cacheName == null)
        throw new NullPointerException("Null cache name.");
    DynamicCacheDescriptor cacheDesc = ctx.affinity().caches().get(CU.cacheId(cacheName));
    if (cacheDesc == null)
        throw new IllegalArgumentException("Invalid cache name: " + cacheName);
    if (cacheDesc.cacheConfiguration().getCacheMode() == CacheMode.LOCAL)
        return Collections.emptyList();
    CacheGroupContext grp = ctx.cache().cacheGroup(cacheDesc.groupId());
    GridDhtPartitionTopology top;
    if (grp == null) {
        top = ctx.exchange().clientTopologyIfExists(cacheDesc.groupId());
        assert top != null : cacheName;
    } else
        top = grp.topology();
    return top.allOwners();
}
Also used : GridDhtPartitionTopology(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtPartitionTopology) DynamicCacheDescriptor(org.apache.ignite.internal.processors.cache.DynamicCacheDescriptor) CacheGroupContext(org.apache.ignite.internal.processors.cache.CacheGroupContext)

Example 49 with CacheGroupContext

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

the class MovingPartitionIsEvictedDuringClearingTest method testMovingToEvicted.

/**
 * @throws Exception If failed.
 */
@Test
public void testMovingToEvicted() throws Exception {
    IgniteEx crd = startGrids(3);
    crd.cluster().state(ClusterState.ACTIVE);
    final int evictingPart = evictingPartitionsAfterJoin(grid(2), grid(2).cache(DEFAULT_CACHE_NAME), 1).get(0);
    final int cnt = 1_100;
    final int delta = 2_000;
    final int rmv = 1_500;
    loadDataToPartition(evictingPart, getTestIgniteInstanceName(0), DEFAULT_CACHE_NAME, cnt, 0, 3);
    forceCheckpoint();
    stopGrid(2);
    loadDataToPartition(evictingPart, getTestIgniteInstanceName(0), DEFAULT_CACHE_NAME, delta, cnt, 3);
    // Removal required for triggering full rebalancing.
    List<Integer> clearKeys = partitionKeys(grid(0).cache(DEFAULT_CACHE_NAME), evictingPart, 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 == evictingPart ? new GridDhtLocalPartitionSyncEviction(ctx, grp, id, recovery, 2, lock, unlock) : new GridDhtLocalPartition(ctx, grp, id, recovery);
                    }
                });
            }
            return instance;
        }
    });
    assertTrue(U.await(lock, GridDhtLocalPartitionSyncEviction.TIMEOUT, TimeUnit.MILLISECONDS));
    startGrid(4);
    resetBaselineTopology();
    awaitPartitionMapExchange();
    // Give some time for partition state messages to process.
    doSleep(3_000);
    // Finish clearing.
    unlock.countDown();
    awaitPartitionMapExchange();
    // Partition will remaing in renting state until next exchange.
    assertEquals(RENTING, g2.cachex(DEFAULT_CACHE_NAME).context().topology().localPartition(evictingPart).state());
    validadate(cnt + delta - rmv);
    stopGrid(2);
    startGrid(2);
    awaitPartitionMapExchange(true, true, null);
    validadate(cnt + delta - rmv);
}
Also used : CountDownLatch(java.util.concurrent.CountDownLatch) GridCacheSharedContext(org.apache.ignite.internal.processors.cache.GridCacheSharedContext) DependencyResolver(org.apache.ignite.internal.processors.resource.DependencyResolver) IgniteEx(org.apache.ignite.internal.IgniteEx) CacheGroupContext(org.apache.ignite.internal.processors.cache.CacheGroupContext) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 50 with CacheGroupContext

use of org.apache.ignite.internal.processors.cache.CacheGroupContext 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

CacheGroupContext (org.apache.ignite.internal.processors.cache.CacheGroupContext)103 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)31 IgniteEx (org.apache.ignite.internal.IgniteEx)29 Map (java.util.Map)27 HashMap (java.util.HashMap)24 IgniteException (org.apache.ignite.IgniteException)22 ArrayList (java.util.ArrayList)21 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)20 Test (org.junit.Test)20 GridDhtLocalPartition (org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtLocalPartition)19 List (java.util.List)17 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)17 GridCacheContext (org.apache.ignite.internal.processors.cache.GridCacheContext)16 GridDhtPartitionTopology (org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtPartitionTopology)16 HashSet (java.util.HashSet)13 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)12 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)12 GridCacheSharedContext (org.apache.ignite.internal.processors.cache.GridCacheSharedContext)12 Set (java.util.Set)11 Collection (java.util.Collection)10