Search in sources :

Example 1 with ReadableChannel

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

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

the class PhysicalLogCommandReadersTest method channelWithRelGroupRecord.

private static ReadableChannel channelWithRelGroupRecord(long id, byte inUse, short type, long next, long firstOut, long firstIn, long firstLoop, long owningNode) throws IOException {
    ReadableChannel channel = mock(ReadableChannel.class);
    when(channel.get()).thenReturn(NeoCommandType.REL_GROUP_COMMAND).thenReturn(inUse);
    when(channel.getLong()).thenReturn(id).thenReturn(next).thenReturn(firstOut).thenReturn(firstIn).thenReturn(firstLoop).thenReturn(owningNode);
    when(channel.getShort()).thenReturn(type);
    return channel;
}
Also used : ReadableChannel(org.neo4j.io.fs.ReadableChannel)

Example 3 with ReadableChannel

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

the class TransactionLogFileTest method shouldReadOlderLogs.

@Test
void shouldReadOlderLogs() throws Exception {
    // GIVEN
    LogFiles logFiles = buildLogFiles();
    life.start();
    life.add(logFiles);
    // WHEN
    LogFile logFile = logFiles.getLogFile();
    TransactionLogWriter logWriter = logFile.getTransactionLogWriter();
    var writer = logWriter.getChannel();
    LogPosition position1 = logWriter.getCurrentPosition();
    int intValue = 45;
    long longValue = 4854587;
    byte[] someBytes = someBytes(40);
    writer.putInt(intValue);
    writer.putLong(longValue);
    writer.put(someBytes, someBytes.length);
    logFile.flush();
    LogPosition position2 = logWriter.getCurrentPosition();
    long longValue2 = 123456789L;
    writer.putLong(longValue2);
    writer.put(someBytes, someBytes.length);
    logFile.flush();
    // THEN
    try (ReadableChannel reader = logFile.getReader(position1)) {
        assertEquals(intValue, reader.getInt());
        assertEquals(longValue, reader.getLong());
        assertArrayEquals(someBytes, readBytes(reader, 40));
    }
    try (ReadableChannel reader = logFile.getReader(position2)) {
        assertEquals(longValue2, reader.getLong());
        assertArrayEquals(someBytes, readBytes(reader, 40));
    }
}
Also used : LogFile(org.neo4j.kernel.impl.transaction.log.files.LogFile) ReadableChannel(org.neo4j.io.fs.ReadableChannel) LogFiles(org.neo4j.kernel.impl.transaction.log.files.LogFiles) Test(org.junit.jupiter.api.Test)

Example 4 with ReadableChannel

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

the class TransactionLogFileTest method shouldWriteSomeDataIntoTheLog.

@Test
void shouldWriteSomeDataIntoTheLog() throws Exception {
    // GIVEN
    LogFiles logFiles = buildLogFiles();
    life.start();
    life.add(logFiles);
    // WHEN
    LogFile logFile = logFiles.getLogFile();
    TransactionLogWriter transactionLogWriter = logFile.getTransactionLogWriter();
    var channel = transactionLogWriter.getChannel();
    LogPosition currentPosition = transactionLogWriter.getCurrentPosition();
    int intValue = 45;
    long longValue = 4854587;
    channel.putInt(intValue);
    channel.putLong(longValue);
    logFile.flush();
    // THEN
    try (ReadableChannel reader = logFile.getReader(currentPosition)) {
        assertEquals(intValue, reader.getInt());
        assertEquals(longValue, reader.getLong());
    }
}
Also used : LogFile(org.neo4j.kernel.impl.transaction.log.files.LogFile) ReadableChannel(org.neo4j.io.fs.ReadableChannel) LogFiles(org.neo4j.kernel.impl.transaction.log.files.LogFiles) Test(org.junit.jupiter.api.Test)

Aggregations

ReadableChannel (org.neo4j.io.fs.ReadableChannel)4 Test (org.junit.jupiter.api.Test)2 LogFile (org.neo4j.kernel.impl.transaction.log.files.LogFile)2 LogFiles (org.neo4j.kernel.impl.transaction.log.files.LogFiles)2 ReadAheadChannel (org.neo4j.io.fs.ReadAheadChannel)1 ReadPastEndException (org.neo4j.io.fs.ReadPastEndException)1 NativeScopedBuffer (org.neo4j.io.memory.NativeScopedBuffer)1