Search in sources :

Example 1 with DatabaseLayout

use of org.neo4j.io.layout.DatabaseLayout 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 DatabaseLayout

use of org.neo4j.io.layout.DatabaseLayout in project neo4j by neo4j.

the class StoreMigratorTest method shouldNotMigrateFilesForVersionsWithSameCapability.

@Test
void shouldNotMigrateFilesForVersionsWithSameCapability() throws Exception {
    // Prepare migrator and file
    RecordStorageMigrator migrator = newStoreMigrator();
    DatabaseLayout dbLayout = databaseLayout;
    Path neoStore = dbLayout.metadataStore();
    Files.createFile(neoStore);
    // Monitor what happens
    MyProgressReporter progressReporter = new MyProgressReporter();
    // Migrate with two storeversions that have the same FORMAT capabilities
    DatabaseLayout migrationLayout = neo4jLayout.databaseLayout("migrationDir");
    fileSystem.mkdirs(migrationLayout.databaseDirectory());
    migrator.migrate(dbLayout, migrationLayout, progressReporter, StandardV4_0.STORE_VERSION, StandardV4_0.STORE_VERSION, IndexImporterFactory.EMPTY);
    // Should not have started any migration
    assertFalse(progressReporter.started);
}
Also used : Path(java.nio.file.Path) DatabaseLayout(org.neo4j.io.layout.DatabaseLayout) Test(org.junit.jupiter.api.Test)

Example 3 with DatabaseLayout

use of org.neo4j.io.layout.DatabaseLayout in project neo4j by neo4j.

the class StoreUpgraderTest method failToMoveTransactionLogsIfTheyAlreadyExist.

@ParameterizedTest
@MethodSource("versions")
void failToMoveTransactionLogsIfTheyAlreadyExist(RecordFormats formats) throws IOException {
    init(formats);
    Path txRoot = testDirectory.directory("customTxRoot");
    AssertableLogProvider logProvider = new AssertableLogProvider();
    StoreVersionCheck check = getVersionCheck(pageCache);
    Config config = Config.newBuilder().fromConfig(allowMigrateConfig).set(neo4j_home, testDirectory.homePath()).set(GraphDatabaseSettings.transaction_logs_root_path, txRoot.toAbsolutePath()).set(default_database, databaseLayout.getDatabaseName()).build();
    DatabaseLayout migrationLayout = DatabaseLayout.of(config);
    Path databaseTransactionLogsHome = txRoot.resolve(migrationLayout.getDatabaseName());
    fileSystem.mkdir(databaseTransactionLogsHome);
    createDummyTxLogFiles(databaseTransactionLogsHome);
    assertThrows(StoreUpgrader.TransactionLogsRelocationException.class, () -> newUpgrader(check, pageCache, config, new VisibleMigrationProgressMonitor(logProvider.getLog("test"))).migrateIfNeeded(migrationLayout, false));
}
Also used : Path(java.nio.file.Path) StoreVersionCheck(org.neo4j.storageengine.api.StoreVersionCheck) Config(org.neo4j.configuration.Config) DatabaseLayout(org.neo4j.io.layout.DatabaseLayout) AssertableLogProvider(org.neo4j.logging.AssertableLogProvider) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 4 with DatabaseLayout

use of org.neo4j.io.layout.DatabaseLayout in project neo4j by neo4j.

the class StoreUpgraderTest method upgradeMoveTransactionLogs.

@ParameterizedTest
@MethodSource("versions")
void upgradeMoveTransactionLogs(RecordFormats formats) throws IOException {
    init(formats);
    Path txRoot = testDirectory.directory("customTxRoot");
    AssertableLogProvider logProvider = new AssertableLogProvider();
    StoreVersionCheck check = getVersionCheck(pageCache);
    Config config = Config.newBuilder().fromConfig(allowMigrateConfig).set(neo4j_home, testDirectory.homePath()).set(GraphDatabaseSettings.transaction_logs_root_path, txRoot.toAbsolutePath()).set(default_database, databaseLayout.getDatabaseName()).build();
    DatabaseLayout migrationLayout = DatabaseLayout.of(config);
    newUpgrader(check, pageCache, config, new VisibleMigrationProgressMonitor(logProvider.getLog("test"))).migrateIfNeeded(migrationLayout, false);
    assertThat(logProvider).containsMessages("Starting transaction logs migration.", "Transaction logs migration completed.");
    assertThat(getLogFiles(migrationLayout.databaseDirectory())).isEmpty();
    Path databaseTransactionLogsHome = txRoot.resolve(migrationLayout.getDatabaseName());
    assertTrue(fileSystem.fileExists(databaseTransactionLogsHome));
    Set<String> logFileNames = getLogFileNames(databaseTransactionLogsHome);
    assertThat(logFileNames).isNotEmpty();
    assertThat(logFileNames).containsAll(getLogFileNames(prepareDatabaseDirectory));
}
Also used : Path(java.nio.file.Path) StoreVersionCheck(org.neo4j.storageengine.api.StoreVersionCheck) Config(org.neo4j.configuration.Config) DatabaseLayout(org.neo4j.io.layout.DatabaseLayout) AssertableLogProvider(org.neo4j.logging.AssertableLogProvider) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 5 with DatabaseLayout

use of org.neo4j.io.layout.DatabaseLayout in project neo4j by neo4j.

the class LogsUpgrader method assertCleanlyShutDown.

public void assertCleanlyShutDown(DatabaseLayout layout) {
    Throwable suppressibleException = null;
    try {
        // we should not use provided database layout here since transaction log location is different compare to previous versions
        // and that's why we need to use custom transaction logs locator and database layout
        DatabaseLayout oldDatabaseLayout = buildLegacyLogsLayout(layout);
        LogFiles logFiles = buildLogFiles(oldDatabaseLayout);
        LogTailInformation tail = logFiles.getTailInformation();
        if (!tail.isRecoveryRequired()) {
            // All good
            return;
        }
        if (tail.logsMissing()) {
            // There are no log files in the legacy logs location.
            // Either log files are missing entirely, or they are already in their correct place.
            logFiles = buildLogFiles(layout);
            tail = logFiles.getTailInformation();
            if (!tail.isRecoveryRequired()) {
                // Log file is already in its new location, and looks good.
                return;
            }
            if (tail.logsMissing() && !config.get(fail_on_missing_files)) {
                // We don't have any log files, but we were told to ignore this.
                return;
            }
        }
    } catch (Throwable throwable) {
        // ignore exception and throw db not cleanly shutdown
        suppressibleException = throwable;
    }
    StoreUpgrader.DatabaseNotCleanlyShutDownException exception = new StoreUpgrader.DatabaseNotCleanlyShutDownException();
    if (suppressibleException != null) {
        exception.addSuppressed(suppressibleException);
    }
    throw exception;
}
Also used : LogTailInformation(org.neo4j.kernel.impl.transaction.log.files.LogTailInformation) DatabaseLayout(org.neo4j.io.layout.DatabaseLayout) LogFiles(org.neo4j.kernel.impl.transaction.log.files.LogFiles)

Aggregations

DatabaseLayout (org.neo4j.io.layout.DatabaseLayout)108 Test (org.junit.jupiter.api.Test)66 Path (java.nio.file.Path)51 Config (org.neo4j.configuration.Config)35 FileSystemAbstraction (org.neo4j.io.fs.FileSystemAbstraction)24 GraphDatabaseAPI (org.neo4j.kernel.internal.GraphDatabaseAPI)19 DefaultFileSystemAbstraction (org.neo4j.io.fs.DefaultFileSystemAbstraction)17 PageCache (org.neo4j.io.pagecache.PageCache)17 IOException (java.io.IOException)16 ConsistencyCheckService (org.neo4j.consistency.ConsistencyCheckService)16 Transaction (org.neo4j.graphdb.Transaction)13 DefaultIdGeneratorFactory (org.neo4j.internal.id.DefaultIdGeneratorFactory)10 DatabaseManagementService (org.neo4j.dbms.api.DatabaseManagementService)9 TestDatabaseManagementServiceBuilder (org.neo4j.test.TestDatabaseManagementServiceBuilder)9 CommandFailedException (org.neo4j.cli.CommandFailedException)8 ExecutionContext (org.neo4j.cli.ExecutionContext)8 PageCacheTracer (org.neo4j.io.pagecache.tracing.PageCacheTracer)8 StorageEngineFactory (org.neo4j.storageengine.api.StorageEngineFactory)8 Closeable (java.io.Closeable)7 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)7