Search in sources :

Example 1 with StorageEngineFactory

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());
}
Also used : Path(java.nio.file.Path) SimpleLogService(org.neo4j.logging.internal.SimpleLogService) Config(org.neo4j.configuration.Config) StorageEngineFactory(org.neo4j.storageengine.api.StorageEngineFactory) LogFiles(org.neo4j.kernel.impl.transaction.log.files.LogFiles) TestDatabaseManagementServiceBuilder(org.neo4j.test.TestDatabaseManagementServiceBuilder) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) Transaction(org.neo4j.graphdb.Transaction) DatabaseLayout(org.neo4j.io.layout.DatabaseLayout) DatabaseManagementService(org.neo4j.dbms.api.DatabaseManagementService) NullLogService(org.neo4j.logging.internal.NullLogService) SimpleLogService(org.neo4j.logging.internal.SimpleLogService) LogService(org.neo4j.logging.internal.LogService) LogPosition(org.neo4j.kernel.impl.transaction.log.LogPosition)

Example 2 with StorageEngineFactory

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;
}
Also used : DatabaseHealth(org.neo4j.monitoring.DatabaseHealth) StorageEngineFactory(org.neo4j.storageengine.api.StorageEngineFactory) Monitors(org.neo4j.monitoring.Monitors) NullLogService(org.neo4j.logging.internal.NullLogService) BatchImporterFactory(org.neo4j.internal.batchimport.BatchImporterFactory) Dependencies(org.neo4j.collection.Dependencies) SchemaIndexMigrator(org.neo4j.storageengine.migration.SchemaIndexMigrator)

Example 3 with StorageEngineFactory

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");
}
Also used : Path(java.nio.file.Path) TestDatabaseManagementServiceBuilder(org.neo4j.test.TestDatabaseManagementServiceBuilder) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) Transaction(org.neo4j.graphdb.Transaction) StorageEngineFactory(org.neo4j.storageengine.api.StorageEngineFactory) Node(org.neo4j.graphdb.Node) AssertableLogProvider(org.neo4j.logging.AssertableLogProvider) Test(org.junit.jupiter.api.Test)

Example 4 with StorageEngineFactory

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);
    }
}
Also used : StorageEngineFactory(org.neo4j.storageengine.api.StorageEngineFactory) CursorContext(org.neo4j.io.pagecache.context.CursorContext)

Example 5 with StorageEngineFactory

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);
    }
}
Also used : JobScheduler(org.neo4j.scheduler.JobScheduler) StorageEngineFactory(org.neo4j.storageengine.api.StorageEngineFactory) DatabasePageCache(org.neo4j.dbms.database.DatabasePageCache) PageCache(org.neo4j.io.pagecache.PageCache)

Aggregations

StorageEngineFactory (org.neo4j.storageengine.api.StorageEngineFactory)24 Test (org.junit.jupiter.api.Test)9 Path (java.nio.file.Path)7 DatabaseLayout (org.neo4j.io.layout.DatabaseLayout)7 DatabaseManagementService (org.neo4j.dbms.api.DatabaseManagementService)5 AssertableLogProvider (org.neo4j.logging.AssertableLogProvider)5 TestDatabaseManagementServiceBuilder (org.neo4j.test.TestDatabaseManagementServiceBuilder)4 Dependencies (org.neo4j.collection.Dependencies)3 Config (org.neo4j.configuration.Config)3 FileSystemAbstraction (org.neo4j.io.fs.FileSystemAbstraction)3 CursorContext (org.neo4j.io.pagecache.context.CursorContext)3 GraphDatabaseAPI (org.neo4j.kernel.internal.GraphDatabaseAPI)3 StoreVersion (org.neo4j.storageengine.api.StoreVersion)3 SchemaIndexMigrator (org.neo4j.storageengine.migration.SchemaIndexMigrator)3 ArrayList (java.util.ArrayList)2 Transaction (org.neo4j.graphdb.Transaction)2 IndexProviderDescriptor (org.neo4j.internal.schema.IndexProviderDescriptor)2 Neo4jLayout (org.neo4j.io.layout.Neo4jLayout)2 PageCache (org.neo4j.io.pagecache.PageCache)2 IndexDirectoryStructure (org.neo4j.kernel.api.index.IndexDirectoryStructure)2