Search in sources :

Example 1 with NameUtils.getStreamForReaderGroup

use of io.pravega.shared.NameUtils.getStreamForReaderGroup in project pravega by pravega.

the class ReaderGroupManagerImpl method deleteReaderGroup.

@Override
public void deleteReaderGroup(String groupName) {
    UUID readerGroupId = null;
    ReaderGroupConfig syncConfig = null;
    try {
        @Cleanup StateSynchronizer<ReaderGroupState> synchronizer = clientFactory.createStateSynchronizer(NameUtils.getStreamForReaderGroup(groupName), new ReaderGroupStateUpdatesSerializer(), new ReaderGroupStateInitSerializer(), SynchronizerConfig.builder().build());
        synchronizer.fetchUpdates();
        syncConfig = synchronizer.getState().getConfig();
        readerGroupId = syncConfig.getReaderGroupId();
        if (ReaderGroupConfig.DEFAULT_UUID.equals(syncConfig.getReaderGroupId()) && ReaderGroupConfig.DEFAULT_GENERATION == syncConfig.getGeneration()) {
            // migrate RG case
            try {
                controller.getReaderGroupConfig(scope, groupName).thenCompose(conf -> controller.deleteReaderGroup(scope, groupName, conf.getReaderGroupId())).join();
            } catch (ReaderGroupNotFoundException ex) {
                controller.sealStream(scope, getStreamForReaderGroup(groupName)).thenCompose(b -> controller.deleteStream(scope, getStreamForReaderGroup(groupName))).exceptionally(e -> {
                    log.warn("Failed to delete ReaderGroup Stream {}", getStreamForReaderGroup(groupName), e);
                    throw Exceptions.sneakyThrow(e);
                }).join();
            }
            return;
        }
    } catch (InvalidStreamException ex) {
        log.warn("State-Synchronizer Stream for ReaderGroup {} was not found.", NameUtils.getScopedReaderGroupName(scope, groupName));
        // if the State Synchronizer Stream was deleted, but the RG still exists, get Id from Controller
        readerGroupId = getAndHandleExceptions(controller.getReaderGroupConfig(scope, groupName), RuntimeException::new).getReaderGroupId();
    }
    // normal delete
    getAndHandleExceptions(controller.deleteReaderGroup(scope, groupName, readerGroupId), RuntimeException::new);
}
Also used : ReaderGroupConfig(io.pravega.client.stream.ReaderGroupConfig) StateSynchronizer(io.pravega.client.state.StateSynchronizer) Arrays(java.util.Arrays) ReaderGroupImpl(io.pravega.client.stream.impl.ReaderGroupImpl) Getter(lombok.Getter) SneakyThrows(lombok.SneakyThrows) ConnectionFactory(io.pravega.client.connection.impl.ConnectionFactory) Exceptions(io.pravega.common.Exceptions) Cleanup(lombok.Cleanup) ReaderGroup(io.pravega.client.stream.ReaderGroup) ConnectionPoolImpl(io.pravega.client.connection.impl.ConnectionPoolImpl) ByteBuffer(java.nio.ByteBuffer) NameUtils.getStreamForReaderGroup(io.pravega.shared.NameUtils.getStreamForReaderGroup) Update(io.pravega.client.state.Update) ReaderGroupNotFoundException(io.pravega.client.stream.ReaderGroupNotFoundException) AccessLevel(lombok.AccessLevel) ClientFactoryImpl(io.pravega.client.stream.impl.ClientFactoryImpl) ReaderGroupManager(io.pravega.client.admin.ReaderGroupManager) Map(java.util.Map) Futures.getThrowingException(io.pravega.common.concurrent.Futures.getThrowingException) SynchronizerConfig(io.pravega.client.state.SynchronizerConfig) ReaderGroupConfig(io.pravega.client.stream.ReaderGroupConfig) Serializer(io.pravega.client.stream.Serializer) NameUtils(io.pravega.shared.NameUtils) Futures.getAndHandleExceptions(io.pravega.common.concurrent.Futures.getAndHandleExceptions) IOException(java.io.IOException) UUID(java.util.UUID) InitialUpdate(io.pravega.client.state.InitialUpdate) SegmentWithRange(io.pravega.client.stream.impl.SegmentWithRange) AbstractClientFactoryImpl(io.pravega.client.stream.impl.AbstractClientFactoryImpl) ControllerImplConfig(io.pravega.client.control.impl.ControllerImplConfig) Slf4j(lombok.extern.slf4j.Slf4j) ByteArraySegment(io.pravega.common.util.ByteArraySegment) ConfigMismatchException(io.pravega.client.stream.ConfigMismatchException) ReaderGroupImpl.getEndSegmentsForStreams(io.pravega.client.stream.impl.ReaderGroupImpl.getEndSegmentsForStreams) ControllerImpl(io.pravega.client.control.impl.ControllerImpl) InvalidStreamException(io.pravega.client.stream.InvalidStreamException) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Controller(io.pravega.client.control.impl.Controller) ClientConfig(io.pravega.client.ClientConfig) ReaderGroupState(io.pravega.client.stream.impl.ReaderGroupState) ReaderGroupNotFoundException(io.pravega.client.stream.ReaderGroupNotFoundException) UUID(java.util.UUID) ReaderGroupState(io.pravega.client.stream.impl.ReaderGroupState) Cleanup(lombok.Cleanup) InvalidStreamException(io.pravega.client.stream.InvalidStreamException)

Aggregations

VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 ClientConfig (io.pravega.client.ClientConfig)1 ReaderGroupManager (io.pravega.client.admin.ReaderGroupManager)1 ConnectionFactory (io.pravega.client.connection.impl.ConnectionFactory)1 ConnectionPoolImpl (io.pravega.client.connection.impl.ConnectionPoolImpl)1 Controller (io.pravega.client.control.impl.Controller)1 ControllerImpl (io.pravega.client.control.impl.ControllerImpl)1 ControllerImplConfig (io.pravega.client.control.impl.ControllerImplConfig)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 ConfigMismatchException (io.pravega.client.stream.ConfigMismatchException)1 InvalidStreamException (io.pravega.client.stream.InvalidStreamException)1 ReaderGroup (io.pravega.client.stream.ReaderGroup)1 ReaderGroupConfig (io.pravega.client.stream.ReaderGroupConfig)1 ReaderGroupNotFoundException (io.pravega.client.stream.ReaderGroupNotFoundException)1 Serializer (io.pravega.client.stream.Serializer)1 AbstractClientFactoryImpl (io.pravega.client.stream.impl.AbstractClientFactoryImpl)1 ClientFactoryImpl (io.pravega.client.stream.impl.ClientFactoryImpl)1