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