Search in sources :

Example 1 with RETENTION_FREQUENCY

use of io.pravega.shared.MetricsNames.RETENTION_FREQUENCY in project pravega by pravega.

the class StreamMetadataTasks method retention.

/**
 * Method to check retention policy and generate new periodic cuts and/or truncate stream at an existing stream cut.
 *
 * @param scope scope
 * @param stream stream
 * @param policy retention policy
 * @param recordingTime time of recording
 * @param contextOpt operation context
 * @param delegationToken token to be sent to segmentstore to authorize this operation.
 * @return future.
 */
public CompletableFuture<Void> retention(final String scope, final String stream, final RetentionPolicy policy, final long recordingTime, final OperationContext contextOpt, final String delegationToken) {
    Preconditions.checkNotNull(policy);
    final OperationContext context = contextOpt == null ? streamMetadataStore.createContext(scope, stream) : contextOpt;
    return streamMetadataStore.getStreamCutsFromRetentionSet(scope, stream, context, executor).thenCompose(retentionSet -> {
        StreamCutRecord latestCut = retentionSet.stream().max(Comparator.comparingLong(StreamCutRecord::getRecordingTime)).orElse(null);
        return checkGenerateStreamCut(scope, stream, context, latestCut, recordingTime, delegationToken).thenCompose(newRecord -> truncate(scope, stream, policy, context, retentionSet, newRecord, recordingTime));
    }).thenAccept(x -> DYNAMIC_LOGGER.recordMeterEvents(nameFromStream(RETENTION_FREQUENCY, scope, stream), 1));
}
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) StreamCutRecord(io.pravega.controller.store.stream.StreamCutRecord)

Aggregations

VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Preconditions (com.google.common.base.Preconditions)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 ScalingPolicy (io.pravega.client.stream.ScalingPolicy)1 StreamConfiguration (io.pravega.client.stream.StreamConfiguration)1 ModelHelper (io.pravega.client.stream.impl.ModelHelper)1 Exceptions (io.pravega.common.Exceptions)1 Futures (io.pravega.common.concurrent.Futures)1 SegmentHelper (io.pravega.controller.server.SegmentHelper)1 ControllerEventProcessors (io.pravega.controller.server.eventProcessor.ControllerEventProcessors)1 TaskExceptions (io.pravega.controller.server.eventProcessor.requesthandlers.TaskExceptions)1 PravegaInterceptor (io.pravega.controller.server.rpc.auth.PravegaInterceptor)1 HostControllerStore (io.pravega.controller.store.host.HostControllerStore)1 CreateStreamResponse (io.pravega.controller.store.stream.CreateStreamResponse)1 OperationContext (io.pravega.controller.store.stream.OperationContext)1