use of org.neo4j.io.pagecache.PageCache in project neo4j by neo4j.
the class PageCacheStressTest method run.
public void run() throws Exception {
try (FileSystemAbstraction fs = new DefaultFileSystemAbstraction()) {
PageSwapperFactory swapperFactory = new SingleFilePageSwapperFactory();
swapperFactory.setFileSystemAbstraction(fs);
try (PageCache pageCacheUnderTest = new MuninnPageCache(swapperFactory, numberOfCachePages, cachePageSize, tracer, pageCursorTracerSupplier)) {
PageCacheStresser pageCacheStresser = new PageCacheStresser(numberOfPages, numberOfThreads, workingDirectory);
pageCacheStresser.stress(pageCacheUnderTest, condition);
}
}
}
use of org.neo4j.io.pagecache.PageCache in project neo4j by neo4j.
the class StoreMigrator method migrateWithBatchImporter.
private void migrateWithBatchImporter(File storeDir, File migrationDir, long lastTxId, long lastTxChecksum, long lastTxLogVersion, long lastTxLogByteOffset, MigrationProgressMonitor.Section progressMonitor, RecordFormats oldFormat, RecordFormats newFormat) throws IOException {
prepareBatchImportMigration(storeDir, migrationDir, oldFormat, newFormat);
boolean requiresDynamicStoreMigration = !newFormat.dynamic().equals(oldFormat.dynamic());
boolean requiresPropertyMigration = !newFormat.property().equals(oldFormat.property()) || requiresDynamicStoreMigration;
File badFile = new File(storeDir, Configuration.BAD_FILE_NAME);
try (NeoStores legacyStore = instantiateLegacyStore(oldFormat, storeDir);
RecordCursors nodeInputCursors = new RecordCursors(legacyStore);
RecordCursors relationshipInputCursors = new RecordCursors(legacyStore);
OutputStream badOutput = new BufferedOutputStream(new FileOutputStream(badFile, false))) {
Configuration importConfig = new Configuration.Overridden(config);
AdditionalInitialIds additionalInitialIds = readAdditionalIds(lastTxId, lastTxChecksum, lastTxLogVersion, lastTxLogByteOffset);
// We have to make sure to keep the token ids if we're migrating properties/labels
BatchImporter importer = new ParallelBatchImporter(migrationDir.getAbsoluteFile(), fileSystem, pageCache, importConfig, logService, withDynamicProcessorAssignment(migrationBatchImporterMonitor(legacyStore, progressMonitor, importConfig), importConfig), additionalInitialIds, config, newFormat);
InputIterable<InputNode> nodes = legacyNodesAsInput(legacyStore, requiresPropertyMigration, nodeInputCursors);
InputIterable<InputRelationship> relationships = legacyRelationshipsAsInput(legacyStore, requiresPropertyMigration, relationshipInputCursors);
importer.doImport(Inputs.input(nodes, relationships, IdMappers.actual(), IdGenerators.fromInput(), Collectors.badCollector(badOutput, 0)));
// During migration the batch importer doesn't necessarily writes all entities, depending on
// which stores needs migration. Node, relationship, relationship group stores are always written
// anyways and cannot be avoided with the importer, but delete the store files that weren't written
// (left empty) so that we don't overwrite those in the real store directory later.
Collection<StoreFile> storesToDeleteFromMigratedDirectory = new ArrayList<>();
storesToDeleteFromMigratedDirectory.add(StoreFile.NEO_STORE);
if (!requiresPropertyMigration) {
// We didn't migrate properties, so the property stores in the migrated store are just empty/bogus
storesToDeleteFromMigratedDirectory.addAll(asList(StoreFile.PROPERTY_STORE, StoreFile.PROPERTY_STRING_STORE, StoreFile.PROPERTY_ARRAY_STORE));
}
if (!requiresDynamicStoreMigration) {
// We didn't migrate labels (dynamic node labels) or any other dynamic store
storesToDeleteFromMigratedDirectory.addAll(asList(StoreFile.NODE_LABEL_STORE, StoreFile.LABEL_TOKEN_STORE, StoreFile.LABEL_TOKEN_NAMES_STORE, StoreFile.RELATIONSHIP_TYPE_TOKEN_STORE, StoreFile.RELATIONSHIP_TYPE_TOKEN_NAMES_STORE, StoreFile.PROPERTY_KEY_TOKEN_STORE, StoreFile.PROPERTY_KEY_TOKEN_NAMES_STORE, StoreFile.SCHEMA_STORE));
}
StoreFile.fileOperation(DELETE, fileSystem, migrationDir, null, storesToDeleteFromMigratedDirectory, true, null, StoreFileType.values());
// When migrating on a block device there might be some files only accessible via the page cache.
try {
Predicate<FileHandle> fileHandlePredicate = fileHandle -> storesToDeleteFromMigratedDirectory.stream().anyMatch(storeFile -> storeFile.fileName(StoreFileType.STORE).equals(fileHandle.getFile().getName()));
pageCache.streamFilesRecursive(migrationDir).filter(fileHandlePredicate).forEach(FileHandle.HANDLE_DELETE);
} catch (NoSuchFileException e) {
// This means that we had no files only present in the page cache, this is fine.
}
}
}
use of org.neo4j.io.pagecache.PageCache in project neo4j by neo4j.
the class NeoStoreDataSourceTest method flushOfThePageCacheOnShutdownDoesNotHappenIfTheDbIsUnhealthy.
@Test
public void flushOfThePageCacheOnShutdownDoesNotHappenIfTheDbIsUnhealthy() throws IOException {
DatabaseHealth health = mock(DatabaseHealth.class);
when(health.isHealthy()).thenReturn(false);
PageCache pageCache = spy(pageCacheRule.getPageCache(fs.get()));
NeoStoreDataSource ds = dsRule.getDataSource(dir.graphDbDir(), fs.get(), pageCache, stringMap(), health);
ds.init();
ds.start();
verify(pageCache, never()).flushAndForce();
ds.stop();
ds.shutdown();
verify(pageCache, never()).flushAndForce(IOLimiter.unlimited());
}
use of org.neo4j.io.pagecache.PageCache in project neo4j by neo4j.
the class NeoStoreDataSourceTest method logModuleSetUpError.
@Test
public void logModuleSetUpError() throws Exception {
Config config = Config.embeddedDefaults(stringMap());
IdGeneratorFactory idGeneratorFactory = mock(IdGeneratorFactory.class);
Throwable openStoresError = new RuntimeException("Can't set up modules");
doThrow(openStoresError).when(idGeneratorFactory).create(any(File.class), anyLong(), anyBoolean());
CommunityIdTypeConfigurationProvider idTypeConfigurationProvider = new CommunityIdTypeConfigurationProvider();
AssertableLogProvider logProvider = new AssertableLogProvider();
SimpleLogService logService = new SimpleLogService(logProvider, logProvider);
PageCache pageCache = pageCacheRule.getPageCache(fs.get());
NeoStoreDataSource dataSource = dsRule.getDataSource(dir.graphDbDir(), fs.get(), idGeneratorFactory, idTypeConfigurationProvider, pageCache, config, mock(DatabaseHealth.class), logService);
try {
dataSource.start();
fail("Exception expected");
} catch (Exception e) {
assertEquals(openStoresError, e);
}
logProvider.assertAtLeastOnce(inLog(NeoStoreDataSource.class).warn(equalTo("Exception occurred while setting up store modules. Attempting to close things down."), equalTo(openStoresError)));
}
use of org.neo4j.io.pagecache.PageCache in project neo4j by neo4j.
the class NeoStoreDataSourceTest method flushOfThePageCacheHappensOnlyOnceDuringShutdown.
@Test
public void flushOfThePageCacheHappensOnlyOnceDuringShutdown() throws IOException {
PageCache pageCache = spy(pageCacheRule.getPageCache(fs.get()));
NeoStoreDataSource ds = dsRule.getDataSource(dir.graphDbDir(), fs.get(), pageCache, stringMap());
ds.init();
ds.start();
verify(pageCache, never()).flushAndForce();
verify(pageCache, never()).flushAndForce(any(IOLimiter.class));
ds.stop();
ds.shutdown();
verify(pageCache).flushAndForce(IOLimiter.unlimited());
}
Aggregations