Search in sources :

Example 1 with RemoveReader

use of io.pravega.client.stream.impl.ReaderGroupState.RemoveReader in project pravega by pravega.

the class ReaderGroupStateManager method readerShutdown.

/**
 * Shuts down a reader, releasing all of its segments. The reader should cease all operations.
 * @param lastPosition The last position the reader successfully read from.
 */
static void readerShutdown(String readerId, Position lastPosition, StateSynchronizer<ReaderGroupState> sync) {
    sync.fetchUpdates();
    sync.updateState((state, updates) -> {
        Set<Segment> segments = state.getSegments(readerId);
        if (segments == null) {
            return;
        }
        log.debug("Removing reader {} from reader group. CurrentState is: {}. Position is: {}.", readerId, state, lastPosition);
        updates.add(new RemoveReader(readerId, lastPosition == null ? Collections.emptyMap() : lastPosition.asImpl().getOwnedSegmentsWithOffsets()));
    });
}
Also used : RemoveReader(io.pravega.client.stream.impl.ReaderGroupState.RemoveReader) ReleaseSegment(io.pravega.client.stream.impl.ReaderGroupState.ReleaseSegment) Segment(io.pravega.client.segment.impl.Segment) AcquireSegment(io.pravega.client.stream.impl.ReaderGroupState.AcquireSegment)

Example 2 with RemoveReader

use of io.pravega.client.stream.impl.ReaderGroupState.RemoveReader in project pravega by pravega.

the class SerializationTest method testReaderGroupUpdates.

@Test
public void testReaderGroupUpdates() throws Exception {
    ReaderGroupUpdateSerializer serializer = new ReaderGroupUpdateSerializer();
    verify(serializer, new AddReader(createString()));
    verify(serializer, new RemoveReader(createString(), createSegmentToLongMap()));
    verify(serializer, new ReleaseSegment(createString(), createSegment(), r.nextLong()));
    verify(serializer, new AcquireSegment(createString(), createSegment()));
    verify(serializer, new UpdateDistanceToTail(createString(), r.nextLong(), createSegmentRangeMap()));
    verify(serializer, new SegmentCompleted(createString(), createSegmentWithRange(), createMap(this::createSegmentWithRange, this::createLongList)));
    verify(serializer, new CheckpointReader(createString(), createString(), createSegmentToLongMap()));
    verify(serializer, new CreateCheckpoint(createString()));
    verify(serializer, new ClearCheckpointsBefore(createString()));
    verify(serializer, new UpdatingConfig(r.nextBoolean()));
}
Also used : ReleaseSegment(io.pravega.client.stream.impl.ReaderGroupState.ReleaseSegment) ReaderGroupUpdateSerializer(io.pravega.client.stream.impl.ReaderGroupState.ReaderGroupUpdateSerializer) AcquireSegment(io.pravega.client.stream.impl.ReaderGroupState.AcquireSegment) UpdateDistanceToTail(io.pravega.client.stream.impl.ReaderGroupState.UpdateDistanceToTail) CreateCheckpoint(io.pravega.client.stream.impl.ReaderGroupState.CreateCheckpoint) CheckpointReader(io.pravega.client.stream.impl.ReaderGroupState.CheckpointReader) ClearCheckpointsBefore(io.pravega.client.stream.impl.ReaderGroupState.ClearCheckpointsBefore) RemoveReader(io.pravega.client.stream.impl.ReaderGroupState.RemoveReader) AddReader(io.pravega.client.stream.impl.ReaderGroupState.AddReader) UpdatingConfig(io.pravega.client.stream.impl.ReaderGroupState.UpdatingConfig) SegmentCompleted(io.pravega.client.stream.impl.ReaderGroupState.SegmentCompleted) Test(org.junit.Test)

Aggregations

AcquireSegment (io.pravega.client.stream.impl.ReaderGroupState.AcquireSegment)2 ReleaseSegment (io.pravega.client.stream.impl.ReaderGroupState.ReleaseSegment)2 RemoveReader (io.pravega.client.stream.impl.ReaderGroupState.RemoveReader)2 Segment (io.pravega.client.segment.impl.Segment)1 AddReader (io.pravega.client.stream.impl.ReaderGroupState.AddReader)1 CheckpointReader (io.pravega.client.stream.impl.ReaderGroupState.CheckpointReader)1 ClearCheckpointsBefore (io.pravega.client.stream.impl.ReaderGroupState.ClearCheckpointsBefore)1 CreateCheckpoint (io.pravega.client.stream.impl.ReaderGroupState.CreateCheckpoint)1 ReaderGroupUpdateSerializer (io.pravega.client.stream.impl.ReaderGroupState.ReaderGroupUpdateSerializer)1 SegmentCompleted (io.pravega.client.stream.impl.ReaderGroupState.SegmentCompleted)1 UpdateDistanceToTail (io.pravega.client.stream.impl.ReaderGroupState.UpdateDistanceToTail)1 UpdatingConfig (io.pravega.client.stream.impl.ReaderGroupState.UpdatingConfig)1 Test (org.junit.Test)1