Search in sources :

Example 1 with PendingEntriesTree

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

the class IgniteCacheOffheapManagerImpl method onCacheStarted.

/**
 * {@inheritDoc}
 */
public void onCacheStarted(GridCacheContext cctx) throws IgniteCheckedException {
    if (cctx.affinityNode() && cctx.ttl().eagerTtlEnabled() && pendingEntries == null) {
        String name = "PendingEntries";
        long rootPage = allocateForTree();
        pendingEntries = new PendingEntriesTree(grp, name, grp.dataRegion().pageMemory(), rootPage, grp.reuseList(), true);
    }
}
Also used : PendingEntriesTree(org.apache.ignite.internal.processors.cache.tree.PendingEntriesTree)

Example 2 with PendingEntriesTree

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

the class GridCacheOffheapManager method onCacheStarted.

/**
 * {@inheritDoc}
 */
@Override
public void onCacheStarted(GridCacheContext cctx) throws IgniteCheckedException {
    if (cctx.affinityNode() && cctx.ttl().eagerTtlEnabled() && pendingEntries == null) {
        ctx.database().checkpointReadLock();
        try {
            final String name = "PendingEntries";
            RootPage pendingRootPage = indexStorage.getOrAllocateForTree(name);
            pendingEntries = new PendingEntriesTree(grp, name, grp.dataRegion().pageMemory(), pendingRootPage.pageId().pageId(), reuseList, pendingRootPage.isAllocated());
        } finally {
            ctx.database().checkpointReadUnlock();
        }
    }
}
Also used : PendingEntriesTree(org.apache.ignite.internal.processors.cache.tree.PendingEntriesTree)

Example 3 with PendingEntriesTree

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

the class CachePartitionDefragmentationManager method copyPartitionData.

/**
 * Defragmentate partition.
 *
 * @param partCtx
 * @param treeIter
 * @throws IgniteCheckedException If failed.
 */
private void copyPartitionData(PartitionContext partCtx, TreeIterator treeIter) throws IgniteCheckedException {
    CacheDataTree tree = partCtx.oldCacheDataStore.tree();
    CacheDataTree newTree = partCtx.newCacheDataStore.tree();
    newTree.enableSequentialWriteMode();
    PendingEntriesTree newPendingTree = partCtx.newCacheDataStore.pendingTree();
    AbstractFreeList<CacheDataRow> freeList = partCtx.newCacheDataStore.getCacheStoreFreeList();
    long cpLockThreshold = 150L;
    defragmentationCheckpoint.checkpointTimeoutLock().checkpointReadLock();
    try {
        AtomicLong lastCpLockTs = new AtomicLong(System.currentTimeMillis());
        AtomicInteger entriesProcessed = new AtomicInteger();
        treeIter.iterate(tree, partCtx.cachePageMemory, (tree0, io, pageAddr, idx) -> {
            checkCancellation();
            if (System.currentTimeMillis() - lastCpLockTs.get() >= cpLockThreshold) {
                defragmentationCheckpoint.checkpointTimeoutLock().checkpointReadUnlock();
                defragmentationCheckpoint.checkpointTimeoutLock().checkpointReadLock();
                lastCpLockTs.set(System.currentTimeMillis());
            }
            AbstractDataLeafIO leafIo = (AbstractDataLeafIO) io;
            CacheDataRow row = tree.getRow(io, pageAddr, idx);
            int cacheId = row.cacheId();
            // Reuse row that we just read.
            row.link(0);
            // "insertDataRow" will corrupt page memory if we don't do this.
            if (row instanceof DataRow && !partCtx.oldGrpCtx.storeCacheIdInDataPage())
                ((DataRow) row).cacheId(CU.UNDEFINED_CACHE_ID);
            freeList.insertDataRow(row, IoStatisticsHolderNoOp.INSTANCE);
            // Put it back.
            if (row instanceof DataRow)
                ((DataRow) row).cacheId(cacheId);
            newTree.putx(row);
            long newLink = row.link();
            partCtx.linkMap.put(leafIo.getLink(pageAddr, idx), newLink);
            if (row.expireTime() != 0)
                newPendingTree.putx(new PendingRow(cacheId, row.expireTime(), newLink));
            entriesProcessed.incrementAndGet();
            return true;
        });
        checkCancellation();
        defragmentationCheckpoint.checkpointTimeoutLock().checkpointReadUnlock();
        defragmentationCheckpoint.checkpointTimeoutLock().checkpointReadLock();
        freeList.saveMetadata(IoStatisticsHolderNoOp.INSTANCE);
        copyCacheMetadata(partCtx);
    } finally {
        defragmentationCheckpoint.checkpointTimeoutLock().checkpointReadUnlock();
    }
}
Also used : CacheDataRow(org.apache.ignite.internal.processors.cache.persistence.CacheDataRow) GridAtomicLong(org.apache.ignite.internal.util.GridAtomicLong) AtomicLong(java.util.concurrent.atomic.AtomicLong) AbstractDataLeafIO(org.apache.ignite.internal.processors.cache.tree.AbstractDataLeafIO) CacheDataTree(org.apache.ignite.internal.processors.cache.tree.CacheDataTree) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) PendingEntriesTree(org.apache.ignite.internal.processors.cache.tree.PendingEntriesTree) DataRow(org.apache.ignite.internal.processors.cache.tree.DataRow) CacheDataRow(org.apache.ignite.internal.processors.cache.persistence.CacheDataRow) SimpleDataRow(org.apache.ignite.internal.processors.cache.persistence.freelist.SimpleDataRow) PendingRow(org.apache.ignite.internal.processors.cache.tree.PendingRow)

Example 4 with PendingEntriesTree

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

the class IgniteCacheOffheapManagerImpl method initPendingTree.

/**
 * @param cctx Cache context.
 * @throws IgniteCheckedException If failed.
 */
protected void initPendingTree(GridCacheContext<?, ?> cctx) throws IgniteCheckedException {
    assert !cctx.group().persistenceEnabled();
    if (cctx.affinityNode() && cctx.ttl().eagerTtlEnabled() && pendingEntries == null) {
        String pendingEntriesTreeName = cctx.name() + "##PendingEntries";
        long rootPage = allocateForTree();
        pendingEntries = new PendingEntriesTree(grp, pendingEntriesTreeName, grp.dataRegion().pageMemory(), rootPage, grp.reuseList(), true, ctx.diagnostic().pageLockTracker(), FLAG_IDX);
    }
}
Also used : PendingEntriesTree(org.apache.ignite.internal.processors.cache.tree.PendingEntriesTree)

Example 5 with PendingEntriesTree

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

Aggregations

PendingEntriesTree (org.apache.ignite.internal.processors.cache.tree.PendingEntriesTree)6 PendingRow (org.apache.ignite.internal.processors.cache.tree.PendingRow)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 Duration (javax.cache.expiry.Duration)1 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)1 IgniteEx (org.apache.ignite.internal.IgniteEx)1 CacheGroupContext (org.apache.ignite.internal.processors.cache.CacheGroupContext)1 IgniteCacheOffheapManager (org.apache.ignite.internal.processors.cache.IgniteCacheOffheapManager)1 CacheDataRow (org.apache.ignite.internal.processors.cache.persistence.CacheDataRow)1 GridCacheOffheapManager (org.apache.ignite.internal.processors.cache.persistence.GridCacheOffheapManager)1 IgniteCacheDatabaseSharedManager (org.apache.ignite.internal.processors.cache.persistence.IgniteCacheDatabaseSharedManager)1 IndexStorage (org.apache.ignite.internal.processors.cache.persistence.IndexStorage)1 RootPage (org.apache.ignite.internal.processors.cache.persistence.RootPage)1 SimpleDataRow (org.apache.ignite.internal.processors.cache.persistence.freelist.SimpleDataRow)1 AbstractDataLeafIO (org.apache.ignite.internal.processors.cache.tree.AbstractDataLeafIO)1 CacheDataTree (org.apache.ignite.internal.processors.cache.tree.CacheDataTree)1 DataRow (org.apache.ignite.internal.processors.cache.tree.DataRow)1 GridAtomicLong (org.apache.ignite.internal.util.GridAtomicLong)1 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)1