Search in sources :

Example 21 with SimpleTransactionIdStore

use of org.neo4j.kernel.impl.transaction.SimpleTransactionIdStore in project neo4j by neo4j.

the class PhysicalLogicalTransactionStoreTest method shouldExtractMetadataFromExistingTransaction.

@Test
void shouldExtractMetadataFromExistingTransaction() 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 LogicalTransactionStore store = new PhysicalLogicalTransactionStore(logFiles, positionCache, logEntryReader(), monitors, true);
    // WHEN
    life.start();
    try {
        verifyTransaction(positionCache, additionalHeader, timeStarted, latestCommittedTxWhenStarted, timeCommitted, store);
    } finally {
        life.shutdown();
    }
}
Also used : TransactionIdStore(org.neo4j.storageengine.api.TransactionIdStore) SimpleTransactionIdStore(org.neo4j.kernel.impl.transaction.SimpleTransactionIdStore) SimpleTransactionIdStore(org.neo4j.kernel.impl.transaction.SimpleTransactionIdStore) LogFiles(org.neo4j.kernel.impl.transaction.log.files.LogFiles) LifeSupport(org.neo4j.kernel.lifecycle.LifeSupport) Test(org.junit.jupiter.api.Test)

Example 22 with SimpleTransactionIdStore

use of org.neo4j.kernel.impl.transaction.SimpleTransactionIdStore in project neo4j by neo4j.

the class PhysicalLogicalTransactionStoreTest method extractTransactionFromLogFilesSkippingLastLogFileWithoutHeader.

@Test
void extractTransactionFromLogFilesSkippingLastLogFileWithoutHeader() throws IOException {
    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.add(logFiles);
    life.start();
    try {
        addATransactionAndRewind(life, logFiles, positionCache, transactionIdStore, additionalHeader, timeStarted, latestCommittedTxWhenStarted, timeCommitted);
    } finally {
        life.shutdown();
    }
    // create empty transaction log file and clear transaction cache to force re-read
    LogFile logFile = logFiles.getLogFile();
    fileSystem.write(logFile.getLogFileForVersion(logFile.getHighestLogVersion() + 1)).close();
    positionCache.clear();
    final LogicalTransactionStore store = new PhysicalLogicalTransactionStore(logFiles, positionCache, logEntryReader(), monitors, true);
    verifyTransaction(positionCache, additionalHeader, timeStarted, latestCommittedTxWhenStarted, timeCommitted, store);
}
Also used : LogFile(org.neo4j.kernel.impl.transaction.log.files.LogFile) TransactionIdStore(org.neo4j.storageengine.api.TransactionIdStore) SimpleTransactionIdStore(org.neo4j.kernel.impl.transaction.SimpleTransactionIdStore) SimpleTransactionIdStore(org.neo4j.kernel.impl.transaction.SimpleTransactionIdStore) LogFiles(org.neo4j.kernel.impl.transaction.log.files.LogFiles) LifeSupport(org.neo4j.kernel.lifecycle.LifeSupport) Test(org.junit.jupiter.api.Test)

Example 23 with SimpleTransactionIdStore

use of org.neo4j.kernel.impl.transaction.SimpleTransactionIdStore 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

SimpleTransactionIdStore (org.neo4j.kernel.impl.transaction.SimpleTransactionIdStore)23 Test (org.junit.jupiter.api.Test)17 SimpleLogVersionRepository (org.neo4j.kernel.impl.transaction.SimpleLogVersionRepository)17 LogFiles (org.neo4j.kernel.impl.transaction.log.files.LogFiles)14 Lifespan (org.neo4j.kernel.lifecycle.Lifespan)7 TransactionIdStore (org.neo4j.storageengine.api.TransactionIdStore)6 LogFile (org.neo4j.kernel.impl.transaction.log.files.LogFile)5 LogPosition (org.neo4j.kernel.impl.transaction.log.LogPosition)4 LifeSupport (org.neo4j.kernel.lifecycle.LifeSupport)4 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)3 BeforeEach (org.junit.jupiter.api.BeforeEach)3 LogVersionRepository (org.neo4j.storageengine.api.LogVersionRepository)3 ArrayList (java.util.ArrayList)2 Config (org.neo4j.configuration.Config)2 TestCommandReaderFactory (org.neo4j.kernel.impl.api.TestCommandReaderFactory)2 TransactionLogWriter (org.neo4j.kernel.impl.transaction.log.TransactionLogWriter)2 VersionAwareLogEntryReader (org.neo4j.kernel.impl.transaction.log.entry.VersionAwareLogEntryReader)2 DatabaseHealth (org.neo4j.monitoring.DatabaseHealth)2 IOException (java.io.IOException)1 Path (java.nio.file.Path)1