use of org.apache.ignite.internal.processors.cache.persistence.pagemem.PageMemoryImpl in project ignite by apache.
the class IndexPageCounter method countIdxPagesInMemory.
/**
* Returns the number of index pages residing inside the Page Memory of the given cache group.
*/
long countIdxPagesInMemory(int grpId) throws IgniteCheckedException {
DataRegion dataRegion = grid.context().cache().context().database().dataRegion(null);
PageMemory pageMemory = dataRegion.pageMemory();
long idxPageCnt = 0;
for (int i = 0; i < pageMemory.loadedPages(); i++) {
long pageId = PageIdUtils.pageId(PageIdAllocator.INDEX_PARTITION, (byte) 0, i);
if (persistenceEnabled) {
// if persistence is enabled, avoid loading a displaced page into memory
PageMemoryImpl pageMemoryImpl = (PageMemoryImpl) dataRegion.pageMemory();
if (!pageMemoryImpl.hasLoadedPage(new FullPageId(pageId, grpId)))
continue;
}
long pageAddr = pageMemory.acquirePage(grpId, pageId);
try {
long pageReadAddr = pageMemory.readLockForce(grpId, pageId, pageAddr);
try {
// check the rotation ID in case a page was freed (its page type does not get overwritten)
long rotationId = PageIdUtils.rotationId(PageIO.getPageId(pageReadAddr));
long prevRotationId = pageIdToRotationId.computeIfAbsent(pageId, id -> rotationId);
if (prevRotationId == rotationId && PageIO.isIndexPage(PageIO.getType(pageReadAddr)))
idxPageCnt += 1;
} finally {
pageMemory.readUnlock(grpId, pageId, pageAddr);
}
} finally {
pageMemory.releasePage(grpId, pageId, pageAddr);
}
}
return idxPageCnt;
}
Aggregations