Search in sources :

Example 11 with PageSwapperFactory

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

the class SingleFilePageSwapperTest method reportExternalIoOnSwapInWithMultipleBuffers.

@Test
void reportExternalIoOnSwapInWithMultipleBuffers() throws IOException {
    byte[] bytes = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 };
    try (StoreChannel channel = getFs().write(getPath())) {
        channel.writeAll(wrap(bytes));
    }
    PageSwapperFactory factory = createSwapperFactory(getFs());
    CountingIOController controller = new CountingIOController();
    try (var swapper = createSwapper(factory, getPath(), 4, null, false, false, true, controller)) {
        long target1 = createPage(4);
        long target2 = createPage(4);
        long target3 = createPage(4);
        int numberOfReads = 12;
        int buffers = 3;
        for (int i = 0; i < numberOfReads; i++) {
            assertEquals(12, swapper.read(0, new long[] { target1, target2, target3 }, new int[] { 4, 4, 4 }, buffers));
        }
        long expectedIO = getEphemeralFileSystem() == getFs() ? numberOfReads * buffers : numberOfReads;
        assertEquals(expectedIO, controller.getExternalIOCounter());
    }
}
Also used : PageSwapperFactory(org.neo4j.io.pagecache.PageSwapperFactory) StoreChannel(org.neo4j.io.fs.StoreChannel) DelegatingStoreChannel(org.neo4j.io.fs.DelegatingStoreChannel) PageSwapperTest(org.neo4j.io.pagecache.PageSwapperTest) Test(org.junit.jupiter.api.Test)

Example 12 with PageSwapperFactory

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

the class SingleFilePageSwapperTest method mustHandleMischiefInPositionedVectoredRead.

@Test
void mustHandleMischiefInPositionedVectoredRead() throws Exception {
    int bytesTotal = 512;
    int bytesPerPage = 32;
    int pageCount = bytesTotal / bytesPerPage;
    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, bytesPerPage, NO_CALLBACK, false);
    long[] pages = new long[pageCount];
    int[] pageLengths = new int[pageCount];
    for (int i = 0; i < pageCount; i++) {
        pages[i] = createPage(bytesPerPage);
        pageLengths[i] = bytesPerPage;
    }
    byte[] temp = new byte[bytesPerPage];
    try {
        for (int i = 0; i < 10_000; i++) {
            for (long page : pages) {
                clear(page);
            }
            assertThat(swapper.read(0, pages, pageLengths, pages.length)).isEqualTo(bytesTotal);
            for (int j = 0; j < pageCount; j++) {
                System.arraycopy(data, j * bytesPerPage, temp, 0, bytesPerPage);
                assertThat(array(pages[j])).isEqualTo(temp);
            }
        }
    } 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 13 with PageSwapperFactory

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

the class ConfiguringPageCacheFactory method createAndConfigureSwapperFactory.

private PageSwapperFactory createAndConfigureSwapperFactory(FileSystemAbstraction fs, Config config, Log log) {
    String desiredImplementation = config.get(pagecache_swapper);
    if (desiredImplementation != null) {
        for (PageSwapperFactory factory : Service.load(PageSwapperFactory.class)) {
            if (factory.implementationName().equals(desiredImplementation)) {
                factory.setFileSystemAbstraction(fs);
                if (factory instanceof ConfigurablePageSwapperFactory) {
                    ConfigurablePageSwapperFactory configurableFactory = (ConfigurablePageSwapperFactory) factory;
                    configurableFactory.configure(config);
                }
                log.info("Configured " + pagecache_swapper.name() + ": " + desiredImplementation);
                return factory;
            }
        }
        throw new IllegalArgumentException("Cannot find PageSwapperFactory: " + desiredImplementation);
    }
    SingleFilePageSwapperFactory factory = new SingleFilePageSwapperFactory();
    factory.setFileSystemAbstraction(fs);
    return factory;
}
Also used : PageSwapperFactory(org.neo4j.io.pagecache.PageSwapperFactory) SingleFilePageSwapperFactory(org.neo4j.io.pagecache.impl.SingleFilePageSwapperFactory) SingleFilePageSwapperFactory(org.neo4j.io.pagecache.impl.SingleFilePageSwapperFactory)

Example 14 with PageSwapperFactory

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

the class MuninnPageCacheTest method flushFileWithSeveralChunks.

@Test
void flushFileWithSeveralChunks() throws IOException {
    assumeFalse(DISABLED_BUFFER_FACTORY.equals(fixture.getBufferFactory()));
    var pageCacheTracer = new InfoTracer();
    int maxPages = 4096 + /* chunk size */
    10;
    PageSwapperFactory swapperFactory = new MultiChunkSwapperFilePageSwapperFactory();
    try (MuninnPageCache pageCache = createPageCache(swapperFactory, maxPages, pageCacheTracer);
        PagedFile pagedFile = map(pageCache, file("a"), (int) ByteUnit.kibiBytes(8))) {
        for (int pageId = 0; pageId < maxPages; pageId++) {
            try (PageCursor cursor = pagedFile.io(pageId, PF_SHARED_WRITE_LOCK, NULL)) {
                assertTrue(cursor.next());
                cursor.putLong(1);
            }
        }
        pagedFile.flushAndForce();
        var observedChunks = pageCacheTracer.getObservedChunks();
        assertThat(observedChunks).hasSize(2);
        var chunkInfo = observedChunks.get(0);
        assertThat(chunkInfo.getFlushPerChunk()).isGreaterThanOrEqualTo(4096 / pagecache_flush_buffer_size_in_pages.defaultValue());
        var chunkInfo2 = observedChunks.get(1);
        assertThat(chunkInfo2.getFlushPerChunk()).isEqualTo(1);
        observedChunks.clear();
    }
}
Also used : PageSwapperFactory(org.neo4j.io.pagecache.PageSwapperFactory) SingleFilePageSwapperFactory(org.neo4j.io.pagecache.impl.SingleFilePageSwapperFactory) PagedFile(org.neo4j.io.pagecache.PagedFile) PageCursor(org.neo4j.io.pagecache.PageCursor) PageCacheTest(org.neo4j.io.pagecache.PageCacheTest) Test(org.junit.jupiter.api.Test)

Example 15 with PageSwapperFactory

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

the class PageCacheStressTest method run.

public void run() throws Exception {
    try (FileSystemAbstraction fs = new DefaultFileSystemAbstraction();
        JobScheduler jobScheduler = new ThreadPoolJobScheduler()) {
        PageSwapperFactory swapperFactory = new SingleFilePageSwapperFactory(fs);
        try (PageCache pageCacheUnderTest = new MuninnPageCache(swapperFactory, jobScheduler, config(numberOfCachePages).pageCacheTracer(tracer))) {
            PageCacheStresser pageCacheStresser = new PageCacheStresser(numberOfPages, numberOfThreads, workingDirectory);
            pageCacheStresser.stress(pageCacheUnderTest, tracer, condition);
        }
    }
}
Also used : ThreadPoolJobScheduler(org.neo4j.test.scheduler.ThreadPoolJobScheduler) JobScheduler(org.neo4j.scheduler.JobScheduler) PageSwapperFactory(org.neo4j.io.pagecache.PageSwapperFactory) SingleFilePageSwapperFactory(org.neo4j.io.pagecache.impl.SingleFilePageSwapperFactory) DefaultFileSystemAbstraction(org.neo4j.io.fs.DefaultFileSystemAbstraction) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) DefaultFileSystemAbstraction(org.neo4j.io.fs.DefaultFileSystemAbstraction) MuninnPageCache(org.neo4j.io.pagecache.impl.muninn.MuninnPageCache) SingleFilePageSwapperFactory(org.neo4j.io.pagecache.impl.SingleFilePageSwapperFactory) ThreadPoolJobScheduler(org.neo4j.test.scheduler.ThreadPoolJobScheduler) PageCache(org.neo4j.io.pagecache.PageCache) MuninnPageCache(org.neo4j.io.pagecache.impl.muninn.MuninnPageCache)

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