Search in sources :

Example 1 with NativeScopedBuffer

use of org.neo4j.io.memory.NativeScopedBuffer in project neo4j by neo4j.

the class CorruptedLogsTruncator method isRecoveredLogCorrupted.

private boolean isRecoveredLogCorrupted(long recoveredTransactionLogVersion, long recoveredTransactionOffset) throws IOException {
    try {
        LogFile logFile = logFiles.getLogFile();
        if (Files.size(logFile.getLogFileForVersion(recoveredTransactionLogVersion)) > recoveredTransactionOffset) {
            try (PhysicalLogVersionedStoreChannel channel = logFile.openForVersion(recoveredTransactionLogVersion);
                var scopedBuffer = new NativeScopedBuffer(safeCastLongToInt(kibiBytes(64)), memoryTracker)) {
                channel.position(recoveredTransactionOffset);
                ByteBuffer byteBuffer = scopedBuffer.getBuffer();
                while (channel.read(byteBuffer) >= 0) {
                    byteBuffer.flip();
                    while (byteBuffer.hasRemaining()) {
                        if (byteBuffer.get() != 0) {
                            return true;
                        }
                    }
                    byteBuffer.clear();
                }
            }
        }
        return false;
    } catch (NoSuchFileException ignored) {
        return false;
    }
}
Also used : LogFile(org.neo4j.kernel.impl.transaction.log.files.LogFile) NoSuchFileException(java.nio.file.NoSuchFileException) PhysicalLogVersionedStoreChannel(org.neo4j.kernel.impl.transaction.log.PhysicalLogVersionedStoreChannel) NativeScopedBuffer(org.neo4j.io.memory.NativeScopedBuffer) ByteBuffer(java.nio.ByteBuffer)

Example 2 with NativeScopedBuffer

use of org.neo4j.io.memory.NativeScopedBuffer in project neo4j by neo4j.

the class TokenScanWriteMonitor method dumpFile.

private static long dumpFile(FileSystemAbstraction fs, Path file, Dumper dumper, TxFilter txFilter, long session) throws IOException {
    try (ReadableChannel channel = new ReadAheadChannel<>(fs.read(file), new NativeScopedBuffer(DEFAULT_READ_AHEAD_SIZE, INSTANCE))) {
        long range = -1;
        int tokenId = -1;
        long flush = 0;
        // noinspection InfiniteLoopStatement
        while (true) {
            byte type = channel.get();
            switch(type) {
                case TYPE_RANGE:
                    range = channel.getLong();
                    tokenId = channel.getInt();
                    if (txFilter != null) {
                        txFilter.clear();
                    }
                    break;
                case TYPE_PREPARE_ADD:
                case TYPE_PREPARE_REMOVE:
                    dumpPrepare(dumper, type, channel, range, tokenId, txFilter, session, flush);
                    break;
                case TYPE_MERGE_ADD:
                case TYPE_MERGE_REMOVE:
                    dumpMerge(dumper, type, channel, range, tokenId, txFilter, session, flush);
                    break;
                case TYPE_FLUSH:
                    flush++;
                    break;
                case TYPE_SESSION_END:
                    session++;
                    flush = 0;
                    break;
                default:
                    System.out.println("Unknown type " + type + " at " + ((ReadAheadChannel) channel).position());
                    break;
            }
        }
    } catch (ReadPastEndException e) {
    // This is OK. we're done with this file
    }
    return session;
}
Also used : ReadableChannel(org.neo4j.io.fs.ReadableChannel) NativeScopedBuffer(org.neo4j.io.memory.NativeScopedBuffer) ReadAheadChannel(org.neo4j.io.fs.ReadAheadChannel) ReadPastEndException(org.neo4j.io.fs.ReadPastEndException)

Example 3 with NativeScopedBuffer

use of org.neo4j.io.memory.NativeScopedBuffer in project neo4j by neo4j.

the class LoggingIndexedIdGeneratorMonitor method dumpFile.

private static void dumpFile(FileSystemAbstraction fs, Path path, Dumper dumper) throws IOException {
    dumper.path(path);
    try (var channel = new ReadAheadChannel<>(fs.read(path), new NativeScopedBuffer(DEFAULT_READ_AHEAD_SIZE, INSTANCE))) {
        while (true) {
            byte typeByte = channel.get();
            if (typeByte < 0 || typeByte >= TYPES.length) {
                System.out.println("Unknown type " + typeByte + " at " + channel.position());
                continue;
            }
            Type type = TYPES[typeByte];
            long time = channel.getLong();
            switch(type) {
                case CLEARING_CACHE:
                case CLEARED_CACHE:
                case CLOSED:
                    dumper.type(type, time);
                    break;
                case ALLOCATE_HIGH:
                case ALLOCATE_REUSED:
                case CACHED:
                case MARK_USED:
                case MARK_DELETED:
                case MARK_FREE:
                case MARK_RESERVED:
                case MARK_UNRESERVED:
                case MARK_DELETED_AND_FREE:
                case NORMALIZED:
                case BRIDGED:
                    dumper.typeAndId(type, time, channel.getLong());
                    break;
                case OPENED:
                case CHECKPOINT:
                    dumper.typeAndTwoIds(type, time, channel.getLong(), channel.getLong());
                    break;
                default:
                    System.out.println("Unknown type " + type + " at " + channel.position());
                    break;
            }
        }
    } catch (ReadPastEndException e) {
    // This is OK. we're done with this file
    }
}
Also used : NativeScopedBuffer(org.neo4j.io.memory.NativeScopedBuffer) ReadAheadChannel(org.neo4j.io.fs.ReadAheadChannel) ReadPastEndException(org.neo4j.io.fs.ReadPastEndException)

Example 4 with NativeScopedBuffer

use of org.neo4j.io.memory.NativeScopedBuffer in project neo4j by neo4j.

the class TransactionLogFile method start.

@Override
public void start() throws IOException {
    long currentLogVersion = logVersionRepository.getCurrentLogVersion();
    channel = createLogChannelForVersion(currentLogVersion, context::getLastCommittedTransactionId);
    context.getMonitors().newMonitor(LogRotationMonitor.class).started(channel.getPath(), currentLogVersion);
    // try to set position
    seekChannelPosition(currentLogVersion);
    writer = new PositionAwarePhysicalFlushableChecksumChannel(channel, new NativeScopedBuffer(calculateLogBufferSize(), memoryTracker));
    transactionLogWriter = new TransactionLogWriter(writer, new DbmsLogEntryWriterFactory(context.getKernelVersionProvider()));
}
Also used : LogRotationMonitor(org.neo4j.kernel.impl.transaction.log.rotation.monitor.LogRotationMonitor) PositionAwarePhysicalFlushableChecksumChannel(org.neo4j.kernel.impl.transaction.log.PositionAwarePhysicalFlushableChecksumChannel) DbmsLogEntryWriterFactory(org.neo4j.kernel.database.DbmsLogEntryWriterFactory) TransactionLogWriter(org.neo4j.kernel.impl.transaction.log.TransactionLogWriter) NativeScopedBuffer(org.neo4j.io.memory.NativeScopedBuffer)

Example 5 with NativeScopedBuffer

use of org.neo4j.io.memory.NativeScopedBuffer in project neo4j by neo4j.

the class DetachedCheckpointAppender method start.

@Override
public void start() throws IOException {
    this.storeId = context.getStoreId();
    logVersionRepository = requireNonNull(context.getLogVersionRepository());
    long initialVersion = logVersionRepository.getCheckpointLogVersion();
    channel = channelAllocator.createLogChannel(initialVersion, context::getLastCommittedTransactionId);
    context.getMonitors().newMonitor(LogRotationMonitor.class).started(channel.getPath(), initialVersion);
    channel.position(channel.size());
    buffer = new NativeScopedBuffer(kibiBytes(1), context.getMemoryTracker());
    writer = new PositionAwarePhysicalFlushableChecksumChannel(channel, buffer);
    checkpointWriter = new DetachedCheckpointLogEntryWriter(writer);
}
Also used : LogRotationMonitor(org.neo4j.kernel.impl.transaction.log.rotation.monitor.LogRotationMonitor) PositionAwarePhysicalFlushableChecksumChannel(org.neo4j.kernel.impl.transaction.log.PositionAwarePhysicalFlushableChecksumChannel) NativeScopedBuffer(org.neo4j.io.memory.NativeScopedBuffer) DetachedCheckpointLogEntryWriter(org.neo4j.kernel.impl.transaction.log.entry.DetachedCheckpointLogEntryWriter)

Aggregations

NativeScopedBuffer (org.neo4j.io.memory.NativeScopedBuffer)7 ReadAheadChannel (org.neo4j.io.fs.ReadAheadChannel)2 ReadPastEndException (org.neo4j.io.fs.ReadPastEndException)2 PositionAwarePhysicalFlushableChecksumChannel (org.neo4j.kernel.impl.transaction.log.PositionAwarePhysicalFlushableChecksumChannel)2 LogRotationMonitor (org.neo4j.kernel.impl.transaction.log.rotation.monitor.LogRotationMonitor)2 ByteBuffer (java.nio.ByteBuffer)1 NoSuchFileException (java.nio.file.NoSuchFileException)1 Path (java.nio.file.Path)1 Test (org.junit.jupiter.api.Test)1 NativeMemoryAllocationRefusedError (org.neo4j.internal.unsafe.NativeMemoryAllocationRefusedError)1 ReadableChannel (org.neo4j.io.fs.ReadableChannel)1 StoreChannel (org.neo4j.io.fs.StoreChannel)1 HeapScopedBuffer (org.neo4j.io.memory.HeapScopedBuffer)1 DbmsLogEntryWriterFactory (org.neo4j.kernel.database.DbmsLogEntryWriterFactory)1 PhysicalLogVersionedStoreChannel (org.neo4j.kernel.impl.transaction.log.PhysicalLogVersionedStoreChannel)1 TransactionLogWriter (org.neo4j.kernel.impl.transaction.log.TransactionLogWriter)1 DetachedCheckpointLogEntryWriter (org.neo4j.kernel.impl.transaction.log.entry.DetachedCheckpointLogEntryWriter)1 LogFile (org.neo4j.kernel.impl.transaction.log.files.LogFile)1