Search in sources :

Example 61 with OperationContext

use of io.pravega.controller.store.stream.OperationContext in project pravega by pravega.

the class ControllerService method createScope.

/**
 * Controller Service API to create scope.
 *
 * @param scope Name of scope to be created.
 * @param requestId request id
 * @return Status of create scope.
 */
public CompletableFuture<CreateScopeStatus> createScope(final String scope, final long requestId) {
    Exceptions.checkNotNullOrEmpty(scope, "scope");
    Timer timer = new Timer();
    try {
        NameUtils.validateScopeName(scope);
    } catch (IllegalArgumentException | NullPointerException e) {
        log.error(requestId, "Create scope failed due to invalid scope name {}", scope);
        return CompletableFuture.completedFuture(CreateScopeStatus.newBuilder().setStatus(CreateScopeStatus.Status.INVALID_SCOPE_NAME).build());
    }
    OperationContext context = streamStore.createScopeContext(scope, requestId);
    return streamStore.createScope(scope, context, executor).thenApply(r -> reportCreateScopeMetrics(scope, r, timer.getElapsed()));
}
Also used : OperationContext(io.pravega.controller.store.stream.OperationContext) Timer(io.pravega.common.Timer)

Example 62 with OperationContext

use of io.pravega.controller.store.stream.OperationContext in project pravega by pravega.

the class ControllerService method getKeyValueTableConfiguration.

public CompletableFuture<KeyValueTableConfigResponse> getKeyValueTableConfiguration(final String scope, final String kvtName, final long requestId) {
    Exceptions.checkNotNullOrEmpty(scope, "Scope name");
    Exceptions.checkNotNullOrEmpty(kvtName, "KeyValueTable name.");
    OperationContext context = kvtMetadataStore.createContext(scope, kvtName, requestId);
    return kvtMetadataStore.getConfiguration(scope, kvtName, context, executor).handleAsync((r, ex) -> {
        if (ex == null) {
            return KeyValueTableConfigResponse.newBuilder().setConfig(ModelHelper.decode(scope, kvtName, r)).setStatus(KeyValueTableConfigResponse.Status.SUCCESS).build();
        } else if (Exceptions.unwrap(ex) instanceof StoreException.DataNotFoundException) {
            return KeyValueTableConfigResponse.newBuilder().setStatus(KeyValueTableConfigResponse.Status.TABLE_NOT_FOUND).build();
        }
        return KeyValueTableConfigResponse.newBuilder().setStatus(KeyValueTableConfigResponse.Status.FAILURE).build();
    });
}
Also used : OperationContext(io.pravega.controller.store.stream.OperationContext) StoreException(io.pravega.controller.store.stream.StoreException)

Example 63 with OperationContext

use of io.pravega.controller.store.stream.OperationContext in project pravega by pravega.

the class ControllerService method isStreamCutValid.

/**
 * Checks if its a well formed streamcut. Well formed stream cuts are those that can unambiguously split the stream into two parts,
 * before and after. Any event position can be compared against a streamcut to determine unambiguously if it lies
 * before, On, or after the streamcut.
 *
 * @param scope scope
 * @param stream stream name
 * @param streamCut stream cut to validate
 * @param requestId request id
 * @return future that when completed will indicate if the stream cut is well formed or not.
 */
public CompletableFuture<Boolean> isStreamCutValid(final String scope, final String stream, final Map<Long, Long> streamCut, final long requestId) {
    Exceptions.checkNotNullOrEmpty(scope, "scope");
    Exceptions.checkNotNullOrEmpty(stream, "stream");
    OperationContext context = streamStore.createStreamContext(scope, stream, requestId);
    return streamStore.isStreamCutValid(scope, stream, streamCut, context, executor);
}
Also used : OperationContext(io.pravega.controller.store.stream.OperationContext)

Example 64 with OperationContext

use of io.pravega.controller.store.stream.OperationContext in project pravega by pravega.

the class ControllerService method getCurrentSegments.

public CompletableFuture<List<SegmentRange>> getCurrentSegments(final String scope, final String stream, long requestId) {
    Exceptions.checkNotNullOrEmpty(scope, "scope");
    Exceptions.checkNotNullOrEmpty(stream, "stream");
    // Fetch active segments from segment store.
    OperationContext context = streamStore.createStreamContext(scope, stream, requestId);
    return streamStore.getActiveSegments(scope, stream, context, executor).thenApplyAsync(activeSegments -> getSegmentRanges(activeSegments, scope, stream), executor);
}
Also used : OperationContext(io.pravega.controller.store.stream.OperationContext)

Example 65 with OperationContext

use of io.pravega.controller.store.stream.OperationContext in project pravega by pravega.

the class DeleteTableTask method execute.

@Override
public CompletableFuture<Void> execute(final DeleteTableEvent request) {
    String scope = request.getScope();
    String kvt = request.getKvtName();
    long requestId = request.getRequestId();
    String kvTableId = request.getTableId().toString();
    final OperationContext context = kvtMetadataStore.createContext(scope, kvt, requestId);
    return RetryHelper.withRetriesAsync(() -> getKeyValueTable(scope, kvt).thenCompose(table -> table.getId(context)).thenCompose(id -> {
        if (!id.equals(kvTableId)) {
            log.debug(requestId, "Skipped processing delete event for KeyValueTable {}/{} with Id:{} as UUIDs did not match.", scope, kvt, id);
            return CompletableFuture.completedFuture(null);
        } else {
            return Futures.exceptionallyExpecting(kvtMetadataStore.getAllSegmentIds(scope, kvt, context, executor).thenComposeAsync(allSegments -> kvtMetadataTasks.deleteSegments(scope, kvt, allSegments, kvtMetadataTasks.retrieveDelegationToken(), requestId), executor), e -> Exceptions.unwrap(e) instanceof StoreException.DataNotFoundException, null).thenCompose(v -> this.kvtMetadataStore.deleteKeyValueTable(scope, kvt, context, executor));
        }
    }), e -> Exceptions.unwrap(e) instanceof RetryableException, Integer.MAX_VALUE, executor);
}
Also used : OperationContext(io.pravega.controller.store.stream.OperationContext) OperationContext(io.pravega.controller.store.stream.OperationContext) KeyValueTable(io.pravega.controller.store.kvtable.KeyValueTable) Exceptions(io.pravega.common.Exceptions) LoggerFactory(org.slf4j.LoggerFactory) CompletableFuture(java.util.concurrent.CompletableFuture) TableMetadataTasks(io.pravega.controller.task.KeyValueTable.TableMetadataTasks) KVTableMetadataStore(io.pravega.controller.store.kvtable.KVTableMetadataStore) TagLogger(io.pravega.common.tracing.TagLogger) StoreException(io.pravega.controller.store.stream.StoreException) RetryableException(io.pravega.controller.retryable.RetryableException) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) Preconditions(com.google.common.base.Preconditions) DeleteTableEvent(io.pravega.shared.controller.event.kvtable.DeleteTableEvent) Futures(io.pravega.common.concurrent.Futures) RetryHelper(io.pravega.controller.util.RetryHelper) RetryableException(io.pravega.controller.retryable.RetryableException) StoreException(io.pravega.controller.store.stream.StoreException)

Aggregations

OperationContext (io.pravega.controller.store.stream.OperationContext)76 CompletableFuture (java.util.concurrent.CompletableFuture)53 Futures (io.pravega.common.concurrent.Futures)48 StreamMetadataStore (io.pravega.controller.store.stream.StreamMetadataStore)44 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)42 Exceptions (io.pravega.common.Exceptions)41 Collectors (java.util.stream.Collectors)41 UUID (java.util.UUID)39 StoreException (io.pravega.controller.store.stream.StoreException)38 List (java.util.List)38 TagLogger (io.pravega.common.tracing.TagLogger)37 LoggerFactory (org.slf4j.LoggerFactory)37 Preconditions (com.google.common.base.Preconditions)36 Map (java.util.Map)32 NameUtils (io.pravega.shared.NameUtils)31 VisibleForTesting (com.google.common.annotations.VisibleForTesting)27 StreamConfiguration (io.pravega.client.stream.StreamConfiguration)26 State (io.pravega.controller.store.stream.State)26 CompletionException (java.util.concurrent.CompletionException)26 BucketStore (io.pravega.controller.store.stream.BucketStore)25