Search in sources :

Example 1 with Futures.getThrowingException

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;
        }
    }
}
Also used : lombok.val(lombok.val) ReaderGroupConfig(io.pravega.client.stream.ReaderGroupConfig) StreamCut(io.pravega.client.stream.StreamCut) ReaderGroupStateInit(io.pravega.client.stream.impl.ReaderGroupState.ReaderGroupStateInit) SneakyThrows(lombok.SneakyThrows) UpdatingConfig(io.pravega.client.stream.impl.ReaderGroupState.UpdatingConfig) ReaderGroup(io.pravega.client.stream.ReaderGroup) ReaderGroupMetrics(io.pravega.client.stream.ReaderGroupMetrics) EndOfDataNotification(io.pravega.client.stream.notifications.EndOfDataNotification) Position(io.pravega.client.stream.Position) Stream(io.pravega.client.stream.Stream) AccessOperation(io.pravega.shared.security.auth.AccessOperation) Duration(java.time.Duration) Map(java.util.Map) Checkpoint(io.pravega.client.stream.Checkpoint) Futures.getThrowingException(io.pravega.common.concurrent.Futures.getThrowingException) ReaderGroupConfig(io.pravega.client.stream.ReaderGroupConfig) ImmutableMap(com.google.common.collect.ImmutableMap) Set(java.util.Set) DelegationTokenProviderFactory(io.pravega.client.security.auth.DelegationTokenProviderFactory) UUID(java.util.UUID) InitialUpdate(io.pravega.client.state.InitialUpdate) Collectors(java.util.stream.Collectors) SegmentMetadataClient(io.pravega.client.segment.impl.SegmentMetadataClient) NotifierFactory(io.pravega.client.stream.notifications.NotifierFactory) Base64(java.util.Base64) List(java.util.List) Slf4j(lombok.extern.slf4j.Slf4j) Observable(io.pravega.client.stream.notifications.Observable) Entry(java.util.Map.Entry) Optional(java.util.Optional) Controller(io.pravega.client.control.impl.Controller) Futures(io.pravega.common.concurrent.Futures) ClearCheckpointsBefore(io.pravega.client.stream.impl.ReaderGroupState.ClearCheckpointsBefore) StateSynchronizer(io.pravega.client.state.StateSynchronizer) Segment(io.pravega.client.segment.impl.Segment) NotificationSystem(io.pravega.client.stream.notifications.NotificationSystem) Exceptions(io.pravega.common.Exceptions) SegmentMetadataClientFactoryImpl(io.pravega.client.segment.impl.SegmentMetadataClientFactoryImpl) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) ReaderGroupConfigRejectedException(io.pravega.client.control.impl.ReaderGroupConfigRejectedException) SegmentMetadataClientFactory(io.pravega.client.segment.impl.SegmentMetadataClientFactory) ArrayList(java.util.ArrayList) Update(io.pravega.client.state.Update) SegmentNotification(io.pravega.client.stream.notifications.SegmentNotification) CreateCheckpoint(io.pravega.client.stream.impl.ReaderGroupState.CreateCheckpoint) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) SynchronizerConfig(io.pravega.client.state.SynchronizerConfig) Serializer(io.pravega.client.stream.Serializer) NameUtils(io.pravega.shared.NameUtils) Futures.getAndHandleExceptions(io.pravega.common.concurrent.Futures.getAndHandleExceptions) ConnectionPool(io.pravega.client.connection.impl.ConnectionPool) lombok.val(lombok.val) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) Futures.allOfWithResults(io.pravega.common.concurrent.Futures.allOfWithResults) DelegationTokenProvider(io.pravega.client.security.auth.DelegationTokenProvider) SynchronizerClientFactory(io.pravega.client.SynchronizerClientFactory) ReaderSegmentDistribution(io.pravega.client.stream.ReaderSegmentDistribution) Data(lombok.Data) InvalidStreamException(io.pravega.client.stream.InvalidStreamException) Preconditions(com.google.common.base.Preconditions) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Collections(java.util.Collections) ReaderGroupConfigRejectedException(io.pravega.client.control.impl.ReaderGroupConfigRejectedException) UpdatingConfig(io.pravega.client.stream.impl.ReaderGroupState.UpdatingConfig)

Aggregations

VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Preconditions (com.google.common.base.Preconditions)1 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 SynchronizerClientFactory (io.pravega.client.SynchronizerClientFactory)1 ConnectionPool (io.pravega.client.connection.impl.ConnectionPool)1 Controller (io.pravega.client.control.impl.Controller)1 ReaderGroupConfigRejectedException (io.pravega.client.control.impl.ReaderGroupConfigRejectedException)1 DelegationTokenProvider (io.pravega.client.security.auth.DelegationTokenProvider)1 DelegationTokenProviderFactory (io.pravega.client.security.auth.DelegationTokenProviderFactory)1 Segment (io.pravega.client.segment.impl.Segment)1 SegmentMetadataClient (io.pravega.client.segment.impl.SegmentMetadataClient)1 SegmentMetadataClientFactory (io.pravega.client.segment.impl.SegmentMetadataClientFactory)1 SegmentMetadataClientFactoryImpl (io.pravega.client.segment.impl.SegmentMetadataClientFactoryImpl)1 InitialUpdate (io.pravega.client.state.InitialUpdate)1 StateSynchronizer (io.pravega.client.state.StateSynchronizer)1 SynchronizerConfig (io.pravega.client.state.SynchronizerConfig)1 Update (io.pravega.client.state.Update)1 Checkpoint (io.pravega.client.stream.Checkpoint)1 InvalidStreamException (io.pravega.client.stream.InvalidStreamException)1