Search in sources :

Example 6 with PageMemory

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

the class IgniteCacheDatabaseSharedManager method initMemory.

/**
     * @param memCfg memory configuration with common parameters.
     * @param plcCfg memory policy with PageMemory specific parameters.
     * @param memMetrics {@link MemoryMetrics} object to collect memory usage metrics.
     * @return Memory policy instance.
     */
private MemoryPolicy initMemory(MemoryConfiguration memCfg, MemoryPolicyConfiguration plcCfg, MemoryMetricsImpl memMetrics) {
    File allocPath = buildAllocPath(plcCfg);
    DirectMemoryProvider memProvider = allocPath == null ? new UnsafeMemoryProvider(log) : new MappedFileMemoryProvider(log, allocPath);
    PageMemory pageMem = createPageMemory(memProvider, memCfg, plcCfg, memMetrics);
    return new MemoryPolicy(pageMem, plcCfg, memMetrics, createPageEvictionTracker(plcCfg, pageMem));
}
Also used : MappedFileMemoryProvider(org.apache.ignite.internal.mem.file.MappedFileMemoryProvider) DirectMemoryProvider(org.apache.ignite.internal.mem.DirectMemoryProvider) PageMemory(org.apache.ignite.internal.pagemem.PageMemory) File(java.io.File) UnsafeMemoryProvider(org.apache.ignite.internal.mem.unsafe.UnsafeMemoryProvider)

Example 7 with PageMemory

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

the class InlineIndexHelperTest method testStringTruncate.

/** */
public void testStringTruncate() throws Exception {
    MemoryPolicyConfiguration plcCfg = new MemoryPolicyConfiguration().setMaxSize(1024 * MB);
    JavaLogger log = new JavaLogger();
    PageMemory pageMem = new PageMemoryNoStoreImpl(log, new UnsafeMemoryProvider(log), null, PAGE_SIZE, plcCfg, new MemoryMetricsImpl(plcCfg), false);
    pageMem.start();
    long pageId = 0L;
    long page = 0L;
    try {
        pageId = pageMem.allocatePage(CACHE_ID, 1, PageIdAllocator.FLAG_DATA);
        page = pageMem.acquirePage(CACHE_ID, pageId);
        long pageAddr = pageMem.readLock(CACHE_ID, pageId, page);
        int off = 0;
        InlineIndexHelper ih = new InlineIndexHelper(Value.STRING, 1, 0);
        ih.put(pageAddr, off, ValueString.get("aaaaaaa"), 3 + 5);
        assertFalse(ih.isValueFull(pageAddr, off));
        assertEquals("aaaaa", ih.get(pageAddr, off, 3 + 5).getString());
        ih.put(pageAddr, off, ValueString.get("aaa"), 3 + 5);
        assertTrue(ih.isValueFull(pageAddr, off));
        assertEquals("aaa", ih.get(pageAddr, off, 3 + 5).getString());
    } finally {
        if (page != 0L)
            pageMem.releasePage(CACHE_ID, pageId, page);
        pageMem.stop();
    }
}
Also used : PageMemoryNoStoreImpl(org.apache.ignite.internal.pagemem.impl.PageMemoryNoStoreImpl) PageMemory(org.apache.ignite.internal.pagemem.PageMemory) MemoryPolicyConfiguration(org.apache.ignite.configuration.MemoryPolicyConfiguration) JavaLogger(org.apache.ignite.logger.java.JavaLogger) UnsafeMemoryProvider(org.apache.ignite.internal.mem.unsafe.UnsafeMemoryProvider) MemoryMetricsImpl(org.apache.ignite.internal.processors.cache.database.MemoryMetricsImpl)

Example 8 with PageMemory

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

the class InlineIndexHelperTest method testPutGet.

/** */
private void testPutGet(Value v1, Value v2, Value v3) throws Exception {
    MemoryPolicyConfiguration plcCfg = new MemoryPolicyConfiguration().setMaxSize(1024 * MB);
    JavaLogger log = new JavaLogger();
    PageMemory pageMem = new PageMemoryNoStoreImpl(log, new UnsafeMemoryProvider(log), null, PAGE_SIZE, plcCfg, new MemoryMetricsImpl(plcCfg), false);
    pageMem.start();
    long pageId = 0L;
    long page = 0L;
    try {
        pageId = pageMem.allocatePage(CACHE_ID, 1, PageIdAllocator.FLAG_DATA);
        page = pageMem.acquirePage(CACHE_ID, pageId);
        long pageAddr = pageMem.readLock(CACHE_ID, pageId, page);
        int off = 0;
        int max = 255;
        InlineIndexHelper ih = new InlineIndexHelper(v1.getType(), 1, 0);
        off += ih.put(pageAddr, off, v1, max - off);
        off += ih.put(pageAddr, off, v2, max - off);
        off += ih.put(pageAddr, off, v3, max - off);
        Value v11 = ih.get(pageAddr, 0, max);
        Value v22 = ih.get(pageAddr, ih.fullSize(pageAddr, 0), max);
        assertEquals(v1.getObject(), v11.getObject());
        assertEquals(v2.getObject(), v22.getObject());
    } finally {
        if (page != 0L)
            pageMem.releasePage(CACHE_ID, pageId, page);
        pageMem.stop();
    }
}
Also used : PageMemoryNoStoreImpl(org.apache.ignite.internal.pagemem.impl.PageMemoryNoStoreImpl) PageMemory(org.apache.ignite.internal.pagemem.PageMemory) Value(org.h2.value.Value) MemoryPolicyConfiguration(org.apache.ignite.configuration.MemoryPolicyConfiguration) JavaLogger(org.apache.ignite.logger.java.JavaLogger) UnsafeMemoryProvider(org.apache.ignite.internal.mem.unsafe.UnsafeMemoryProvider) MemoryMetricsImpl(org.apache.ignite.internal.processors.cache.database.MemoryMetricsImpl)

Example 9 with PageMemory

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

the class InlineIndexHelperTest method testBytes.

/** */
public void testBytes() throws Exception {
    MemoryPolicyConfiguration plcCfg = new MemoryPolicyConfiguration().setMaxSize(1024 * MB);
    JavaLogger log = new JavaLogger();
    PageMemory pageMem = new PageMemoryNoStoreImpl(log, new UnsafeMemoryProvider(log), null, PAGE_SIZE, plcCfg, new MemoryMetricsImpl(plcCfg), false);
    pageMem.start();
    long pageId = 0L;
    long page = 0L;
    try {
        pageId = pageMem.allocatePage(CACHE_ID, 1, PageIdAllocator.FLAG_DATA);
        page = pageMem.acquirePage(CACHE_ID, pageId);
        long pageAddr = pageMem.readLock(CACHE_ID, pageId, page);
        int off = 0;
        InlineIndexHelper ih = new InlineIndexHelper(Value.BYTES, 1, 0);
        ih.put(pageAddr, off, ValueBytes.get(new byte[] { 1, 2, 3, 4, 5 }), 3 + 3);
        assertFalse(ih.isValueFull(pageAddr, off));
        assertTrue(Arrays.equals(new byte[] { 1, 2, 3 }, ih.get(pageAddr, off, 3 + 5).getBytes()));
        ih.put(pageAddr, off, ValueBytes.get(new byte[] { 1, 2, 3, 4, 5 }), 3 + 5);
        assertTrue(ih.isValueFull(pageAddr, off));
        assertTrue(Arrays.equals(new byte[] { 1, 2, 3, 4, 5 }, ih.get(pageAddr, off, 3 + 5).getBytes()));
    } finally {
        if (page != 0L)
            pageMem.releasePage(CACHE_ID, pageId, page);
        pageMem.stop();
    }
}
Also used : PageMemoryNoStoreImpl(org.apache.ignite.internal.pagemem.impl.PageMemoryNoStoreImpl) PageMemory(org.apache.ignite.internal.pagemem.PageMemory) MemoryPolicyConfiguration(org.apache.ignite.configuration.MemoryPolicyConfiguration) JavaLogger(org.apache.ignite.logger.java.JavaLogger) UnsafeMemoryProvider(org.apache.ignite.internal.mem.unsafe.UnsafeMemoryProvider) MemoryMetricsImpl(org.apache.ignite.internal.processors.cache.database.MemoryMetricsImpl)

Example 10 with PageMemory

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

the class PageMemoryNoLoadSelfTest method testPageIdRotation.

/**
     * @throws Exception If failed.
     */
public void testPageIdRotation() throws Exception {
    PageMemory mem = memory();
    mem.start();
    try {
        int pages = 5;
        Collection<FullPageId> old = new ArrayList<>();
        Collection<FullPageId> updated = new ArrayList<>();
        for (int i = 0; i < pages; i++) old.add(allocatePage(mem));
        // Check that initial pages are accessible.
        for (FullPageId id : old) {
            long pageApsPtr = mem.acquirePage(id.cacheId(), id.pageId());
            try {
                long pageAddr = mem.writeLock(id.cacheId(), id.pageId(), pageApsPtr);
                assertNotNull(pageAddr);
                try {
                    long updId = PageIdUtils.rotatePageId(id.pageId());
                    PageIO.setPageId(pageAddr, updId);
                    updated.add(new FullPageId(updId, id.cacheId()));
                } finally {
                    mem.writeUnlock(id.cacheId(), id.pageId(), pageApsPtr, null, true);
                }
            } finally {
                mem.releasePage(id.cacheId(), id.pageId(), pageApsPtr);
            }
        }
        // Check that updated pages are inaccessible using old IDs.
        for (FullPageId id : old) {
            long pageApsPtr = mem.acquirePage(id.cacheId(), id.pageId());
            try {
                long pageAddr = mem.writeLock(id.cacheId(), id.pageId(), pageApsPtr);
                if (pageAddr != 0L) {
                    mem.writeUnlock(id.cacheId(), id.pageId(), pageApsPtr, null, false);
                    fail("Was able to acquire page write lock.");
                }
                mem.readLock(id.cacheId(), id.pageId(), pageApsPtr);
                if (pageAddr != 0) {
                    mem.readUnlock(id.cacheId(), id.pageId(), pageApsPtr);
                    fail("Was able to acquire page read lock.");
                }
            } finally {
                mem.releasePage(id.cacheId(), id.pageId(), pageApsPtr);
            }
        }
        // Check that updated pages are accessible using new IDs.
        for (FullPageId id : updated) {
            long pageApsPtr = mem.acquirePage(id.cacheId(), id.pageId());
            try {
                long pageAddr = mem.writeLock(id.cacheId(), id.pageId(), pageApsPtr);
                assertNotSame(0L, pageAddr);
                try {
                    assertEquals(id.pageId(), PageIO.getPageId(pageAddr));
                } finally {
                    mem.writeUnlock(id.cacheId(), id.pageId(), pageApsPtr, null, false);
                }
                pageAddr = mem.readLock(id.cacheId(), id.pageId(), pageApsPtr);
                assertNotSame(0L, pageAddr);
                try {
                    assertEquals(id.pageId(), PageIO.getPageId(pageAddr));
                } finally {
                    mem.readUnlock(id.cacheId(), id.pageId(), pageApsPtr);
                }
            } finally {
                mem.releasePage(id.cacheId(), id.pageId(), pageApsPtr);
            }
        }
    } finally {
        mem.stop();
    }
}
Also used : PageMemory(org.apache.ignite.internal.pagemem.PageMemory) ArrayList(java.util.ArrayList) FullPageId(org.apache.ignite.internal.pagemem.FullPageId)

Aggregations

PageMemory (org.apache.ignite.internal.pagemem.PageMemory)14 UnsafeMemoryProvider (org.apache.ignite.internal.mem.unsafe.UnsafeMemoryProvider)7 MemoryPolicyConfiguration (org.apache.ignite.configuration.MemoryPolicyConfiguration)6 PageMemoryNoStoreImpl (org.apache.ignite.internal.pagemem.impl.PageMemoryNoStoreImpl)6 MemoryMetricsImpl (org.apache.ignite.internal.processors.cache.database.MemoryMetricsImpl)6 FullPageId (org.apache.ignite.internal.pagemem.FullPageId)5 JavaLogger (org.apache.ignite.logger.java.JavaLogger)4 ArrayList (java.util.ArrayList)2 File (java.io.File)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 DirectMemoryProvider (org.apache.ignite.internal.mem.DirectMemoryProvider)1 IgniteOutOfMemoryException (org.apache.ignite.internal.mem.IgniteOutOfMemoryException)1 MappedFileMemoryProvider (org.apache.ignite.internal.mem.file.MappedFileMemoryProvider)1 MetadataStorage (org.apache.ignite.internal.processors.cache.database.MetadataStorage)1 RootPage (org.apache.ignite.internal.processors.cache.database.RootPage)1 FreeListImpl (org.apache.ignite.internal.processors.cache.database.freelist.FreeListImpl)1 Value (org.h2.value.Value)1