Search in sources :

Example 1 with EndOfStreamException

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;
}
Also used : EndOfStreamException(org.neo4j.causalclustering.messaging.EndOfStreamException) EntryRecord(org.neo4j.causalclustering.core.consensus.log.EntryRecord) IOException(java.io.IOException)

Example 2 with EndOfStreamException

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;
    }
}
Also used : EndOfStreamException(org.neo4j.causalclustering.messaging.EndOfStreamException) IOException(java.io.IOException) LogPosition(org.neo4j.causalclustering.core.consensus.log.LogPosition)

Example 3 with EndOfStreamException

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);
    }
}
Also used : EndOfStreamException(org.neo4j.causalclustering.messaging.EndOfStreamException) ReplicatedContent(org.neo4j.causalclustering.core.replication.ReplicatedContent) ReadPastEndException(org.neo4j.storageengine.api.ReadPastEndException)

Example 4 with EndOfStreamException

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
    }
}
Also used : MemberId(org.neo4j.causalclustering.identity.MemberId) EndOfStreamException(org.neo4j.causalclustering.messaging.EndOfStreamException) NetworkFlushableChannelNetty4(org.neo4j.causalclustering.messaging.NetworkFlushableChannelNetty4) ByteBuf(io.netty.buffer.ByteBuf) NetworkReadableClosableChannelNetty4(org.neo4j.causalclustering.messaging.NetworkReadableClosableChannelNetty4) Test(org.junit.Test)

Example 5 with EndOfStreamException

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
    }
}
Also used : EndOfStreamException(org.neo4j.causalclustering.messaging.EndOfStreamException) InMemoryVersionableReadableClosablePositionAwareChannel(org.neo4j.kernel.impl.transaction.log.InMemoryVersionableReadableClosablePositionAwareChannel) Test(org.junit.Test)

Aggregations

EndOfStreamException (org.neo4j.causalclustering.messaging.EndOfStreamException)8 Test (org.junit.Test)3 IOException (java.io.IOException)2 EntryRecord (org.neo4j.causalclustering.core.consensus.log.EntryRecord)2 ByteBuf (io.netty.buffer.ByteBuf)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 SortedMap (java.util.SortedMap)1 LogPosition (org.neo4j.causalclustering.core.consensus.log.LogPosition)1 ReplicatedContent (org.neo4j.causalclustering.core.replication.ReplicatedContent)1 MemberId (org.neo4j.causalclustering.identity.MemberId)1 NetworkFlushableChannelNetty4 (org.neo4j.causalclustering.messaging.NetworkFlushableChannelNetty4)1 NetworkReadableClosableChannelNetty4 (org.neo4j.causalclustering.messaging.NetworkReadableClosableChannelNetty4)1 InMemoryClosableChannel (org.neo4j.kernel.impl.transaction.log.InMemoryClosableChannel)1 InMemoryVersionableReadableClosablePositionAwareChannel (org.neo4j.kernel.impl.transaction.log.InMemoryVersionableReadableClosablePositionAwareChannel)1 ReadAheadChannel (org.neo4j.kernel.impl.transaction.log.ReadAheadChannel)1 ReadableClosableChannel (org.neo4j.kernel.impl.transaction.log.ReadableClosableChannel)1 ReadPastEndException (org.neo4j.storageengine.api.ReadPastEndException)1