Search in sources :

Example 1 with PageSwapperFactory

use of org.neo4j.io.pagecache.PageSwapperFactory in project neo4j by neo4j.

the class ConfigurablePageCacheRule method createPageCache.

private PageCache createPageCache(FileSystemAbstraction fs, PageCacheConfig pageCacheConfig, Config config) {
    PageCacheTracer tracer = selectConfig(baseConfig.tracer, pageCacheConfig.tracer, PageCacheTracer.NULL);
    PageCursorTracerSupplier cursorTracerSupplier = selectConfig(baseConfig.pageCursorTracerSupplier, pageCacheConfig.pageCursorTracerSupplier, DefaultPageCursorTracerSupplier.INSTANCE);
    Config finalConfig = config.withDefaults(MapUtil.stringMap(GraphDatabaseSettings.pagecache_memory.name(), "8M"));
    FormattedLogProvider logProvider = FormattedLogProvider.toOutputStream(System.err);
    ConfiguringPageCacheFactory pageCacheFactory = new ConfiguringPageCacheFactory(fs, finalConfig, tracer, cursorTracerSupplier, logProvider.getLog(PageCache.class)) {

        @Override
        public int calculatePageSize(Config config, PageSwapperFactory swapperFactory) {
            if (pageCacheConfig.pageSize != null) {
                return pageCacheConfig.pageSize;
            }
            return super.calculatePageSize(config, swapperFactory);
        }
    };
    return pageCacheFactory.getOrCreatePageCache();
}
Also used : PageSwapperFactory(org.neo4j.io.pagecache.PageSwapperFactory) PageCursorTracerSupplier(org.neo4j.io.pagecache.tracing.cursor.PageCursorTracerSupplier) DefaultPageCursorTracerSupplier(org.neo4j.io.pagecache.tracing.cursor.DefaultPageCursorTracerSupplier) Config(org.neo4j.kernel.configuration.Config) PageCacheTracer(org.neo4j.io.pagecache.tracing.PageCacheTracer) ConfiguringPageCacheFactory(org.neo4j.kernel.impl.pagecache.ConfiguringPageCacheFactory) PageCache(org.neo4j.io.pagecache.PageCache) FormattedLogProvider(org.neo4j.logging.FormattedLogProvider)

Example 2 with PageSwapperFactory

use of org.neo4j.io.pagecache.PageSwapperFactory in project neo4j by neo4j.

the class SingleFilePageSwapperTest method reportExternalIoOnSwapOut.

@Test
void reportExternalIoOnSwapOut() throws IOException {
    createEmptyFile();
    PageSwapperFactory factory = createSwapperFactory(getFs());
    CountingIOController controller = new CountingIOController();
    try (var swapper = createSwapper(factory, getPath(), 4, null, false, false, true, controller)) {
        long target = createPage(4);
        int numberOfWrites = 42;
        for (int i = 0; i < numberOfWrites; i++) {
            assertEquals(4, swapper.write(0, target));
        }
        assertEquals(numberOfWrites, controller.getExternalIOCounter());
    }
}
Also used : PageSwapperFactory(org.neo4j.io.pagecache.PageSwapperFactory) PageSwapperTest(org.neo4j.io.pagecache.PageSwapperTest) Test(org.junit.jupiter.api.Test)

Example 3 with PageSwapperFactory

use of org.neo4j.io.pagecache.PageSwapperFactory in project neo4j by neo4j.

the class SingleFilePageSwapperTest method mustHandleMischiefInPositionedRead.

@Test
void mustHandleMischiefInPositionedRead() throws Exception {
    int bytesTotal = 512;
    byte[] data = new byte[bytesTotal];
    ThreadLocalRandom.current().nextBytes(data);
    PageSwapperFactory factory = createSwapperFactory(getFs());
    Path file = getPath();
    PageSwapper swapper = createSwapper(factory, file, bytesTotal, NO_CALLBACK, true);
    try {
        long page = createPage(data);
        swapper.write(0, page);
    } finally {
        swapper.close();
    }
    RandomAdversary adversary = new RandomAdversary(0.5, 0.0, 0.0);
    factory = createSwapperFactory(new AdversarialFileSystemAbstraction(adversary, getFs()));
    swapper = createSwapper(factory, file, bytesTotal, NO_CALLBACK, false);
    long page = createPage(bytesTotal);
    try {
        for (int i = 0; i < 10_000; i++) {
            clear(page);
            assertThat(swapper.read(0, page)).isEqualTo(bytesTotal);
            assertThat(array(page)).isEqualTo(data);
        }
    } finally {
        swapper.close();
    }
}
Also used : Path(java.nio.file.Path) PageSwapperFactory(org.neo4j.io.pagecache.PageSwapperFactory) PageSwapper(org.neo4j.io.pagecache.PageSwapper) AdversarialFileSystemAbstraction(org.neo4j.adversaries.fs.AdversarialFileSystemAbstraction) RandomAdversary(org.neo4j.adversaries.RandomAdversary) PageSwapperTest(org.neo4j.io.pagecache.PageSwapperTest) Test(org.junit.jupiter.api.Test)

Example 4 with PageSwapperFactory

use of org.neo4j.io.pagecache.PageSwapperFactory in project neo4j by neo4j.

the class SingleFilePageSwapperTest method mustHandleMischiefInPositionedWrite.

@Test
void mustHandleMischiefInPositionedWrite() throws Exception {
    int bytesTotal = 512;
    byte[] data = new byte[bytesTotal];
    ThreadLocalRandom.current().nextBytes(data);
    long zeroPage = createPage(bytesTotal);
    clear(zeroPage);
    Path file = getPath();
    RandomAdversary adversary = new RandomAdversary(0.5, 0.0, 0.0);
    PageSwapperFactory factory = createSwapperFactory(new AdversarialFileSystemAbstraction(adversary, getFs()));
    PageSwapper swapper = createSwapper(factory, file, bytesTotal, NO_CALLBACK, true);
    long page = createPage(bytesTotal);
    try {
        for (int i = 0; i < 10_000; i++) {
            adversary.setProbabilityFactor(0);
            swapper.write(0, zeroPage);
            putBytes(page, data, 0, 0, data.length);
            adversary.setProbabilityFactor(1);
            assertThat(swapper.write(0, page)).isEqualTo(bytesTotal);
            clear(page);
            adversary.setProbabilityFactor(0);
            swapper.read(0, page);
            assertThat(array(page)).isEqualTo(data);
        }
    } finally {
        swapper.close();
    }
}
Also used : Path(java.nio.file.Path) PageSwapperFactory(org.neo4j.io.pagecache.PageSwapperFactory) PageSwapper(org.neo4j.io.pagecache.PageSwapper) AdversarialFileSystemAbstraction(org.neo4j.adversaries.fs.AdversarialFileSystemAbstraction) RandomAdversary(org.neo4j.adversaries.RandomAdversary) PageSwapperTest(org.neo4j.io.pagecache.PageSwapperTest) Test(org.junit.jupiter.api.Test)

Example 5 with PageSwapperFactory

use of org.neo4j.io.pagecache.PageSwapperFactory in project neo4j by neo4j.

the class SingleFilePageSwapperTest method fileMustRemainLockedEvenIfChannelIsClosedByStrayInterrupt.

@Test
@DisabledOnOs(OS.WINDOWS)
void fileMustRemainLockedEvenIfChannelIsClosedByStrayInterrupt() throws Exception {
    PageSwapperFactory factory = createSwapperFactory(fileSystem);
    Path file = testDir.file("file");
    ((StoreChannel) fileSystem.write(file)).close();
    PageSwapper pageSwapper = createSwapper(factory, file, 4, NO_CALLBACK, false);
    try {
        StoreChannel channel = fileSystem.write(file);
        Thread.currentThread().interrupt();
        pageSwapper.force();
        assertThrows(OverlappingFileLockException.class, channel::tryLock);
    } finally {
        pageSwapper.close();
    }
}
Also used : Path(java.nio.file.Path) PageSwapperFactory(org.neo4j.io.pagecache.PageSwapperFactory) StoreChannel(org.neo4j.io.fs.StoreChannel) DelegatingStoreChannel(org.neo4j.io.fs.DelegatingStoreChannel) PageSwapper(org.neo4j.io.pagecache.PageSwapper) DisabledOnOs(org.junit.jupiter.api.condition.DisabledOnOs) PageSwapperTest(org.neo4j.io.pagecache.PageSwapperTest) Test(org.junit.jupiter.api.Test)

Aggregations

PageSwapperFactory (org.neo4j.io.pagecache.PageSwapperFactory)27 Test (org.junit.jupiter.api.Test)23 PageSwapperTest (org.neo4j.io.pagecache.PageSwapperTest)22 DelegatingStoreChannel (org.neo4j.io.fs.DelegatingStoreChannel)13 StoreChannel (org.neo4j.io.fs.StoreChannel)13 PageSwapper (org.neo4j.io.pagecache.PageSwapper)12 Path (java.nio.file.Path)11 DisabledOnOs (org.junit.jupiter.api.condition.DisabledOnOs)6 RandomAdversary (org.neo4j.adversaries.RandomAdversary)5 AdversarialFileSystemAbstraction (org.neo4j.adversaries.fs.AdversarialFileSystemAbstraction)5 SingleFilePageSwapperFactory (org.neo4j.io.pagecache.impl.SingleFilePageSwapperFactory)4 InputStream (java.io.InputStream)3 FileLock (java.nio.channels.FileLock)3 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)3 IOException (java.io.IOException)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 FileSystemAbstraction (org.neo4j.io.fs.FileSystemAbstraction)2 StoreFileChannel (org.neo4j.io.fs.StoreFileChannel)2 PageCache (org.neo4j.io.pagecache.PageCache)2 PagedFile (org.neo4j.io.pagecache.PagedFile)2