Search in sources :

Example 1 with CorruptedLogsTruncator

use of org.neo4j.kernel.recovery.CorruptedLogsTruncator in project neo4j by neo4j.

the class PhysicalLogicalTransactionStoreTest method shouldOpenAndRecoverExistingData.

@Test
void shouldOpenAndRecoverExistingData() throws Exception {
    // GIVEN
    TransactionIdStore transactionIdStore = new SimpleTransactionIdStore();
    TransactionMetadataCache positionCache = new TransactionMetadataCache();
    final byte[] additionalHeader = new byte[] { 1, 2, 5 };
    final long timeStarted = 12345;
    long latestCommittedTxWhenStarted = 4545;
    long timeCommitted = timeStarted + 10;
    LifeSupport life = new LifeSupport();
    final LogFiles logFiles = buildLogFiles(transactionIdStore);
    life.start();
    life.add(logFiles);
    try {
        addATransactionAndRewind(life, logFiles, positionCache, transactionIdStore, additionalHeader, timeStarted, latestCommittedTxWhenStarted, timeCommitted);
    } finally {
        life.shutdown();
    }
    life = new LifeSupport();
    life.add(logFiles);
    final AtomicBoolean recoveryPerformed = new AtomicBoolean();
    FakeRecoveryVisitor visitor = new FakeRecoveryVisitor(additionalHeader, timeStarted, timeCommitted, latestCommittedTxWhenStarted);
    LogicalTransactionStore txStore = new PhysicalLogicalTransactionStore(logFiles, positionCache, logEntryReader(), monitors, true);
    life.add(new BatchingTransactionAppender(logFiles, NO_ROTATION, positionCache, transactionIdStore, DATABASE_HEALTH));
    CorruptedLogsTruncator logPruner = new CorruptedLogsTruncator(databaseDirectory, logFiles, fileSystem, INSTANCE);
    life.add(new TransactionLogsRecovery(new TestRecoveryService(visitor, logFiles, txStore, recoveryPerformed), logPruner, new LifecycleAdapter(), mock(RecoveryMonitor.class), ProgressReporter.SILENT, false, EMPTY_CHECKER, PageCacheTracer.NULL));
    // WHEN
    try {
        life.start();
    } finally {
        life.shutdown();
    }
    // THEN
    assertEquals(1, visitor.getVisitedTransactions());
    assertTrue(recoveryPerformed.get());
}
Also used : TransactionIdStore(org.neo4j.storageengine.api.TransactionIdStore) SimpleTransactionIdStore(org.neo4j.kernel.impl.transaction.SimpleTransactionIdStore) CorruptedLogsTruncator(org.neo4j.kernel.recovery.CorruptedLogsTruncator) SimpleTransactionIdStore(org.neo4j.kernel.impl.transaction.SimpleTransactionIdStore) LogFiles(org.neo4j.kernel.impl.transaction.log.files.LogFiles) LifecycleAdapter(org.neo4j.kernel.lifecycle.LifecycleAdapter) TransactionLogsRecovery(org.neo4j.kernel.recovery.TransactionLogsRecovery) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) LifeSupport(org.neo4j.kernel.lifecycle.LifeSupport) Test(org.junit.jupiter.api.Test)

Aggregations

AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 Test (org.junit.jupiter.api.Test)1 SimpleTransactionIdStore (org.neo4j.kernel.impl.transaction.SimpleTransactionIdStore)1 LogFiles (org.neo4j.kernel.impl.transaction.log.files.LogFiles)1 LifeSupport (org.neo4j.kernel.lifecycle.LifeSupport)1 LifecycleAdapter (org.neo4j.kernel.lifecycle.LifecycleAdapter)1 CorruptedLogsTruncator (org.neo4j.kernel.recovery.CorruptedLogsTruncator)1 TransactionLogsRecovery (org.neo4j.kernel.recovery.TransactionLogsRecovery)1 TransactionIdStore (org.neo4j.storageengine.api.TransactionIdStore)1