Search in sources :

Example 1 with PageMemory

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

the class MetadataStorageSelfTest 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, MetadataStorage> 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));
            MetadataStorage metaStore = storeMap.get(cacheId);
            if (metaStore == null) {
                metaStore = new MetadataStorage(mem, null, new AtomicLong(), cacheId, PageIdAllocator.INDEX_PARTITION, PageMemory.FLAG_IDX, null, mem.allocatePage(cacheId, PageIdAllocator.INDEX_PARTITION, PageMemory.FLAG_IDX), true);
                storeMap.put(cacheId, metaStore);
            }
            final RootPage rootPage = metaStore.getOrAllocateForTree(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).getOrAllocateForTree(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();
    }
}
Also used : HashMap(java.util.HashMap) PageMemory(org.apache.ignite.internal.pagemem.PageMemory) AtomicLong(java.util.concurrent.atomic.AtomicLong) RootPage(org.apache.ignite.internal.processors.cache.database.RootPage) MetadataStorage(org.apache.ignite.internal.processors.cache.database.MetadataStorage) HashMap(java.util.HashMap) Map(java.util.Map) FullPageId(org.apache.ignite.internal.pagemem.FullPageId)

Example 2 with PageMemory

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

the class IgniteCacheDatabaseSharedManager method ensureFreeSpace.

/**
     * See {@link GridCacheMapEntry#ensureFreeSpace()}
     *
     * @param memPlc Memory policy.
     */
public void ensureFreeSpace(MemoryPolicy memPlc) throws IgniteCheckedException {
    if (memPlc == null)
        return;
    MemoryPolicyConfiguration plcCfg = memPlc.config();
    if (plcCfg.getPageEvictionMode() == DataPageEvictionMode.DISABLED)
        return;
    long memorySize = plcCfg.getMaxSize();
    PageMemory pageMem = memPlc.pageMemory();
    int sysPageSize = pageMem.systemPageSize();
    FreeListImpl freeListImpl = freeListMap.get(plcCfg.getName());
    for (; ; ) {
        long allocatedPagesCnt = pageMem.loadedPages();
        int emptyDataPagesCnt = freeListImpl.emptyDataPages();
        boolean shouldEvict = allocatedPagesCnt > (memorySize / sysPageSize * plcCfg.getEvictionThreshold()) && emptyDataPagesCnt < plcCfg.getEmptyPagesPoolSize();
        if (shouldEvict)
            memPlc.evictionTracker().evictDataPage();
        else
            break;
    }
}
Also used : FreeListImpl(org.apache.ignite.internal.processors.cache.database.freelist.FreeListImpl) PageMemory(org.apache.ignite.internal.pagemem.PageMemory) MemoryPolicyConfiguration(org.apache.ignite.configuration.MemoryPolicyConfiguration)

Example 3 with PageMemory

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

the class CacheFreeListImplSelfTest method createPageMemory.

/**
 * @return Page memory.
 */
protected PageMemory createPageMemory(int pageSize, DataRegionConfiguration plcCfg) throws Exception {
    PageMemory pageMem = new PageMemoryNoStoreImpl(log, new UnsafeMemoryProvider(log), null, pageSize, plcCfg, new DataRegionMetricsImpl(plcCfg), true);
    pageMem.start();
    return pageMem;
}
Also used : PageMemoryNoStoreImpl(org.apache.ignite.internal.pagemem.impl.PageMemoryNoStoreImpl) PageMemory(org.apache.ignite.internal.pagemem.PageMemory) DataRegionMetricsImpl(org.apache.ignite.internal.processors.cache.persistence.DataRegionMetricsImpl) UnsafeMemoryProvider(org.apache.ignite.internal.mem.unsafe.UnsafeMemoryProvider)

Example 4 with PageMemory

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

the class IgniteCacheDatabaseSharedManager method ensureFreeSpace.

/**
 * See {@link GridCacheMapEntry#ensureFreeSpace()}
 *
 * @param memPlc data region.
 */
public void ensureFreeSpace(DataRegion memPlc) throws IgniteCheckedException {
    if (memPlc == null)
        return;
    DataRegionConfiguration plcCfg = memPlc.config();
    if (plcCfg.getPageEvictionMode() == DataPageEvictionMode.DISABLED || plcCfg.isPersistenceEnabled())
        return;
    long memorySize = plcCfg.getMaxSize();
    PageMemory pageMem = memPlc.pageMemory();
    int sysPageSize = pageMem.systemPageSize();
    CacheFreeListImpl freeListImpl = freeListMap.get(plcCfg.getName());
    for (; ; ) {
        long allocatedPagesCnt = pageMem.loadedPages();
        int emptyDataPagesCnt = freeListImpl.emptyDataPages();
        boolean shouldEvict = allocatedPagesCnt > (memorySize / sysPageSize * plcCfg.getEvictionThreshold()) && emptyDataPagesCnt < plcCfg.getEmptyPagesPoolSize();
        if (shouldEvict) {
            memPlc.evictionTracker().evictDataPage();
            memPlc.memoryMetrics().updateEvictionRate();
        } else
            break;
    }
}
Also used : DataRegionConfiguration(org.apache.ignite.configuration.DataRegionConfiguration) CacheFreeListImpl(org.apache.ignite.internal.processors.cache.persistence.freelist.CacheFreeListImpl) PageMemory(org.apache.ignite.internal.pagemem.PageMemory)

Example 5 with PageMemory

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

the class H2RowCache method touch.

/**
 * Update page
 *
 * @param link Link.
 * @throws IgniteCheckedException On error.
 */
private void touch(long link) throws IgniteCheckedException {
    PageMemory mem = grpCtx.dataRegion().pageMemory();
    int grpId = grpCtx.groupId();
    final long pageId = PageIdUtils.pageId(link);
    final long page = mem.acquirePage(grpId, pageId);
    try {
        // Touch page timestamp
        mem.readLock(grpId, pageId, page);
        mem.readUnlock(grpId, pageId, page);
    } finally {
        mem.releasePage(grpId, pageId, page);
    }
}
Also used : PageMemory(org.apache.ignite.internal.pagemem.PageMemory)

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