Search in sources :

Example 1 with SingleFilePageSwapperFactory

use of org.neo4j.io.pagecache.impl.SingleFilePageSwapperFactory in project neo4j by neo4j.

the class StandalonePageCacheFactory method createPageCache.

public static PageCache createPageCache(FileSystemAbstraction fileSystem, Integer pageSize, PageCacheTracer tracer, PageCursorTracerSupplier cursorTracerSupplier) {
    SingleFilePageSwapperFactory factory = new SingleFilePageSwapperFactory();
    factory.setFileSystemAbstraction(fileSystem);
    int cachePageSize = pageSize != null ? pageSize : factory.getCachePageSizeHint();
    long pageCacheMemory = ByteUnit.mebiBytes(8);
    long pageCount = pageCacheMemory / cachePageSize;
    return new MuninnPageCache(factory, (int) pageCount, cachePageSize, tracer, cursorTracerSupplier);
}
Also used : SingleFilePageSwapperFactory(org.neo4j.io.pagecache.impl.SingleFilePageSwapperFactory)

Example 2 with SingleFilePageSwapperFactory

use of org.neo4j.io.pagecache.impl.SingleFilePageSwapperFactory in project neo4j by neo4j.

the class PageCacheTestSupport method createPageCache.

protected T createPageCache(FileSystemAbstraction fs, int maxPages, int pageSize, PageCacheTracer tracer, PageCursorTracerSupplier cursorTracerSupplier) {
    PageSwapperFactory swapperFactory = new SingleFilePageSwapperFactory();
    swapperFactory.setFileSystemAbstraction(fs);
    return createPageCache(swapperFactory, maxPages, pageSize, tracer, cursorTracerSupplier);
}
Also used : SingleFilePageSwapperFactory(org.neo4j.io.pagecache.impl.SingleFilePageSwapperFactory) SingleFilePageSwapperFactory(org.neo4j.io.pagecache.impl.SingleFilePageSwapperFactory)

Example 3 with SingleFilePageSwapperFactory

use of org.neo4j.io.pagecache.impl.SingleFilePageSwapperFactory in project neo4j by neo4j.

the class PageCacheTest method mustClosePageSwapperFactoryOnPageCacheClose.

@Test
public void mustClosePageSwapperFactoryOnPageCacheClose() throws Exception {
    AtomicBoolean closed = new AtomicBoolean();
    PageSwapperFactory swapperFactory = new SingleFilePageSwapperFactory() {

        @Override
        public void close() {
            closed.set(true);
        }
    };
    PageCache cache = createPageCache(swapperFactory, maxPages, pageCachePageSize, PageCacheTracer.NULL, PageCursorTracerSupplier.NULL);
    Exception exception = null;
    try {
        assertFalse(closed.get());
    } catch (Exception e) {
        exception = e;
    } finally {
        try {
            cache.close();
            assertTrue(closed.get());
        } catch (Exception e) {
            if (exception == null) {
                exception = e;
            } else {
                exception.addSuppressed(e);
            }
        }
        if (exception != null) {
            throw exception;
        }
    }
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) SingleFilePageSwapperFactory(org.neo4j.io.pagecache.impl.SingleFilePageSwapperFactory) SingleFilePageSwapperFactory(org.neo4j.io.pagecache.impl.SingleFilePageSwapperFactory) FileIsMappedException(org.neo4j.io.pagecache.impl.FileIsMappedException) NoSuchFileException(java.nio.file.NoSuchFileException) ClosedChannelException(java.nio.channels.ClosedChannelException) IOException(java.io.IOException) FileAlreadyExistsException(java.nio.file.FileAlreadyExistsException) Test(org.junit.Test)

Example 4 with SingleFilePageSwapperFactory

use of org.neo4j.io.pagecache.impl.SingleFilePageSwapperFactory in project neo4j by neo4j.

the class PageCacheTest method closingOfPageCacheMustBeConsideredSuccessfulEvenIfPageSwapperFactoryCloseThrows.

@Test
public void closingOfPageCacheMustBeConsideredSuccessfulEvenIfPageSwapperFactoryCloseThrows() throws Exception {
    AtomicInteger closed = new AtomicInteger();
    PageSwapperFactory swapperFactory = new SingleFilePageSwapperFactory() {

        @Override
        public void close() {
            closed.getAndIncrement();
            throw new RuntimeException("boo");
        }
    };
    PageCache cache = createPageCache(swapperFactory, maxPages, pageCachePageSize, PageCacheTracer.NULL, PageCursorTracerSupplier.NULL);
    try {
        cache.close();
        fail("Should have thrown");
    } catch (Exception e) {
        assertThat(e.getMessage(), is("boo"));
    }
    // We must still consider this a success, and not call PageSwapperFactory.close() again
    cache.close();
}
Also used : SingleFilePageSwapperFactory(org.neo4j.io.pagecache.impl.SingleFilePageSwapperFactory) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) SingleFilePageSwapperFactory(org.neo4j.io.pagecache.impl.SingleFilePageSwapperFactory) FileIsMappedException(org.neo4j.io.pagecache.impl.FileIsMappedException) NoSuchFileException(java.nio.file.NoSuchFileException) ClosedChannelException(java.nio.channels.ClosedChannelException) IOException(java.io.IOException) FileAlreadyExistsException(java.nio.file.FileAlreadyExistsException) Test(org.junit.Test)

Example 5 with SingleFilePageSwapperFactory

use of org.neo4j.io.pagecache.impl.SingleFilePageSwapperFactory in project neo4j by neo4j.

the class PageCacheTest method factoryCountingSyncDevice.

private PageSwapperFactory factoryCountingSyncDevice(final AtomicInteger syncDeviceCounter, final Queue<Integer> expectedCountsInForce) {
    SingleFilePageSwapperFactory factory = new SingleFilePageSwapperFactory() {

        @Override
        public void syncDevice() {
            super.syncDevice();
            syncDeviceCounter.getAndIncrement();
        }

        @Override
        public PageSwapper createPageSwapper(File file, int filePageSize, PageEvictionCallback onEviction, boolean createIfNotExist) throws IOException {
            PageSwapper delegate = super.createPageSwapper(file, filePageSize, onEviction, createIfNotExist);
            return new DelegatingPageSwapper(delegate) {

                @Override
                public void force() throws IOException {
                    super.force();
                    assertThat(syncDeviceCounter.get(), is(expectedCountsInForce.poll()));
                }
            };
        }
    };
    factory.setFileSystemAbstraction(fs);
    return factory;
}
Also used : SingleFilePageSwapperFactory(org.neo4j.io.pagecache.impl.SingleFilePageSwapperFactory) AdversarialPagedFile(org.neo4j.adversaries.pagecache.AdversarialPagedFile) File(java.io.File)

Aggregations

SingleFilePageSwapperFactory (org.neo4j.io.pagecache.impl.SingleFilePageSwapperFactory)8 PageSwapperFactory (org.neo4j.io.pagecache.PageSwapperFactory)3 File (java.io.File)2 IOException (java.io.IOException)2 ClosedChannelException (java.nio.channels.ClosedChannelException)2 FileAlreadyExistsException (java.nio.file.FileAlreadyExistsException)2 NoSuchFileException (java.nio.file.NoSuchFileException)2 Test (org.junit.Test)2 FileSystemAbstraction (org.neo4j.io.fs.FileSystemAbstraction)2 FileIsMappedException (org.neo4j.io.pagecache.impl.FileIsMappedException)2 MuninnPageCache (org.neo4j.io.pagecache.impl.muninn.MuninnPageCache)2 HashMap (java.util.HashMap)1 ExecutorService (java.util.concurrent.ExecutorService)1 Future (java.util.concurrent.Future)1 TimeoutException (java.util.concurrent.TimeoutException)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 RandomAdversary (org.neo4j.adversaries.RandomAdversary)1 AdversarialFileSystemAbstraction (org.neo4j.adversaries.fs.AdversarialFileSystemAbstraction)1 AdversarialPagedFile (org.neo4j.adversaries.pagecache.AdversarialPagedFile)1