Search in sources :

Example 1 with DELETED_STREAMS_TABLE

use of io.pravega.shared.NameUtils.DELETED_STREAMS_TABLE in project pravega by pravega.

the class PravegaTablesStreamMetadataStore method recordLastStreamSegment.

@Override
CompletableFuture<Void> recordLastStreamSegment(final String scope, final String stream, final int lastActiveSegment, OperationContext ctx, final Executor executor) {
    final String key = getScopedStreamName(scope, stream);
    OperationContext context = getOperationContext(ctx);
    long requestId = getOperationContext(context).getRequestId();
    return Futures.completeOn(Futures.handleCompose(storeHelper.getEntry(DELETED_STREAMS_TABLE, key, BYTES_TO_INTEGER_FUNCTION, requestId), (r, e) -> {
        if (e != null) {
            Throwable unwrap = Exceptions.unwrap(e);
            if (unwrap instanceof StoreException.DataContainerNotFoundException) {
                return storeHelper.createTable(DELETED_STREAMS_TABLE, requestId).thenApply(v -> null);
            } else if (unwrap instanceof StoreException.DataNotFoundException) {
                return CompletableFuture.completedFuture(null);
            } else {
                throw new CompletionException(unwrap);
            }
        } else {
            return CompletableFuture.completedFuture(r);
        }
    }).thenCompose(existing -> {
        log.debug(context.getRequestId(), "Recording last segment {} for stream {}/{} on deletion.", lastActiveSegment, scope, stream);
        if (existing != null) {
            final int oldLastActiveSegment = existing.getObject();
            Preconditions.checkArgument(lastActiveSegment >= oldLastActiveSegment, "Old last active segment ({}) for {}/{} is higher than current one {}.", oldLastActiveSegment, scope, stream, lastActiveSegment);
            return Futures.toVoid(storeHelper.updateEntry(DELETED_STREAMS_TABLE, key, lastActiveSegment, INTEGER_TO_BYTES_FUNCTION, existing.getVersion(), requestId));
        } else {
            return Futures.toVoid(storeHelper.addNewEntryIfAbsent(DELETED_STREAMS_TABLE, key, lastActiveSegment, INTEGER_TO_BYTES_FUNCTION, requestId));
        }
    }), executor);
}
Also used : Getter(lombok.Getter) SegmentHelper(io.pravega.controller.server.SegmentHelper) Exceptions(io.pravega.common.Exceptions) LoggerFactory(org.slf4j.LoggerFactory) NameUtils.getQualifiedTableName(io.pravega.shared.NameUtils.getQualifiedTableName) CompletableFuture(java.util.concurrent.CompletableFuture) COMPLETED_TRANSACTIONS_BATCHES_TABLE(io.pravega.shared.NameUtils.COMPLETED_TRANSACTIONS_BATCHES_TABLE) StreamConfiguration(io.pravega.client.stream.StreamConfiguration) AtomicReference(java.util.concurrent.atomic.AtomicReference) Unpooled(io.netty.buffer.Unpooled) ArrayList(java.util.ArrayList) TagLogger(io.pravega.common.tracing.TagLogger) AccessLevel(lombok.AccessLevel) Pair(org.apache.commons.lang3.tuple.Pair) Duration(java.time.Duration) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) DELETING_SCOPES_TABLE(io.pravega.controller.store.PravegaTablesScope.DELETING_SCOPES_TABLE) INTEGER_TO_BYTES_FUNCTION(io.pravega.controller.store.PravegaTablesStoreHelper.INTEGER_TO_BYTES_FUNCTION) NameUtils(io.pravega.shared.NameUtils) DELETED_STREAMS_TABLE(io.pravega.shared.NameUtils.DELETED_STREAMS_TABLE) Executor(java.util.concurrent.Executor) Set(java.util.Set) CompletionException(java.util.concurrent.CompletionException) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) PravegaTablesScope(io.pravega.controller.store.PravegaTablesScope) ZKStoreHelper(io.pravega.controller.store.ZKStoreHelper) Base64(java.util.Base64) List(java.util.List) CuratorFramework(org.apache.curator.framework.CuratorFramework) Version(io.pravega.controller.store.Version) Config(io.pravega.controller.util.Config) COMPLETED_TRANSACTIONS_BATCH_TABLE_FORMAT(io.pravega.shared.NameUtils.COMPLETED_TRANSACTIONS_BATCH_TABLE_FORMAT) Int96(io.pravega.common.lang.Int96) PravegaTablesStoreHelper(io.pravega.controller.store.PravegaTablesStoreHelper) BYTES_TO_INTEGER_FUNCTION(io.pravega.controller.store.PravegaTablesStoreHelper.BYTES_TO_INTEGER_FUNCTION) Preconditions(com.google.common.base.Preconditions) ZKHostIndex(io.pravega.controller.store.index.ZKHostIndex) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Collections(java.util.Collections) Futures(io.pravega.common.concurrent.Futures) GrpcAuthHelper(io.pravega.controller.server.security.auth.GrpcAuthHelper) CompletionException(java.util.concurrent.CompletionException)

Aggregations

VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Preconditions (com.google.common.base.Preconditions)1 Unpooled (io.netty.buffer.Unpooled)1 StreamConfiguration (io.pravega.client.stream.StreamConfiguration)1 Exceptions (io.pravega.common.Exceptions)1 Futures (io.pravega.common.concurrent.Futures)1 Int96 (io.pravega.common.lang.Int96)1 TagLogger (io.pravega.common.tracing.TagLogger)1 SegmentHelper (io.pravega.controller.server.SegmentHelper)1 GrpcAuthHelper (io.pravega.controller.server.security.auth.GrpcAuthHelper)1 PravegaTablesScope (io.pravega.controller.store.PravegaTablesScope)1 DELETING_SCOPES_TABLE (io.pravega.controller.store.PravegaTablesScope.DELETING_SCOPES_TABLE)1 PravegaTablesStoreHelper (io.pravega.controller.store.PravegaTablesStoreHelper)1 BYTES_TO_INTEGER_FUNCTION (io.pravega.controller.store.PravegaTablesStoreHelper.BYTES_TO_INTEGER_FUNCTION)1 INTEGER_TO_BYTES_FUNCTION (io.pravega.controller.store.PravegaTablesStoreHelper.INTEGER_TO_BYTES_FUNCTION)1 Version (io.pravega.controller.store.Version)1 ZKStoreHelper (io.pravega.controller.store.ZKStoreHelper)1 ZKHostIndex (io.pravega.controller.store.index.ZKHostIndex)1 Config (io.pravega.controller.util.Config)1 NameUtils (io.pravega.shared.NameUtils)1