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();
}
}
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;
}
Aggregations