Search in sources :

Example 1 with ReadAheadChannel

use of org.neo4j.io.fs.ReadAheadChannel 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 2 with ReadAheadChannel

use of org.neo4j.io.fs.ReadAheadChannel in project neo4j by neo4j.

the class SimpleEntryStorage method reader.

CURSOR reader() throws IOException {
    if (!allocated) {
        return reader(new ByteArrayPageCursor(NO_ENTRIES));
    }
    // Reuse the existing buffer because we're not writing while reading anyway
    ReadAheadChannel<StoreChannel> channel = new ReadAheadChannel<>(fs.read(file), byteBufferFactory.allocate(blockSize, memoryTracker));
    PageCursor pageCursor = new ReadableChannelPageCursor(channel);
    return reader(pageCursor);
}
Also used : StoreChannel(org.neo4j.io.fs.StoreChannel) ByteArrayPageCursor(org.neo4j.io.pagecache.ByteArrayPageCursor) ReadAheadChannel(org.neo4j.io.fs.ReadAheadChannel) PageCursor(org.neo4j.io.pagecache.PageCursor) ByteArrayPageCursor(org.neo4j.io.pagecache.ByteArrayPageCursor)

Example 3 with ReadAheadChannel

use of org.neo4j.io.fs.ReadAheadChannel 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)

Aggregations

ReadAheadChannel (org.neo4j.io.fs.ReadAheadChannel)3 ReadPastEndException (org.neo4j.io.fs.ReadPastEndException)2 NativeScopedBuffer (org.neo4j.io.memory.NativeScopedBuffer)2 ReadableChannel (org.neo4j.io.fs.ReadableChannel)1 StoreChannel (org.neo4j.io.fs.StoreChannel)1 ByteArrayPageCursor (org.neo4j.io.pagecache.ByteArrayPageCursor)1 PageCursor (org.neo4j.io.pagecache.PageCursor)1