Search in sources :

Example 31 with DatabaseLayout

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

the class RecoveryIT method recoverySetsCheckpointLogVersionFieldSeveralCheckpointFiles.

@Test
void recoverySetsCheckpointLogVersionFieldSeveralCheckpointFiles() throws Exception {
    GraphDatabaseAPI db = createDatabase();
    generateSomeData(db);
    var checkpointFile = db.getDependencyResolver().resolveDependency(LogFiles.class).getCheckpointFile();
    var appender = (DetachedCheckpointAppender) checkpointFile.getCheckpointAppender();
    appender.rotate();
    appender.checkPoint(LogCheckPointEvent.NULL, new LogPosition(0, BASE_TX_LOG_BYTE_OFFSET), Instant.now(), "test1");
    appender.rotate();
    appender.checkPoint(LogCheckPointEvent.NULL, new LogPosition(0, BASE_TX_LOG_BYTE_OFFSET), Instant.now(), "test2");
    appender.rotate();
    appender.checkPoint(LogCheckPointEvent.NULL, new LogPosition(0, BASE_TX_LOG_BYTE_OFFSET), Instant.now(), "test3");
    DatabaseLayout layout = db.databaseLayout();
    managementService.shutdown();
    removeFileWithCheckpoint();
    assertTrue(isRecoveryRequired(layout));
    MetaDataStore.setRecord(pageCache, layout.metadataStore(), CHECKPOINT_LOG_VERSION, -5, layout.getDatabaseName(), NULL);
    recoverDatabase();
    assertFalse(isRecoveryRequired(layout));
    assertEquals(2, MetaDataStore.getRecord(pageCache, layout.metadataStore(), CHECKPOINT_LOG_VERSION, layout.getDatabaseName(), NULL));
}
Also used : GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) DetachedCheckpointAppender(org.neo4j.kernel.impl.transaction.log.checkpoint.DetachedCheckpointAppender) LogFiles(org.neo4j.kernel.impl.transaction.log.files.LogFiles) DatabaseLayout(org.neo4j.io.layout.DatabaseLayout) LogPosition(org.neo4j.kernel.impl.transaction.log.LogPosition) Test(org.junit.jupiter.api.Test)

Example 32 with DatabaseLayout

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

the class RecoveryIT method keepCheckpointVersionOnMissingLogFilesWhenValueIsReasonable.

@Test
void keepCheckpointVersionOnMissingLogFilesWhenValueIsReasonable() throws Exception {
    GraphDatabaseAPI db = createDatabase();
    generateSomeData(db);
    DatabaseLayout layout = db.databaseLayout();
    managementService.shutdown();
    removeTransactionLogs();
    assertTrue(isRecoveryRequired(layout));
    MetaDataStore.setRecord(pageCache, layout.metadataStore(), CHECKPOINT_LOG_VERSION, 18, layout.getDatabaseName(), NULL);
    recoverDatabase();
    assertFalse(isRecoveryRequired(layout));
    assertEquals(18, MetaDataStore.getRecord(pageCache, layout.metadataStore(), CHECKPOINT_LOG_VERSION, layout.getDatabaseName(), NULL));
}
Also used : GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) DatabaseLayout(org.neo4j.io.layout.DatabaseLayout) Test(org.junit.jupiter.api.Test)

Example 33 with DatabaseLayout

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

the class RecoveryIT method failToStartDatabaseWithTransactionLogsInLegacyLocation.

@Test
void failToStartDatabaseWithTransactionLogsInLegacyLocation() throws Exception {
    GraphDatabaseAPI database = createDatabase();
    generateSomeData(database);
    managementService.shutdown();
    LogFiles logFiles = buildLogFiles();
    Path[] txLogFiles = fileSystem.listFiles(logFiles.logFilesDirectory(), path -> path.getFileName().toString().startsWith(DEFAULT_NAME));
    txLogFiles = ArrayUtil.concat(txLogFiles, logFiles.getCheckpointFile().getDetachedCheckpointFiles());
    Path databasesDirectory = databaseLayout.getNeo4jLayout().databasesDirectory();
    DatabaseLayout legacyLayout = Neo4jLayout.ofFlat(databasesDirectory).databaseLayout(databaseLayout.getDatabaseName());
    LegacyTransactionLogsLocator logsLocator = new LegacyTransactionLogsLocator(Config.defaults(), legacyLayout);
    Path transactionLogsDirectory = logsLocator.getTransactionLogsDirectory();
    assertNotNull(txLogFiles);
    assertTrue(txLogFiles.length > 0);
    for (Path logFile : txLogFiles) {
        fileSystem.moveToDirectory(logFile, transactionLogsDirectory);
    }
    AssertableLogProvider logProvider = new AssertableLogProvider();
    builder.setInternalLogProvider(logProvider);
    GraphDatabaseAPI restartedDb = createDatabase();
    try {
        DatabaseStateService dbStateService = restartedDb.getDependencyResolver().resolveDependency(DatabaseStateService.class);
        var failure = dbStateService.causeOfFailure(restartedDb.databaseId());
        assertTrue(failure.isPresent());
        assertThat(failure.get()).hasRootCauseMessage("Transaction logs are missing and recovery is not possible.");
        assertThat(logProvider.serialize()).contains(txLogFiles[0].getFileName().toString());
    } finally {
        managementService.shutdown();
    }
}
Also used : Path(java.nio.file.Path) LegacyTransactionLogsLocator(org.neo4j.kernel.impl.storemigration.LegacyTransactionLogsLocator) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) LogFiles(org.neo4j.kernel.impl.transaction.log.files.LogFiles) DatabaseLayout(org.neo4j.io.layout.DatabaseLayout) DatabaseStateService(org.neo4j.dbms.DatabaseStateService) AssertableLogProvider(org.neo4j.logging.AssertableLogProvider) Test(org.junit.jupiter.api.Test)

Example 34 with DatabaseLayout

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

the class RecoveryWithTokenIndexesIT method recoverDatabaseWithTokenIndexes.

@ParameterizedTest(name = "{0}")
@MethodSource("arguments")
void recoverDatabaseWithTokenIndexes(String name, boolean checkpointIndexes) throws Throwable {
    config = Config.newBuilder().set(neo4j_home, testDirectory.homePath()).build();
    EphemeralFileSystemAbstraction fs = new EphemeralFileSystemAbstraction();
    GraphDatabaseService db = startDatabase(fs);
    IndexingTestUtil.assertOnlyDefaultTokenIndexesExists(db);
    if (checkpointIndexes) {
        // Checkpoint to not make index creation part of the recovery.
        checkPoint(db);
    }
    int numberOfEntities = 10;
    for (int i = 0; i < numberOfEntities; i++) {
        createEntities(db);
    }
    // Don't flush/checkpoint before taking the snapshot, to make the indexes need to recover (clean crash generation)
    EphemeralFileSystemAbstraction crashedFs = fs.snapshot();
    managementService.shutdown();
    fs.close();
    try (PageCache cache = pageCacheExtension.getPageCache(crashedFs)) {
        DatabaseLayout layout = DatabaseLayout.of(config);
        recoverDatabase(layout, crashedFs, cache);
    }
    db = startDatabase(crashedFs);
    // Verify that the default token indexes still exist
    IndexingTestUtil.assertOnlyDefaultTokenIndexesExists(db);
    awaitIndexesOnline(db);
    try (Transaction tx = db.beginTx()) {
        assertEquals(numberOfEntities, tx.findNodes(label).stream().count());
        assertEquals(numberOfEntities, tx.findRelationships(type).stream().count());
    }
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) Transaction(org.neo4j.graphdb.Transaction) EphemeralFileSystemAbstraction(org.neo4j.io.fs.EphemeralFileSystemAbstraction) DatabaseLayout(org.neo4j.io.layout.DatabaseLayout) PageCache(org.neo4j.io.pagecache.PageCache) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 35 with DatabaseLayout

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

the class RecoveryWithTokenIndexesIT method recoverDatabaseWithInjectedTokenIndex.

@Test
void recoverDatabaseWithInjectedTokenIndex() throws Throwable {
    // Starting an existing database on 4.3 or newer binaries should make the old label scan store
    // into a token index - but there is no schema rule for it in store until after upgrade transaction has been run
    // (there is just an injected indexRule in the cache).
    // This tests that recovery on a database with the injected version of the NLI keeps it through recovery.
    config = Config.newBuilder().set(allow_single_automatic_upgrade, false).set(allow_upgrade, true).build();
    // Database with 10 nodes with label 'label' and 10 relationships with type 'type'.
    int numberOfEntities = 10;
    GraphDatabaseService database = createDatabaseOfOlderVersion("4-2-data-10-nodes-rels.zip");
    DatabaseLayout layout = ((GraphDatabaseAPI) database).databaseLayout();
    verifyInjectedNLIExistAndOnline(database);
    managementService.shutdown();
    // Remove check point from shutdown, store upgrade, and shutdown done when creating the 4.2 store.
    RecoveryHelpers.removeLastCheckpointRecordFromLastLogFile(layout, fileSystem);
    RecoveryHelpers.removeLastCheckpointRecordFromLastLogFile(layout, fileSystem);
    RecoveryHelpers.removeLastCheckpointRecordFromLastLogFile(layout, fileSystem);
    try (PageCache pageCache = pageCacheExtension.getPageCache(fileSystem)) {
        recoverDatabaseOfOlderVersion(layout, pageCache);
    }
    GraphDatabaseService recoveredDatabase = startDatabaseOfOlderVersion();
    // Verify that the injected NLI still exist
    verifyInjectedNLIExistAndOnline(recoveredDatabase);
    try (Transaction tx = recoveredDatabase.beginTx()) {
        assertEquals(numberOfEntities, tx.findNodes(label).stream().count());
        assertEquals(numberOfEntities, tx.findRelationships(type).stream().count());
    }
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) Transaction(org.neo4j.graphdb.Transaction) DatabaseLayout(org.neo4j.io.layout.DatabaseLayout) PageCache(org.neo4j.io.pagecache.PageCache) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

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