Search in sources :

Example 41 with PageMemory

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

the class IgnitePdsRecoveryAfterFileCorruptionTest method checkRestore.

/**
 * @param ig Ig.
 * @param pages Pages.
 */
private void checkRestore(IgniteEx ig, FullPageId[] pages) throws IgniteCheckedException {
    GridCacheSharedContext<Object, Object> shared = ig.context().cache().context();
    GridCacheDatabaseSharedManager dbMgr = (GridCacheDatabaseSharedManager) shared.database();
    dbMgr.enableCheckpoints(false).get();
    PageMemory mem = shared.database().dataRegion(null).pageMemory();
    dbMgr.checkpointReadLock();
    try {
        for (FullPageId fullId : pages) {
            long page = mem.acquirePage(fullId.groupId(), fullId.pageId());
            try {
                long pageAddr = mem.readLock(fullId.groupId(), fullId.pageId(), page);
                for (int j = PageIO.COMMON_HEADER_END; j < mem.realPageSize(fullId.groupId()); j += 4) assertEquals(j + (int) fullId.pageId(), PageUtils.getInt(pageAddr, j));
                mem.readUnlock(fullId.groupId(), fullId.pageId(), page);
            } finally {
                mem.releasePage(fullId.groupId(), fullId.pageId(), page);
            }
        }
    } finally {
        dbMgr.checkpointReadUnlock();
    }
}
Also used : PageMemory(org.apache.ignite.internal.pagemem.PageMemory) FullPageId(org.apache.ignite.internal.pagemem.FullPageId)

Example 42 with PageMemory

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

the class CacheFreeListSelfTest method createPageMemory.

/**
 * @return Page memory.
 */
protected PageMemory createPageMemory(int pageSize, DataRegionConfiguration plcCfg) {
    PageMemory pageMem = new PageMemoryNoStoreImpl(log, new UnsafeMemoryProvider(log), null, pageSize, plcCfg, new DataRegionMetricsImpl(plcCfg, new GridTestKernalContext(log())), true);
    pageMem.start();
    return pageMem;
}
Also used : 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 43 with PageMemory

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

the class IndexStorageSelfTest method metaAllocation.

/**
 * @throws Exception If failed.
 */
private void metaAllocation() throws Exception {
    PageMemory mem = memory(true);
    int[] cacheIds = new int[] { 1, "partitioned".hashCode(), "replicated".hashCode() };
    Map<Integer, Map<String, RootPage>> allocatedIdxs = new HashMap<>();
    mem.start();
    try {
        final Map<Integer, IndexStorageImpl> storeMap = new HashMap<>();
        for (int i = 0; i < 1_000; i++) {
            int cacheId = cacheIds[i % cacheIds.length];
            Map<String, RootPage> idxMap = allocatedIdxs.get(cacheId);
            if (idxMap == null) {
                idxMap = new HashMap<>();
                allocatedIdxs.put(cacheId, idxMap);
            }
            String idxName;
            do {
                idxName = randomName();
            } while (idxMap.containsKey(idxName));
            IndexStorageImpl metaStore = storeMap.get(cacheId);
            if (metaStore == null) {
                PageLockTrackerManager pageLockTrackerManager = mock(PageLockTrackerManager.class);
                when(pageLockTrackerManager.createPageLockTracker(anyString())).thenReturn(NOOP_LSNR);
                metaStore = new IndexStorageImpl("indexStorageTree", mem, null, new AtomicLong(), cacheId, false, PageIdAllocator.INDEX_PARTITION, PageMemory.FLAG_IDX, null, mem.allocatePage(cacheId, PageIdAllocator.INDEX_PARTITION, PageMemory.FLAG_IDX), true, null, pageLockTrackerManager);
                storeMap.put(cacheId, metaStore);
            }
            final RootPage rootPage = metaStore.allocateIndex(idxName);
            assertTrue(rootPage.isAllocated());
            idxMap.put(idxName, rootPage);
        }
        for (int cacheId : cacheIds) {
            Map<String, RootPage> idxMap = allocatedIdxs.get(cacheId);
            for (Map.Entry<String, RootPage> entry : idxMap.entrySet()) {
                String idxName = entry.getKey();
                FullPageId rootPageId = entry.getValue().pageId();
                final RootPage rootPage = storeMap.get(cacheId).allocateIndex(idxName);
                assertEquals("Invalid root page ID restored [cacheId=" + cacheId + ", idxName=" + idxName + ']', rootPageId, rootPage.pageId());
                assertFalse("Root page already allocated [cacheId=" + cacheId + ", idxName=" + idxName + ']', rootPage.isAllocated());
            }
        }
    } finally {
        mem.stop(true);
    }
}
Also used : IndexStorageImpl(org.apache.ignite.internal.processors.cache.persistence.IndexStorageImpl) HashMap(java.util.HashMap) PageMemory(org.apache.ignite.internal.pagemem.PageMemory) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) PageLockTrackerManager(org.apache.ignite.internal.processors.cache.persistence.diagnostic.pagelocktracker.PageLockTrackerManager) AtomicLong(java.util.concurrent.atomic.AtomicLong) RootPage(org.apache.ignite.internal.processors.cache.persistence.RootPage) HashMap(java.util.HashMap) Map(java.util.Map) FullPageId(org.apache.ignite.internal.pagemem.FullPageId)

Example 44 with PageMemory

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

the class BPlusTreeSelfTest method createPageMemory.

/**
 * @return Page memory.
 */
protected PageMemory createPageMemory() throws Exception {
    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 45 with PageMemory

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

the class PageMemoryNoLoadSelfTest method testLoadedPagesCount.

/**
 * @throws Exception If failed.
 */
@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) {
        e.printStackTrace();
        // Expected.
        assertEquals(mem.loadedPages(), expPages);
    } finally {
        mem.stop(true);
    }
}
Also used : IgniteOutOfMemoryException(org.apache.ignite.internal.mem.IgniteOutOfMemoryException) PageMemory(org.apache.ignite.internal.pagemem.PageMemory) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

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