Search in sources :

Example 11 with PageMemoryImpl

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;
}
Also used : PageMemory(org.apache.ignite.internal.pagemem.PageMemory) PageMemoryImpl(org.apache.ignite.internal.processors.cache.persistence.pagemem.PageMemoryImpl) DataRegion(org.apache.ignite.internal.processors.cache.persistence.DataRegion) FullPageId(org.apache.ignite.internal.pagemem.FullPageId)

Aggregations

PageMemoryImpl (org.apache.ignite.internal.processors.cache.persistence.pagemem.PageMemoryImpl)11 FullPageId (org.apache.ignite.internal.pagemem.FullPageId)7 GridCacheDatabaseSharedManager (org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager)6 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)5 PageMemory (org.apache.ignite.internal.pagemem.PageMemory)5 DataStorageConfiguration (org.apache.ignite.configuration.DataStorageConfiguration)4 IgniteEx (org.apache.ignite.internal.IgniteEx)4 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)4 Test (org.junit.Test)4 HashSet (java.util.HashSet)3 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)3 DataRegionConfiguration (org.apache.ignite.configuration.DataRegionConfiguration)3 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)3 PageIdAllocator (org.apache.ignite.internal.pagemem.PageIdAllocator)3 IgnitePageStoreManager (org.apache.ignite.internal.pagemem.store.IgnitePageStoreManager)3 CacheGroupContext (org.apache.ignite.internal.processors.cache.CacheGroupContext)3 GridCacheSharedContext (org.apache.ignite.internal.processors.cache.GridCacheSharedContext)3 IOException (java.io.IOException)2 ByteBuffer (java.nio.ByteBuffer)2 ByteOrder (java.nio.ByteOrder)2