Search in sources :

Example 1 with DataRow

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

Aggregations

AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 CacheDataRow (org.apache.ignite.internal.processors.cache.persistence.CacheDataRow)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 PendingEntriesTree (org.apache.ignite.internal.processors.cache.tree.PendingEntriesTree)1 PendingRow (org.apache.ignite.internal.processors.cache.tree.PendingRow)1 GridAtomicLong (org.apache.ignite.internal.util.GridAtomicLong)1