use of org.neo4j.io.fs.ReadPastEndException in project neo4j by neo4j.
the class LogTruncationTest method assertHandlesLogTruncation.
private void assertHandlesLogTruncation(Command cmd) throws IOException {
inMemoryChannel.reset();
cmd.serialize(inMemoryChannel);
int bytesSuccessfullyWritten = inMemoryChannel.writerPosition();
try {
StorageCommand command = serialization.read(inMemoryChannel);
assertEquals(cmd, command);
} catch (Exception e) {
throw new AssertionError("Failed to deserialize " + cmd + ", because: ", e);
}
bytesSuccessfullyWritten--;
while (bytesSuccessfullyWritten-- > 0) {
inMemoryChannel.reset();
cmd.serialize(inMemoryChannel);
inMemoryChannel.truncateTo(bytesSuccessfullyWritten);
Command command = null;
try {
command = serialization.read(inMemoryChannel);
} catch (ReadPastEndException e) {
assertNull(command, "Deserialization did not detect log truncation!" + "Record: " + cmd + ", deserialized: " + command);
}
}
}
use of org.neo4j.io.fs.ReadPastEndException 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.ReadPastEndException in project neo4j by neo4j.
the class VersionAwareLogEntryReader method readLogEntry.
@Override
public LogEntry readLogEntry(ReadableClosablePositionAwareChecksumChannel channel) throws IOException {
try {
while (true) {
channel.getCurrentPosition(positionMarker);
byte versionCode = channel.get();
if (versionCode == 0) {
// and we report that we reach end of record stream from our point of view
if (channel instanceof PositionableChannel) {
resetChannelPosition(channel);
} else {
throw new IllegalStateException("Log reader expects positionable channel to be able to reset offset. Current channel: " + channel);
}
return null;
}
if (parserSet == null || parserSet.getIntroductionVersion().version() != versionCode) {
try {
parserSet = LogEntryParserSets.parserSet(KernelVersion.getForVersion(versionCode));
} catch (IllegalArgumentException e) {
throw new UnsupportedLogVersionException(String.format("Log file contains entries with prefix %d, and the lowest supported prefix is %s. This " + "indicates that the log files originates from an older version of neo4j, which we don't support " + "migrations from.", versionCode, KernelVersion.V2_3));
}
// a new checksum segment if we change version parser.
if (channel instanceof PositionableChannel) {
resetChannelPosition(channel);
channel.beginChecksum();
channel.get();
}
}
byte typeCode = channel.get();
LogEntryParser entryReader;
LogEntry entry;
try {
entryReader = parserSet.select(typeCode);
entry = entryReader.parse(parserSet.getIntroductionVersion(), channel, positionMarker, commandReaderFactory);
} catch (ReadPastEndException e) {
// Make these exceptions slip by straight out to the outer handler
throw e;
} catch (Exception e) {
// Tag all other exceptions with log position and other useful information
LogPosition position = positionMarker.newPosition();
withMessage(e, e.getMessage() + ". At position " + position + " and entry version " + versionCode);
throwIfInstanceOf(e, UnsupportedLogVersionException.class);
throw new IOException(e);
}
verifyChecksumChain(entry);
return entry;
}
} catch (ReadPastEndException e) {
return null;
}
}
use of org.neo4j.io.fs.ReadPastEndException 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.fs.ReadPastEndException in project neo4j by neo4j.
the class TransactionRecordStateTest method readFromChannel.
@SuppressWarnings("InfiniteLoopStatement")
private static CommandsToApply readFromChannel(ReadableLogChannel channel) throws IOException {
CommandReader reader = LogCommandSerializationV4_0.INSTANCE;
List<StorageCommand> commands = new ArrayList<>();
try {
while (true) {
commands.add(reader.read(channel));
}
} catch (ReadPastEndException e) {
// reached the end
}
return new GroupOfCommands(commands.toArray(new StorageCommand[0]));
}
Aggregations