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