Search in sources :

Example 1 with IgniteOutOfMemoryException

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

the class PageMemoryNoStoreImpl method allocatePage.

/**
 * {@inheritDoc}
 */
@Override
public long allocatePage(int grpId, int partId, byte flags) {
    assert started;
    long relPtr = borrowFreePage();
    long absPtr = 0;
    if (relPtr != INVALID_REL_PTR) {
        int pageIdx = PageIdUtils.pageIndex(relPtr);
        Segment seg = segment(pageIdx);
        absPtr = seg.absolute(pageIdx);
    } else {
        // No segments contained a free page.
        Segment[] seg0 = segments;
        Segment allocSeg = seg0[seg0.length - 1];
        while (allocSeg != null) {
            relPtr = allocSeg.allocateFreePage(flags);
            if (relPtr != INVALID_REL_PTR) {
                absPtr = allocSeg.absolute(PageIdUtils.pageIndex(relPtr));
                allocatedPages.incrementAndGet();
                break;
            } else {
                allocSeg = addSegment(seg0);
            }
        }
    }
    if (relPtr == INVALID_REL_PTR) {
        IgniteOutOfMemoryException oom = new IgniteOutOfMemoryException("Out of memory in data region [" + "name=" + dataRegionCfg.name() + ", initSize=" + IgniteUtils.readableSize(dataRegionCfg.initSize(), false) + ", maxSize=" + IgniteUtils.readableSize(dataRegionCfg.maxSize(), false) + ", persistenceEnabled=" + dataRegionCfg.persistent() + "] Try the following:\n" + "  ^-- Increase maximum off-heap memory size (DataRegionConfiguration.maxSize)\n" + "  ^-- Enable Ignite persistence (DataRegionConfiguration.persistenceEnabled)\n" + "  ^-- Enable eviction or expiration policies");
        throw oom;
    }
    assert (relPtr & ~PageIdUtils.PAGE_IDX_MASK) == 0 : IgniteUtils.hexLong(relPtr & ~PageIdUtils.PAGE_IDX_MASK);
    // Assign page ID according to flags and partition ID.
    long pageId = PageIdUtils.pageId(partId, flags, (int) relPtr);
    writePageId(absPtr, pageId);
    GridUnsafe.zeroMemory(absPtr + PAGE_OVERHEAD, sysPageSize - PAGE_OVERHEAD);
    return pageId;
}
Also used : IgniteOutOfMemoryException(org.apache.ignite.internal.pagememory.mem.IgniteOutOfMemoryException)

Example 2 with IgniteOutOfMemoryException

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

the class PageMemoryNoLoadSelfTest method testLoadedPagesCount.

@Test
public void testLoadedPagesCount() throws Exception {
    PageMemory mem = memory();
    mem.start();
    int expPages = MAX_MEMORY_SIZE / mem.systemPageSize();
    try {
        for (int i = 0; i < expPages * 2; i++) {
            allocatePage(mem);
        }
    } catch (IgniteOutOfMemoryException e) {
        log.error(e.getMessage(), e);
        // Expected.
        assertEquals(mem.loadedPages(), expPages);
    } finally {
        mem.stop(true);
    }
}
Also used : IgniteOutOfMemoryException(org.apache.ignite.internal.pagememory.mem.IgniteOutOfMemoryException) PageMemory(org.apache.ignite.internal.pagememory.PageMemory) BaseIgniteAbstractTest(org.apache.ignite.internal.testframework.BaseIgniteAbstractTest) Test(org.junit.jupiter.api.Test)

Example 3 with IgniteOutOfMemoryException

use of org.apache.ignite.internal.pagememory.mem.IgniteOutOfMemoryException 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

IgniteOutOfMemoryException (org.apache.ignite.internal.pagememory.mem.IgniteOutOfMemoryException)3 FullPageId (org.apache.ignite.internal.pagememory.FullPageId)1 PageMemory (org.apache.ignite.internal.pagememory.PageMemory)1 BaseIgniteAbstractTest (org.apache.ignite.internal.testframework.BaseIgniteAbstractTest)1 Test (org.junit.jupiter.api.Test)1