Search in sources :

Example 21 with PageMemory

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

the class IgnitePdsCheckpointSimulationWithRealCpDisabledTest method testCheckpointSimulationMultiThreaded.

/**
 * @throws Exception if failed.
 */
@Test
public void testCheckpointSimulationMultiThreaded() throws Exception {
    IgniteEx ig = startGrid(0);
    ig.cluster().active(true);
    GridCacheSharedContext<Object, Object> shared = ig.context().cache().context();
    GridCacheDatabaseSharedManager dbMgr = (GridCacheDatabaseSharedManager) shared.database();
    IgnitePageStoreManager pageStore = shared.pageStore();
    U.sleep(1_000);
    // Disable integrated checkpoint thread.
    dbMgr.enableCheckpoints(false).get();
    // Must put something in partition 0 in order to initialize meta page.
    // Otherwise we will violate page store integrity rules.
    ig.cache(CACHE_NAME).put(0, 0);
    PageMemory mem = shared.database().dataRegion(null).pageMemory();
    IgniteBiTuple<Map<FullPageId, Integer>, WALPointer> res;
    try {
        res = runCheckpointing(ig, (PageMemoryImpl) mem, pageStore, shared.wal(), shared.cache().cache(CACHE_NAME).context().cacheId());
    } catch (Throwable th) {
        log().error("Error while running checkpointing", th);
        throw th;
    } finally {
        dbMgr.enableCheckpoints(true).get();
        stopAllGrids(false);
    }
    ig = startGrid(0);
    ig.cluster().active(true);
    shared = ig.context().cache().context();
    dbMgr = (GridCacheDatabaseSharedManager) shared.database();
    dbMgr.enableCheckpoints(false).get();
    mem = shared.database().dataRegion(null).pageMemory();
    verifyReads(ig.context(), res.get1(), mem, res.get2(), shared.wal());
}
Also used : IgnitePageStoreManager(org.apache.ignite.internal.pagemem.store.IgnitePageStoreManager) GridCacheDatabaseSharedManager(org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager) IgniteEx(org.apache.ignite.internal.IgniteEx) PageMemory(org.apache.ignite.internal.pagemem.PageMemory) PageMemoryImpl(org.apache.ignite.internal.processors.cache.persistence.pagemem.PageMemoryImpl) CacheObject(org.apache.ignite.internal.processors.cache.CacheObject) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) WALPointer(org.apache.ignite.internal.processors.cache.persistence.wal.WALPointer) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 22 with PageMemory

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

the class PageMemoryTracker method checkPages.

/**
 * Checks if there are any differences between the Ignite's data regions content and pages inside the tracker.
 *
 * @param checkAll Check all tracked pages, otherwise check until first error.
 * @param checkPageCnt Check tracked and allocated pages count. This check can be done only if there is no
 * concurrent modification of pages in the system (for example when checkpointWriteLock is held). Some threads
 * (for example MVCC vacuum cleaner) can modify pages even if there is no activity from a users point of view.
 * @return {@code true} if content of all tracked pages equals to content of these pages in the ignite instance.
 */
private boolean checkPages(boolean checkAll, boolean checkPageCnt) throws IgniteCheckedException {
    if (!started)
        throw new IgniteCheckedException("Page memory checking only possible when tracker is started.");
    GridCacheProcessor cacheProc = gridCtx.cache();
    boolean res = true;
    synchronized (pageAllocatorMux) {
        long totalAllocated = pageStoreAllocatedPages();
        log.info(">>> Total tracked pages: " + pages.size());
        log.info(">>> Total allocated pages: " + totalAllocated);
        dumpStats();
        if (emptyPds && checkPageCnt && pages.size() != totalAllocated) {
            res = false;
            log.error("Started from empty PDS, but tracked pages count not equals to allocated pages count");
            dumpPagesCountDiff();
            if (!checkAll)
                return false;
        }
    }
    Set<Integer> groupsWarned = new HashSet<>();
    for (DirectMemoryPage page : pages.values()) {
        FullPageId fullPageId = page.fullPageId();
        PageMemory pageMem;
        if (fullPageId.groupId() == MetaStorage.METASTORAGE_CACHE_ID)
            pageMem = cacheProc.context().database().metaStorage().pageMemory();
        else if (fullPageId.groupId() == TxLog.TX_LOG_CACHE_ID)
            pageMem = cacheProc.context().database().dataRegion(TxLog.TX_LOG_CACHE_NAME).pageMemory();
        else {
            CacheGroupContext ctx = cacheProc.cacheGroup(fullPageId.groupId());
            if (ctx != null)
                pageMem = ctx.dataRegion().pageMemory();
            else {
                if (!groupsWarned.contains(fullPageId.groupId())) {
                    log.warning("Cache group " + fullPageId.groupId() + " not found.");
                    groupsWarned.add(fullPageId.groupId());
                }
                continue;
            }
        }
        assert pageMem instanceof PageMemoryImpl;
        long rmtPage = pageMem.acquirePage(fullPageId.groupId(), fullPageId.pageId());
        try {
            long rmtPageAddr = pageMem.readLockForce(fullPageId.groupId(), fullPageId.pageId(), rmtPage);
            try {
                page.lock();
                try {
                    if (rmtPageAddr == 0L) {
                        res = false;
                        log.error("Can't lock page: " + fullPageId);
                        dumpHistory(page);
                    } else if (!comparePages(fullPageId, page, rmtPageAddr))
                        res = false;
                    if (!res && !checkAll)
                        return false;
                } finally {
                    page.unlock();
                }
            } finally {
                if (rmtPageAddr != 0L)
                    pageMem.readUnlock(fullPageId.groupId(), fullPageId.pageId(), rmtPage);
            }
        } finally {
            pageMem.releasePage(fullPageId.groupId(), fullPageId.pageId(), rmtPage);
        }
    }
    return res;
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) PageMemory(org.apache.ignite.internal.pagemem.PageMemory) PageMemoryImpl(org.apache.ignite.internal.processors.cache.persistence.pagemem.PageMemoryImpl) CacheGroupContext(org.apache.ignite.internal.processors.cache.CacheGroupContext) GridCacheProcessor(org.apache.ignite.internal.processors.cache.GridCacheProcessor) HashSet(java.util.HashSet) FullPageId(org.apache.ignite.internal.pagemem.FullPageId)

Example 23 with PageMemory

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

the class PageMemoryTracker method mockPageMemory.

/**
 * Creates a mock for the Page Memory.
 */
private PageMemory mockPageMemory() {
    PageMemory mock = mock(PageMemory.class);
    when(mock.pageSize()).thenReturn(pageSize);
    when(mock.realPageSize(Mockito.anyInt())).then(invocation -> {
        int grpId = (Integer) invocation.getArguments()[0];
        if (gridCtx.encryption().getActiveKey(grpId) == null)
            return pageSize;
        EncryptionSpi encSpi = ctx.igniteConfiguration().getEncryptionSpi();
        return pageSize - (encSpi.encryptedSizeNoPadding(pageSize) - pageSize) - encSpi.blockSize();
    });
    when(mock.pageBuffer(Mockito.anyLong())).then(invocation -> {
        long pageAddr = (Long) invocation.getArguments()[0];
        return GridUnsafe.wrapPointer(pageAddr, pageSize);
    });
    when(mock.metrics()).thenReturn(new DataRegionMetricsImpl(new DataRegionConfiguration(), gridCtx));
    return mock;
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) DataRegionConfiguration(org.apache.ignite.configuration.DataRegionConfiguration) PageMemory(org.apache.ignite.internal.pagemem.PageMemory) DataRegionMetricsImpl(org.apache.ignite.internal.processors.cache.persistence.DataRegionMetricsImpl) EncryptionSpi(org.apache.ignite.spi.encryption.EncryptionSpi)

Example 24 with PageMemory

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

the class BPlusTreeReplaceRemoveRaceTest method createPageMemory.

/**
 * @return Page memory.
 */
protected PageMemory createPageMemory() {
    DataRegionConfiguration plcCfg = new DataRegionConfiguration().setInitialSize(1024 * MB).setMaxSize(1024 * MB);
    PageMemory pageMem = new PageMemoryNoStoreImpl(log, new UnsafeMemoryProvider(log), null, PAGE_SIZE, plcCfg, new DataRegionMetricsImpl(plcCfg, new GridTestKernalContext(log())), true);
    pageMem.start();
    return pageMem;
}
Also used : DataRegionConfiguration(org.apache.ignite.configuration.DataRegionConfiguration) PageMemoryNoStoreImpl(org.apache.ignite.internal.pagemem.impl.PageMemoryNoStoreImpl) PageMemory(org.apache.ignite.internal.pagemem.PageMemory) GridTestKernalContext(org.apache.ignite.testframework.junits.GridTestKernalContext) DataRegionMetricsImpl(org.apache.ignite.internal.processors.cache.persistence.DataRegionMetricsImpl) UnsafeMemoryProvider(org.apache.ignite.internal.mem.unsafe.UnsafeMemoryProvider)

Example 25 with PageMemory

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

the class SwapPathConstructionSelfTest method extractDefaultPageMemoryAllocPath.

/**
 * @param context Context.
 */
private String extractDefaultPageMemoryAllocPath(GridKernalContext context) {
    IgniteCacheDatabaseSharedManager dbMgr = context.cache().context().database();
    Map<String, DataRegion> memPlcMap = U.field(dbMgr, "dataRegionMap");
    PageMemory pageMem = memPlcMap.get("default").pageMemory();
    Object memProvider = U.field(pageMem, "directMemoryProvider");
    Object memProvider0 = U.field(memProvider, "memProvider");
    return ((File) U.field(memProvider0, "allocationPath")).getAbsolutePath();
}
Also used : PageMemory(org.apache.ignite.internal.pagemem.PageMemory) File(java.io.File) IgniteCacheDatabaseSharedManager(org.apache.ignite.internal.processors.cache.persistence.IgniteCacheDatabaseSharedManager) DataRegion(org.apache.ignite.internal.processors.cache.persistence.DataRegion)

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