use of org.neo4j.storageengine.api.ReadPastEndException in project neo4j by neo4j.
the class VersionAwareLogEntryReader method readLogEntry.
@Override
public LogEntry readLogEntry(SOURCE channel) throws IOException {
try {
LogPositionMarker positionMarker = new LogPositionMarker();
channel.getCurrentPosition(positionMarker);
while (true) {
LogEntryVersion version = null;
LogEntryParser<LogEntry> entryReader;
try {
/*
* if the read type is negative than it is actually the log entry version
* so we need to read an extra byte which will contain the type
*/
byte typeCode = channel.get();
byte versionCode = 0;
if (typeCode < 0) {
versionCode = typeCode;
typeCode = channel.get();
}
version = byVersion(versionCode);
entryReader = version.entryParser(typeCode);
} 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();
e = withMessage(e, e.getMessage() + ". At position " + position + " and entry version " + version);
throw launderedException(IOException.class, e);
}
LogEntry entry = entryReader.parse(version, channel, positionMarker, commandReaderFactory);
if (!entryReader.skip()) {
return entry;
}
}
} catch (ReadPastEndException e) {
return null;
}
}
use of org.neo4j.storageengine.api.ReadPastEndException in project neo4j by neo4j.
the class EntryRecord method read.
public static EntryRecord read(ReadableChannel channel, ChannelMarshal<ReplicatedContent> contentMarshal) throws IOException, EndOfStreamException {
try {
long appendIndex = channel.getLong();
long term = channel.getLong();
ReplicatedContent content = contentMarshal.unmarshal(channel);
return new EntryRecord(appendIndex, new RaftLogEntry(term, content));
} catch (ReadPastEndException e) {
throw new EndOfStreamException(e);
}
}
use of org.neo4j.storageengine.api.ReadPastEndException in project neo4j by neo4j.
the class ReadAheadChannelTest method shouldThrowExceptionForReadAfterEOFIfNotEnoughBytesExist.
@Test
public void shouldThrowExceptionForReadAfterEOFIfNotEnoughBytesExist() throws Exception {
// Given
FileSystemAbstraction fileSystem = fileSystemRule.get();
StoreChannel storeChannel = fileSystem.open(new File("foo.txt"), "rw");
ByteBuffer buffer = ByteBuffer.allocate(1);
buffer.put((byte) 1);
buffer.flip();
storeChannel.writeAll(buffer);
storeChannel.force(false);
storeChannel.close();
storeChannel = fileSystem.open(new File("foo.txt"), "r");
ReadAheadChannel<StoreChannel> channel = new ReadAheadChannel<>(storeChannel);
assertEquals((byte) 1, channel.get());
try {
channel.get();
fail("Should have thrown exception signalling end of file reached");
} catch (ReadPastEndException endOfFile) {
// outstanding
}
try {
channel.get();
fail("Should have thrown exception signalling end of file reached");
} catch (ReadPastEndException endOfFile) {
// outstanding
}
}
use of org.neo4j.storageengine.api.ReadPastEndException in project neo4j by neo4j.
the class ReadAheadChannelTest method shouldReturnValueIfSufficientBytesAreBufferedEvenIfEOFHasBeenEncountered.
@Test
public void shouldReturnValueIfSufficientBytesAreBufferedEvenIfEOFHasBeenEncountered() throws Exception {
// Given
FileSystemAbstraction fileSystem = fileSystemRule.get();
StoreChannel storeChannel = fileSystem.open(new File("foo.txt"), "rw");
ByteBuffer buffer = ByteBuffer.allocate(1);
buffer.put((byte) 1);
buffer.flip();
storeChannel.writeAll(buffer);
storeChannel.force(false);
storeChannel.close();
storeChannel = fileSystem.open(new File("foo.txt"), "r");
ReadAheadChannel<StoreChannel> channel = new ReadAheadChannel<>(storeChannel);
try {
channel.getShort();
fail("Should have thrown exception signalling end of file reached");
} catch (ReadPastEndException endOfFile) {
// outstanding
}
assertEquals((byte) 1, channel.get());
try {
channel.get();
fail("Should have thrown exception signalling end of file reached");
} catch (ReadPastEndException endOfFile) {
// outstanding
}
}
use of org.neo4j.storageengine.api.ReadPastEndException in project neo4j by neo4j.
the class ReadAheadChannelTest method shouldHandleRunningOutOfBytesWhenRequestSpansMultipleFiles.
@Test
public void shouldHandleRunningOutOfBytesWhenRequestSpansMultipleFiles() throws Exception {
// Given
FileSystemAbstraction fileSystem = fileSystemRule.get();
StoreChannel storeChannel1 = fileSystem.open(new File("foo.1"), "rw");
ByteBuffer buffer = ByteBuffer.allocate(2);
buffer.put((byte) 0);
buffer.put((byte) 0);
buffer.flip();
storeChannel1.writeAll(buffer);
storeChannel1.force(false);
storeChannel1.close();
buffer.flip();
StoreChannel storeChannel2 = fileSystem.open(new File("foo.2"), "r");
buffer.put((byte) 0);
buffer.put((byte) 1);
buffer.flip();
storeChannel2.writeAll(buffer);
storeChannel2.force(false);
storeChannel2.close();
storeChannel1 = fileSystem.open(new File("foo.1"), "r");
final StoreChannel storeChannel2Copy = fileSystem.open(new File("foo.2"), "r");
ReadAheadChannel<StoreChannel> channel = new ReadAheadChannel<StoreChannel>(storeChannel1) {
@Override
protected StoreChannel next(StoreChannel channel) throws IOException {
return storeChannel2Copy;
}
};
try {
channel.getLong();
fail("Should have thrown exception signalling end of file reached");
} catch (ReadPastEndException endOfFile) {
// outstanding
}
assertEquals(1, channel.getInt());
try {
channel.get();
fail("Should have thrown exception signalling end of file reached");
} catch (ReadPastEndException endOfFile) {
// outstanding
}
}
Aggregations