Search in sources :

Example 21 with LogPositionMarker

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

the class TransactionLogsRecoveryTest method shouldTruncateLogAfterSinglePartialTransaction.

@Test
void shouldTruncateLogAfterSinglePartialTransaction() throws Exception {
    // GIVEN
    Path file = logFiles.getLogFile().getLogFileForVersion(logVersion);
    final LogPositionMarker marker = new LogPositionMarker();
    writeSomeData(file, pair -> {
        LogEntryWriter writer = pair.first();
        Consumer<LogPositionMarker> consumer = pair.other();
        // incomplete tx
        // <-- marker has the last good position
        consumer.accept(marker);
        writer.writeStartEntry(5L, 4L, 0, new byte[0]);
        return true;
    });
    // WHEN
    boolean recoveryRequired = recover(storeDir, logFiles);
    // THEN
    assertTrue(recoveryRequired);
    assertEquals(marker.getByteOffset(), Files.size(file));
}
Also used : Path(java.nio.file.Path) LogEntryWriter(org.neo4j.kernel.impl.transaction.log.entry.LogEntryWriter) LogPositionMarker(org.neo4j.kernel.impl.transaction.log.LogPositionMarker) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 22 with LogPositionMarker

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

the class TransactionLogsRecoveryTest method shouldTellTransactionIdStoreAfterSuccessfulRecovery.

@Test
void shouldTellTransactionIdStoreAfterSuccessfulRecovery() throws Exception {
    // GIVEN
    Path file = logFiles.getLogFile().getLogFileForVersion(logVersion);
    final LogPositionMarker marker = new LogPositionMarker();
    final byte[] additionalHeaderData = new byte[0];
    final long transactionId = 4;
    final long commitTimestamp = 5;
    writeSomeData(file, pair -> {
        LogEntryWriter writer = pair.first();
        Consumer<LogPositionMarker> consumer = pair.other();
        // last committed tx
        writer.writeStartEntry(2L, 3L, BASE_TX_CHECKSUM, additionalHeaderData);
        writer.writeCommitEntry(transactionId, commitTimestamp);
        consumer.accept(marker);
        return true;
    });
    // WHEN
    boolean recoveryRequired = recover(storeDir, logFiles);
    // THEN
    assertTrue(recoveryRequired);
    long[] lastClosedTransaction = transactionIdStore.getLastClosedTransaction();
    assertEquals(transactionId, lastClosedTransaction[0]);
    assertEquals(commitTimestamp, transactionIdStore.getLastCommittedTransaction().commitTimestamp());
    assertEquals(logVersion, lastClosedTransaction[1]);
    assertEquals(marker.getByteOffset(), lastClosedTransaction[2]);
}
Also used : Path(java.nio.file.Path) LogEntryWriter(org.neo4j.kernel.impl.transaction.log.entry.LogEntryWriter) LogPositionMarker(org.neo4j.kernel.impl.transaction.log.LogPositionMarker) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

LogPositionMarker (org.neo4j.kernel.impl.transaction.log.LogPositionMarker)22 LogEntryWriter (org.neo4j.kernel.impl.transaction.log.entry.LogEntryWriter)16 Test (org.junit.jupiter.api.Test)12 LogPosition (org.neo4j.kernel.impl.transaction.log.LogPosition)12 IOException (java.io.IOException)10 Path (java.nio.file.Path)9 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)9 File (java.io.File)7 Consumer (java.util.function.Consumer)7 Test (org.junit.Test)7 PhysicalLogFile (org.neo4j.kernel.impl.transaction.log.PhysicalLogFile)7 PhysicalLogFiles (org.neo4j.kernel.impl.transaction.log.PhysicalLogFiles)7 LifeSupport (org.neo4j.kernel.lifecycle.LifeSupport)7 Pair (org.neo4j.helpers.collection.Pair)6 LogFile (org.neo4j.kernel.impl.transaction.log.LogFile)6 LogicalTransactionStore (org.neo4j.kernel.impl.transaction.log.LogicalTransactionStore)6 PhysicalLogicalTransactionStore (org.neo4j.kernel.impl.transaction.log.PhysicalLogicalTransactionStore)6 TransactionMetadataCache (org.neo4j.kernel.impl.transaction.log.TransactionMetadataCache)6 StorageEngine (org.neo4j.storageengine.api.StorageEngine)6 CommittedTransactionRepresentation (org.neo4j.kernel.impl.transaction.CommittedTransactionRepresentation)5