Search in sources :

Example 16 with LogHeader

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

the class TransactionLogFileInformationTest method shouldReadAndCacheFirstCommittedTransactionIdForAGivenVersionWhenNotCached.

@Test
void shouldReadAndCacheFirstCommittedTransactionIdForAGivenVersionWhenNotCached() throws Exception {
    TransactionLogFileInformation info = new TransactionLogFileInformation(logFiles, logHeaderCache, context);
    long expected = 5;
    long version = 10L;
    when(logHeaderCache.getLogHeader(version)).thenReturn(null);
    when(logFiles.getLogFile().versionExists(version)).thenReturn(true);
    LogHeader expectedHeader = new LogHeader((byte) -1, /*ignored*/
    -1L, /*ignored*/
    expected - 1L, CURRENT_FORMAT_LOG_HEADER_SIZE);
    when(logFiles.getLogFile().extractHeader(version)).thenReturn(expectedHeader);
    long firstCommittedTxId = info.getFirstEntryId(version);
    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 17 with LogHeader

use of org.neo4j.kernel.impl.transaction.log.entry.LogHeader 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 18 with LogHeader

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

the class LogHeaderCacheTest method shouldReturnTheHeaderIfInTheCache.

@Test
void shouldReturnTheHeaderIfInTheCache() {
    // given
    final LogHeaderCache cache = new LogHeaderCache(2);
    // when
    cache.putHeader(5, new LogHeader(1, 3, StoreId.UNKNOWN));
    final LogHeader logHeader = cache.getLogHeader(5);
    // then
    assertEquals(3, logHeader.getLastCommittedTxId());
}
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)

Example 19 with LogHeader

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

the class LogHeaderCacheTest method shouldReturnNullWhenThereIsNoHeaderInTheCache.

@Test
void shouldReturnNullWhenThereIsNoHeaderInTheCache() {
    // given
    final LogHeaderCache cache = new LogHeaderCache(2);
    // when
    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)

Example 20 with LogHeader

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

the class TransactionRangeDiagnostics method dumpTransactionLogInformation.

private void dumpTransactionLogInformation(DiagnosticsLogger logger, LogFile logFile) throws IOException {
    logger.log("Transaction log files:");
    logger.log(" - existing transaction log versions " + logFile.getLowestLogVersion() + "-" + logFile.getHighestLogVersion());
    for (long logVersion = logFile.getLowestLogVersion(); logFile.versionExists(logVersion); logVersion++) {
        if (logFile.hasAnyEntries(logVersion)) {
            LogHeader header = logFile.extractHeader(logVersion);
            long firstTransactionIdInThisLog = header.getLastCommittedTxId() + 1;
            logger.log(" - oldest transaction " + firstTransactionIdInThisLog + " found in log with version " + logVersion);
            return;
        }
    }
    logger.log(" - no transactions found");
}
Also used : LogHeader(org.neo4j.kernel.impl.transaction.log.entry.LogHeader)

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