Search in sources :

Example 1 with DeleteReaderGroupEvent

use of io.pravega.shared.controller.event.DeleteReaderGroupEvent in project pravega by pravega.

the class StreamMetadataTasksTest method readerGroupFailureTests.

@Test(timeout = 30000)
public void readerGroupFailureTests() throws InterruptedException {
    WriterMock requestEventWriter = new WriterMock(streamMetadataTasks, executor);
    streamMetadataTasks.setRequestEventWriter(requestEventWriter);
    UpdateReaderGroupEvent badUpdateEvent = new UpdateReaderGroupEvent(SCOPE, "rg3", 2L, UUID.randomUUID(), 0L, false, ImmutableSet.of());
    requestEventWriter.writeEvent(badUpdateEvent);
    AssertExtensions.assertFutureThrows("DataNotFoundException", processFailingEvent(requestEventWriter), e -> Exceptions.unwrap(e) instanceof StoreException.DataNotFoundException);
    String scopedStreamName = "scope/stream";
    ReaderGroupConfig rgConf = ReaderGroupConfig.builder().disableAutomaticCheckpoints().stream(scopedStreamName).retentionType(ReaderGroupConfig.StreamDataRetention.NONE).build();
    CreateReaderGroupEvent badCreateEvent = buildCreateRGEvent(SCOPE, "rg", rgConf, 1L, System.currentTimeMillis());
    requestEventWriter.writeEvent(badCreateEvent);
    AssertExtensions.assertFutureThrows("DataNotFoundException", processFailingEvent(requestEventWriter), e -> Exceptions.unwrap(e) instanceof StoreException.DataNotFoundException);
    DeleteReaderGroupEvent badDeleteEvent = new DeleteReaderGroupEvent(SCOPE, "rg3", 1L, UUID.randomUUID());
    requestEventWriter.writeEvent(badDeleteEvent);
    AssertExtensions.assertFutureThrows("DataNotFoundException", processFailingEvent(requestEventWriter), e -> Exceptions.unwrap(e) instanceof StoreException.DataNotFoundException);
}
Also used : ReaderGroupConfig(io.pravega.client.stream.ReaderGroupConfig) CreateReaderGroupEvent(io.pravega.shared.controller.event.CreateReaderGroupEvent) DeleteReaderGroupEvent(io.pravega.shared.controller.event.DeleteReaderGroupEvent) UpdateReaderGroupEvent(io.pravega.shared.controller.event.UpdateReaderGroupEvent) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ControllerEventStreamWriterMock(io.pravega.controller.mocks.ControllerEventStreamWriterMock) EventStreamWriterMock(io.pravega.controller.mocks.EventStreamWriterMock) StoreException(io.pravega.controller.store.stream.StoreException) Test(org.junit.Test)

Example 2 with DeleteReaderGroupEvent

use of io.pravega.shared.controller.event.DeleteReaderGroupEvent in project pravega by pravega.

the class DeleteReaderGroupTask method execute.

@Override
public CompletableFuture<Void> execute(final DeleteReaderGroupEvent request) {
    String scope = request.getScope();
    String readerGroup = request.getRgName();
    long requestId = request.getRequestId();
    UUID readerGroupId = request.getReaderGroupId();
    final OperationContext context = streamMetadataStore.createRGContext(scope, readerGroup, requestId);
    return streamMetadataStore.getReaderGroupId(scope, readerGroup, context, executor).thenCompose(id -> {
        if (!id.equals(readerGroupId)) {
            log.warn(requestId, "Skipping processing of Reader Group delete request {} as UUIDs did not match.", requestId);
            return CompletableFuture.completedFuture(null);
        }
        return streamMetadataStore.getReaderGroupConfigRecord(scope, readerGroup, context, executor).thenCompose(configRecord -> {
            if (!ReaderGroupConfig.StreamDataRetention.values()[configRecord.getObject().getRetentionTypeOrdinal()].equals(ReaderGroupConfig.StreamDataRetention.NONE)) {
                String scopedRGName = NameUtils.getScopedReaderGroupName(scope, readerGroup);
                // update Stream metadata tables, if RG is a Subscriber
                Iterator<String> streamIter = configRecord.getObject().getStartingStreamCuts().keySet().iterator();
                return Futures.loop(streamIter::hasNext, () -> {
                    Stream stream = Stream.of(streamIter.next());
                    OperationContext streamContext = streamMetadataStore.createStreamContext(stream.getScope(), stream.getStreamName(), requestId);
                    return streamMetadataStore.deleteSubscriber(stream.getScope(), stream.getStreamName(), scopedRGName, configRecord.getObject().getGeneration(), streamContext, executor);
                }, executor);
            }
            return CompletableFuture.completedFuture(null);
        }).thenCompose(v -> {
            String rgStreamContext = NameUtils.getStreamForReaderGroup(readerGroup);
            OperationContext streamContext = streamMetadataStore.createStreamContext(scope, rgStreamContext, requestId);
            return streamMetadataTasks.sealStream(scope, rgStreamContext, streamContext).thenCompose(z -> streamMetadataTasks.deleteStream(scope, rgStreamContext, streamContext));
        }).thenCompose(v1 -> streamMetadataStore.deleteReaderGroup(scope, readerGroup, context, executor));
    });
}
Also used : OperationContext(io.pravega.controller.store.stream.OperationContext) OperationContext(io.pravega.controller.store.stream.OperationContext) NameUtils(io.pravega.shared.NameUtils) Iterator(java.util.Iterator) DeleteReaderGroupEvent(io.pravega.shared.controller.event.DeleteReaderGroupEvent) LoggerFactory(org.slf4j.LoggerFactory) CompletableFuture(java.util.concurrent.CompletableFuture) UUID(java.util.UUID) TagLogger(io.pravega.common.tracing.TagLogger) Stream(io.pravega.client.stream.Stream) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) StreamMetadataTasks(io.pravega.controller.task.Stream.StreamMetadataTasks) Preconditions(com.google.common.base.Preconditions) StreamMetadataStore(io.pravega.controller.store.stream.StreamMetadataStore) Futures(io.pravega.common.concurrent.Futures) ReaderGroupConfig(io.pravega.client.stream.ReaderGroupConfig) Stream(io.pravega.client.stream.Stream) UUID(java.util.UUID)

Aggregations

ReaderGroupConfig (io.pravega.client.stream.ReaderGroupConfig)2 DeleteReaderGroupEvent (io.pravega.shared.controller.event.DeleteReaderGroupEvent)2 Preconditions (com.google.common.base.Preconditions)1 Stream (io.pravega.client.stream.Stream)1 Futures (io.pravega.common.concurrent.Futures)1 TagLogger (io.pravega.common.tracing.TagLogger)1 ControllerEventStreamWriterMock (io.pravega.controller.mocks.ControllerEventStreamWriterMock)1 EventStreamWriterMock (io.pravega.controller.mocks.EventStreamWriterMock)1 OperationContext (io.pravega.controller.store.stream.OperationContext)1 StoreException (io.pravega.controller.store.stream.StoreException)1 StreamMetadataStore (io.pravega.controller.store.stream.StreamMetadataStore)1 StreamMetadataTasks (io.pravega.controller.task.Stream.StreamMetadataTasks)1 NameUtils (io.pravega.shared.NameUtils)1 CreateReaderGroupEvent (io.pravega.shared.controller.event.CreateReaderGroupEvent)1 UpdateReaderGroupEvent (io.pravega.shared.controller.event.UpdateReaderGroupEvent)1 Iterator (java.util.Iterator)1 UUID (java.util.UUID)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)1 Test (org.junit.Test)1