use of org.neo4j.causalclustering.messaging.EndOfStreamException in project neo4j by neo4j.
the class EntryRecordCursor method next.
@Override
public boolean next() throws IOException {
EntryRecord entryRecord;
try {
entryRecord = read(bufferedReader, contentMarshal);
} catch (EndOfStreamException e) {
currentRecord.invalidate();
return false;
} catch (IOException e) {
hadError = true;
throw e;
}
currentRecord.set(entryRecord);
position.byteOffset = bufferedReader.position();
position.logIndex++;
return true;
}
use of org.neo4j.causalclustering.messaging.EndOfStreamException in project neo4j by neo4j.
the class SegmentFile method getCursor.
/**
* Channels must be closed when no longer used, so that they are released back to the pool of readers.
*/
IOCursor<EntryRecord> getCursor(long logIndex) throws IOException, DisposedException {
assert logIndex > header.prevIndex();
if (!refCount.increase()) {
throw new DisposedException();
}
/* This is the relative index within the file, starting from zero. */
long offsetIndex = logIndex - (header.prevIndex() + 1);
LogPosition position = positionCache.lookup(offsetIndex);
Reader reader = readerPool.acquire(version, position.byteOffset);
try {
long currentIndex = position.logIndex;
return new EntryRecordCursor(reader, contentMarshal, currentIndex, offsetIndex, this);
} catch (EndOfStreamException e) {
readerPool.release(reader);
refCount.decrease();
return IOCursor.getEmpty();
} catch (IOException e) {
reader.close();
refCount.decrease();
throw e;
}
}
use of org.neo4j.causalclustering.messaging.EndOfStreamException 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.causalclustering.messaging.EndOfStreamException in project neo4j by neo4j.
the class MemberIdMarshalTest method shouldThrowExceptionForHalfWrittenInstance.
@Test
public void shouldThrowExceptionForHalfWrittenInstance() throws Exception {
// given
// a CoreMember and a ByteBuffer to write it to
MemberId.Marshal marshal = new MemberId.Marshal();
final MemberId aRealMember = new MemberId(UUID.randomUUID());
ByteBuf buffer = Unpooled.buffer(1000);
// and the CoreMember is serialized but for 5 bytes at the end
marshal.marshal(aRealMember, new NetworkFlushableChannelNetty4(buffer));
ByteBuf bufferWithMissingBytes = buffer.copy(0, buffer.writerIndex() - 5);
// when
try {
marshal.unmarshal(new NetworkReadableClosableChannelNetty4(bufferWithMissingBytes));
fail("Should have thrown exception");
} catch (EndOfStreamException e) {
// expected
}
}
use of org.neo4j.causalclustering.messaging.EndOfStreamException in project neo4j by neo4j.
the class IdAllocationStateTest method shouldThrowExceptionForHalfWrittenEntries.
@Test
public void shouldThrowExceptionForHalfWrittenEntries() throws IOException, EndOfStreamException {
// given
final IdAllocationState state = new IdAllocationState();
for (int i = 1; i <= 3; i++) {
state.firstUnallocated(IdType.NODE, 1024 * i);
state.logIndex(i);
}
final IdAllocationState.Marshal marshal = new IdAllocationState.Marshal();
// when
InMemoryVersionableReadableClosablePositionAwareChannel channel = new InMemoryVersionableReadableClosablePositionAwareChannel();
marshal.marshal(state, channel);
// append some garbage
channel.putInt(1).putInt(2).putInt(3).putLong(4L);
// read back in the first one
marshal.unmarshal(channel);
// the second one will be half read (the ints and longs appended above).
try {
marshal.unmarshal(channel);
fail();
} catch (EndOfStreamException e) {
// expected
}
}
Aggregations