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