Search in sources :

Example 1 with CreateReaderGroupEvent

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

the class CreateReaderGroupTask method execute.

@Override
public CompletableFuture<Void> execute(final CreateReaderGroupEvent request) {
    String scope = request.getScope();
    String readerGroup = request.getRgName();
    UUID readerGroupId = request.getReaderGroupId();
    ReaderGroupConfig config = getConfigFromEvent(request);
    long requestId = request.getRequestId();
    OperationContext context = streamMetadataStore.createRGContext(scope, readerGroup, requestId);
    return streamMetadataStore.isScopeSealed(scope, context, executor).thenCompose(exists -> {
        if (exists) {
            log.warn(requestId, "Scope {} already in sealed state", scope);
            return CompletableFuture.completedFuture(null);
        }
        return RetryHelper.withRetriesAsync(() -> streamMetadataStore.getReaderGroupId(scope, readerGroup, context, executor).thenCompose(rgId -> {
            if (!rgId.equals(readerGroupId)) {
                log.warn(requestId, "Skipping processing of CreateReaderGroupEvent with stale UUID.");
                return CompletableFuture.completedFuture(null);
            }
            return streamMetadataTasks.isRGCreationComplete(scope, readerGroup, context).thenCompose(complete -> {
                if (!complete) {
                    return Futures.toVoid(streamMetadataTasks.createReaderGroupTasks(scope, readerGroup, config, request.getCreateTimeStamp(), context));
                }
                return CompletableFuture.completedFuture(null);
            });
        }), e -> Exceptions.unwrap(e) instanceof RetryableException, Integer.MAX_VALUE, executor);
    });
}
Also used : ReaderGroupConfig(io.pravega.client.stream.ReaderGroupConfig) OperationContext(io.pravega.controller.store.stream.OperationContext) OperationContext(io.pravega.controller.store.stream.OperationContext) StreamCut(io.pravega.client.stream.StreamCut) Exceptions(io.pravega.common.Exceptions) LoggerFactory(org.slf4j.LoggerFactory) CompletableFuture(java.util.concurrent.CompletableFuture) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) TagLogger(io.pravega.common.tracing.TagLogger) Stream(io.pravega.client.stream.Stream) RetryableException(io.pravega.controller.retryable.RetryableException) Map(java.util.Map) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) StreamMetadataTasks(io.pravega.controller.task.Stream.StreamMetadataTasks) RGStreamCutRecord(io.pravega.shared.controller.event.RGStreamCutRecord) Preconditions(com.google.common.base.Preconditions) StreamMetadataStore(io.pravega.controller.store.stream.StreamMetadataStore) Futures(io.pravega.common.concurrent.Futures) CreateReaderGroupEvent(io.pravega.shared.controller.event.CreateReaderGroupEvent) ReaderGroupConfig(io.pravega.client.stream.ReaderGroupConfig) RetryHelper(io.pravega.controller.util.RetryHelper) RetryableException(io.pravega.controller.retryable.RetryableException) UUID(java.util.UUID)

Example 2 with CreateReaderGroupEvent

use of io.pravega.shared.controller.event.CreateReaderGroupEvent 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)

Aggregations

ReaderGroupConfig (io.pravega.client.stream.ReaderGroupConfig)2 CreateReaderGroupEvent (io.pravega.shared.controller.event.CreateReaderGroupEvent)2 Preconditions (com.google.common.base.Preconditions)1 Stream (io.pravega.client.stream.Stream)1 StreamCut (io.pravega.client.stream.StreamCut)1 Exceptions (io.pravega.common.Exceptions)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 RetryableException (io.pravega.controller.retryable.RetryableException)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 RetryHelper (io.pravega.controller.util.RetryHelper)1 DeleteReaderGroupEvent (io.pravega.shared.controller.event.DeleteReaderGroupEvent)1 RGStreamCutRecord (io.pravega.shared.controller.event.RGStreamCutRecord)1 UpdateReaderGroupEvent (io.pravega.shared.controller.event.UpdateReaderGroupEvent)1 Map (java.util.Map)1