Search in sources :

Example 1 with DbmsLogEntryWriterFactory

use of org.neo4j.kernel.database.DbmsLogEntryWriterFactory 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 2 with DbmsLogEntryWriterFactory

use of org.neo4j.kernel.database.DbmsLogEntryWriterFactory 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 3 with DbmsLogEntryWriterFactory

use of org.neo4j.kernel.database.DbmsLogEntryWriterFactory 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 4 with DbmsLogEntryWriterFactory

use of org.neo4j.kernel.database.DbmsLogEntryWriterFactory in project neo4j by neo4j.

the class TransactionLogFile method start.

@Override
public void start() throws IOException {
    long currentLogVersion = logVersionRepository.getCurrentLogVersion();
    channel = createLogChannelForVersion(currentLogVersion, context::getLastCommittedTransactionId);
    context.getMonitors().newMonitor(LogRotationMonitor.class).started(channel.getPath(), currentLogVersion);
    // try to set position
    seekChannelPosition(currentLogVersion);
    writer = new PositionAwarePhysicalFlushableChecksumChannel(channel, new NativeScopedBuffer(calculateLogBufferSize(), memoryTracker));
    transactionLogWriter = new TransactionLogWriter(writer, new DbmsLogEntryWriterFactory(context.getKernelVersionProvider()));
}
Also used : LogRotationMonitor(org.neo4j.kernel.impl.transaction.log.rotation.monitor.LogRotationMonitor) PositionAwarePhysicalFlushableChecksumChannel(org.neo4j.kernel.impl.transaction.log.PositionAwarePhysicalFlushableChecksumChannel) DbmsLogEntryWriterFactory(org.neo4j.kernel.database.DbmsLogEntryWriterFactory) TransactionLogWriter(org.neo4j.kernel.impl.transaction.log.TransactionLogWriter) NativeScopedBuffer(org.neo4j.io.memory.NativeScopedBuffer)

Example 5 with DbmsLogEntryWriterFactory

use of org.neo4j.kernel.database.DbmsLogEntryWriterFactory in project neo4j by neo4j.

the class BatchingTransactionAppenderTest method shouldAppendSingleTransaction.

@Test
void shouldAppendSingleTransaction() throws Exception {
    // GIVEN
    when(logFile.getTransactionLogWriter()).thenReturn(new TransactionLogWriter(channel, new DbmsLogEntryWriterFactory(() -> LATEST)));
    long txId = 15;
    when(transactionIdStore.nextCommittingTransactionId()).thenReturn(txId);
    when(transactionIdStore.getLastCommittedTransaction()).thenReturn(new TransactionId(txId, BASE_TX_CHECKSUM, BASE_TX_COMMIT_TIMESTAMP));
    TransactionAppender appender = life.add(createTransactionAppender());
    // WHEN
    TransactionRepresentation transaction = transaction(singleTestCommand(), new byte[] { 1, 2, 5 }, 12345, 4545, 12345 + 10);
    appender.append(new TransactionToApply(transaction, NULL), logAppendEvent);
    // THEN
    final LogEntryReader logEntryReader = logEntryReader();
    try (PhysicalTransactionCursor reader = new PhysicalTransactionCursor(channel, logEntryReader)) {
        reader.next();
        TransactionRepresentation tx = reader.get().getTransactionRepresentation();
        assertArrayEquals(transaction.additionalHeader(), tx.additionalHeader());
        assertEquals(transaction.getTimeStarted(), tx.getTimeStarted());
        assertEquals(transaction.getTimeCommitted(), tx.getTimeCommitted());
        assertEquals(transaction.getLatestCommittedTxWhenStarted(), tx.getLatestCommittedTxWhenStarted());
    }
}
Also used : TransactionToApply(org.neo4j.kernel.impl.api.TransactionToApply) DbmsLogEntryWriterFactory(org.neo4j.kernel.database.DbmsLogEntryWriterFactory) 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) Test(org.junit.jupiter.api.Test)

Aggregations

DbmsLogEntryWriterFactory (org.neo4j.kernel.database.DbmsLogEntryWriterFactory)7 Test (org.junit.jupiter.api.Test)6 TransactionToApply (org.neo4j.kernel.impl.api.TransactionToApply)6 CommittedTransactionRepresentation (org.neo4j.kernel.impl.transaction.CommittedTransactionRepresentation)5 TransactionRepresentation (org.neo4j.kernel.impl.transaction.TransactionRepresentation)4 TransactionId (org.neo4j.storageengine.api.TransactionId)4 IOException (java.io.IOException)2 CursorContext (org.neo4j.io.pagecache.context.CursorContext)2 LogEntryCommit (org.neo4j.kernel.impl.transaction.log.entry.LogEntryCommit)2 LogEntryReader (org.neo4j.kernel.impl.transaction.log.entry.LogEntryReader)2 LogEntryStart (org.neo4j.kernel.impl.transaction.log.entry.LogEntryStart)2 Flushable (java.io.Flushable)1 HeapScopedBuffer (org.neo4j.io.memory.HeapScopedBuffer)1 NativeScopedBuffer (org.neo4j.io.memory.NativeScopedBuffer)1 PositionAwarePhysicalFlushableChecksumChannel (org.neo4j.kernel.impl.transaction.log.PositionAwarePhysicalFlushableChecksumChannel)1 TransactionLogWriter (org.neo4j.kernel.impl.transaction.log.TransactionLogWriter)1 LogRotationMonitor (org.neo4j.kernel.impl.transaction.log.rotation.monitor.LogRotationMonitor)1 TransactionIdStore (org.neo4j.storageengine.api.TransactionIdStore)1