Search in sources :

Example 6 with StreamCut

use of io.pravega.client.stream.StreamCut in project pravega by pravega.

the class ReaderGroupImpl method getUnreadBytes.

private long getUnreadBytes(Map<Stream, Map<Segment, Long>> positions, SegmentMetadataClientFactory metaFactory) {
    log.debug("Compute unread bytes from position {}", positions);
    long totalLength = 0;
    for (Entry<Stream, Map<Segment, Long>> streamPosition : positions.entrySet()) {
        StreamCut position = new StreamCutImpl(streamPosition.getKey(), streamPosition.getValue());
        totalLength += getRemainingBytes(metaFactory, position);
    }
    return totalLength;
}
Also used : StreamCut(io.pravega.client.stream.StreamCut) Stream(io.pravega.client.stream.Stream) Map(java.util.Map) HashMap(java.util.HashMap)

Example 7 with StreamCut

use of io.pravega.client.stream.StreamCut in project pravega by pravega.

the class ReaderGroupImpl method getStreamCuts.

@Override
public Map<Stream, StreamCut> getStreamCuts() {
    @Cleanup StateSynchronizer<ReaderGroupState> synchronizer = createSynchronizer();
    synchronizer.fetchUpdates();
    ReaderGroupState state = synchronizer.getState();
    Map<Stream, Map<Segment, Long>> positions = state.getPositions();
    HashMap<Stream, StreamCut> cuts = new HashMap<>();
    for (Entry<Stream, Map<Segment, Long>> streamPosition : positions.entrySet()) {
        StreamCut position = new StreamCutImpl(streamPosition.getKey(), streamPosition.getValue());
        cuts.put(streamPosition.getKey(), position);
    }
    return cuts;
}
Also used : StreamCut(io.pravega.client.stream.StreamCut) HashMap(java.util.HashMap) Stream(io.pravega.client.stream.Stream) Cleanup(lombok.Cleanup) Map(java.util.Map) HashMap(java.util.HashMap)

Example 8 with StreamCut

use of io.pravega.client.stream.StreamCut in project pravega by pravega.

the class ReaderGroupImpl method resetReadersToCheckpoint.

@SuppressWarnings("deprecation")
@Override
public void resetReadersToCheckpoint(Checkpoint checkpoint) {
    @Cleanup StateSynchronizer<ReaderGroupState> synchronizer = createSynchronizer();
    synchronizer.updateState(state -> {
        ReaderGroupConfig config = state.getConfig();
        Map<Segment, Long> positions = new HashMap<>();
        for (StreamCut cut : checkpoint.asImpl().getPositions().values()) {
            positions.putAll(cut.asImpl().getPositions());
        }
        return Collections.singletonList(new ReaderGroupStateInit(config, positions));
    });
}
Also used : ReaderGroupConfig(io.pravega.client.stream.ReaderGroupConfig) ReaderGroupStateInit(io.pravega.client.stream.impl.ReaderGroupState.ReaderGroupStateInit) StreamCut(io.pravega.client.stream.StreamCut) HashMap(java.util.HashMap) Cleanup(lombok.Cleanup) Segment(io.pravega.client.segment.impl.Segment)

Example 9 with StreamCut

use of io.pravega.client.stream.StreamCut in project pravega by pravega.

the class ControllerImplTest method testCutpointSuccessors.

@Test
public void testCutpointSuccessors() throws Exception {
    String scope = "scope1";
    String stream = "stream1";
    Stream s = new StreamImpl(scope, stream);
    Map<Segment, Long> segments = new HashMap<>();
    segments.put(new Segment(scope, stream, 0), 4L);
    segments.put(new Segment(scope, stream, 1), 6L);
    StreamCut cut = new StreamCutImpl(s, segments);
    Set<Segment> successors = controllerClient.getSuccessors(cut).get().getSegments();
    assertEquals(ImmutableSet.of(new Segment(scope, stream, 0), new Segment(scope, stream, 1), new Segment(scope, stream, 2), new Segment(scope, stream, 3), new Segment(scope, stream, 4), new Segment(scope, stream, 5), new Segment(scope, stream, 6), new Segment(scope, stream, 7)), successors);
}
Also used : StreamCut(io.pravega.client.stream.StreamCut) HashMap(java.util.HashMap) Stream(io.pravega.client.stream.Stream) Segment(io.pravega.client.segment.impl.Segment) Test(org.junit.Test)

Example 10 with StreamCut

use of io.pravega.client.stream.StreamCut in project pravega by pravega.

the class ControllerImplTest method testGetSegmentsWithValidStreamCuts.

@Test
public void testGetSegmentsWithValidStreamCuts() throws Exception {
    String scope = "scope1";
    String stream = "stream1";
    Stream s = new StreamImpl(scope, stream);
    Map<Segment, Long> startSegments = new HashMap<>();
    startSegments.put(new Segment(scope, stream, 0), 4L);
    startSegments.put(new Segment(scope, stream, 1), 6L);
    StreamCut cut = new StreamCutImpl(s, startSegments);
    Map<Segment, Long> endSegments = new HashMap<>();
    endSegments.put(new Segment(scope, stream, 6), 10L);
    endSegments.put(new Segment(scope, stream, 7), 10L);
    StreamCut endSC = new StreamCutImpl(s, endSegments);
    Set<Segment> result = controllerClient.getSegments(cut, endSC).get().getSegments();
    assertEquals(ImmutableSet.of(new Segment(scope, stream, 0), new Segment(scope, stream, 1), new Segment(scope, stream, 2), new Segment(scope, stream, 3), new Segment(scope, stream, 4), new Segment(scope, stream, 5), new Segment(scope, stream, 6), new Segment(scope, stream, 7)), result);
}
Also used : StreamCut(io.pravega.client.stream.StreamCut) HashMap(java.util.HashMap) Stream(io.pravega.client.stream.Stream) Segment(io.pravega.client.segment.impl.Segment) Test(org.junit.Test)

Aggregations

StreamCut (io.pravega.client.stream.StreamCut)11 HashMap (java.util.HashMap)11 Stream (io.pravega.client.stream.Stream)10 Test (org.junit.Test)8 Segment (io.pravega.client.segment.impl.Segment)7 Cleanup (lombok.Cleanup)4 ClientFactory (io.pravega.client.ClientFactory)2 ReaderGroupManager (io.pravega.client.admin.ReaderGroupManager)2 ReaderGroup (io.pravega.client.stream.ReaderGroup)2 Map (java.util.Map)2 ReaderGroupManagerImpl (io.pravega.client.admin.impl.ReaderGroupManagerImpl)1 ConnectionFactory (io.pravega.client.netty.impl.ConnectionFactory)1 ConnectionFactoryImpl (io.pravega.client.netty.impl.ConnectionFactoryImpl)1 ReaderGroupConfig (io.pravega.client.stream.ReaderGroupConfig)1 StreamConfiguration (io.pravega.client.stream.StreamConfiguration)1 ClientFactoryImpl (io.pravega.client.stream.impl.ClientFactoryImpl)1 Controller (io.pravega.client.stream.impl.Controller)1 ReaderGroupStateInit (io.pravega.client.stream.impl.ReaderGroupState.ReaderGroupStateInit)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1