Search in sources :

Example 11 with LogHeader

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

the class LogTestUtils method transferLogicalLogHeader.

private static LogHeader transferLogicalLogHeader(StoreChannel in, StoreChannel out, ByteBuffer buffer) throws IOException {
    LogHeader header = readLogHeader(buffer, in, true, null);
    writeLogHeader(buffer, header.logVersion, header.lastCommittedTxId);
    buffer.flip();
    out.write(buffer);
    return header;
}
Also used : LogHeaderReader.readLogHeader(org.neo4j.kernel.impl.transaction.log.entry.LogHeaderReader.readLogHeader) LogHeaderWriter.writeLogHeader(org.neo4j.kernel.impl.transaction.log.entry.LogHeaderWriter.writeLogHeader) LogHeader(org.neo4j.kernel.impl.transaction.log.entry.LogHeader)

Example 12 with LogHeader

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

the class LogMatchers method logEntries.

public static List<LogEntry> logEntries(FileSystemAbstraction fileSystem, String logPath) throws IOException {
    File logFile = new File(logPath);
    StoreChannel fileChannel = fileSystem.open(logFile, "r");
    // Always a header
    LogHeader header = readLogHeader(ByteBuffer.allocateDirect(LOG_HEADER_SIZE), fileChannel, true, logFile);
    // Read all log entries
    PhysicalLogVersionedStoreChannel versionedStoreChannel = new PhysicalLogVersionedStoreChannel(fileChannel, header.logVersion, header.logFormatVersion);
    ReadableLogChannel logChannel = new ReadAheadLogChannel(versionedStoreChannel, NO_MORE_CHANNELS);
    LogEntryCursor logEntryCursor = new LogEntryCursor(new VersionAwareLogEntryReader<>(), logChannel);
    return Iterables.asList(new IOCursorAsResourceIterable<>(logEntryCursor));
}
Also used : ReadableLogChannel(org.neo4j.kernel.impl.transaction.log.ReadableLogChannel) StoreChannel(org.neo4j.io.fs.StoreChannel) PhysicalLogVersionedStoreChannel(org.neo4j.kernel.impl.transaction.log.PhysicalLogVersionedStoreChannel) PhysicalLogVersionedStoreChannel(org.neo4j.kernel.impl.transaction.log.PhysicalLogVersionedStoreChannel) File(java.io.File) ReadAheadLogChannel(org.neo4j.kernel.impl.transaction.log.ReadAheadLogChannel) LogEntryCursor(org.neo4j.kernel.impl.transaction.log.LogEntryCursor) LogHeaderReader.readLogHeader(org.neo4j.kernel.impl.transaction.log.entry.LogHeaderReader.readLogHeader) LogHeader(org.neo4j.kernel.impl.transaction.log.entry.LogHeader)

Example 13 with LogHeader

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

the class LegacyLogEntryReader method openReadableChannel.

public Pair<LogHeader, IOCursor<LogEntry>> openReadableChannel(File logFile) throws IOException {
    final StoreChannel rawChannel = fs.open(logFile, "r");
    final LogHeader header = readLogHeader(ByteBuffer.allocate(LOG_HEADER_SIZE), rawChannel, false, logFile);
    LogEntryReader<ReadableLogChannel> reader = readerFactory.apply(header);
    // this ensures that the last committed txId field in the header is initialized properly
    long lastCommittedTxId = Math.max(BASE_TX_ID, header.lastCommittedTxId);
    final PhysicalLogVersionedStoreChannel channel = new PhysicalLogVersionedStoreChannel(rawChannel, header.logVersion, header.logFormatVersion);
    final ReadableLogChannel readableChannel = new ReadAheadLogChannel(channel, NO_MORE_CHANNELS);
    final IOCursor<LogEntry> cursor = new LogEntrySortingCursor(reader, readableChannel);
    return Pair.of(new LogHeader(CURRENT_LOG_VERSION, header.logVersion, lastCommittedTxId), cursor);
}
Also used : ReadableLogChannel(org.neo4j.kernel.impl.transaction.log.ReadableLogChannel) StoreChannel(org.neo4j.io.fs.StoreChannel) PhysicalLogVersionedStoreChannel(org.neo4j.kernel.impl.transaction.log.PhysicalLogVersionedStoreChannel) PhysicalLogVersionedStoreChannel(org.neo4j.kernel.impl.transaction.log.PhysicalLogVersionedStoreChannel) ReadAheadLogChannel(org.neo4j.kernel.impl.transaction.log.ReadAheadLogChannel) LogHeaderReader.readLogHeader(org.neo4j.kernel.impl.transaction.log.entry.LogHeaderReader.readLogHeader) LogHeader(org.neo4j.kernel.impl.transaction.log.entry.LogHeader) LogEntry(org.neo4j.kernel.impl.transaction.log.entry.LogEntry)

Example 14 with LogHeader

use of org.neo4j.kernel.impl.transaction.log.entry.LogHeader 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());
}
Also used : TransactionToApply(org.neo4j.kernel.impl.api.TransactionToApply) LogFile(org.neo4j.kernel.impl.transaction.log.files.LogFile) Path(java.nio.file.Path) Health(org.neo4j.monitoring.Health) DatabaseHealth(org.neo4j.monitoring.DatabaseHealth) LogRotationMonitor(org.neo4j.kernel.impl.transaction.log.rotation.monitor.LogRotationMonitor) LogFiles(org.neo4j.kernel.impl.transaction.log.files.LogFiles) FileLogRotation(org.neo4j.kernel.impl.transaction.log.rotation.FileLogRotation) LogRotation(org.neo4j.kernel.impl.transaction.log.rotation.LogRotation) LogAppendEvent(org.neo4j.kernel.impl.transaction.tracing.LogAppendEvent) LogHeader(org.neo4j.kernel.impl.transaction.log.entry.LogHeader) Test(org.junit.jupiter.api.Test)

Example 15 with LogHeader

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

the class TransactionLogFileTest method shouldOpenInFreshDirectoryAndFinallyAddHeader.

@Test
void shouldOpenInFreshDirectoryAndFinallyAddHeader() throws Exception {
    // GIVEN
    LogFiles logFiles = buildLogFiles();
    // WHEN
    life.start();
    life.add(logFiles);
    life.shutdown();
    // THEN
    Path file = LogFilesBuilder.logFilesBasedOnlyBuilder(databaseLayout.getTransactionLogsDirectory(), fileSystem).withLogEntryReader(logEntryReader()).build().getLogFile().getLogFileForVersion(1L);
    LogHeader header = readLogHeader(fileSystem, file, INSTANCE);
    assertEquals(1L, header.getLogVersion());
    assertEquals(2L, header.getLastCommittedTxId());
}
Also used : Path(java.nio.file.Path) LogFiles(org.neo4j.kernel.impl.transaction.log.files.LogFiles) LogHeaderReader.readLogHeader(org.neo4j.kernel.impl.transaction.log.entry.LogHeaderReader.readLogHeader) 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