Search in sources :

Example 6 with FullPageId

use of org.apache.ignite.internal.pagememory.FullPageId in project ignite-3 by apache.

the class SegmentedLruPageReplacementPolicy method replace.

/**
 * {@inheritDoc}
 */
@Override
public long replace() throws IgniteInternalCheckedException {
    LoadedPagesMap loadedPages = seg.loadedPages();
    for (int i = 0; i < loadedPages.size(); i++) {
        int pageIdx = lruList.poll();
        long relPtr = seg.relative(pageIdx);
        long absPtr = seg.absolute(relPtr);
        FullPageId fullId = fullPageId(absPtr);
        // Check loaded pages map for outdated page.
        relPtr = loadedPages.get(fullId.groupId(), fullId.effectivePageId(), seg.partGeneration(fullId.groupId(), partitionId(fullId.pageId())), INVALID_REL_PTR, OUTDATED_REL_PTR);
        assert relPtr != INVALID_REL_PTR;
        if (relPtr == OUTDATED_REL_PTR) {
            return seg.refreshOutdatedPage(fullId.groupId(), fullId.pageId(), true);
        }
        if (seg.tryToRemovePage(fullId, absPtr)) {
            return relPtr;
        }
        // Return page to the LRU list.
        lruList.addToTail(pageIdx, true);
    }
    throw seg.oomException("no pages to replace");
}
Also used : FullPageId(org.apache.ignite.internal.pagememory.FullPageId)

Example 7 with FullPageId

use of org.apache.ignite.internal.pagememory.FullPageId in project ignite-3 by apache.

the class PageMemoryNoLoadSelfTest method testPageHandleDeallocation.

@Test
public void testPageHandleDeallocation() throws Exception {
    PageMemory mem = memory();
    mem.start();
    try {
        int pages = 3 * 1024 * 1024 / (8 * 1024);
        Collection<FullPageId> handles = new HashSet<>();
        for (int i = 0; i < pages; i++) {
            handles.add(allocatePage(mem));
        }
        for (FullPageId fullId : handles) {
            mem.freePage(fullId.groupId(), fullId.pageId());
        }
        for (int i = 0; i < pages; i++) {
            assertFalse(handles.add(allocatePage(mem)));
        }
    } finally {
        mem.stop(true);
    }
}
Also used : PageMemory(org.apache.ignite.internal.pagememory.PageMemory) FullPageId(org.apache.ignite.internal.pagememory.FullPageId) HashSet(java.util.HashSet) BaseIgniteAbstractTest(org.apache.ignite.internal.testframework.BaseIgniteAbstractTest) Test(org.junit.jupiter.api.Test)

Example 8 with FullPageId

use of org.apache.ignite.internal.pagememory.FullPageId in project ignite-3 by apache.

the class PageMemoryNoLoadSelfTest method testPageIdRotation.

@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()));
                    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, 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, 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, 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.pagememory.PageMemory) ArrayList(java.util.ArrayList) FullPageId(org.apache.ignite.internal.pagememory.FullPageId) BaseIgniteAbstractTest(org.apache.ignite.internal.testframework.BaseIgniteAbstractTest) Test(org.junit.jupiter.api.Test)

Example 9 with FullPageId

use of org.apache.ignite.internal.pagememory.FullPageId in project ignite-3 by apache.

the class TestPageReadWriteManager method allocatePage.

/**
 * {@inheritDoc}
 */
@Override
public long allocatePage(int grpId, int partId, byte flags) {
    long root = pageId(partId, flags, 0);
    FullPageId fullId = new FullPageId(root, grpId);
    AtomicInteger allocator = allocators.computeIfAbsent(fullId, fullPageId -> new AtomicInteger(1));
    return pageId(partId, flags, allocator.getAndIncrement());
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) FullPageId(org.apache.ignite.internal.pagememory.FullPageId)

Example 10 with FullPageId

use of org.apache.ignite.internal.pagememory.FullPageId in project ignite-3 by apache.

the class PageMemoryImpl method allocatePage.

/**
 * {@inheritDoc}
 */
@Override
public long allocatePage(int grpId, int partId, byte flags) throws IgniteInternalCheckedException {
    assert partId <= MAX_PARTITION_ID || partId == INDEX_PARTITION && flags == FLAG_AUX : "flags = " + flags + ", partId = " + partId;
    assert started;
    long pageId = pmPageMgr.allocatePage(grpId, partId, flags);
    // it's crucial for tracking pages (zero page is super one)
    assert pageIndex(pageId) > 0;
    // We need to allocate page in memory for marking it dirty to save it in the next checkpoint.
    // Otherwise it is possible that on file will be empty page which will be saved at snapshot and read with error
    // because there is no crc inside them.
    Segment seg = segment(grpId, pageId);
    seg.writeLock().lock();
    FullPageId fullId = new FullPageId(pageId, grpId);
    try {
        long relPtr = seg.loadedPages.get(grpId, effectivePageId(pageId), seg.partGeneration(grpId, partId), INVALID_REL_PTR, OUTDATED_REL_PTR);
        if (relPtr == OUTDATED_REL_PTR) {
            relPtr = seg.refreshOutdatedPage(grpId, pageId, false);
            seg.pageReplacementPolicy.onRemove(relPtr);
        }
        if (relPtr == INVALID_REL_PTR) {
            relPtr = seg.borrowOrAllocateFreePage(pageId);
        }
        if (relPtr == INVALID_REL_PTR) {
            relPtr = seg.removePageForReplacement();
        }
        long absPtr = seg.absolute(relPtr);
        setMemory(absPtr + PAGE_OVERHEAD, pageSize(), (byte) 0);
        fullPageId(absPtr, fullId);
        writeTimestamp(absPtr, coarseCurrentTimeMillis());
        rwLock.init(absPtr + PAGE_LOCK_OFFSET, tag(pageId));
        // TODO IGNITE-16612
        assert getCrc(absPtr + PAGE_OVERHEAD) == 0;
        assert !isAcquired(absPtr) : "Pin counter must be 0 for a new page [relPtr=" + hexLong(relPtr) + ", absPtr=" + hexLong(absPtr) + ", pinCntr=" + PageHeader.pinCount(absPtr) + ']';
        setDirty(fullId, absPtr, true, true);
        seg.pageReplacementPolicy.onMiss(relPtr);
        seg.loadedPages.put(grpId, effectivePageId(pageId), relPtr, seg.partGeneration(grpId, partId));
    } catch (IgniteOutOfMemoryException oom) {
        IgniteOutOfMemoryException e = new IgniteOutOfMemoryException("Out of memory in data region [" + "name=" + dataRegionCfg.name() + ", initSize=" + readableSize(dataRegionCfg.initSize(), false) + ", maxSize=" + readableSize(dataRegionCfg.maxSize(), false) + ", persistenceEnabled=" + dataRegionCfg.persistent() + "] Try the following:" + lineSeparator() + "  ^-- Increase maximum off-heap memory size (PageMemoryDataRegionConfiguration.maxSize)" + lineSeparator() + "  ^-- Enable eviction or expiration policies");
        e.initCause(oom);
        throw e;
    } finally {
        seg.writeLock().unlock();
    }
    return pageId;
}
Also used : IgniteOutOfMemoryException(org.apache.ignite.internal.pagememory.mem.IgniteOutOfMemoryException) FullPageId(org.apache.ignite.internal.pagememory.FullPageId)

Aggregations

FullPageId (org.apache.ignite.internal.pagememory.FullPageId)11 PageMemory (org.apache.ignite.internal.pagememory.PageMemory)4 BaseIgniteAbstractTest (org.apache.ignite.internal.testframework.BaseIgniteAbstractTest)4 Test (org.junit.jupiter.api.Test)4 ArrayList (java.util.ArrayList)2 ByteBuffer (java.nio.ByteBuffer)1 HashSet (java.util.HashSet)1 ThreadLocalRandom (java.util.concurrent.ThreadLocalRandom)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 IgniteOutOfMemoryException (org.apache.ignite.internal.pagememory.mem.IgniteOutOfMemoryException)1