Search in sources :

Example 1 with AbstractDataLeafIO

use of org.apache.ignite.internal.processors.cache.tree.AbstractDataLeafIO 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 2 with AbstractDataLeafIO

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

the class PageMemoryTracker method comparePages.

/**
 * Compare pages content.
 *
 * @param fullPageId Full page ID.
 * @param expPage Expected page.
 * @param actualPageAddr Actual page address.
 * @return {@code True} if pages are equals, {@code False} otherwise.
 * @throws IgniteCheckedException If fails.
 */
private boolean comparePages(FullPageId fullPageId, DirectMemoryPage expPage, long actualPageAddr) throws IgniteCheckedException {
    long expPageAddr = expPage.address();
    GridCacheProcessor cacheProc = gridCtx.cache();
    ByteBuffer locBuf = GridUnsafe.wrapPointer(expPageAddr, pageSize);
    ByteBuffer rmtBuf = GridUnsafe.wrapPointer(actualPageAddr, pageSize);
    PageIO pageIo = PageIO.getPageIO(actualPageAddr);
    if (pageIo.getType() == T_DATA_REF_MVCC_LEAF || pageIo.getType() == T_CACHE_ID_DATA_REF_MVCC_LEAF) {
        assert cacheProc.cacheGroup(fullPageId.groupId()).mvccEnabled();
        AbstractDataLeafIO io = (AbstractDataLeafIO) pageIo;
        int cnt = io.getMaxCount(actualPageAddr, pageSize);
        // Reset lock info as there is no sense to log it into WAL.
        for (int i = 0; i < cnt; i++) {
            io.setMvccLockCoordinatorVersion(expPageAddr, i, io.getMvccLockCoordinatorVersion(actualPageAddr, i));
            io.setMvccLockCounter(expPageAddr, i, io.getMvccLockCounter(actualPageAddr, i));
        }
    }
    // Compare only meaningful data.
    if (pageIo instanceof CompactablePageIO) {
        tmpBuf1.clear();
        tmpBuf2.clear();
        ((CompactablePageIO) pageIo).compactPage(locBuf, tmpBuf1, pageSize);
        ((CompactablePageIO) pageIo).compactPage(rmtBuf, tmpBuf2, pageSize);
        locBuf = tmpBuf1;
        rmtBuf = tmpBuf2;
    }
    if (!locBuf.equals(rmtBuf)) {
        log.error("Page buffers are not equals [fullPageId=" + fullPageId + ", pageIo=" + pageIo + ']');
        dumpDiff(locBuf, rmtBuf);
        dumpHistory(expPage);
        return false;
    }
    return true;
}
Also used : AbstractDataLeafIO(org.apache.ignite.internal.processors.cache.tree.AbstractDataLeafIO) CompactablePageIO(org.apache.ignite.internal.processors.cache.persistence.tree.io.CompactablePageIO) GridCacheProcessor(org.apache.ignite.internal.processors.cache.GridCacheProcessor) ByteBuffer(java.nio.ByteBuffer) CompactablePageIO(org.apache.ignite.internal.processors.cache.persistence.tree.io.CompactablePageIO) PageIO(org.apache.ignite.internal.processors.cache.persistence.tree.io.PageIO)

Aggregations

AbstractDataLeafIO (org.apache.ignite.internal.processors.cache.tree.AbstractDataLeafIO)2 ByteBuffer (java.nio.ByteBuffer)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 GridCacheProcessor (org.apache.ignite.internal.processors.cache.GridCacheProcessor)1 CacheDataRow (org.apache.ignite.internal.processors.cache.persistence.CacheDataRow)1 SimpleDataRow (org.apache.ignite.internal.processors.cache.persistence.freelist.SimpleDataRow)1 CompactablePageIO (org.apache.ignite.internal.processors.cache.persistence.tree.io.CompactablePageIO)1 PageIO (org.apache.ignite.internal.processors.cache.persistence.tree.io.PageIO)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