use of io.pravega.common.concurrent.Futures.getThrowingException 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;
}
}
}
Aggregations