Search in sources :

Example 1 with LogFileCreateEvent

use of org.neo4j.kernel.impl.transaction.tracing.LogFileCreateEvent 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);
    }
}
Also used : HeapScopedBuffer(org.neo4j.io.memory.HeapScopedBuffer) LogFileCreateEvent(org.neo4j.kernel.impl.transaction.tracing.LogFileCreateEvent) PhysicalLogVersionedStoreChannel(org.neo4j.kernel.impl.transaction.log.PhysicalLogVersionedStoreChannel) LogHeaderReader.readLogHeader(org.neo4j.kernel.impl.transaction.log.entry.LogHeaderReader.readLogHeader) LogHeader(org.neo4j.kernel.impl.transaction.log.entry.LogHeader)

Aggregations

HeapScopedBuffer (org.neo4j.io.memory.HeapScopedBuffer)1 PhysicalLogVersionedStoreChannel (org.neo4j.kernel.impl.transaction.log.PhysicalLogVersionedStoreChannel)1 LogHeader (org.neo4j.kernel.impl.transaction.log.entry.LogHeader)1 LogHeaderReader.readLogHeader (org.neo4j.kernel.impl.transaction.log.entry.LogHeaderReader.readLogHeader)1 LogFileCreateEvent (org.neo4j.kernel.impl.transaction.tracing.LogFileCreateEvent)1