Search in sources :

Example 1 with SealStreamEvent

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

the class SealStreamTask method execute.

@Override
public CompletableFuture<Void> execute(final SealStreamEvent request) {
    String scope = request.getScope();
    String stream = request.getStream();
    final OperationContext context = streamMetadataStore.createContext(scope, stream);
    // when seal stream task is picked, if the state is sealing/sealed, process sealing, else postpone.
    return streamMetadataStore.getState(scope, stream, true, context, executor).thenAccept(state -> {
        if (!state.equals(State.SEALING) && !state.equals(State.SEALED)) {
            throw new TaskExceptions.StartException("Seal stream task not started yet.");
        }
    }).thenCompose(x -> streamMetadataStore.getActiveSegments(scope, stream, context, executor)).thenCompose(activeSegments -> {
        if (activeSegments.isEmpty()) {
            // Do not update the state if the stream is already sealed.
            return CompletableFuture.completedFuture(null);
        } else {
            return notifySealed(scope, stream, context, activeSegments);
        }
    });
}
Also used : OperationContext(io.pravega.controller.store.stream.OperationContext) OperationContext(io.pravega.controller.store.stream.OperationContext) CompletableFuture(java.util.concurrent.CompletableFuture) State(io.pravega.controller.store.stream.tables.State) Collectors(java.util.stream.Collectors) SealStreamEvent(io.pravega.shared.controller.event.SealStreamEvent) List(java.util.List) Slf4j(lombok.extern.slf4j.Slf4j) CompletionStage(java.util.concurrent.CompletionStage) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) StreamMetadataTasks(io.pravega.controller.task.Stream.StreamMetadataTasks) Preconditions(com.google.common.base.Preconditions) Segment(io.pravega.controller.store.stream.Segment) StreamMetadataStore(io.pravega.controller.store.stream.StreamMetadataStore) Futures(io.pravega.common.concurrent.Futures)

Example 2 with SealStreamEvent

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

the class StreamMetadataTasks method sealStream.

/**
 * Seal a stream.
 *
 * @param scope      scope.
 * @param stream     stream name.
 * @param contextOpt optional context
 * @return update status.
 */
public CompletableFuture<UpdateStreamStatus.Status> sealStream(String scope, String stream, OperationContext contextOpt) {
    final OperationContext context = contextOpt == null ? streamMetadataStore.createContext(scope, stream) : contextOpt;
    // 1. post event for seal.
    SealStreamEvent event = new SealStreamEvent(scope, stream);
    return writeEvent(event).thenCompose(x -> streamMetadataStore.getState(scope, stream, false, context, executor)).thenCompose(state -> {
        if (state.equals(State.SEALED)) {
            return CompletableFuture.completedFuture(true);
        } else {
            return streamMetadataStore.setState(scope, stream, State.SEALING, context, executor);
        }
    }).thenCompose(result -> {
        if (result) {
            return checkDone(() -> isSealed(scope, stream, context)).thenApply(x -> UpdateStreamStatus.Status.SUCCESS);
        } else {
            return CompletableFuture.completedFuture(UpdateStreamStatus.Status.FAILURE);
        }
    }).exceptionally(ex -> {
        log.warn("Exception thrown in trying to notify sealed segments {}", ex.getMessage());
        return handleUpdateStreamError(ex);
    });
}
Also used : OperationContext(io.pravega.controller.store.stream.OperationContext) UpdateStreamEvent(io.pravega.shared.controller.event.UpdateStreamEvent) ControllerEventProcessors(io.pravega.controller.server.eventProcessor.ControllerEventProcessors) EventStreamWriter(io.pravega.client.stream.EventStreamWriter) StreamConfiguration(io.pravega.client.stream.StreamConfiguration) SealStreamEvent(io.pravega.shared.controller.event.SealStreamEvent) StoreException(io.pravega.controller.store.stream.StoreException) TaskMetadataStore(io.pravega.controller.store.task.TaskMetadataStore) TaskStepsRetryHelper.withRetries(io.pravega.controller.task.Stream.TaskStepsRetryHelper.withRetries) Duration(java.time.Duration) Map(java.util.Map) TaskExceptions(io.pravega.controller.server.eventProcessor.requesthandlers.TaskExceptions) CreateStreamStatus(io.pravega.controller.stream.api.grpc.v1.Controller.CreateStreamStatus) ScaleOperationExceptions(io.pravega.controller.store.stream.ScaleOperationExceptions) ImmutableMap(com.google.common.collect.ImmutableMap) DeleteStreamEvent(io.pravega.shared.controller.event.DeleteStreamEvent) CompletionException(java.util.concurrent.CompletionException) State(io.pravega.controller.store.stream.tables.State) Collectors(java.util.stream.Collectors) ControllerEvent(io.pravega.shared.controller.event.ControllerEvent) Serializable(java.io.Serializable) MetricsProvider(io.pravega.shared.metrics.MetricsProvider) List(java.util.List) Slf4j(lombok.extern.slf4j.Slf4j) CompletionStage(java.util.concurrent.CompletionStage) Config(io.pravega.controller.util.Config) ClientFactory(io.pravega.client.ClientFactory) Optional(java.util.Optional) Resource(io.pravega.controller.store.task.Resource) StreamMetadataStore(io.pravega.controller.store.stream.StreamMetadataStore) Futures(io.pravega.common.concurrent.Futures) IntStream(java.util.stream.IntStream) NotImplementedException(org.apache.commons.lang3.NotImplementedException) OperationContext(io.pravega.controller.store.stream.OperationContext) SegmentHelper(io.pravega.controller.server.SegmentHelper) RetentionPolicy(io.pravega.client.stream.RetentionPolicy) Exceptions(io.pravega.common.Exceptions) PravegaInterceptor(io.pravega.controller.server.rpc.auth.PravegaInterceptor) TruncateStreamEvent(io.pravega.shared.controller.event.TruncateStreamEvent) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ScaleStatusResponse(io.pravega.controller.stream.api.grpc.v1.Controller.ScaleStatusResponse) CompletableFuture(java.util.concurrent.CompletableFuture) AtomicReference(java.util.concurrent.atomic.AtomicReference) Supplier(java.util.function.Supplier) StreamCutRecord(io.pravega.controller.store.stream.StreamCutRecord) DynamicLogger(io.pravega.shared.metrics.DynamicLogger) DeleteStreamStatus(io.pravega.controller.stream.api.grpc.v1.Controller.DeleteStreamStatus) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) Segment(io.pravega.controller.store.stream.Segment) ConnectionFactory(io.pravega.client.netty.impl.ConnectionFactory) ModelHelper(io.pravega.client.stream.impl.ModelHelper) ScaleResponse(io.pravega.controller.stream.api.grpc.v1.Controller.ScaleResponse) EventWriterConfig(io.pravega.client.stream.EventWriterConfig) Task(io.pravega.controller.task.Task) TaskBase(io.pravega.controller.task.TaskBase) MetricsNames.nameFromStream(io.pravega.shared.MetricsNames.nameFromStream) CreateStreamResponse(io.pravega.controller.store.stream.CreateStreamResponse) WireCommands(io.pravega.shared.protocol.netty.WireCommands) SegmentRange(io.pravega.controller.stream.api.grpc.v1.Controller.SegmentRange) AbstractMap(java.util.AbstractMap) UpdateStreamStatus(io.pravega.controller.stream.api.grpc.v1.Controller.UpdateStreamStatus) RETENTION_FREQUENCY(io.pravega.shared.MetricsNames.RETENTION_FREQUENCY) HostControllerStore(io.pravega.controller.store.host.HostControllerStore) Preconditions(com.google.common.base.Preconditions) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Comparator(java.util.Comparator) ScaleOpEvent(io.pravega.shared.controller.event.ScaleOpEvent) ScalingPolicy(io.pravega.client.stream.ScalingPolicy) SealStreamEvent(io.pravega.shared.controller.event.SealStreamEvent)

Aggregations

Preconditions (com.google.common.base.Preconditions)2 Futures (io.pravega.common.concurrent.Futures)2 OperationContext (io.pravega.controller.store.stream.OperationContext)2 Segment (io.pravega.controller.store.stream.Segment)2 StreamMetadataStore (io.pravega.controller.store.stream.StreamMetadataStore)2 State (io.pravega.controller.store.stream.tables.State)2 SealStreamEvent (io.pravega.shared.controller.event.SealStreamEvent)2 List (java.util.List)2 CompletableFuture (java.util.concurrent.CompletableFuture)2 CompletionStage (java.util.concurrent.CompletionStage)2 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)2 Collectors (java.util.stream.Collectors)2 Slf4j (lombok.extern.slf4j.Slf4j)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 ClientFactory (io.pravega.client.ClientFactory)1 ConnectionFactory (io.pravega.client.netty.impl.ConnectionFactory)1 EventStreamWriter (io.pravega.client.stream.EventStreamWriter)1 EventWriterConfig (io.pravega.client.stream.EventWriterConfig)1 RetentionPolicy (io.pravega.client.stream.RetentionPolicy)1