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;
}
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;
}
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));
}
}
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());
}
}
Aggregations