use of io.pravega.client.stream.impl.ReaderGroupState.ReaderGroupStateInit 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));
});
}
use of io.pravega.client.stream.impl.ReaderGroupState.ReaderGroupStateInit in project pravega by pravega.
the class SerializationTest method testReaderGroupInit.
@Test
public void testReaderGroupInit() throws Exception {
ReaderGroupInitSerializer initSerializer = new ReaderGroupInitSerializer();
ReaderGroupConfig config = ReaderGroupConfig.builder().disableAutomaticCheckpoints().groupRefreshTimeMillis(r.nextInt(1000)).stream(createSegment().getStream()).build();
verify(initSerializer, new ReaderGroupStateInit(config, createSegmentRangeMap(), createSegmentToLongMap(), false));
CompactReaderGroupStateBuilder builder = new CompactReaderGroupState.CompactReaderGroupStateBuilder();
builder.assignedSegments(createMap(this::createString, this::createSegmentRangeMap));
builder.checkpointState(new CheckpointState.CheckpointStateBuilder().checkpoints(createList(this::createString)).lastCheckpointPosition(createSegmentToLongMap()).checkpointPositions(createMap(this::createString, this::createSegmentToLongMap)).uncheckpointedHosts(createMap(this::createString, this::createStringList)).build());
builder.config(config);
builder.distanceToTail(createMap(this::createString, r::nextLong));
builder.endSegments(createSegmentToLongMap());
builder.unassignedSegments(createSegmentRangeMap());
builder.futureSegments(createMap(this::createSegmentWithRange, () -> new HashSet<>(createLongList())));
builder.lastReadPosition(createSegmentRangeMap());
verify(initSerializer, builder.build());
ReaderGroupStateInitSerializer newSerializer = new ReaderGroupStateInit.ReaderGroupStateInitSerializer();
ReaderGroupStateInitSerializer oldSerializer = new ReaderGroupStateInit.ReaderGroupStateInitSerializer() {
@Override
protected void declareVersions() {
version(0).revision(0, this::write00, this::read00);
}
};
ReaderGroupStateInit init = new ReaderGroupStateInit(config, createSegmentRangeMap(), createSegmentToLongMap(), false);
ReaderGroupStateInit oldFormat = newSerializer.deserialize(oldSerializer.serialize(init));
assertEquals(init.getStartingSegments().keySet().stream().map(s -> s.getSegment()).collect(Collectors.toSet()), oldFormat.getStartingSegments().keySet().stream().map(s -> s.getSegment()).collect(Collectors.toSet()));
assertEquals(init.getEndSegments(), oldFormat.getEndSegments());
assertEquals(init.getConfig(), oldFormat.getConfig());
}
use of io.pravega.client.stream.impl.ReaderGroupState.ReaderGroupStateInit in project pravega by pravega.
the class ReaderGroupImpl method updateConfigInStateSynchronizer.
private void updateConfigInStateSynchronizer(ReaderGroupConfig config, long newGen) {
Map<SegmentWithRange, Long> segments = getSegmentsForStreams(controller, config);
synchronizer.updateState((s, updates) -> {
updates.add(new ReaderGroupStateInit(ReaderGroupConfig.cloneConfig(config, config.getReaderGroupId(), newGen), segments, getEndSegmentsForStreams(config), false));
});
}
Aggregations