Search in sources :

Example 26 with DataRegion

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

the class ClusterNodeMetricsSelfTest method testAllocatedMemory.

/**
 * @throws Exception If failed.
 */
@Test
public void testAllocatedMemory() throws Exception {
    IgniteEx ignite = grid();
    final IgniteCache cache = ignite.getOrCreateCache(CACHE_NAME);
    DataRegion dataRegion = getDefaultDataRegion(ignite);
    DataRegionMetricsImpl memMetrics = dataRegion.metrics();
    memMetrics.enableMetrics();
    int pageSize = getPageSize(ignite);
    assertEquals(dataRegion.pageMemory().loadedPages(), memMetrics.getTotalAllocatedPages());
    fillCache(cache);
    assertTrue(memMetrics.getTotalAllocatedPages() * pageSize > MAX_VALS_AMOUNT * VAL_SIZE);
}
Also used : IgniteCache(org.apache.ignite.IgniteCache) DataRegionMetricsImpl(org.apache.ignite.internal.processors.cache.persistence.DataRegionMetricsImpl) DataRegion(org.apache.ignite.internal.processors.cache.persistence.DataRegion) GridCommonTest(org.apache.ignite.testframework.junits.common.GridCommonTest) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 27 with DataRegion

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

the class IndexPagesMetricsPersistentTest method validateIdxPagesCnt.

/**
 * {@inheritDoc}
 */
@Override
void validateIdxPagesCnt() throws IgniteCheckedException {
    DataRegion dataRegion = defaultDataRegion();
    DataRegionMetricsImpl dataRegionMetrics = dataRegion.metrics();
    long totalIdxPages = 0;
    for (IgniteInternalCache<?, ?> cache : gridCacheProcessor().caches()) {
        int grpId = cache.context().groupId();
        long idxPages = indexPageCounter.countIdxPagesInMemory(grpId);
        PageMetrics metrics = dataRegionMetrics.cacheGrpPageMetrics(grpId);
        assertThat(metrics.indexPages().value(), is(idxPages));
        totalIdxPages += idxPages;
    }
    assertThat(dataRegionMetrics.pageMetrics().indexPages().value(), is(totalIdxPages));
}
Also used : PageMetrics(org.apache.ignite.internal.processors.cache.persistence.pagemem.PageMetrics) DataRegionMetricsImpl(org.apache.ignite.internal.processors.cache.persistence.DataRegionMetricsImpl) DataRegion(org.apache.ignite.internal.processors.cache.persistence.DataRegion)

Example 28 with DataRegion

use of org.apache.ignite.internal.processors.cache.persistence.DataRegion 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)

Example 29 with DataRegion

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

the class IndexPagesMetricsPageDisplacementTest method touchIdxPages.

/**
 * Acquires all pages inside the index partition for the given cache group in order to load them back into
 * memory if some of them had been displaced to the storage earlier.
 */
private void touchIdxPages(int grpId) throws IgniteCheckedException {
    DataRegion dataRegion = grid.context().cache().context().database().dataRegion(null);
    PageMemory pageMemory = dataRegion.pageMemory();
    for (long pageId : getIdxPagesOnDisk(grpId)) // acquire, but not release all pages, so that they don't get displaced back to the storage
    pageMemory.acquirePage(grpId, pageId);
}
Also used : PageMemory(org.apache.ignite.internal.pagemem.PageMemory) DataRegion(org.apache.ignite.internal.processors.cache.persistence.DataRegion)

Aggregations

DataRegion (org.apache.ignite.internal.processors.cache.persistence.DataRegion)29 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)7 PageMemoryEx (org.apache.ignite.internal.processors.cache.persistence.pagemem.PageMemoryEx)6 PageMetrics (org.apache.ignite.internal.processors.cache.persistence.pagemem.PageMetrics)6 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)6 Test (org.junit.Test)6 DataRegionConfiguration (org.apache.ignite.configuration.DataRegionConfiguration)5 FullPageId (org.apache.ignite.internal.pagemem.FullPageId)5 GridCacheDatabaseSharedManager (org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager)5 File (java.io.File)4 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)4 IgniteEx (org.apache.ignite.internal.IgniteEx)4 PageMemory (org.apache.ignite.internal.pagemem.PageMemory)4 DataRegionMetricsImpl (org.apache.ignite.internal.processors.cache.persistence.DataRegionMetricsImpl)4 ArrayList (java.util.ArrayList)3 Map (java.util.Map)3 IgniteCache (org.apache.ignite.IgniteCache)3 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)3 Collection (java.util.Collection)2 List (java.util.List)2