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