Search in sources :

Example 41 with CommittedTransactionRepresentation

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

the class ReversedMultiFileTransactionCursorTest method shouldReadMultipleVersionsReversed.

@Test
void shouldReadMultipleVersionsReversed() throws Exception {
    // GIVEN
    TransactionCursor cursor = new ReversedMultiFileTransactionCursor(logFile, log(5, 3, 8), 2, start());
    // WHEN
    CommittedTransactionRepresentation[] reversed = exhaust(cursor);
    // THEN
    assertTransactionRange(reversed, 5 + 3 + 8, 0);
}
Also used : CommittedTransactionRepresentation(org.neo4j.kernel.impl.transaction.CommittedTransactionRepresentation) TransactionCursor(org.neo4j.kernel.impl.transaction.log.TransactionCursor) Test(org.junit.jupiter.api.Test)

Example 42 with CommittedTransactionRepresentation

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

the class ReversedMultiFileTransactionCursorTest method assertTransactionRange.

private static void assertTransactionRange(CommittedTransactionRepresentation[] reversed, long highTxId, long lowTxId) {
    long expectedTxId = highTxId;
    for (CommittedTransactionRepresentation transaction : reversed) {
        expectedTxId--;
        assertEquals(expectedTxId, transaction.getCommitEntry().getTxId());
    }
    assertEquals(lowTxId, expectedTxId);
}
Also used : CommittedTransactionRepresentation(org.neo4j.kernel.impl.transaction.CommittedTransactionRepresentation)

Example 43 with CommittedTransactionRepresentation

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

the class ReversedMultiFileTransactionCursorTest method transactions.

private static CommittedTransactionRepresentation[] transactions(int count, AtomicLong txId) {
    CommittedTransactionRepresentation[] result = new CommittedTransactionRepresentation[count];
    for (int i = 0; i < count; i++) {
        CommittedTransactionRepresentation transaction = result[i] = mock(CommittedTransactionRepresentation.class);
        LogEntryCommit commitEntry = mock(LogEntryCommit.class);
        when(commitEntry.getTxId()).thenReturn(txId.getAndIncrement());
        when(transaction.getCommitEntry()).thenReturn(commitEntry);
    }
    return result;
}
Also used : CommittedTransactionRepresentation(org.neo4j.kernel.impl.transaction.CommittedTransactionRepresentation) LogEntryCommit(org.neo4j.kernel.impl.transaction.log.entry.LogEntryCommit)

Example 44 with CommittedTransactionRepresentation

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

the class BatchingTransactionAppenderTest method shouldAppendCommittedTransactions.

@Test
void shouldAppendCommittedTransactions() throws Exception {
    // GIVEN
    when(logFile.getTransactionLogWriter()).thenReturn(new TransactionLogWriter(channel, new DbmsLogEntryWriterFactory(() -> LATEST)));
    long nextTxId = 15;
    when(transactionIdStore.nextCommittingTransactionId()).thenReturn(nextTxId);
    when(transactionIdStore.getLastCommittedTransaction()).thenReturn(new TransactionId(nextTxId, BASE_TX_CHECKSUM, BASE_TX_COMMIT_TIMESTAMP));
    TransactionAppender appender = life.add(new BatchingTransactionAppender(logFiles, NO_ROTATION, positionCache, transactionIdStore, databaseHealth));
    // WHEN
    final byte[] additionalHeader = new byte[] { 1, 2, 5 };
    final long timeStarted = 12345;
    long latestCommittedTxWhenStarted = nextTxId - 5;
    long timeCommitted = timeStarted + 10;
    PhysicalTransactionRepresentation transactionRepresentation = new PhysicalTransactionRepresentation(singleTestCommand());
    transactionRepresentation.setHeader(additionalHeader, timeStarted, latestCommittedTxWhenStarted, timeCommitted, -1, ANONYMOUS);
    LogEntryStart start = new LogEntryStart(0L, latestCommittedTxWhenStarted, 0, null, LogPosition.UNSPECIFIED);
    LogEntryCommit commit = new LogEntryCommit(nextTxId, 0L, BASE_TX_CHECKSUM);
    CommittedTransactionRepresentation transaction = new CommittedTransactionRepresentation(start, transactionRepresentation, commit);
    appender.append(new TransactionToApply(transactionRepresentation, transaction.getCommitEntry().getTxId(), NULL), logAppendEvent);
    // THEN
    LogEntryReader logEntryReader = logEntryReader();
    try (PhysicalTransactionCursor reader = new PhysicalTransactionCursor(channel, logEntryReader)) {
        reader.next();
        TransactionRepresentation result = reader.get().getTransactionRepresentation();
        assertArrayEquals(additionalHeader, result.additionalHeader());
        assertEquals(timeStarted, result.getTimeStarted());
        assertEquals(timeCommitted, result.getTimeCommitted());
        assertEquals(latestCommittedTxWhenStarted, result.getLatestCommittedTxWhenStarted());
    }
}
Also used : LogEntryStart(org.neo4j.kernel.impl.transaction.log.entry.LogEntryStart) TransactionToApply(org.neo4j.kernel.impl.api.TransactionToApply) CommittedTransactionRepresentation(org.neo4j.kernel.impl.transaction.CommittedTransactionRepresentation) CommittedTransactionRepresentation(org.neo4j.kernel.impl.transaction.CommittedTransactionRepresentation) TransactionRepresentation(org.neo4j.kernel.impl.transaction.TransactionRepresentation) LogEntryReader(org.neo4j.kernel.impl.transaction.log.entry.LogEntryReader) TransactionId(org.neo4j.storageengine.api.TransactionId) DbmsLogEntryWriterFactory(org.neo4j.kernel.database.DbmsLogEntryWriterFactory) LogEntryCommit(org.neo4j.kernel.impl.transaction.log.entry.LogEntryCommit) Test(org.junit.jupiter.api.Test)

Example 45 with CommittedTransactionRepresentation

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

the class PhysicalLogicalTransactionStoreTest method verifyTransaction.

private static void verifyTransaction(TransactionMetadataCache positionCache, byte[] additionalHeader, long timeStarted, long latestCommittedTxWhenStarted, long timeCommitted, LogicalTransactionStore store) throws IOException {
    try (TransactionCursor cursor = store.getTransactions(TransactionIdStore.BASE_TX_ID + 1)) {
        boolean hasNext = cursor.next();
        assertTrue(hasNext);
        CommittedTransactionRepresentation tx = cursor.get();
        TransactionRepresentation transaction = tx.getTransactionRepresentation();
        assertArrayEquals(additionalHeader, transaction.additionalHeader());
        assertEquals(timeStarted, transaction.getTimeStarted());
        assertEquals(timeCommitted, transaction.getTimeCommitted());
        assertEquals(latestCommittedTxWhenStarted, transaction.getLatestCommittedTxWhenStarted());
    }
    positionCache.clear();
}
Also used : CommittedTransactionRepresentation(org.neo4j.kernel.impl.transaction.CommittedTransactionRepresentation) CommittedTransactionRepresentation(org.neo4j.kernel.impl.transaction.CommittedTransactionRepresentation) TransactionRepresentation(org.neo4j.kernel.impl.transaction.TransactionRepresentation)

Aggregations

CommittedTransactionRepresentation (org.neo4j.kernel.impl.transaction.CommittedTransactionRepresentation)45 TransactionCursor (org.neo4j.kernel.impl.transaction.log.TransactionCursor)14 Test (org.junit.jupiter.api.Test)12 LogicalTransactionStore (org.neo4j.kernel.impl.transaction.log.LogicalTransactionStore)11 TransactionRepresentation (org.neo4j.kernel.impl.transaction.TransactionRepresentation)10 LogEntryCommit (org.neo4j.kernel.impl.transaction.log.entry.LogEntryCommit)10 IOException (java.io.IOException)8 LogPosition (org.neo4j.kernel.impl.transaction.log.LogPosition)8 LogEntryStart (org.neo4j.kernel.impl.transaction.log.entry.LogEntryStart)8 LifeSupport (org.neo4j.kernel.lifecycle.LifeSupport)6 StorageEngine (org.neo4j.storageengine.api.StorageEngine)6 TransactionToApply (org.neo4j.kernel.impl.api.TransactionToApply)5 VersionAwareLogEntryReader (org.neo4j.kernel.impl.transaction.log.entry.VersionAwareLogEntryReader)5 Test (org.junit.Test)4 Visitor (org.neo4j.helpers.collection.Visitor)4 PhysicalLogFiles (org.neo4j.kernel.impl.transaction.log.PhysicalLogFiles)4 PhysicalLogicalTransactionStore (org.neo4j.kernel.impl.transaction.log.PhysicalLogicalTransactionStore)4 ReadableClosablePositionAwareChannel (org.neo4j.kernel.impl.transaction.log.ReadableClosablePositionAwareChannel)4 TransactionMetadataCache (org.neo4j.kernel.impl.transaction.log.TransactionMetadataCache)4 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)3