Search in sources :

Example 1 with PageMemory

use of org.apache.ignite.internal.pagememory.PageMemory in project ignite-3 by apache.

the class PageMemoryNoLoadSelfTest method testLoadedPagesCount.

@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) {
        log.error(e.getMessage(), e);
        // Expected.
        assertEquals(mem.loadedPages(), expPages);
    } finally {
        mem.stop(true);
    }
}
Also used : IgniteOutOfMemoryException(org.apache.ignite.internal.pagememory.mem.IgniteOutOfMemoryException) PageMemory(org.apache.ignite.internal.pagememory.PageMemory) BaseIgniteAbstractTest(org.apache.ignite.internal.testframework.BaseIgniteAbstractTest) Test(org.junit.jupiter.api.Test)

Example 2 with PageMemory

use of org.apache.ignite.internal.pagememory.PageMemory in project ignite-3 by apache.

the class PageMemoryNoLoadSelfTest method testPageTearingSequential.

@Test
public void testPageTearingSequential() throws Exception {
    PageMemory mem = memory();
    mem.start();
    try {
        int pagesCnt = 1024;
        List<FullPageId> pages = new ArrayList<>(pagesCnt);
        for (int i = 0; i < pagesCnt; i++) {
            FullPageId fullId = allocatePage(mem);
            pages.add(fullId);
            long page = mem.acquirePage(fullId.groupId(), fullId.pageId());
            try {
                if (i % 64 == 0) {
                    log.info("Writing page [idx=" + i + ", pageId=" + fullId.pageId() + ", page=" + page + ']');
                }
                writePage(mem, fullId, page, i + 1);
            } finally {
                mem.releasePage(fullId.groupId(), fullId.pageId(), page);
            }
        }
        for (int i = 0; i < pagesCnt; i++) {
            FullPageId fullId = pages.get(i);
            long page = mem.acquirePage(fullId.groupId(), fullId.pageId());
            try {
                if (i % 64 == 0) {
                    log.info("Reading page [idx=" + i + ", pageId=" + fullId.pageId() + ", page=" + page + ']');
                }
                readPage(mem, fullId.pageId(), page, i + 1);
            } finally {
                mem.releasePage(fullId.groupId(), fullId.pageId(), page);
            }
        }
    } finally {
        mem.stop(true);
    }
}
Also used : PageMemory(org.apache.ignite.internal.pagememory.PageMemory) ArrayList(java.util.ArrayList) FullPageId(org.apache.ignite.internal.pagememory.FullPageId) BaseIgniteAbstractTest(org.apache.ignite.internal.testframework.BaseIgniteAbstractTest) Test(org.junit.jupiter.api.Test)

Example 3 with PageMemory

use of org.apache.ignite.internal.pagememory.PageMemory in project ignite-3 by apache.

the class PageMemoryNoLoadSelfTest method memory.

/**
 * Creates new page memory instance.
 *
 * @return Page memory implementation.
 * @throws Exception If failed.
 */
protected PageMemory memory() throws Exception {
    dataRegionCfg.change(cfg -> cfg.convert(PageMemoryDataRegionChange.class).changePageSize(PAGE_SIZE).changeInitSize(MAX_MEMORY_SIZE).changeMaxSize(MAX_MEMORY_SIZE)).get(1, SECONDS);
    DirectMemoryProvider provider = new UnsafeMemoryProvider(null);
    PageIoRegistry ioRegistry = new PageIoRegistry();
    ioRegistry.loadFromServiceLoader();
    return new PageMemoryNoStoreImpl(provider, (PageMemoryDataRegionConfiguration) fixConfiguration(dataRegionCfg), ioRegistry);
}
Also used : Assertions.fail(org.junit.jupiter.api.Assertions.fail) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) PageMemory(org.apache.ignite.internal.pagememory.PageMemory) DirectMemoryProvider(org.apache.ignite.internal.pagememory.mem.DirectMemoryProvider) PageIoRegistry(org.apache.ignite.internal.pagememory.io.PageIoRegistry) PageMemoryDataRegionChange(org.apache.ignite.configuration.schemas.store.PageMemoryDataRegionChange) PageMemoryDataRegionConfigurationSchema(org.apache.ignite.configuration.schemas.store.PageMemoryDataRegionConfigurationSchema) FullPageId(org.apache.ignite.internal.pagememory.FullPageId) PageIdAllocator(org.apache.ignite.internal.pagememory.PageIdAllocator) ArrayList(java.util.ArrayList) InjectConfiguration(org.apache.ignite.internal.configuration.testframework.InjectConfiguration) TestPageIo(org.apache.ignite.internal.pagememory.TestPageIoModule.TestPageIo) HashSet(java.util.HashSet) IgniteOutOfMemoryException(org.apache.ignite.internal.pagememory.mem.IgniteOutOfMemoryException) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) UnsafeMemoryAllocatorConfigurationSchema(org.apache.ignite.configuration.schemas.store.UnsafeMemoryAllocatorConfigurationSchema) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) ConfigurationExtension(org.apache.ignite.internal.configuration.testframework.ConfigurationExtension) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) UnsafeMemoryProvider(org.apache.ignite.internal.pagememory.mem.unsafe.UnsafeMemoryProvider) DataRegionConfiguration(org.apache.ignite.configuration.schemas.store.DataRegionConfiguration) Collection(java.util.Collection) PageIo(org.apache.ignite.internal.pagememory.io.PageIo) Assertions.assertNotSame(org.junit.jupiter.api.Assertions.assertNotSame) BaseIgniteAbstractTest(org.apache.ignite.internal.testframework.BaseIgniteAbstractTest) PageUtils(org.apache.ignite.internal.pagememory.util.PageUtils) ConfigurationTestUtils.fixConfiguration(org.apache.ignite.internal.configuration.ConfigurationTestUtils.fixConfiguration) Test(org.junit.jupiter.api.Test) List(java.util.List) IgniteInternalCheckedException(org.apache.ignite.lang.IgniteInternalCheckedException) PageIdUtils(org.apache.ignite.internal.pagememory.util.PageIdUtils) PageMemoryDataRegionConfiguration(org.apache.ignite.configuration.schemas.store.PageMemoryDataRegionConfiguration) SECONDS(java.util.concurrent.TimeUnit.SECONDS) DirectMemoryProvider(org.apache.ignite.internal.pagememory.mem.DirectMemoryProvider) PageMemoryDataRegionChange(org.apache.ignite.configuration.schemas.store.PageMemoryDataRegionChange) UnsafeMemoryProvider(org.apache.ignite.internal.pagememory.mem.unsafe.UnsafeMemoryProvider) PageIoRegistry(org.apache.ignite.internal.pagememory.io.PageIoRegistry)

Example 4 with PageMemory

use of org.apache.ignite.internal.pagememory.PageMemory in project ignite-3 by apache.

the class PageMemoryNoLoadSelfTest method testPageTearingInner.

@Test
public void testPageTearingInner() throws Exception {
    PageMemory mem = memory();
    mem.start();
    try {
        FullPageId fullId1 = allocatePage(mem);
        FullPageId fullId2 = allocatePage(mem);
        long page1 = mem.acquirePage(fullId1.groupId(), fullId1.pageId());
        try {
            long page2 = mem.acquirePage(fullId2.groupId(), fullId2.pageId());
            log.info("Allocated pages [page1Id=" + fullId1.pageId() + ", page1=" + page1 + ", page2Id=" + fullId2.pageId() + ", page2=" + page2 + ']');
            try {
                writePage(mem, fullId1, page1, 1);
                writePage(mem, fullId2, page2, 2);
                readPage(mem, fullId1.pageId(), page1, 1);
                readPage(mem, fullId2.pageId(), page2, 2);
                // Check read after read.
                readPage(mem, fullId1.pageId(), page1, 1);
                readPage(mem, fullId2.pageId(), page2, 2);
            } finally {
                mem.releasePage(fullId2.groupId(), fullId2.pageId(), page2);
            }
        } finally {
            mem.releasePage(fullId1.groupId(), fullId1.pageId(), page1);
        }
    } finally {
        mem.stop(true);
    }
}
Also used : PageMemory(org.apache.ignite.internal.pagememory.PageMemory) FullPageId(org.apache.ignite.internal.pagememory.FullPageId) BaseIgniteAbstractTest(org.apache.ignite.internal.testframework.BaseIgniteAbstractTest) Test(org.junit.jupiter.api.Test)

Example 5 with PageMemory

use of org.apache.ignite.internal.pagememory.PageMemory in project ignite-3 by apache.

the class AbstractFreeListTest method createPageMemory.

private PageMemory createPageMemory(int pageSize) throws Exception {
    dataRegionCfg.change(c -> c.convert(PageMemoryDataRegionChange.class).changePageSize(pageSize).changeInitSize(MAX_SIZE).changeMaxSize(MAX_SIZE)).get(1, TimeUnit.SECONDS);
    TestPageIoRegistry ioRegistry = new TestPageIoRegistry();
    ioRegistry.loadFromServiceLoader();
    ioRegistry.load(TestDataPageIo.VERSIONS);
    return new PageMemoryNoStoreImpl(new UnsafeMemoryProvider(null), (PageMemoryDataRegionConfiguration) fixConfiguration(dataRegionCfg), ioRegistry);
}
Also used : PageMemory(org.apache.ignite.internal.pagememory.PageMemory) TestPageIoRegistry(org.apache.ignite.internal.pagememory.TestPageIoRegistry) Assertions.assertNotEquals(org.junit.jupiter.api.Assertions.assertNotEquals) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) PageMemoryDataRegionChange(org.apache.ignite.configuration.schemas.store.PageMemoryDataRegionChange) PageMemoryDataRegionConfigurationSchema(org.apache.ignite.configuration.schemas.store.PageMemoryDataRegionConfigurationSchema) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) MINUTES(java.util.concurrent.TimeUnit.MINUTES) HashMap(java.util.HashMap) Random(java.util.Random) FLAG_AUX(org.apache.ignite.internal.pagememory.PageIdAllocator.FLAG_AUX) ArrayList(java.util.ArrayList) InjectConfiguration(org.apache.ignite.internal.configuration.testframework.InjectConfiguration) IoStatisticsHolderNoOp(org.apache.ignite.internal.pagememory.metric.IoStatisticsHolderNoOp) PageLockListenerNoOp(org.apache.ignite.internal.pagememory.util.PageLockListenerNoOp) IgniteTestUtils.runMultiThreadedAsync(org.apache.ignite.internal.testframework.IgniteTestUtils.runMultiThreadedAsync) UnsafeMemoryAllocatorConfigurationSchema(org.apache.ignite.configuration.schemas.store.UnsafeMemoryAllocatorConfigurationSchema) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) ConfigurationExtension(org.apache.ignite.internal.configuration.testframework.ConfigurationExtension) PageMemoryNoStoreImpl(org.apache.ignite.internal.pagememory.impl.PageMemoryNoStoreImpl) Map(java.util.Map) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) MethodSource(org.junit.jupiter.params.provider.MethodSource) UnsafeMemoryProvider(org.apache.ignite.internal.pagememory.mem.unsafe.UnsafeMemoryProvider) Iterator(java.util.Iterator) PageIdUtils.partitionId(org.apache.ignite.internal.pagememory.util.PageIdUtils.partitionId) DataRegionConfiguration(org.apache.ignite.configuration.schemas.store.DataRegionConfiguration) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Arguments(org.junit.jupiter.params.provider.Arguments) BaseIgniteAbstractTest(org.apache.ignite.internal.testframework.BaseIgniteAbstractTest) ConfigurationTestUtils.fixConfiguration(org.apache.ignite.internal.configuration.ConfigurationTestUtils.fixConfiguration) TimeUnit(java.util.concurrent.TimeUnit) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) IgniteInternalCheckedException(org.apache.ignite.lang.IgniteInternalCheckedException) AfterEach(org.junit.jupiter.api.AfterEach) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Stream(java.util.stream.Stream) PageEvictionTrackerNoOp(org.apache.ignite.internal.pagememory.evict.PageEvictionTrackerNoOp) FLAG_DATA(org.apache.ignite.internal.pagememory.PageIdAllocator.FLAG_DATA) MiB(org.apache.ignite.internal.util.Constants.MiB) PageMemoryDataRegionConfiguration(org.apache.ignite.configuration.schemas.store.PageMemoryDataRegionConfiguration) IoStatisticsHolder(org.apache.ignite.internal.pagememory.metric.IoStatisticsHolder) PageMemoryNoStoreImpl(org.apache.ignite.internal.pagememory.impl.PageMemoryNoStoreImpl) TestPageIoRegistry(org.apache.ignite.internal.pagememory.TestPageIoRegistry) PageMemoryDataRegionChange(org.apache.ignite.configuration.schemas.store.PageMemoryDataRegionChange) UnsafeMemoryProvider(org.apache.ignite.internal.pagememory.mem.unsafe.UnsafeMemoryProvider)

Aggregations

PageMemory (org.apache.ignite.internal.pagememory.PageMemory)12 BaseIgniteAbstractTest (org.apache.ignite.internal.testframework.BaseIgniteAbstractTest)9 Test (org.junit.jupiter.api.Test)9 PageMemoryDataRegionChange (org.apache.ignite.configuration.schemas.store.PageMemoryDataRegionChange)7 PageMemoryDataRegionConfiguration (org.apache.ignite.configuration.schemas.store.PageMemoryDataRegionConfiguration)7 ConfigurationTestUtils.fixConfiguration (org.apache.ignite.internal.configuration.ConfigurationTestUtils.fixConfiguration)7 FullPageId (org.apache.ignite.internal.pagememory.FullPageId)7 UnsafeMemoryProvider (org.apache.ignite.internal.pagememory.mem.unsafe.UnsafeMemoryProvider)7 ArrayList (java.util.ArrayList)5 TimeUnit (java.util.concurrent.TimeUnit)5 TestPageIoRegistry (org.apache.ignite.internal.pagememory.TestPageIoRegistry)5 MiB (org.apache.ignite.internal.util.Constants.MiB)5 DataRegionConfiguration (org.apache.ignite.configuration.schemas.store.DataRegionConfiguration)4 PageMemoryDataRegionConfigurationSchema (org.apache.ignite.configuration.schemas.store.PageMemoryDataRegionConfigurationSchema)4 UnsafeMemoryAllocatorConfigurationSchema (org.apache.ignite.configuration.schemas.store.UnsafeMemoryAllocatorConfigurationSchema)4 ConfigurationExtension (org.apache.ignite.internal.configuration.testframework.ConfigurationExtension)4 InjectConfiguration (org.apache.ignite.internal.configuration.testframework.InjectConfiguration)4 IgniteInternalCheckedException (org.apache.ignite.lang.IgniteInternalCheckedException)4 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)4 ExtendWith (org.junit.jupiter.api.extension.ExtendWith)4