Search in sources :

Example 1 with UpdatingConfig

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;
        }
    }
}
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)

Example 2 with UpdatingConfig

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()));
}
Also used : ReleaseSegment(io.pravega.client.stream.impl.ReaderGroupState.ReleaseSegment) ReaderGroupUpdateSerializer(io.pravega.client.stream.impl.ReaderGroupState.ReaderGroupUpdateSerializer) AcquireSegment(io.pravega.client.stream.impl.ReaderGroupState.AcquireSegment) UpdateDistanceToTail(io.pravega.client.stream.impl.ReaderGroupState.UpdateDistanceToTail) CreateCheckpoint(io.pravega.client.stream.impl.ReaderGroupState.CreateCheckpoint) CheckpointReader(io.pravega.client.stream.impl.ReaderGroupState.CheckpointReader) ClearCheckpointsBefore(io.pravega.client.stream.impl.ReaderGroupState.ClearCheckpointsBefore) RemoveReader(io.pravega.client.stream.impl.ReaderGroupState.RemoveReader) AddReader(io.pravega.client.stream.impl.ReaderGroupState.AddReader) UpdatingConfig(io.pravega.client.stream.impl.ReaderGroupState.UpdatingConfig) SegmentCompleted(io.pravega.client.stream.impl.ReaderGroupState.SegmentCompleted) Test(org.junit.Test)

Example 3 with UpdatingConfig

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());
}
Also used : UpdatingConfig(io.pravega.client.stream.impl.ReaderGroupState.UpdatingConfig) Test(org.junit.Test)

Aggregations

UpdatingConfig (io.pravega.client.stream.impl.ReaderGroupState.UpdatingConfig)3 ClearCheckpointsBefore (io.pravega.client.stream.impl.ReaderGroupState.ClearCheckpointsBefore)2 CreateCheckpoint (io.pravega.client.stream.impl.ReaderGroupState.CreateCheckpoint)2 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