Search in sources :

Example 41 with LogHeader

use of org.neo4j.kernel.impl.transaction.log.entry.LogHeader in project neo4j by neo4j.

the class InlinedLogTailScanner method findLogTail.

protected LogTailInformation findLogTail() throws IOException {
    LogFile logFile = logFiles.getLogFile();
    final long highestLogVersion = logFile.getHighestLogVersion();
    long version = highestLogVersion;
    long versionToSearchForCommits = highestLogVersion;
    LogEntryStart latestStartEntry = null;
    long oldestStartEntryTransaction = NO_TRANSACTION_ID;
    long oldestVersionFound = -1;
    byte latestLogEntryVersion = 0;
    boolean startRecordAfterCheckpoint = false;
    boolean corruptedTransactionLogs = false;
    while (version >= logFile.getLowestLogVersion() && version >= INITIAL_LOG_VERSION) {
        log.info("Scanning log file with version %d for checkpoint entries", version);
        oldestVersionFound = version;
        CheckpointInfo latestCheckPoint = null;
        StoreId storeId = StoreId.UNKNOWN;
        try (LogVersionedStoreChannel channel = logFile.openForVersion(version);
            var readAheadChannel = new ReadAheadLogChannel(channel, memoryTracker);
            LogEntryCursor cursor = new LogEntryCursor(logEntryReader, readAheadChannel)) {
            LogHeader logHeader = logFile.extractHeader(version);
            storeId = logHeader.getStoreId();
            LogEntry entry;
            long position = logHeader.getStartPosition().getByteOffset();
            long channelVersion = version;
            while (cursor.next()) {
                entry = cursor.get();
                // Collect data about latest checkpoint
                if (entry instanceof LogEntryInlinedCheckPoint) {
                    latestCheckPoint = new CheckpointInfo((LogEntryInlinedCheckPoint) entry, storeId, new LogPosition(channelVersion, position));
                } else if (entry instanceof LogEntryCommit) {
                    if (oldestStartEntryTransaction == NO_TRANSACTION_ID) {
                        oldestStartEntryTransaction = ((LogEntryCommit) entry).getTxId();
                    }
                } else if (entry instanceof LogEntryStart) {
                    LogEntryStart startEntry = (LogEntryStart) entry;
                    if (version == versionToSearchForCommits) {
                        latestStartEntry = startEntry;
                    }
                    startRecordAfterCheckpoint = true;
                }
                // Collect data about latest entry version, only in first log file
                if (version == versionToSearchForCommits || latestLogEntryVersion == 0) {
                    latestLogEntryVersion = entry.getVersion().version();
                }
                position = channel.position();
                channelVersion = channel.getVersion();
            }
            verifyReaderPosition(version, logEntryReader.lastPosition());
        } catch (Error | ClosedByInterruptException e) {
            // These should not be parsing errors
            throw e;
        } catch (Throwable t) {
            monitor.corruptedLogFile(version, t);
            if (failOnCorruptedLogFiles) {
                throwUnableToCleanRecover(t);
            }
            corruptedTransactionLogs = true;
        }
        if (latestCheckPoint != null) {
            return checkpointTailInformation(highestLogVersion, latestStartEntry, oldestVersionFound, latestLogEntryVersion, latestCheckPoint, corruptedTransactionLogs, storeId);
        }
        version--;
        // if we have found no commits in the latest log, keep searching in the next one
        if (latestStartEntry == null) {
            versionToSearchForCommits--;
        }
    }
    return new LogTailInformation(corruptedTransactionLogs || startRecordAfterCheckpoint, oldestStartEntryTransaction, oldestVersionFound == UNKNOWN, highestLogVersion, latestLogEntryVersion);
}
Also used : LogEntryStart(org.neo4j.kernel.impl.transaction.log.entry.LogEntryStart) LogVersionedStoreChannel(org.neo4j.kernel.impl.transaction.log.LogVersionedStoreChannel) LogTailInformation(org.neo4j.kernel.impl.transaction.log.files.LogTailInformation) LogEntryCursor(org.neo4j.kernel.impl.transaction.log.LogEntryCursor) LogFile(org.neo4j.kernel.impl.transaction.log.files.LogFile) ClosedByInterruptException(java.nio.channels.ClosedByInterruptException) StoreId(org.neo4j.storageengine.api.StoreId) LogEntryCommit(org.neo4j.kernel.impl.transaction.log.entry.LogEntryCommit) LogEntryInlinedCheckPoint(org.neo4j.kernel.impl.transaction.log.entry.LogEntryInlinedCheckPoint) ReadAheadLogChannel(org.neo4j.kernel.impl.transaction.log.ReadAheadLogChannel) LogHeader(org.neo4j.kernel.impl.transaction.log.entry.LogHeader) LogEntry(org.neo4j.kernel.impl.transaction.log.entry.LogEntry) LogPosition(org.neo4j.kernel.impl.transaction.log.LogPosition)

Example 42 with LogHeader

use of org.neo4j.kernel.impl.transaction.log.entry.LogHeader in project neo4j by neo4j.

the class TransactionLogFileInformationTest method shouldReadFirstCommittedTransactionIdForAGivenVersionWhenCached.

@Test
void shouldReadFirstCommittedTransactionIdForAGivenVersionWhenCached() throws Exception {
    TransactionLogFileInformation info = new TransactionLogFileInformation(logFiles, logHeaderCache, context);
    long expected = 5;
    long version = 10L;
    LogHeader expectedHeader = new LogHeader((byte) -1, /*ignored*/
    -1L, /*ignored*/
    expected - 1L, CURRENT_FORMAT_LOG_HEADER_SIZE);
    when(logHeaderCache.getLogHeader(version)).thenReturn(expectedHeader);
    long firstCommittedTxId = info.getFirstEntryId(version);
    assertEquals(expected, firstCommittedTxId);
}
Also used : LogHeader(org.neo4j.kernel.impl.transaction.log.entry.LogHeader) Test(org.junit.jupiter.api.Test)

Example 43 with LogHeader

use of org.neo4j.kernel.impl.transaction.log.entry.LogHeader in project neo4j by neo4j.

the class TransactionLogFileInformationTest method shouldReadAndCacheFirstCommittedTransactionIdWhenNotCached.

@Test
void shouldReadAndCacheFirstCommittedTransactionIdWhenNotCached() throws Exception {
    TransactionLogFileInformation info = new TransactionLogFileInformation(logFiles, logHeaderCache, context);
    long expected = 5;
    long version = 10L;
    when(logFile.getHighestLogVersion()).thenReturn(version);
    when(logHeaderCache.getLogHeader(version)).thenReturn(null);
    when(logFile.versionExists(version)).thenReturn(true);
    LogHeader expectedHeader = new LogHeader((byte) -1, /*ignored*/
    -1L, /*ignored*/
    expected - 1L, CURRENT_FORMAT_LOG_HEADER_SIZE);
    when(logFile.extractHeader(version)).thenReturn(expectedHeader);
    when(logFile.hasAnyEntries(version)).thenReturn(true);
    long firstCommittedTxId = info.getFirstExistingEntryId();
    assertEquals(expected, firstCommittedTxId);
    verify(logHeaderCache).putHeader(version, expectedHeader);
}
Also used : LogHeader(org.neo4j.kernel.impl.transaction.log.entry.LogHeader) Test(org.junit.jupiter.api.Test)

Example 44 with LogHeader

use of org.neo4j.kernel.impl.transaction.log.entry.LogHeader in project neo4j by neo4j.

the class TransactionLogFileInformationTest method shouldReadFirstCommittedTransactionIdWhenCached.

@Test
void shouldReadFirstCommittedTransactionIdWhenCached() throws Exception {
    TransactionLogFileInformation info = new TransactionLogFileInformation(logFiles, logHeaderCache, context);
    long expected = 5;
    long version = 10L;
    when(logFile.getHighestLogVersion()).thenReturn(version);
    when(logFile.versionExists(version)).thenReturn(true);
    LogHeader expectedHeader = new LogHeader((byte) -1, /*ignored*/
    -1L, /*ignored*/
    expected - 1L, CURRENT_FORMAT_LOG_HEADER_SIZE);
    when(logHeaderCache.getLogHeader(version)).thenReturn(expectedHeader);
    when(logFile.hasAnyEntries(version)).thenReturn(true);
    long firstCommittedTxId = info.getFirstExistingEntryId();
    assertEquals(expected, firstCommittedTxId);
}
Also used : LogHeader(org.neo4j.kernel.impl.transaction.log.entry.LogHeader) Test(org.junit.jupiter.api.Test)

Example 45 with LogHeader

use of org.neo4j.kernel.impl.transaction.log.entry.LogHeader in project neo4j by neo4j.

the class LogHeaderCacheTest method shouldClearTheCache.

@Test
void shouldClearTheCache() {
    // given
    final LogHeaderCache cache = new LogHeaderCache(2);
    // when
    cache.putHeader(5, new LogHeader(1, 3, StoreId.UNKNOWN));
    cache.clear();
    final LogHeader logHeader = cache.getLogHeader(5);
    // then
    assertNull(logHeader);
}
Also used : LogHeaderCache(org.neo4j.kernel.impl.transaction.log.LogHeaderCache) LogHeader(org.neo4j.kernel.impl.transaction.log.entry.LogHeader) Test(org.junit.jupiter.api.Test)

Aggregations

LogHeader (org.neo4j.kernel.impl.transaction.log.entry.LogHeader)45 LogHeaderReader.readLogHeader (org.neo4j.kernel.impl.transaction.log.entry.LogHeaderReader.readLogHeader)18 Test (org.junit.jupiter.api.Test)13 LogEntry (org.neo4j.kernel.impl.transaction.log.entry.LogEntry)12 File (java.io.File)11 StoreChannel (org.neo4j.io.fs.StoreChannel)11 PhysicalLogVersionedStoreChannel (org.neo4j.kernel.impl.transaction.log.PhysicalLogVersionedStoreChannel)11 LogHeaderWriter.writeLogHeader (org.neo4j.kernel.impl.transaction.log.entry.LogHeaderWriter.writeLogHeader)10 ReadAheadLogChannel (org.neo4j.kernel.impl.transaction.log.ReadAheadLogChannel)9 Path (java.nio.file.Path)7 Test (org.junit.Test)6 LogEntryCursor (org.neo4j.kernel.impl.transaction.log.LogEntryCursor)6 LogVersionedStoreChannel (org.neo4j.kernel.impl.transaction.log.LogVersionedStoreChannel)6 IOException (java.io.IOException)5 LogPosition (org.neo4j.kernel.impl.transaction.log.LogPosition)5 ReadableLogChannel (org.neo4j.kernel.impl.transaction.log.ReadableLogChannel)5 LogHeaderCache (org.neo4j.kernel.impl.transaction.log.LogHeaderCache)4 LogEntryStart (org.neo4j.kernel.impl.transaction.log.entry.LogEntryStart)4 VersionAwareLogEntryReader (org.neo4j.kernel.impl.transaction.log.entry.VersionAwareLogEntryReader)4 ByteBuffer (java.nio.ByteBuffer)3