Search in sources :

Example 1 with DetachedCheckpointAppender

use of org.neo4j.kernel.impl.transaction.log.checkpoint.DetachedCheckpointAppender 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 2 with DetachedCheckpointAppender

use of org.neo4j.kernel.impl.transaction.log.checkpoint.DetachedCheckpointAppender in project neo4j by neo4j.

the class RecoveryCorruptedTransactionLogIT method restoreCheckpointLogVersionFromFileVersion.

@Test
void restoreCheckpointLogVersionFromFileVersion() throws IOException {
    DatabaseManagementService managementService = databaseFactory.build();
    GraphDatabaseAPI database = (GraphDatabaseAPI) managementService.database(DEFAULT_DATABASE_NAME);
    logFiles = buildDefaultLogFiles(getStoreId(database));
    generateTransaction(database);
    managementService.shutdown();
    int rotations = 10;
    try (Lifespan lifespan = new Lifespan(logFiles)) {
        CheckpointFile checkpointFile = logFiles.getCheckpointFile();
        DetachedCheckpointAppender checkpointAppender = (DetachedCheckpointAppender) checkpointFile.getCheckpointAppender();
        for (int i = 0; i < rotations; i++) {
            checkpointAppender.checkPoint(LogCheckPointEvent.NULL, new LogPosition(0, HEADER_OFFSET), Instant.now(), "test" + i);
            checkpointAppender.rotate();
        }
    }
    for (int i = rotations - 1; i > 0; i--) {
        var restartedDbms = databaseFactory.build();
        try {
            StorageEngine storageEngine = ((GraphDatabaseAPI) restartedDbms.database(DEFAULT_DATABASE_NAME)).getDependencyResolver().resolveDependency(StorageEngine.class);
            assertEquals(i, storageEngine.metadataProvider().getCheckpointLogVersion());
        } finally {
            restartedDbms.shutdown();
        }
        // we remove 3 checkpoints: 1 from shutdown and 1 from recovery and one that we created in a loop before
        removeLastCheckpointRecordFromLastLogFile();
        removeLastCheckpointRecordFromLastLogFile();
        removeLastCheckpointRecordFromLastLogFile();
    }
}
Also used : GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) DetachedCheckpointAppender(org.neo4j.kernel.impl.transaction.log.checkpoint.DetachedCheckpointAppender) StorageEngine(org.neo4j.storageengine.api.StorageEngine) DatabaseManagementService(org.neo4j.dbms.api.DatabaseManagementService) Lifespan(org.neo4j.kernel.lifecycle.Lifespan) CheckpointFile(org.neo4j.kernel.impl.transaction.log.files.checkpoint.CheckpointFile) LogPosition(org.neo4j.kernel.impl.transaction.log.LogPosition) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

Test (org.junit.jupiter.api.Test)2 LogPosition (org.neo4j.kernel.impl.transaction.log.LogPosition)2 DetachedCheckpointAppender (org.neo4j.kernel.impl.transaction.log.checkpoint.DetachedCheckpointAppender)2 GraphDatabaseAPI (org.neo4j.kernel.internal.GraphDatabaseAPI)2 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1 DatabaseManagementService (org.neo4j.dbms.api.DatabaseManagementService)1 DatabaseLayout (org.neo4j.io.layout.DatabaseLayout)1 LogFiles (org.neo4j.kernel.impl.transaction.log.files.LogFiles)1 CheckpointFile (org.neo4j.kernel.impl.transaction.log.files.checkpoint.CheckpointFile)1 Lifespan (org.neo4j.kernel.lifecycle.Lifespan)1 StorageEngine (org.neo4j.storageengine.api.StorageEngine)1