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);
}
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));
}
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");
}
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()));
}
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());
}
}
Aggregations