Search in sources :

Example 41 with CacheGroupContext

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

the class IgnitePdsDefragmentationTest method defragmentAndValidateSizesDecreasedAfterDefragmentation.

/**
 * Start node, wait for defragmentation and validate that sizes of caches are less than those before the defragmentation.
 * @param gridId Idx of ignite grid.
 * @param groups Cache groups to check.
 * @throws Exception If failed.
 */
protected void defragmentAndValidateSizesDecreasedAfterDefragmentation(int gridId, CacheGroupContext... groups) throws Exception {
    for (CacheGroupContext grp : groups) {
        final long[] oldPartLen = partitionSizes(grp);
        startGrid(0);
        waitForDefragmentation(0);
        stopGrid(0);
        final long[] newPartLen = partitionSizes(grp);
        boolean atLeastOneSmaller = false;
        for (int p = 0; p < oldPartLen.length; p++) {
            assertTrue(newPartLen[p] <= oldPartLen[p]);
            if (newPartLen[p] < oldPartLen[p])
                atLeastOneSmaller = true;
        }
        assertTrue(atLeastOneSmaller);
    }
}
Also used : CacheGroupContext(org.apache.ignite.internal.processors.cache.CacheGroupContext)

Example 42 with CacheGroupContext

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

the class PendingTreeCorruptionTest method testCorruptionWhileLoadingData.

/**
 */
@Test
public void testCorruptionWhileLoadingData() throws Exception {
    IgniteEx ig = startGrid(0);
    ig.cluster().state(ClusterState.ACTIVE);
    String expireCacheName = "cacheWithExpire";
    String regularCacheName = "cacheWithoutExpire";
    String grpName = "cacheGroup";
    IgniteCache<Object, Object> expireCache = ig.getOrCreateCache(new CacheConfiguration<>(expireCacheName).setExpiryPolicyFactory(AccessedExpiryPolicy.factoryOf(new Duration(MINUTES, 10))).setGroupName(grpName));
    IgniteCache<Object, Object> regularCache = ig.getOrCreateCache(new CacheConfiguration<>(regularCacheName).setGroupName(grpName));
    // This will initialize partition and cache structures.
    expireCache.put(0, 0);
    expireCache.remove(0);
    int expireCacheId = CU.cacheGroupId(expireCacheName, grpName);
    CacheGroupContext grp = ig.context().cache().cacheGroup(CU.cacheId(grpName));
    IgniteCacheOffheapManager.CacheDataStore store = grp.topology().localPartition(0).dataStore();
    assertNotNull(store);
    // Get pending tree of expire cache.
    PendingEntriesTree pendingTree = store.pendingTree();
    long year = TimeUnit.DAYS.toMillis(365);
    long expiration = System.currentTimeMillis() + year;
    ig.context().cache().context().database().checkpointReadLock();
    try {
        // Carefully calculated number. Just enough for the first split to happen, but not more.
        for (int i = 0; i < 202; i++) // link != 0
        pendingTree.putx(new PendingRow(expireCacheId, expiration, expiration + i));
        // Open cursor, it'll cache first leaf of the tree.
        GridCursor<PendingRow> cur = pendingTree.find(null, new PendingRow(expireCacheId, expiration + year, 0), PendingEntriesTree.WITHOUT_KEY);
        // Required for "do" loop to work.
        assertTrue(cur.next());
        int cnt = 0;
        // Emulate real expiry loop but with a more precise control.
        do {
            PendingRow row = cur.get();
            pendingTree.removex(row);
            // with its sibling, meaning that cached "nextPageId" points to empty page from reuse list.
            if (row.link - row.expireTime == 100) {
                // Put into another cache will take a page from reuse list first. This means that cached
                // "nextPageId" points to a data page.
                regularCache.put(0, 0);
            }
            cnt++;
        } while (cur.next());
        assertEquals(202, cnt);
    } finally {
        ig.context().cache().context().database().checkpointReadUnlock();
    }
}
Also used : Duration(javax.cache.expiry.Duration) PendingEntriesTree(org.apache.ignite.internal.processors.cache.tree.PendingEntriesTree) PendingRow(org.apache.ignite.internal.processors.cache.tree.PendingRow) IgniteCacheOffheapManager(org.apache.ignite.internal.processors.cache.IgniteCacheOffheapManager) IgniteEx(org.apache.ignite.internal.IgniteEx) CacheGroupContext(org.apache.ignite.internal.processors.cache.CacheGroupContext) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 43 with CacheGroupContext

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

the class LocalWalModeChangeDuringRebalancingSelfTest method doTestSimple.

/**
 * @throws Exception If failed.
 */
private void doTestSimple() throws Exception {
    Ignite ignite = startGrids(3);
    ignite.cluster().baselineAutoAdjustEnabled(false);
    ignite.cluster().state(ACTIVE);
    IgniteCache<Integer, Integer> cache = ignite.cache(DEFAULT_CACHE_NAME);
    IgniteCache<Integer, Integer> cache2 = ignite.cache(REPL_CACHE);
    int keysCnt = getKeysCount();
    for (int k = 0; k < keysCnt; k++) {
        cache.put(k, k);
        // Empty cache causes skipped checkpoint.
        cache2.put(k, k);
    }
    IgniteEx newIgnite = startGrid(3);
    final CheckpointHistory cpHist = ((GridCacheDatabaseSharedManager) newIgnite.context().cache().context().database()).checkpointHistory();
    waitForCondition(new GridAbsPredicate() {

        @Override
        public boolean apply() {
            return !cpHist.checkpoints().isEmpty();
        }
    }, 10_000);
    // To ensure timestamp granularity.
    U.sleep(10);
    long newIgniteStartedTimestamp = System.currentTimeMillis();
    newIgnite.cluster().setBaselineTopology(4);
    awaitExchange(newIgnite);
    CacheGroupContext grpCtx = newIgnite.cachex(DEFAULT_CACHE_NAME).context().group();
    assertEquals(!disableWalDuringRebalancing, grpCtx.walEnabled());
    // To ensure timestamp granularity.
    U.sleep(10);
    long rebalanceStartedTimestamp = System.currentTimeMillis();
    for (Ignite g : G.allGrids()) g.cache(DEFAULT_CACHE_NAME).rebalance();
    awaitPartitionMapExchange();
    assertTrue(grpCtx.walEnabled());
    // To ensure timestamp granularity.
    U.sleep(10);
    long rebalanceFinishedTimestamp = System.currentTimeMillis();
    for (Integer k = 0; k < keysCnt; k++) assertEquals("k=" + k, k, cache.get(k));
    int checkpointsBeforeNodeStarted = 0;
    int checkpointsBeforeRebalance = 0;
    int checkpointsAfterRebalance = 0;
    for (Long timestamp : cpHist.checkpoints()) {
        if (timestamp < newIgniteStartedTimestamp)
            checkpointsBeforeNodeStarted++;
        else if (timestamp >= newIgniteStartedTimestamp && timestamp < rebalanceStartedTimestamp)
            checkpointsBeforeRebalance++;
        else if (timestamp >= rebalanceStartedTimestamp && timestamp <= rebalanceFinishedTimestamp)
            checkpointsAfterRebalance++;
    }
    // checkpoint on start
    assertEquals(1, checkpointsBeforeNodeStarted);
    assertEquals(0, checkpointsBeforeRebalance);
    // Expecting a checkpoint for each group.
    assertEquals(disableWalDuringRebalancing ? newIgnite.context().cache().cacheGroups().size() : 0, // checkpoint if WAL was re-activated
    checkpointsAfterRebalance);
}
Also used : GridAbsPredicate(org.apache.ignite.internal.util.lang.GridAbsPredicate) 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)

Example 44 with CacheGroupContext

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

the class LocalWalModeChangeDuringRebalancingSelfTest method doTestParallelExchange.

/**
 * @throws Exception If failed.
 */
private void doTestParallelExchange(AtomicReference<CountDownLatch> latchRef) 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);
    CacheGroupContext grpCtx = newIgnite.cachex(DEFAULT_CACHE_NAME).context().group();
    CountDownLatch latch = new CountDownLatch(1);
    latchRef.set(latch);
    ignite.cluster().setBaselineTopology(ignite.cluster().nodes());
    // Await fully exchange complete.
    awaitExchange(newIgnite);
    assertFalse(grpCtx.walEnabled());
    // TODO : test with client node as well
    // Trigger exchange
    startGrid(4);
    assertFalse(grpCtx.walEnabled());
    latch.countDown();
    assertFalse(grpCtx.walEnabled());
    for (Ignite g : G.allGrids()) g.cache(DEFAULT_CACHE_NAME).rebalance();
    awaitPartitionMapExchange();
    assertTrue(waitForCondition(grpCtx::walEnabled, 2_000));
}
Also used : IgniteEx(org.apache.ignite.internal.IgniteEx) Ignite(org.apache.ignite.Ignite) CacheGroupContext(org.apache.ignite.internal.processors.cache.CacheGroupContext) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 45 with CacheGroupContext

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

the class LocalWalModeChangeDuringRebalancingSelfTest method testWalNotDisabledAfterShrinkingBaselineTopology.

/**
 * @throws Exception If failed.
 */
@Test
public void testWalNotDisabledAfterShrinkingBaselineTopology() throws Exception {
    Ignite ignite = startGrids(4);
    ignite.cluster().baselineAutoAdjustEnabled(false);
    ignite.cluster().state(ACTIVE);
    IgniteCache<Integer, Integer> cache = ignite.cache(DEFAULT_CACHE_NAME);
    int keysCnt = getKeysCount();
    for (int k = 0; k < keysCnt; k++) cache.put(k, k);
    for (Ignite g : G.allGrids()) {
        CacheGroupContext grpCtx = ((IgniteEx) g).cachex(DEFAULT_CACHE_NAME).context().group();
        assertTrue(grpCtx.walEnabled());
    }
    stopGrid(2);
    ignite.cluster().setBaselineTopology(5);
    ignite.resetLostPartitions(Collections.singleton(DEFAULT_CACHE_NAME));
    // Await fully exchange complete.
    awaitExchange((IgniteEx) ignite);
    for (Ignite g : G.allGrids()) {
        CacheGroupContext grpCtx = ((IgniteEx) g).cachex(DEFAULT_CACHE_NAME).context().group();
        assertTrue(grpCtx.walEnabled());
        g.cache(DEFAULT_CACHE_NAME).rebalance();
    }
    awaitPartitionMapExchange();
    for (Ignite g : G.allGrids()) {
        CacheGroupContext grpCtx = ((IgniteEx) g).cachex(DEFAULT_CACHE_NAME).context().group();
        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)

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