Search in sources :

Example 11 with PageMetrics

use of org.apache.ignite.internal.processors.cache.persistence.pagemem.PageMetrics in project ignite by apache.

the class PageMemoryNoStoreImpl method allocatePage.

/**
 * {@inheritDoc}
 */
@Override
public long allocatePage(int grpId, int partId, byte flags) {
    assert started;
    long relPtr = borrowFreePage(grpId);
    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();
                PageMetrics grpPageMetrics = dataRegionMetrics.cacheGrpPageMetrics(grpId);
                grpPageMetrics.totalPages().increment();
                break;
            } else
                allocSeg = addSegment(seg0);
        }
    }
    if (relPtr == INVALID_REL_PTR) {
        IgniteOutOfMemoryException oom = new IgniteOutOfMemoryException("Out of memory in data region [" + "name=" + dataRegionCfg.getName() + ", initSize=" + U.readableSize(dataRegionCfg.getInitialSize(), false) + ", maxSize=" + U.readableSize(dataRegionCfg.getMaxSize(), false) + ", persistenceEnabled=" + dataRegionCfg.isPersistenceEnabled() + "] Try the following:" + U.nl() + "  ^-- Increase maximum off-heap memory size (DataRegionConfiguration.maxSize)" + U.nl() + "  ^-- Enable Ignite persistence (DataRegionConfiguration.persistenceEnabled)" + U.nl() + "  ^-- Enable eviction or expiration policies");
        if (ctx != null)
            ctx.kernalContext().failure().process(new FailureContext(FailureType.CRITICAL_ERROR, oom));
        throw oom;
    }
    assert (relPtr & ~PageIdUtils.PAGE_IDX_MASK) == 0 : U.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);
    // TODO pass an argument to decide whether the page should be cleaned.
    GridUnsafe.setMemory(absPtr + PAGE_OVERHEAD, sysPageSize - PAGE_OVERHEAD, (byte) 0);
    return pageId;
}
Also used : IgniteOutOfMemoryException(org.apache.ignite.internal.mem.IgniteOutOfMemoryException) FailureContext(org.apache.ignite.failure.FailureContext) PageMetrics(org.apache.ignite.internal.processors.cache.persistence.pagemem.PageMetrics)

Example 12 with PageMetrics

use of org.apache.ignite.internal.processors.cache.persistence.pagemem.PageMetrics in project ignite by apache.

the class IndexPagesMetricsPageDisplacementTest method testPageDisplacement.

/**
 * Inserts data into the cache as long as it fills enough for some data pages to get dumped to the
 * storage. Since index page metrics should reflect the number of in-memory pages, the metric value is expected to
 * go down.
 */
@Test
public void testPageDisplacement() throws IgniteCheckedException {
    int grpId = grid.cachex(TEST_CACHE_NAME).context().groupId();
    DataRegion dataRegion = grid.context().cache().context().database().dataRegion(null);
    PageMetrics pageMetrics = dataRegion.metrics().cacheGrpPageMetrics(grpId);
    int personId = 0;
    long idxPagesOnDisk;
    long idxPagesInMemory;
    do {
        // insert data into the cache until some index pages get displaced to the storage
        for (int i = 0; i < 100; i++, personId++) cache.put(personId, new Person(personId, "foobar"));
        forceCheckpoint(grid);
        idxPagesOnDisk = getIdxPagesOnDisk(grpId).size();
        idxPagesInMemory = idxPageCounter.countIdxPagesInMemory(grpId);
        assertThat(pageMetrics.indexPages().value(), is(idxPagesInMemory));
    } while (idxPagesOnDisk <= idxPagesInMemory);
    // load pages back into memory and check that the metric value has increased
    touchIdxPages(grpId);
    long allIdxPagesInMemory = idxPageCounter.countIdxPagesInMemory(grpId);
    assertThat(allIdxPagesInMemory, greaterThan(idxPagesInMemory));
    assertThat(pageMetrics.indexPages().value(), is(allIdxPagesInMemory));
}
Also used : PageMetrics(org.apache.ignite.internal.processors.cache.persistence.pagemem.PageMetrics) Person(org.apache.ignite.client.Person) DataRegion(org.apache.ignite.internal.processors.cache.persistence.DataRegion) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 13 with PageMetrics

use of org.apache.ignite.internal.processors.cache.persistence.pagemem.PageMetrics in project ignite by apache.

the class PageHandler method doInitPage.

/**
 * @param pageMem Page memory.
 * @param grpId Group ID.
 * @param pageId Page ID.
 * @param page Page pointer.
 * @param pageAddr Page address.
 * @param init Initial IO.
 * @param wal Write ahead log.
 * @throws IgniteCheckedException If failed.
 */
private static void doInitPage(PageMemory pageMem, int grpId, long pageId, long page, long pageAddr, PageIO init, IgniteWriteAheadLogManager wal) throws IgniteCheckedException {
    // TODO GG-11480
    assert PageIO.getCrc(pageAddr) == 0;
    PageMetrics metrics = pageMem.metrics().cacheGrpPageMetrics(grpId);
    init.initNewPage(pageAddr, pageId, pageMem.realPageSize(grpId), metrics);
    // Here we should never write full page, because it is known to be new.
    if (isWalDeltaRecordNeeded(pageMem, grpId, pageId, page, wal, FALSE))
        wal.log(new InitNewPageRecord(grpId, pageId, init.getType(), init.getVersion(), pageId));
}
Also used : PageMetrics(org.apache.ignite.internal.processors.cache.persistence.pagemem.PageMetrics) InitNewPageRecord(org.apache.ignite.internal.pagemem.wal.record.delta.InitNewPageRecord)

Example 14 with PageMetrics

use of org.apache.ignite.internal.processors.cache.persistence.pagemem.PageMetrics in project ignite by apache.

the class PageMemoryNoStoreImpl method borrowFreePage.

/**
 * @return Relative pointer to a free page that was borrowed from the allocated pool.
 */
private long borrowFreePage(int grpId) {
    while (true) {
        long freePageRelPtrMasked = freePageListHead.get();
        long freePageRelPtr = freePageRelPtrMasked & ADDRESS_MASK;
        // no free pages available
        if (freePageRelPtr == INVALID_REL_PTR)
            return INVALID_REL_PTR;
        int pageIdx = PageIdUtils.pageIndex(freePageRelPtr);
        Segment seg = segment(pageIdx);
        long freePageAbsPtr = seg.absolute(pageIdx);
        long nextFreePageRelPtr = GridUnsafe.getLong(freePageAbsPtr) & ADDRESS_MASK;
        long cnt = ((freePageRelPtrMasked & COUNTER_MASK) + COUNTER_INC) & COUNTER_MASK;
        if (freePageListHead.compareAndSet(freePageRelPtrMasked, nextFreePageRelPtr | cnt)) {
            GridUnsafe.putLong(freePageAbsPtr, PAGE_MARKER);
            allocatedPages.incrementAndGet();
            PageMetrics grpPageMetrics = dataRegionMetrics.cacheGrpPageMetrics(grpId);
            grpPageMetrics.totalPages().increment();
            return freePageRelPtr;
        }
    }
}
Also used : PageMetrics(org.apache.ignite.internal.processors.cache.persistence.pagemem.PageMetrics)

Example 15 with PageMetrics

use of org.apache.ignite.internal.processors.cache.persistence.pagemem.PageMetrics in project ignite by apache.

the class PageMemoryNoStoreImpl method releaseFreePage.

/**
 * @param pageId Page ID to release.
 */
private void releaseFreePage(int grpId, long pageId) {
    int pageIdx = PageIdUtils.pageIndex(pageId);
    // Clear out flags and file ID.
    long relPtr = PageIdUtils.pageId(0, (byte) 0, pageIdx);
    Segment seg = segment(pageIdx);
    long absPtr = seg.absolute(pageIdx);
    // Second, write clean relative pointer instead of page ID.
    writePageId(absPtr, relPtr);
    // Third, link the free page.
    while (true) {
        long freePageRelPtrMasked = freePageListHead.get();
        long freePageRelPtr = freePageRelPtrMasked & RELATIVE_PTR_MASK;
        GridUnsafe.putLong(absPtr, freePageRelPtr);
        if (freePageListHead.compareAndSet(freePageRelPtrMasked, relPtr)) {
            allocatedPages.decrementAndGet();
            PageMetrics pageMetrics = dataRegionMetrics.cacheGrpPageMetrics(grpId);
            pageMetrics.totalPages().decrement();
            return;
        }
    }
}
Also used : PageMetrics(org.apache.ignite.internal.processors.cache.persistence.pagemem.PageMetrics)

Aggregations

PageMetrics (org.apache.ignite.internal.processors.cache.persistence.pagemem.PageMetrics)21 DataRegion (org.apache.ignite.internal.processors.cache.persistence.DataRegion)6 PageMemory (org.apache.ignite.internal.pagemem.PageMemory)3 MetaPageInitRecord (org.apache.ignite.internal.pagemem.wal.record.delta.MetaPageInitRecord)3 PageMemoryEx (org.apache.ignite.internal.processors.cache.persistence.pagemem.PageMemoryEx)3 File (java.io.File)2 DataRegionConfiguration (org.apache.ignite.configuration.DataRegionConfiguration)2 FullPageId (org.apache.ignite.internal.pagemem.FullPageId)2 IgniteWriteAheadLogManager (org.apache.ignite.internal.pagemem.wal.IgniteWriteAheadLogManager)2 DataRegionMetricsImpl (org.apache.ignite.internal.processors.cache.persistence.DataRegionMetricsImpl)2 PageMetaIO (org.apache.ignite.internal.processors.cache.persistence.tree.io.PageMetaIO)2 LongAdderMetric (org.apache.ignite.internal.processors.metric.impl.LongAdderMetric)2 IntHashMap (org.apache.ignite.internal.util.collection.IntHashMap)2 Optional (java.util.Optional)1 DataRegionMetrics (org.apache.ignite.DataRegionMetrics)1 DataRegionMetricsProvider (org.apache.ignite.DataRegionMetricsProvider)1 Person (org.apache.ignite.client.Person)1 FailureContext (org.apache.ignite.failure.FailureContext)1 GridKernalContext (org.apache.ignite.internal.GridKernalContext)1 IgniteOutOfMemoryException (org.apache.ignite.internal.mem.IgniteOutOfMemoryException)1