use of org.neo4j.io.pagecache.PageCache in project neo4j by neo4j.
the class ConfiguringPageCacheFactoryTest method shouldFitAsManyPagesAsItCan.
@Test
public void shouldFitAsManyPagesAsItCan() throws Throwable {
// Given
final int pageSize = 8192;
final int maxPages = 60;
Config config = Config.embeddedDefaults(stringMap(pagecache_memory.name(), Integer.toString(pageSize * maxPages)));
// When
ConfiguringPageCacheFactory factory = new ConfiguringPageCacheFactory(fsRule.get(), config, PageCacheTracer.NULL, PageCursorTracerSupplier.NULL, NullLog.getInstance());
// Then
try (PageCache cache = factory.getOrCreatePageCache()) {
assertThat(cache.pageSize(), equalTo(pageSize));
assertThat(cache.maxCachedPages(), equalTo(maxPages));
}
}
use of org.neo4j.io.pagecache.PageCache 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.PageCache in project neo4j by neo4j.
the class BatchInserterImplTest method testHonorsPassedInParams.
@Test
public void testHonorsPassedInParams() throws Exception {
BatchInserter inserter = BatchInserters.inserter(testDirectory.graphDbDir(), fileSystemRule.get(), stringMap(GraphDatabaseSettings.pagecache_memory.name(), "280K"));
NeoStores neoStores = ReflectionUtil.getPrivateField(inserter, "neoStores", NeoStores.class);
PageCache pageCache = ReflectionUtil.getPrivateField(neoStores, "pageCache", PageCache.class);
inserter.shutdown();
int mappedMemoryTotalSize = pageCache.maxCachedPages() * pageCache.pageSize();
assertThat("memory mapped config is active", mappedMemoryTotalSize, is(280 * 1024));
}
use of org.neo4j.io.pagecache.PageCache in project neo4j by neo4j.
the class StoreMigrator method moveMigratedFiles.
@Override
public void moveMigratedFiles(File migrationDir, File storeDir, String versionToUpgradeFrom, String versionToUpgradeTo) throws IOException {
// Move the migrated ones into the store directory
StoreFile.fileOperation(MOVE, fileSystem, migrationDir, storeDir, StoreFile.currentStoreFiles(), // allow to skip non existent source files
true, // allow to overwrite target files
ExistingTargetStrategy.OVERWRITE, StoreFileType.values());
// move the files with the page cache.
try {
Iterable<FileHandle> fileHandles = pageCache.streamFilesRecursive(migrationDir)::iterator;
for (FileHandle fh : fileHandles) {
Predicate<StoreFile> predicate = storeFile -> storeFile.fileName(StoreFileType.STORE).equals(fh.getFile().getName());
if (StreamSupport.stream(StoreFile.currentStoreFiles().spliterator(), false).anyMatch(predicate)) {
final Optional<PagedFile> optionalPagedFile = pageCache.getExistingMapping(fh.getFile());
if (optionalPagedFile.isPresent()) {
optionalPagedFile.get().close();
}
fh.rename(new File(storeDir, fh.getFile().getName()), StandardCopyOption.REPLACE_EXISTING);
}
}
} catch (NoSuchFileException e) {
//This means that we had no files only present in the page cache, this is fine.
}
RecordFormats oldFormat = selectForVersion(versionToUpgradeFrom);
RecordFormats newFormat = selectForVersion(versionToUpgradeTo);
boolean movingAwayFromVersionTrailers = oldFormat.hasCapability(VERSION_TRAILERS) && !newFormat.hasCapability(VERSION_TRAILERS);
if (movingAwayFromVersionTrailers) {
StoreFile.removeTrailers(versionToUpgradeFrom, fileSystem, storeDir, pageCache.pageSize());
}
File neoStore = new File(storeDir, MetaDataStore.DEFAULT_NAME);
long logVersion = MetaDataStore.getRecord(pageCache, neoStore, Position.LOG_VERSION);
long lastCommittedTx = MetaDataStore.getRecord(pageCache, neoStore, Position.LAST_TRANSACTION_ID);
// update or add upgrade id and time and other necessary neostore records
updateOrAddNeoStoreFieldsAsPartOfMigration(migrationDir, storeDir, versionToUpgradeTo);
// delete old logs
legacyLogs.deleteUnusedLogFiles(storeDir);
if (movingAwayFromVersionTrailers) {
// write a check point in the log in order to make recovery work in the newer version
new StoreMigratorCheckPointer(storeDir, fileSystem).checkPoint(logVersion, lastCommittedTx);
}
}
use of org.neo4j.io.pagecache.PageCache in project neo4j by neo4j.
the class RecordFormatsMigrationIT method assertStoreFormat.
private void assertStoreFormat(RecordFormats expected) throws IOException {
Config config = Config.embeddedDefaults(stringMap(GraphDatabaseSettings.pagecache_memory.name(), "8m"));
try (PageCache pageCache = ConfigurableStandalonePageCacheFactory.createPageCache(fileSystemRule.get(), config)) {
RecordFormats actual = RecordFormatSelector.selectForStoreOrConfig(config, testDirectory.graphDbDir(), fileSystemRule.get(), pageCache, NullLogProvider.getInstance());
assertNotNull(actual);
assertEquals(expected.storeVersion(), actual.storeVersion());
}
}
Aggregations