Search in sources :

Example 1 with Scope

use of io.pravega.controller.store.Scope in project pravega by pravega.

the class AbstractKVTableMetadataStore method getScope.

public Scope getScope(final String scopeName, final OperationContext context) {
    if (context instanceof KVTOperationContext) {
        return ((KVTOperationContext) context).getScope();
    }
    Scope scope = scopeCache.getUnchecked(scopeName);
    scope.refresh();
    return scope;
}
Also used : Scope(io.pravega.controller.store.Scope)

Example 2 with Scope

use of io.pravega.controller.store.Scope in project pravega by pravega.

the class AbstractStreamMetadataStore method getScope.

public Scope getScope(final String scopeName, final OperationContext context) {
    if (context != null) {
        if (context instanceof StreamOperationContext) {
            return ((StreamOperationContext) context).getScope();
        } else if (context instanceof RGOperationContext) {
            return ((RGOperationContext) context).getScope();
        }
    }
    Scope scope = scopeCache.getUnchecked(scopeName);
    scope.refresh();
    return scope;
}
Also used : Scope(io.pravega.controller.store.Scope)

Example 3 with Scope

use of io.pravega.controller.store.Scope in project pravega by pravega.

the class InMemoryStreamMetadataStore method listStreamsInScope.

/**
 * List the streams in scope.
 *
 * @param scopeName Name of scope
 * @return List of streams in scope
 */
@Override
@Synchronized
public CompletableFuture<Map<String, StreamConfiguration>> listStreamsInScope(final String scopeName, final OperationContext ctx, final Executor executor) {
    OperationContext context = getOperationContext(ctx);
    InMemoryScope inMemoryScope = scopes.get(scopeName);
    if (inMemoryScope != null) {
        return inMemoryScope.listStreamsInScope(context).thenApply(streams -> {
            HashMap<String, StreamConfiguration> result = new HashMap<>();
            for (String stream : streams) {
                State state = getState(scopeName, stream, true, null, executor).join();
                StreamConfiguration configuration = Futures.exceptionallyExpecting(getConfiguration(scopeName, stream, null, executor), e -> e instanceof StoreException.DataNotFoundException, null).join();
                if (configuration != null && !state.equals(State.CREATING) && !state.equals(State.UNKNOWN)) {
                    result.put(stream, configuration);
                }
            }
            return result;
        });
    } else {
        return Futures.failedFuture(StoreException.create(StoreException.Type.DATA_NOT_FOUND, scopeName));
    }
}
Also used : CreateScopeStatus(io.pravega.controller.stream.api.grpc.v1.Controller.CreateScopeStatus) SneakyThrows(lombok.SneakyThrows) RetentionPolicy(io.pravega.client.stream.RetentionPolicy) Scope(io.pravega.controller.store.Scope) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) StreamConfiguration(io.pravega.client.stream.StreamConfiguration) ArrayList(java.util.ArrayList) Strings(com.google.common.base.Strings) Pair(org.apache.commons.lang3.tuple.Pair) InMemoryScope(io.pravega.controller.store.InMemoryScope) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) ReaderGroupConfig(io.pravega.client.stream.ReaderGroupConfig) DeleteScopeStatus(io.pravega.controller.stream.api.grpc.v1.Controller.DeleteScopeStatus) Synchronized(lombok.Synchronized) Executor(java.util.concurrent.Executor) Set(java.util.Set) IOException(java.io.IOException) UUID(java.util.UUID) GuardedBy(javax.annotation.concurrent.GuardedBy) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) AtomicInt96(io.pravega.common.lang.AtomicInt96) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) Version(io.pravega.controller.store.Version) InMemoryHostIndex(io.pravega.controller.store.index.InMemoryHostIndex) Int96(io.pravega.common.lang.Int96) Preconditions(com.google.common.base.Preconditions) VisibleForTesting(com.google.common.annotations.VisibleForTesting) LinkedTreeMap(com.google.gson.internal.LinkedTreeMap) Futures(io.pravega.common.concurrent.Futures) InMemoryScope(io.pravega.controller.store.InMemoryScope) HashMap(java.util.HashMap) StreamConfiguration(io.pravega.client.stream.StreamConfiguration) Synchronized(lombok.Synchronized)

Example 4 with Scope

use of io.pravega.controller.store.Scope in project pravega by pravega.

the class AbstractStreamMetadataStore method createStreamContext.

@Override
public OperationContext createStreamContext(String scopeName, String streamName, long requestId) {
    Scope scope = getScope(scopeName, null);
    Stream stream = getStream(scopeName, streamName, null);
    return new StreamOperationContext(scope, stream, requestId);
}
Also used : Scope(io.pravega.controller.store.Scope)

Example 5 with Scope

use of io.pravega.controller.store.Scope in project pravega by pravega.

the class AbstractStreamMetadataStore method createScope.

/**
 * Create a scope with given name.
 *
 * @param scopeName Name of scope to created.
 * @return CreateScopeStatus future.
 */
@Override
public CompletableFuture<CreateScopeStatus> createScope(final String scopeName, final OperationContext ctx, Executor executor) {
    OperationContext context = getOperationContext(ctx);
    Scope scope = getScope(scopeName, context);
    return Futures.completeOn(scope.isScopeSealed(scopeName, context).thenCompose(isScopeSealed -> {
        if (isScopeSealed) {
            return CompletableFuture.completedFuture(CreateScopeStatus.newBuilder().setStatus(CreateScopeStatus.Status.SCOPE_EXISTS).build());
        }
        return scope.createScope(context).handle((result, ex) -> {
            if (ex == null) {
                return CreateScopeStatus.newBuilder().setStatus(CreateScopeStatus.Status.SUCCESS).build();
            }
            if (Exceptions.unwrap(ex) instanceof StoreException.DataExistsException) {
                return CreateScopeStatus.newBuilder().setStatus(CreateScopeStatus.Status.SCOPE_EXISTS).build();
            } else {
                log.error(context.getRequestId(), "Create scope failed for scope {} due to ", scopeName, ex);
                return CreateScopeStatus.newBuilder().setStatus(CreateScopeStatus.Status.FAILURE).build();
            }
        });
    }), executor);
}
Also used : LoadingCache(com.google.common.cache.LoadingCache) StreamSegmentRecord(io.pravega.controller.store.stream.records.StreamSegmentRecord) LoggerFactory(org.slf4j.LoggerFactory) StreamConfiguration(io.pravega.client.stream.StreamConfiguration) ParametersAreNonnullByDefault(javax.annotation.ParametersAreNonnullByDefault) ByteBuffer(java.nio.ByteBuffer) TagLogger(io.pravega.common.tracing.TagLogger) VersionedMetadata(io.pravega.controller.store.VersionedMetadata) Pair(org.apache.commons.lang3.tuple.Pair) Map(java.util.Map) ControllerEventSerializer(io.pravega.shared.controller.event.ControllerEventSerializer) ReaderGroupConfig(io.pravega.client.stream.ReaderGroupConfig) DeleteScopeStatus(io.pravega.controller.stream.api.grpc.v1.Controller.DeleteScopeStatus) EpochTransitionRecord(io.pravega.controller.store.stream.records.EpochTransitionRecord) StreamCutReferenceRecord(io.pravega.controller.store.stream.records.StreamCutReferenceRecord) StreamTruncationRecord(io.pravega.controller.store.stream.records.StreamTruncationRecord) ImmutableMap(com.google.common.collect.ImmutableMap) Predicate(java.util.function.Predicate) Set(java.util.Set) ActiveTxnRecord(io.pravega.controller.store.stream.records.ActiveTxnRecord) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) ControllerEvent(io.pravega.shared.controller.event.ControllerEvent) CacheLoader(com.google.common.cache.CacheLoader) List(java.util.List) Int96(io.pravega.common.lang.Int96) Optional(java.util.Optional) CacheBuilder(com.google.common.cache.CacheBuilder) HistoryTimeSeries(io.pravega.controller.store.stream.records.HistoryTimeSeries) Futures(io.pravega.common.concurrent.Futures) StreamMetrics(io.pravega.controller.metrics.StreamMetrics) TransactionMetrics(io.pravega.controller.metrics.TransactionMetrics) CommittingTransactionsRecord(io.pravega.controller.store.stream.records.CommittingTransactionsRecord) Getter(lombok.Getter) CreateScopeStatus(io.pravega.controller.stream.api.grpc.v1.Controller.CreateScopeStatus) Exceptions(io.pravega.common.Exceptions) Scope(io.pravega.controller.store.Scope) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) RetentionSet(io.pravega.controller.store.stream.records.RetentionSet) HostIndex(io.pravega.controller.store.index.HostIndex) ReaderGroupConfigRecord(io.pravega.controller.store.stream.records.ReaderGroupConfigRecord) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) StreamSubscriber(io.pravega.controller.store.stream.records.StreamSubscriber) SimpleEntry(java.util.AbstractMap.SimpleEntry) SealedSegmentsMapShard(io.pravega.controller.store.stream.records.SealedSegmentsMapShard) ControllerService(io.pravega.controller.server.ControllerService) Executor(java.util.concurrent.Executor) WriterMark(io.pravega.controller.store.stream.records.WriterMark) StreamCutRecord(io.pravega.controller.store.stream.records.StreamCutRecord) TxnResource(io.pravega.controller.store.task.TxnResource) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) TimeUnit(java.util.concurrent.TimeUnit) StreamConfigurationRecord(io.pravega.controller.store.stream.records.StreamConfigurationRecord) EpochRecord(io.pravega.controller.store.stream.records.EpochRecord) Version(io.pravega.controller.store.Version) VisibleForTesting(com.google.common.annotations.VisibleForTesting) RandomFactory(io.pravega.common.hash.RandomFactory) Collections(java.util.Collections) Scope(io.pravega.controller.store.Scope)

Aggregations

Scope (io.pravega.controller.store.Scope)6 Futures (io.pravega.common.concurrent.Futures)3 List (java.util.List)3 Set (java.util.Set)3 CompletableFuture (java.util.concurrent.CompletableFuture)3 Executor (java.util.concurrent.Executor)3 ImmutablePair (org.apache.commons.lang3.tuple.ImmutablePair)3 Pair (org.apache.commons.lang3.tuple.Pair)3 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 CacheBuilder (com.google.common.cache.CacheBuilder)2 CacheLoader (com.google.common.cache.CacheLoader)2 LoadingCache (com.google.common.cache.LoadingCache)2 ReaderGroupConfig (io.pravega.client.stream.ReaderGroupConfig)2 StreamConfiguration (io.pravega.client.stream.StreamConfiguration)2 Exceptions (io.pravega.common.Exceptions)2 Int96 (io.pravega.common.lang.Int96)2 ControllerService (io.pravega.controller.server.ControllerService)2 Version (io.pravega.controller.store.Version)2 VersionedMetadata (io.pravega.controller.store.VersionedMetadata)2 HostIndex (io.pravega.controller.store.index.HostIndex)2