Search in sources :

Example 6 with LogEntryStart

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;
    }
}
Also used : LogEntryStart(org.neo4j.kernel.impl.transaction.log.entry.LogEntryStart) CommittedTransactionRepresentation(org.neo4j.kernel.impl.transaction.CommittedTransactionRepresentation) LogEntryCommand(org.neo4j.kernel.impl.transaction.log.entry.LogEntryCommand) LogEntryCommit(org.neo4j.kernel.impl.transaction.log.entry.LogEntryCommit) StorageCommand(org.neo4j.storageengine.api.StorageCommand) ArrayList(java.util.ArrayList) LogEntryInlinedCheckPoint(org.neo4j.kernel.impl.transaction.log.entry.LogEntryInlinedCheckPoint) LogEntry(org.neo4j.kernel.impl.transaction.log.entry.LogEntry)

Example 7 with LogEntryStart

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");
}
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 8 with LogEntryStart

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());
}
Also used : LogEntryStart(org.neo4j.kernel.impl.transaction.log.entry.LogEntryStart) LogHeader(org.neo4j.kernel.impl.transaction.log.entry.LogHeader) Test(org.junit.jupiter.api.Test)

Example 9 with LogEntryStart

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);
}
Also used : LogEntryStart(org.neo4j.kernel.impl.transaction.log.entry.LogEntryStart) LogTailInformation(org.neo4j.kernel.impl.transaction.log.files.LogTailInformation) LogPosition(org.neo4j.kernel.impl.transaction.log.LogPosition) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 10 with LogEntryStart

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);
}
Also used : LogEntryStart(org.neo4j.kernel.impl.transaction.log.entry.LogEntryStart) CommittedTransactionRepresentation(org.neo4j.kernel.impl.transaction.CommittedTransactionRepresentation) TransactionRepresentation(org.neo4j.kernel.impl.transaction.TransactionRepresentation) CommittedTransactionRepresentation(org.neo4j.kernel.impl.transaction.CommittedTransactionRepresentation) PhysicalTransactionRepresentation(org.neo4j.kernel.impl.transaction.log.PhysicalTransactionRepresentation) LogEntryCommit(org.neo4j.kernel.impl.transaction.log.entry.LogEntryCommit) PhysicalTransactionRepresentation(org.neo4j.kernel.impl.transaction.log.PhysicalTransactionRepresentation)

Aggregations

LogEntryStart (org.neo4j.kernel.impl.transaction.log.entry.LogEntryStart)21 LogEntryCommit (org.neo4j.kernel.impl.transaction.log.entry.LogEntryCommit)14 LogEntry (org.neo4j.kernel.impl.transaction.log.entry.LogEntry)12 LogEntryCommand (org.neo4j.kernel.impl.transaction.log.entry.LogEntryCommand)8 CommittedTransactionRepresentation (org.neo4j.kernel.impl.transaction.CommittedTransactionRepresentation)7 LogPosition (org.neo4j.kernel.impl.transaction.log.LogPosition)7 Test (org.junit.Test)5 PhysicalTransactionRepresentation (org.neo4j.kernel.impl.transaction.log.PhysicalTransactionRepresentation)5 OnePhaseCommit (org.neo4j.kernel.impl.transaction.log.entry.OnePhaseCommit)5 Test (org.junit.jupiter.api.Test)4 TransactionRepresentation (org.neo4j.kernel.impl.transaction.TransactionRepresentation)4 Command (org.neo4j.kernel.impl.transaction.command.Command)4 LogEntryCursor (org.neo4j.kernel.impl.transaction.log.LogEntryCursor)4 LogVersionedStoreChannel (org.neo4j.kernel.impl.transaction.log.LogVersionedStoreChannel)4 LogEntryWriter (org.neo4j.kernel.impl.transaction.log.entry.LogEntryWriter)4 LogHeader (org.neo4j.kernel.impl.transaction.log.entry.LogHeader)4 File (java.io.File)3 ArrayList (java.util.ArrayList)3 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)3 ReadableLogChannel (org.neo4j.kernel.impl.transaction.log.ReadableLogChannel)3