use of io.pravega.client.stream.impl.ReaderGroupState.UpdatingConfig in project pravega by pravega.
the class ReaderGroupImpl method resetReaderGroup.
@Override
public void resetReaderGroup(ReaderGroupConfig config) {
log.info("Reset ReaderGroup {} to {}", getGroupName(), config);
synchronizer.fetchUpdates();
while (true) {
val currentConfig = synchronizer.getState().getConfig();
// We only move into the block if the state transition has happened successfully.
if (stateTransition(currentConfig, new UpdatingConfig(true))) {
if (currentConfig.getReaderGroupId() == ReaderGroupConfig.DEFAULT_UUID && currentConfig.getGeneration() == ReaderGroupConfig.DEFAULT_GENERATION) {
// Migration code path, for moving a ReaderGroup from version < 0.9 to 0.9+
final ReaderGroupConfig updateConfig = ReaderGroupConfig.cloneConfig(config, UUID.randomUUID(), 0L);
final long nextGen = Futures.getThrowingException(controller.createReaderGroup(scope, getGroupName(), updateConfig).thenCompose(conf -> {
if (!conf.getReaderGroupId().equals(updateConfig.getReaderGroupId())) {
return controller.updateReaderGroup(scope, groupName, ReaderGroupConfig.cloneConfig(updateConfig, conf.getReaderGroupId(), conf.getGeneration()));
} else {
// ReaderGroup IDs matched so our create was updated on Controller
return CompletableFuture.completedFuture(conf.getGeneration());
}
}));
updateConfigInStateSynchronizer(updateConfig, nextGen);
} else {
// normal code path
// Use the latest generation and reader group Id.
ReaderGroupConfig newConfig = ReaderGroupConfig.cloneConfig(config, currentConfig.getReaderGroupId(), currentConfig.getGeneration());
long newGen = Futures.exceptionallyExpecting(controller.updateReaderGroup(scope, groupName, newConfig), e -> Exceptions.unwrap(e) instanceof ReaderGroupConfigRejectedException, -1L).join();
if (newGen == -1) {
log.debug("Synchronize reader group with the one present on controller.");
synchronizeReaderGroupConfig();
continue;
}
updateConfigInStateSynchronizer(newConfig, newGen);
}
return;
}
}
}
use of io.pravega.client.stream.impl.ReaderGroupState.UpdatingConfig 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()));
}
use of io.pravega.client.stream.impl.ReaderGroupState.UpdatingConfig in project pravega by pravega.
the class ReaderGroupStateTest method testUpdatingConfig.
@Test
public void testUpdatingConfig() {
UpdatingConfig update1 = new UpdatingConfig(true);
update1.applyTo(readerState, revision);
assertTrue(readerState.isUpdatingConfig());
UpdatingConfig update2 = new UpdatingConfig(false);
update2.applyTo(readerState, revision);
assertFalse(readerState.isUpdatingConfig());
}
Aggregations