Search in sources :

Example 46 with PageMemory

use of org.apache.ignite.internal.pagemem.PageMemory in project ignite by apache.

the class PageMemoryNoLoadSelfTest method testPageIdRotation.

/**
 * @throws Exception If failed.
 */
@Test
public void testPageIdRotation() throws Exception {
    PageMemory mem = memory();
    mem.start();
    try {
        int pages = 5;
        Collection<FullPageId> old = new ArrayList<>();
        Collection<FullPageId> updated = new ArrayList<>();
        for (int i = 0; i < pages; i++) old.add(allocatePage(mem));
        // Check that initial pages are accessible.
        for (FullPageId id : old) {
            long pageApsPtr = mem.acquirePage(id.groupId(), id.pageId());
            try {
                long pageAddr = mem.writeLock(id.groupId(), id.pageId(), pageApsPtr);
                assertNotNull(pageAddr);
                try {
                    PAGE_IO.initNewPage(pageAddr, id.pageId(), mem.realPageSize(id.groupId()), null);
                    long updId = PageIdUtils.rotatePageId(id.pageId());
                    PageIO.setPageId(pageAddr, updId);
                    updated.add(new FullPageId(updId, id.groupId()));
                } finally {
                    mem.writeUnlock(id.groupId(), id.pageId(), pageApsPtr, null, true);
                }
            } finally {
                mem.releasePage(id.groupId(), id.pageId(), pageApsPtr);
            }
        }
        // Check that updated pages are inaccessible using old IDs.
        for (FullPageId id : old) {
            long pageApsPtr = mem.acquirePage(id.groupId(), id.pageId());
            try {
                long pageAddr = mem.writeLock(id.groupId(), id.pageId(), pageApsPtr);
                if (pageAddr != 0L) {
                    mem.writeUnlock(id.groupId(), id.pageId(), pageApsPtr, null, false);
                    fail("Was able to acquire page write lock.");
                }
                mem.readLock(id.groupId(), id.pageId(), pageApsPtr);
                if (pageAddr != 0) {
                    mem.readUnlock(id.groupId(), id.pageId(), pageApsPtr);
                    fail("Was able to acquire page read lock.");
                }
            } finally {
                mem.releasePage(id.groupId(), id.pageId(), pageApsPtr);
            }
        }
        // Check that updated pages are accessible using new IDs.
        for (FullPageId id : updated) {
            long pageApsPtr = mem.acquirePage(id.groupId(), id.pageId());
            try {
                long pageAddr = mem.writeLock(id.groupId(), id.pageId(), pageApsPtr);
                assertNotSame(0L, pageAddr);
                try {
                    assertEquals(id.pageId(), PageIO.getPageId(pageAddr));
                } finally {
                    mem.writeUnlock(id.groupId(), id.pageId(), pageApsPtr, null, false);
                }
                pageAddr = mem.readLock(id.groupId(), id.pageId(), pageApsPtr);
                assertNotSame(0L, pageAddr);
                try {
                    assertEquals(id.pageId(), PageIO.getPageId(pageAddr));
                } finally {
                    mem.readUnlock(id.groupId(), id.pageId(), pageApsPtr);
                }
            } finally {
                mem.releasePage(id.groupId(), id.pageId(), pageApsPtr);
            }
        }
    } finally {
        mem.stop(true);
    }
}
Also used : PageMemory(org.apache.ignite.internal.pagemem.PageMemory) ArrayList(java.util.ArrayList) FullPageId(org.apache.ignite.internal.pagemem.FullPageId) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 47 with PageMemory

use of org.apache.ignite.internal.pagemem.PageMemory in project ignite by apache.

the class PageMemoryNoLoadSelfTest method testPageTearingInner.

/**
 * @throws Exception If failed.
 */
@Test
public void testPageTearingInner() throws Exception {
    PageMemory mem = memory();
    mem.start();
    try {
        FullPageId fullId1 = allocatePage(mem);
        FullPageId fullId2 = allocatePage(mem);
        long page1 = mem.acquirePage(fullId1.groupId(), fullId1.pageId());
        try {
            long page2 = mem.acquirePage(fullId2.groupId(), fullId2.pageId());
            info("Allocated pages [page1Id=" + fullId1.pageId() + ", page1=" + page1 + ", page2Id=" + fullId2.pageId() + ", page2=" + page2 + ']');
            try {
                writePage(mem, fullId1, page1, 1);
                writePage(mem, fullId2, page2, 2);
                readPage(mem, fullId1.pageId(), page1, 1);
                readPage(mem, fullId2.pageId(), page2, 2);
                // Check read after read.
                readPage(mem, fullId1.pageId(), page1, 1);
                readPage(mem, fullId2.pageId(), page2, 2);
            } finally {
                mem.releasePage(fullId2.groupId(), fullId2.pageId(), page2);
            }
        } finally {
            mem.releasePage(fullId1.groupId(), fullId1.pageId(), page1);
        }
    } finally {
        mem.stop(true);
    }
}
Also used : PageMemory(org.apache.ignite.internal.pagemem.PageMemory) FullPageId(org.apache.ignite.internal.pagemem.FullPageId) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 48 with PageMemory

use of org.apache.ignite.internal.pagemem.PageMemory in project ignite by apache.

the class IgnitePdsCheckpointSimulationWithRealCpDisabledTest method testPageWalEntries.

/**
 * @throws Exception if failed.
 */
@Test
public void testPageWalEntries() throws Exception {
    IgniteEx ig = startGrid(0);
    ig.cluster().active(true);
    GridCacheSharedContext<Object, Object> sharedCtx = ig.context().cache().context();
    int cacheId = sharedCtx.cache().cache(CACHE_NAME).context().cacheId();
    GridCacheDatabaseSharedManager db = (GridCacheDatabaseSharedManager) sharedCtx.database();
    PageMemory pageMem = sharedCtx.database().dataRegion(null).pageMemory();
    IgniteWriteAheadLogManager wal = sharedCtx.wal();
    db.enableCheckpoints(false).get();
    int pageCnt = 100;
    List<FullPageId> pageIds = new ArrayList<>();
    for (int i = 0; i < pageCnt; i++) {
        db.checkpointReadLock();
        try {
            pageIds.add(new FullPageId(pageMem.allocatePage(cacheId, PageIdAllocator.INDEX_PARTITION, PageIdAllocator.FLAG_IDX), cacheId));
        } finally {
            db.checkpointReadUnlock();
        }
    }
    UUID cpId = UUID.randomUUID();
    WALPointer start = wal.log(new CheckpointRecord(cpId, null));
    wal.flush(start, false);
    ig.context().cache().context().database().checkpointReadLock();
    try {
        for (FullPageId pageId : pageIds) writePageData(pageId, pageMem);
    } finally {
        ig.context().cache().context().database().checkpointReadUnlock();
    }
    // Data will not be written to the page store.
    stopAllGrids();
    ig = startGrid(0);
    ig.cluster().active(true);
    sharedCtx = ig.context().cache().context();
    db = (GridCacheDatabaseSharedManager) sharedCtx.database();
    wal = sharedCtx.wal();
    db.enableCheckpoints(false);
    try (PartitionMetaStateRecordExcludeIterator it = new PartitionMetaStateRecordExcludeIterator(wal.replay(start))) {
        IgniteBiTuple<WALPointer, WALRecord> tup = it.next();
        assert tup.get2() instanceof CheckpointRecord : tup.get2();
        assertEquals(start, tup.get1());
        CheckpointRecord cpRec = (CheckpointRecord) tup.get2();
        assertEquals(cpId, cpRec.checkpointId());
        assertNull(cpRec.checkpointMark());
        assertFalse(cpRec.end());
        int idx = 0;
        while (idx < pageIds.size()) {
            tup = it.next();
            assert tup.get2() instanceof PageSnapshot : tup.get2().getClass();
            PageSnapshot snap = (PageSnapshot) tup.get2();
            // there are extra tracking pages, skip them
            long trackingPageFor = TrackingPageIO.VERSIONS.latest().trackingPageFor(snap.fullPageId().pageId(), pageMem.pageSize());
            if (trackingPageFor == snap.fullPageId().pageId()) {
                tup = it.next();
                assertTrue(tup.get2() instanceof PageSnapshot);
                snap = (PageSnapshot) tup.get2();
            }
            assertEquals(pageIds.get(idx), snap.fullPageId());
            idx++;
        }
    }
}
Also used : WALRecord(org.apache.ignite.internal.pagemem.wal.record.WALRecord) IgniteWriteAheadLogManager(org.apache.ignite.internal.pagemem.wal.IgniteWriteAheadLogManager) GridCacheDatabaseSharedManager(org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager) PageMemory(org.apache.ignite.internal.pagemem.PageMemory) ArrayList(java.util.ArrayList) CheckpointRecord(org.apache.ignite.internal.pagemem.wal.record.CheckpointRecord) IgniteEx(org.apache.ignite.internal.IgniteEx) CacheObject(org.apache.ignite.internal.processors.cache.CacheObject) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject) UUID(java.util.UUID) WALPointer(org.apache.ignite.internal.processors.cache.persistence.wal.WALPointer) FullPageId(org.apache.ignite.internal.pagemem.FullPageId) PageSnapshot(org.apache.ignite.internal.pagemem.wal.record.PageSnapshot) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 49 with PageMemory

use of org.apache.ignite.internal.pagemem.PageMemory in project ignite by apache.

the class IgnitePdsPageReplacementTest method testPageReplacement.

/**
 * @throws Exception If fail.
 */
@Test
public void testPageReplacement() throws Exception {
    final IgniteEx ig = startGrid(0);
    ig.active(true);
    final PageMemory memory = getMemory(ig);
    writeData(ig, memory, CU.cacheId(cacheName));
}
Also used : IgniteEx(org.apache.ignite.internal.IgniteEx) PageMemory(org.apache.ignite.internal.pagemem.PageMemory) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 50 with PageMemory

use of org.apache.ignite.internal.pagemem.PageMemory 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

PageMemory (org.apache.ignite.internal.pagemem.PageMemory)54 UnsafeMemoryProvider (org.apache.ignite.internal.mem.unsafe.UnsafeMemoryProvider)21 DataRegionConfiguration (org.apache.ignite.configuration.DataRegionConfiguration)19 PageMemoryNoStoreImpl (org.apache.ignite.internal.pagemem.impl.PageMemoryNoStoreImpl)19 DataRegionMetricsImpl (org.apache.ignite.internal.processors.cache.persistence.DataRegionMetricsImpl)19 Test (org.junit.Test)16 FullPageId (org.apache.ignite.internal.pagemem.FullPageId)15 GridTestKernalContext (org.apache.ignite.testframework.junits.GridTestKernalContext)12 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)12 IgniteEx (org.apache.ignite.internal.IgniteEx)6 IndexKeyTypeSettings (org.apache.ignite.internal.cache.query.index.sorted.IndexKeyTypeSettings)6 InlineIndexKeyType (org.apache.ignite.internal.cache.query.index.sorted.inline.InlineIndexKeyType)6 StringInlineIndexKeyType (org.apache.ignite.internal.cache.query.index.sorted.inline.types.StringInlineIndexKeyType)6 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)5 DirectMemoryProvider (org.apache.ignite.internal.mem.DirectMemoryProvider)5 ArrayList (java.util.ArrayList)4 DataRegion (org.apache.ignite.internal.processors.cache.persistence.DataRegion)4 GridCacheDatabaseSharedManager (org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager)4 HashMap (java.util.HashMap)3 HashSet (java.util.HashSet)3