use of org.neo4j.kernel.impl.transaction.log.entry.LogEntryStart in project neo4j by neo4j.
the class PhysicalTransactionCursor method next.
@Override
public boolean next() throws IOException {
// Clear the previous deserialized transaction so that it won't have to be kept in heap while deserializing
// the next one. Could be problematic if both are really big.
current = null;
while (true) {
if (!logEntryCursor.next()) {
return false;
}
LogEntry entry = logEntryCursor.get();
if (entry instanceof LogEntryInlinedCheckPoint) {
// this is a good position anyhow
channel.getCurrentPosition(lastGoodPositionMarker);
continue;
}
assert entry instanceof LogEntryStart : "Expected Start entry, read " + entry + " instead";
LogEntryStart startEntry = (LogEntryStart) entry;
LogEntryCommit commitEntry;
List<StorageCommand> entries = new ArrayList<>();
while (true) {
if (!logEntryCursor.next()) {
return false;
}
entry = logEntryCursor.get();
if (entry instanceof LogEntryCommit) {
commitEntry = (LogEntryCommit) entry;
break;
}
LogEntryCommand command = (LogEntryCommand) entry;
entries.add(command.getCommand());
}
PhysicalTransactionRepresentation transaction = new PhysicalTransactionRepresentation(entries);
transaction.setHeader(startEntry.getAdditionalHeader(), startEntry.getTimeWritten(), startEntry.getLastCommittedTxWhenTransactionStarted(), commitEntry.getTimeWritten(), -1, ANONYMOUS);
current = new CommittedTransactionRepresentation(startEntry, transaction, commitEntry);
channel.getCurrentPosition(lastGoodPositionMarker);
return true;
}
}
use of org.neo4j.kernel.impl.transaction.log.entry.LogEntryStart 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.transaction.log.entry.LogEntryStart in project neo4j by neo4j.
the class TransactionLogFileInformationTest method doNotReadAgainPreviouslyObservedLogTransactionTime.
@Test
void doNotReadAgainPreviouslyObservedLogTransactionTime() throws IOException {
var logEntryReader = mock(LogEntryReader.class);
var readableLogChannel = mock(ReadableLogChannel.class);
when(logEntryReader.readLogEntry(readableLogChannel)).thenReturn(new LogEntryStart(1, 1, 1, new byte[] {}, LogPosition.UNSPECIFIED));
when(context.getLogEntryReader()).thenReturn(logEntryReader);
var fileInfo = new TransactionLogFileInformation(logFiles, logHeaderCache, context);
var expectedHeader = new LogHeader((byte) 1, 2, 3, 4);
when(logFile.extractHeader(anyLong())).thenReturn(expectedHeader);
when(logFile.getRawReader(any())).thenReturn(readableLogChannel);
fileInfo.getFirstStartRecordTimestamp(1);
fileInfo.getFirstStartRecordTimestamp(1);
fileInfo.getFirstStartRecordTimestamp(1);
fileInfo.getFirstStartRecordTimestamp(1);
fileInfo.getFirstStartRecordTimestamp(1);
verify(logFile, times(1)).getRawReader(any());
}
use of org.neo4j.kernel.impl.transaction.log.entry.LogEntryStart in project neo4j by neo4j.
the class AbstractLogTailScannerTest method bigFileLatestCheckpointFindsStartAfter.
@ParameterizedTest
@MethodSource("params")
void bigFileLatestCheckpointFindsStartAfter(int startLogVersion, int endLogVersion) throws IOException {
long firstTxAfterCheckpoint = Integer.MAX_VALUE + 4L;
InlinedLogTailScanner tailScanner = new FirstTxIdConfigurableTailScanner(firstTxAfterCheckpoint, logFiles, reader, monitors);
LogEntryStart startEntry = new LogEntryStart(3L, 4L, 0, new byte[] { 5, 6 }, new LogPosition(endLogVersion, Integer.MAX_VALUE + 17L));
CheckpointInfo checkPoint = new CheckpointInfo(new LogPosition(endLogVersion, 16L), StoreId.UNKNOWN, LogPosition.UNSPECIFIED);
LogTailInformation logTailInformation = tailScanner.checkpointTailInformation(endLogVersion, startEntry, endLogVersion, (byte) -1, checkPoint, false, StoreId.UNKNOWN);
assertLatestCheckPoint(true, true, firstTxAfterCheckpoint, false, logTailInformation);
}
use of org.neo4j.kernel.impl.transaction.log.entry.LogEntryStart in project neo4j by neo4j.
the class ParallelRecoveryVisitorTest method tx.
private CommittedTransactionRepresentation tx(long txId, List<StorageCommand> commands) {
commands.forEach(cmd -> ((RecoveryTestBaseCommand) cmd).txId = txId);
LogEntryStart startEntry = new LogEntryStart(0, 0, 0, new byte[0], UNSPECIFIED);
TransactionRepresentation txRepresentation = new PhysicalTransactionRepresentation(commands);
LogEntryCommit commitEntry = new LogEntryCommit(txId, 0, 0);
return new CommittedTransactionRepresentation(startEntry, txRepresentation, commitEntry);
}
Aggregations