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