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);
}
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);
}
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;
}
}
}
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();
}
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;
}
Aggregations