use of org.neo4j.kernel.impl.transaction.log.entry.LogHeader in project neo4j by neo4j.
the class TransactionLogChannelAllocator method createLogChannel.
public PhysicalLogVersionedStoreChannel createLogChannel(long version, LongSupplier lastCommittedTransactionId) throws IOException {
AllocatedFile allocatedFile = allocateFile(version);
var storeChannel = allocatedFile.getStoreChannel();
var logFile = allocatedFile.getPath();
try (var scopedBuffer = new HeapScopedBuffer(CURRENT_FORMAT_LOG_HEADER_SIZE, logFilesContext.getMemoryTracker())) {
var buffer = scopedBuffer.getBuffer();
LogHeader header = readLogHeader(buffer, storeChannel, false, logFile);
if (header == null) {
try (LogFileCreateEvent ignored = databaseTracer.createLogFile()) {
// we always write file header from the beginning of the file
storeChannel.position(0);
long lastTxId = lastCommittedTransactionId.getAsLong();
LogHeader logHeader = new LogHeader(version, lastTxId, logFilesContext.getStoreId());
LogHeaderWriter.writeLogHeader(storeChannel, logHeader, logFilesContext.getMemoryTracker());
logHeaderCache.putHeader(version, logHeader);
}
}
byte formatVersion = header == null ? CURRENT_LOG_FORMAT_VERSION : header.getLogFormatVersion();
return new PhysicalLogVersionedStoreChannel(storeChannel, version, formatVersion, logFile, nativeChannelAccessor);
}
}
use of org.neo4j.kernel.impl.transaction.log.entry.LogHeader in project neo4j by neo4j.
the class TransactionLogFile method extractHeader.
private LogHeader extractHeader(long version, boolean strict) throws IOException {
LogHeader logHeader = logHeaderCache.getLogHeader(version);
if (logHeader == null) {
logHeader = readLogHeader(fileSystem, getLogFileForVersion(version), strict, context.getMemoryTracker());
if (!strict && logHeader == null) {
return null;
}
logHeaderCache.putHeader(version, logHeader);
}
return logHeader;
}
use of org.neo4j.kernel.impl.transaction.log.entry.LogHeader in project neo4j by neo4j.
the class TransactionLogFileInformation method getFirstEntryId.
@Override
public long getFirstEntryId(long version) throws IOException {
LogHeader logHeader = logHeaderCache.getLogHeader(version);
if (logHeader != null) {
// It existed in cache
return logHeader.getLastCommittedTxId() + 1;
}
// Wasn't cached, go look for it
var logFile = logFiles.getLogFile();
if (logFile.versionExists(version)) {
logHeader = logFile.extractHeader(version);
logHeaderCache.putHeader(version, logHeader);
return logHeader.getLastCommittedTxId() + 1;
}
return -1;
}
use of org.neo4j.kernel.impl.transaction.log.entry.LogHeader in project neo4j by neo4j.
the class TransactionLogInitializer method initializeExistingLogFiles.
/**
* Make sure that any existing log files in the given transaction logs directory are initialised.
* This is done when we migrate 3.x stores into a 4.x world.
*/
public void initializeExistingLogFiles(DatabaseLayout layout, Path transactionLogsDirectory, String checkpointReason) throws Exception {
try (LogFilesSpan span = buildLogFiles(layout, transactionLogsDirectory)) {
LogFiles logFiles = span.getLogFiles();
LogFile logFile = logFiles.getLogFile();
LogHeader logHeader = logFile.extractHeader(logFile.getLowestLogVersion());
VersionAwareLogEntryReader entryReader = new VersionAwareLogEntryReader(commandReaderFactory, false);
try (var readableChannel = logFile.getReader(logHeader.getStartPosition());
var cursor = new LogEntryCursor(entryReader, readableChannel)) {
while (cursor.next()) {
LogEntry entry = cursor.get();
if (entry.getType() == LogEntryTypeCodes.TX_COMMIT) {
// The log files already contain a transaction, so we can only append checkpoint for the end of the log files.
appendCheckpoint(logFiles, checkpointReason, logFile.getTransactionLogWriter().getCurrentPosition());
return;
}
}
}
appendEmptyTransactionAndCheckPoint(logFiles, checkpointReason);
}
}
use of org.neo4j.kernel.impl.transaction.log.entry.LogHeader in project neo4j by neo4j.
the class DetachedLogTailScanner method isValidCheckpoint.
/**
* Valid checkpoint points to valid location in a file, which exists and header store id matches with checkpoint store id.
* Otherwise checkpoint is not considered valid and we need to recover.
*/
private boolean isValidCheckpoint(LogFile logFile, CheckpointInfo checkpointInfo) throws IOException {
LogPosition logPosition = checkpointInfo.getTransactionLogPosition();
long logVersion = logPosition.getLogVersion();
if (!logFile.versionExists(logVersion)) {
return false;
}
Path logFileForVersion = logFile.getLogFileForVersion(logVersion);
if (fileSystem.getFileSize(logFileForVersion) < logPosition.getByteOffset()) {
return false;
}
LogHeader logHeader = logFile.extractHeader(logVersion);
StoreId headerStoreId = logHeader.getStoreId();
return StoreId.UNKNOWN.equals(headerStoreId) || headerStoreId.equalsIgnoringVersion(checkpointInfo.storeId());
}
Aggregations