Search in sources :

Example 16 with TransactionToApply

use of org.neo4j.kernel.impl.api.TransactionToApply in project neo4j by neo4j.

the class BatchingTransactionAppenderTest method batchOf.

private static TransactionToApply batchOf(TransactionRepresentation... transactions) {
    TransactionToApply first = null;
    TransactionToApply last = null;
    for (TransactionRepresentation transaction : transactions) {
        TransactionToApply tx = new TransactionToApply(transaction, NULL);
        if (first == null) {
            first = last = tx;
        } else {
            last.next(tx);
            last = tx;
        }
    }
    return first;
}
Also used : TransactionToApply(org.neo4j.kernel.impl.api.TransactionToApply) CommittedTransactionRepresentation(org.neo4j.kernel.impl.transaction.CommittedTransactionRepresentation) TransactionRepresentation(org.neo4j.kernel.impl.transaction.TransactionRepresentation)

Example 17 with TransactionToApply

use of org.neo4j.kernel.impl.api.TransactionToApply in project neo4j by neo4j.

the class BatchingTransactionAppenderTest method shouldNotCallTransactionClosedOnFailedAppendedTransaction.

@Test
void shouldNotCallTransactionClosedOnFailedAppendedTransaction() throws Exception {
    // GIVEN
    long txId = 3;
    String failureMessage = "Forces a failure";
    FlushablePositionAwareChecksumChannel channel = spy(new PositionAwarePhysicalFlushableChecksumChannel(mock(PhysicalLogVersionedStoreChannel.class), new HeapScopedBuffer(Long.BYTES * 2, INSTANCE)));
    IOException failure = new IOException(failureMessage);
    when(channel.putLong(anyLong())).thenThrow(failure);
    when(logFile.getTransactionLogWriter()).thenReturn(new TransactionLogWriter(channel, new DbmsLogEntryWriterFactory(() -> LATEST)));
    when(transactionIdStore.nextCommittingTransactionId()).thenReturn(txId);
    when(transactionIdStore.getLastCommittedTransaction()).thenReturn(new TransactionId(txId, BASE_TX_CHECKSUM, BASE_TX_COMMIT_TIMESTAMP));
    Mockito.reset(databaseHealth);
    TransactionAppender appender = life.add(createTransactionAppender());
    // WHEN
    TransactionRepresentation transaction = mock(TransactionRepresentation.class);
    when(transaction.additionalHeader()).thenReturn(new byte[0]);
    var e = assertThrows(IOException.class, () -> appender.append(new TransactionToApply(transaction, NULL), logAppendEvent));
    assertSame(failure, e);
    verify(transactionIdStore).nextCommittingTransactionId();
    verify(transactionIdStore, never()).transactionClosed(eq(txId), anyLong(), anyLong(), any(CursorContext.class));
    verify(databaseHealth).panic(failure);
}
Also used : TransactionToApply(org.neo4j.kernel.impl.api.TransactionToApply) CommittedTransactionRepresentation(org.neo4j.kernel.impl.transaction.CommittedTransactionRepresentation) TransactionRepresentation(org.neo4j.kernel.impl.transaction.TransactionRepresentation) IOException(java.io.IOException) CursorContext(org.neo4j.io.pagecache.context.CursorContext) TransactionId(org.neo4j.storageengine.api.TransactionId) HeapScopedBuffer(org.neo4j.io.memory.HeapScopedBuffer) DbmsLogEntryWriterFactory(org.neo4j.kernel.database.DbmsLogEntryWriterFactory) Test(org.junit.jupiter.api.Test)

Example 18 with TransactionToApply

use of org.neo4j.kernel.impl.api.TransactionToApply in project neo4j by neo4j.

the class BatchingTransactionAppenderTest method shouldNotCallTransactionClosedOnFailedForceLogToDisk.

@Test
void shouldNotCallTransactionClosedOnFailedForceLogToDisk() throws Exception {
    // GIVEN
    long txId = 3;
    String failureMessage = "Forces a failure";
    FlushablePositionAwareChecksumChannel channel = spy(new InMemoryClosableChannel());
    IOException failure = new IOException(failureMessage);
    final Flushable flushable = mock(Flushable.class);
    doAnswer(invocation -> {
        invocation.callRealMethod();
        return flushable;
    }).when(channel).prepareForFlush();
    when(logFile.forceAfterAppend(any())).thenThrow(failure);
    when(logFile.getTransactionLogWriter()).thenReturn(new TransactionLogWriter(channel, new DbmsLogEntryWriterFactory(() -> LATEST)));
    TransactionMetadataCache metadataCache = new TransactionMetadataCache();
    TransactionIdStore transactionIdStore = mock(TransactionIdStore.class);
    when(transactionIdStore.nextCommittingTransactionId()).thenReturn(txId);
    when(transactionIdStore.getLastCommittedTransaction()).thenReturn(new TransactionId(txId, BASE_TX_CHECKSUM, BASE_TX_COMMIT_TIMESTAMP));
    TransactionAppender appender = life.add(new BatchingTransactionAppender(logFiles, NO_ROTATION, metadataCache, transactionIdStore, databaseHealth));
    // WHEN
    TransactionRepresentation transaction = mock(TransactionRepresentation.class);
    when(transaction.additionalHeader()).thenReturn(new byte[0]);
    var e = assertThrows(IOException.class, () -> appender.append(new TransactionToApply(transaction, NULL), logAppendEvent));
    assertSame(failure, e);
    verify(transactionIdStore).nextCommittingTransactionId();
    verify(transactionIdStore, never()).transactionClosed(eq(txId), anyLong(), anyLong(), any(CursorContext.class));
}
Also used : TransactionToApply(org.neo4j.kernel.impl.api.TransactionToApply) TransactionIdStore(org.neo4j.storageengine.api.TransactionIdStore) CommittedTransactionRepresentation(org.neo4j.kernel.impl.transaction.CommittedTransactionRepresentation) TransactionRepresentation(org.neo4j.kernel.impl.transaction.TransactionRepresentation) IOException(java.io.IOException) CursorContext(org.neo4j.io.pagecache.context.CursorContext) Flushable(java.io.Flushable) TransactionId(org.neo4j.storageengine.api.TransactionId) DbmsLogEntryWriterFactory(org.neo4j.kernel.database.DbmsLogEntryWriterFactory) Test(org.junit.jupiter.api.Test)

Example 19 with TransactionToApply

use of org.neo4j.kernel.impl.api.TransactionToApply in project neo4j by neo4j.

the class BatchingTransactionAppenderTest method shouldNotAppendCommittedTransactionsWhenTooFarAhead.

@Test
void shouldNotAppendCommittedTransactionsWhenTooFarAhead() {
    // GIVEN
    InMemoryClosableChannel channel = new InMemoryClosableChannel();
    when(logFile.getTransactionLogWriter()).thenReturn(new TransactionLogWriter(channel, new DbmsLogEntryWriterFactory(() -> LATEST)));
    TransactionAppender appender = life.add(createTransactionAppender());
    // WHEN
    final byte[] additionalHeader = new byte[] { 1, 2, 5 };
    final long timeStarted = 12345;
    long latestCommittedTxWhenStarted = 4545;
    long timeCommitted = timeStarted + 10;
    PhysicalTransactionRepresentation transactionRepresentation = new PhysicalTransactionRepresentation(singleTestCommand());
    transactionRepresentation.setHeader(additionalHeader, timeStarted, latestCommittedTxWhenStarted, timeCommitted, -1, ANONYMOUS);
    when(transactionIdStore.getLastCommittedTransactionId()).thenReturn(latestCommittedTxWhenStarted);
    LogEntryStart start = new LogEntryStart(0L, latestCommittedTxWhenStarted, 0, null, LogPosition.UNSPECIFIED);
    LogEntryCommit commit = new LogEntryCommit(latestCommittedTxWhenStarted + 2, 0L, BASE_TX_CHECKSUM);
    CommittedTransactionRepresentation transaction = new CommittedTransactionRepresentation(start, transactionRepresentation, commit);
    var e = assertThrows(Exception.class, () -> appender.append(new TransactionToApply(transaction.getTransactionRepresentation(), transaction.getCommitEntry().getTxId(), NULL), logAppendEvent));
    assertThat(e.getMessage()).contains("to be applied, but appending it ended up generating an");
}
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) DbmsLogEntryWriterFactory(org.neo4j.kernel.database.DbmsLogEntryWriterFactory) LogEntryCommit(org.neo4j.kernel.impl.transaction.log.entry.LogEntryCommit) Test(org.junit.jupiter.api.Test)

Example 20 with TransactionToApply

use of org.neo4j.kernel.impl.api.TransactionToApply in project neo4j by neo4j.

the class BatchingTransactionAppenderRotationIT method correctLastAppliedToPreviousLogTransactionInHeaderOnLogFileRotation.

@Test
void correctLastAppliedToPreviousLogTransactionInHeaderOnLogFileRotation() throws IOException {
    LogFiles logFiles = getLogFiles(logVersionRepository, transactionIdStore);
    life.add(logFiles);
    Health databaseHealth = getDatabaseHealth();
    LogRotation logRotation = FileLogRotation.transactionLogRotation(logFiles, Clock.systemUTC(), databaseHealth, monitors.newMonitor(LogRotationMonitor.class));
    TransactionMetadataCache transactionMetadataCache = new TransactionMetadataCache();
    BatchingTransactionAppender transactionAppender = new BatchingTransactionAppender(logFiles, logRotation, transactionMetadataCache, transactionIdStore, databaseHealth);
    life.add(transactionAppender);
    LogAppendEvent logAppendEvent = new RotationLogAppendEvent(logRotation);
    TransactionToApply transactionToApply = prepareTransaction();
    transactionAppender.append(transactionToApply, logAppendEvent);
    LogFile logFile = logFiles.getLogFile();
    assertEquals(1, logFile.getHighestLogVersion());
    Path highestLogFile = logFile.getHighestLogFile();
    LogHeader logHeader = LogHeaderReader.readLogHeader(fileSystem, highestLogFile, INSTANCE);
    assertEquals(2, logHeader.getLastCommittedTxId());
}
Also used : TransactionToApply(org.neo4j.kernel.impl.api.TransactionToApply) LogFile(org.neo4j.kernel.impl.transaction.log.files.LogFile) Path(java.nio.file.Path) Health(org.neo4j.monitoring.Health) DatabaseHealth(org.neo4j.monitoring.DatabaseHealth) LogRotationMonitor(org.neo4j.kernel.impl.transaction.log.rotation.monitor.LogRotationMonitor) LogFiles(org.neo4j.kernel.impl.transaction.log.files.LogFiles) FileLogRotation(org.neo4j.kernel.impl.transaction.log.rotation.FileLogRotation) LogRotation(org.neo4j.kernel.impl.transaction.log.rotation.LogRotation) LogAppendEvent(org.neo4j.kernel.impl.transaction.tracing.LogAppendEvent) LogHeader(org.neo4j.kernel.impl.transaction.log.entry.LogHeader) Test(org.junit.jupiter.api.Test)

Aggregations

TransactionToApply (org.neo4j.kernel.impl.api.TransactionToApply)46 TransactionRepresentation (org.neo4j.kernel.impl.transaction.TransactionRepresentation)14 Test (org.junit.jupiter.api.Test)11 PhysicalTransactionRepresentation (org.neo4j.kernel.impl.transaction.log.PhysicalTransactionRepresentation)11 CommittedTransactionRepresentation (org.neo4j.kernel.impl.transaction.CommittedTransactionRepresentation)9 Test (org.junit.Test)7 IOException (java.io.IOException)6 CursorContext (org.neo4j.io.pagecache.context.CursorContext)6 DbmsLogEntryWriterFactory (org.neo4j.kernel.database.DbmsLogEntryWriterFactory)6 TransactionFailureException (org.neo4j.kernel.api.exceptions.TransactionFailureException)4 TransactionId (org.neo4j.storageengine.api.TransactionId)4 TransactionCommitProcess (org.neo4j.kernel.impl.api.TransactionCommitProcess)3 CommitEvent (org.neo4j.kernel.impl.transaction.tracing.CommitEvent)3 ArrayList (java.util.ArrayList)2 DefaultPageCacheTracer (org.neo4j.io.pagecache.tracing.DefaultPageCacheTracer)2 TransactionApplier (org.neo4j.kernel.impl.api.TransactionApplier)2 LockGroup (org.neo4j.kernel.impl.locking.LockGroup)2 FakeCommitment (org.neo4j.kernel.impl.transaction.log.FakeCommitment)2 LogEntryCommit (org.neo4j.kernel.impl.transaction.log.entry.LogEntryCommit)2 LogEntryReader (org.neo4j.kernel.impl.transaction.log.entry.LogEntryReader)2