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;
}
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));
}
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);
}
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());
}
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());
}
Aggregations