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