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));
}
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();
}
}
Aggregations