use of org.neo4j.storageengine.api.StorageEngineFactory in project neo4j by neo4j.
the class StoreMigratorTest method extractTransactionalInformationFromLogs.
private void extractTransactionalInformationFromLogs(Path customLogsLocation) throws IOException {
Config config = Config.defaults(transaction_logs_root_path, customLogsLocation);
LogService logService = new SimpleLogService(NullLogProvider.getInstance(), NullLogProvider.getInstance());
DatabaseManagementService managementService = new TestDatabaseManagementServiceBuilder(databaseLayout).setConfig(transaction_logs_root_path, customLogsLocation).build();
GraphDatabaseAPI database = (GraphDatabaseAPI) managementService.database(DEFAULT_DATABASE_NAME);
StorageEngineFactory storageEngineFactory = database.getDependencyResolver().resolveDependency(StorageEngineFactory.class);
for (int i = 0; i < 10; i++) {
try (Transaction transaction = database.beginTx()) {
transaction.createNode();
transaction.commit();
}
}
DatabaseLayout databaseLayout = database.databaseLayout();
Path neoStore = databaseLayout.metadataStore();
managementService.shutdown();
MetaDataStore.setRecord(pageCache, neoStore, MetaDataStore.Position.LAST_CLOSED_TRANSACTION_LOG_VERSION, MetaDataRecordFormat.FIELD_NOT_PRESENT, databaseLayout.getDatabaseName(), NULL);
RecordStorageMigrator migrator = new RecordStorageMigrator(fileSystem, pageCache, config, logService, jobScheduler, PageCacheTracer.NULL, batchImporterFactory, INSTANCE);
LogPosition logPosition = migrator.extractTransactionLogPosition(neoStore, databaseLayout, 100, NULL);
LogFiles logFiles = LogFilesBuilder.activeFilesBuilder(databaseLayout, fileSystem, pageCache).withConfig(config).withCommandReaderFactory(storageEngineFactory.commandReaderFactory()).build();
assertEquals(0, logPosition.getLogVersion());
assertEquals(Files.size(logFiles.getLogFile().getHighestLogFile()), logPosition.getByteOffset());
}
use of org.neo4j.storageengine.api.StorageEngineFactory in project neo4j by neo4j.
the class StoreUpgraderTest method newUpgrader.
private StoreUpgrader newUpgrader(StoreVersionCheck storeVersionCheck, PageCache pageCache, Config config, MigrationProgressMonitor progressMonitor, PageCacheTracer pageCacheTracer, boolean forceUpgrade) {
NullLogService instance = NullLogService.getInstance();
BatchImporterFactory batchImporterFactory = BatchImporterFactory.withHighestPriority();
RecordStorageMigrator defaultMigrator = new RecordStorageMigrator(fileSystem, pageCache, getTuningConfig(), instance, jobScheduler, pageCacheTracer, batchImporterFactory, INSTANCE);
StorageEngineFactory storageEngineFactory = StorageEngineFactory.defaultStorageEngine();
SchemaIndexMigrator indexMigrator = new SchemaIndexMigrator("Indexes", fileSystem, pageCache, IndexProvider.EMPTY.directoryStructure(), storageEngineFactory, true);
LegacyTransactionLogsLocator logsLocator = new LegacyTransactionLogsLocator(config, databaseLayout);
DatabaseHealth databaseHealth = new DatabaseHealth(NO_OP, NullLog.getInstance());
Dependencies dependencies = new Dependencies();
dependencies.satisfyDependencies(new Monitors());
LogsUpgrader logsUpgrader = new LogsUpgrader(fileSystem, storageEngineFactory, databaseLayout, pageCache, logsLocator, config, dependencies, pageCacheTracer, INSTANCE, databaseHealth, forceUpgrade);
StoreUpgrader upgrader = new StoreUpgrader(storeVersionCheck, progressMonitor, config, fileSystem, NullLogProvider.getInstance(), logsUpgrader, pageCacheTracer);
upgrader.addParticipant(indexMigrator);
upgrader.addParticipant(NOT_PARTICIPATING);
upgrader.addParticipant(NOT_PARTICIPATING);
upgrader.addParticipant(NOT_PARTICIPATING);
upgrader.addParticipant(NOT_PARTICIPATING);
upgrader.addParticipant(defaultMigrator);
return upgrader;
}
use of org.neo4j.storageengine.api.StorageEngineFactory in project neo4j by neo4j.
the class RecoveryLogIT method transactionsRecoveryLogContainsTimeSpent.
@Test
void transactionsRecoveryLogContainsTimeSpent() throws IOException {
// Create database with forced recovery
Path tmpLogDir = testDirectory.directory("logs");
managementService = new TestDatabaseManagementServiceBuilder(testDirectory.homePath()).build();
GraphDatabaseAPI db = (GraphDatabaseAPI) managementService.database(DEFAULT_DATABASE_NAME);
StorageEngineFactory storageEngineFactory = db.getDependencyResolver().resolveDependency(StorageEngineFactory.class);
try (Transaction tx = db.beginTx()) {
Node node1 = tx.createNode();
Node node2 = tx.createNode();
node1.createRelationshipTo(node2, RelationshipType.withName("likes"));
tx.commit();
}
Path[] txLogs = LogFilesBuilder.logFilesBasedOnlyBuilder(databaseLayout.getTransactionLogsDirectory(), fileSystem).withCommandReaderFactory(storageEngineFactory.commandReaderFactory()).build().logFiles();
for (Path file : txLogs) {
fileSystem.copyToDirectory(file, tmpLogDir);
}
managementService.shutdown();
for (Path txLog : fileSystem.listFiles(databaseLayout.getTransactionLogsDirectory())) {
fileSystem.deleteFile(txLog);
}
for (Path file : LogFilesBuilder.logFilesBasedOnlyBuilder(tmpLogDir, fileSystem).withCommandReaderFactory(storageEngineFactory.commandReaderFactory()).build().logFiles()) {
fileSystem.moveToDirectory(file, databaseLayout.getTransactionLogsDirectory());
}
AssertableLogProvider provider = new AssertableLogProvider();
managementService = new TestDatabaseManagementServiceBuilder(testDirectory.homePath()).setInternalLogProvider(provider).build();
managementService.database(DEFAULT_DATABASE_NAME);
assertThat(provider).containsMessages("Recovery completed", "time spent");
}
use of org.neo4j.storageengine.api.StorageEngineFactory in project neo4j by neo4j.
the class LogFilesBuilder method readOnlyLogVersionRepository.
private LogVersionRepository readOnlyLogVersionRepository() throws IOException {
StorageEngineFactory storageEngineFactory = StorageEngineFactory.defaultStorageEngine();
var pageCacheTracer = databaseTracers.getPageCacheTracer();
try (var cursorContext = new CursorContext(pageCacheTracer.createPageCursorTracer(READ_ONLY_LOG_VERSION_READER_TAG))) {
return storageEngineFactory.readOnlyLogVersionRepository(databaseLayout, pageCache, cursorContext);
}
}
use of org.neo4j.storageengine.api.StorageEngineFactory in project neo4j by neo4j.
the class Recovery method isRecoveryRequired.
/**
* Check if recovery is required for a store described by provided layout.
* Custom root location for transaction logs can be provided using {@link GraphDatabaseSettings#transaction_logs_root_path} config setting value.
*
* @param fs database filesystem
* @param databaseLayout layout of database to check for recovery
* @param config custom configuration
* @return true if recovery is required, false otherwise.
* @throws IOException on any unexpected I/O exception encountered during recovery.
*/
public static boolean isRecoveryRequired(FileSystemAbstraction fs, DatabaseLayout databaseLayout, Config config, MemoryTracker memoryTracker) throws Exception {
requireNonNull(databaseLayout);
requireNonNull(config);
requireNonNull(fs);
try (JobScheduler jobScheduler = JobSchedulerFactory.createInitialisedScheduler();
PageCache pageCache = getPageCache(config, fs, jobScheduler)) {
StorageEngineFactory storageEngineFactory = StorageEngineFactory.defaultStorageEngine();
return isRecoveryRequired(fs, pageCache, databaseLayout, storageEngineFactory, config, Optional.empty(), memoryTracker);
}
}
Aggregations