Search in sources :

Example 1 with INTEGER_TO_BYTES_FUNCTION

use of io.pravega.controller.store.PravegaTablesStoreHelper.INTEGER_TO_BYTES_FUNCTION in project pravega by pravega.

the class PravegaTablesKVTMetadataStore method recordLastKVTableSegment.

@Override
CompletableFuture<Void> recordLastKVTableSegment(final String scope, final String kvtable, int lastActiveSegment, OperationContext ctx, final Executor executor) {
    OperationContext context = getOperationContext(ctx);
    final String key = getScopedKVTName(scope, kvtable);
    return Futures.completeOn(storeHelper.createTable(DELETED_KVTABLES_TABLE, context.getRequestId()).thenCompose(created -> {
        return storeHelper.expectingDataNotFound(storeHelper.getCachedOrLoad(DELETED_KVTABLES_TABLE, key, BYTES_TO_INTEGER_FUNCTION, System.currentTimeMillis(), context.getRequestId()), null).thenCompose(existing -> {
            log.debug(context.getRequestId(), "Recording last segment {} for KeyValueTable {}/{} on deletion.", lastActiveSegment, scope, kvtable);
            if (existing != null) {
                final int oldLastActiveSegment = existing.getObject();
                Preconditions.checkArgument(lastActiveSegment >= oldLastActiveSegment, "Old last active segment ({}) for {}/{} is higher than current one {}.", oldLastActiveSegment, scope, kvtable, lastActiveSegment);
                return Futures.toVoid(storeHelper.updateEntry(DELETED_KVTABLES_TABLE, key, lastActiveSegment, INTEGER_TO_BYTES_FUNCTION, existing.getVersion(), context.getRequestId()));
            } else {
                return Futures.toVoid(storeHelper.addNewEntryIfAbsent(DELETED_KVTABLES_TABLE, key, lastActiveSegment, INTEGER_TO_BYTES_FUNCTION, context.getRequestId()));
            }
        });
    }), executor);
}
Also used : OperationContext(io.pravega.controller.store.stream.OperationContext) OperationContext(io.pravega.controller.store.stream.OperationContext) 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) TagLogger(io.pravega.common.tracing.TagLogger) AccessLevel(lombok.AccessLevel) StoreException(io.pravega.controller.store.stream.StoreException) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) INTEGER_TO_BYTES_FUNCTION(io.pravega.controller.store.PravegaTablesStoreHelper.INTEGER_TO_BYTES_FUNCTION) NameUtils(io.pravega.shared.NameUtils) Executor(java.util.concurrent.Executor) CompletionException(java.util.concurrent.CompletionException) UUID(java.util.UUID) PravegaTablesScope(io.pravega.controller.store.PravegaTablesScope) CuratorFramework(org.apache.curator.framework.CuratorFramework) 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) Futures(io.pravega.common.concurrent.Futures) GrpcAuthHelper(io.pravega.controller.server.security.auth.GrpcAuthHelper)

Example 2 with INTEGER_TO_BYTES_FUNCTION

use of io.pravega.controller.store.PravegaTablesStoreHelper.INTEGER_TO_BYTES_FUNCTION 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)2 Preconditions (com.google.common.base.Preconditions)2 Exceptions (io.pravega.common.Exceptions)2 Futures (io.pravega.common.concurrent.Futures)2 TagLogger (io.pravega.common.tracing.TagLogger)2 SegmentHelper (io.pravega.controller.server.SegmentHelper)2 GrpcAuthHelper (io.pravega.controller.server.security.auth.GrpcAuthHelper)2 PravegaTablesScope (io.pravega.controller.store.PravegaTablesScope)2 PravegaTablesStoreHelper (io.pravega.controller.store.PravegaTablesStoreHelper)2 BYTES_TO_INTEGER_FUNCTION (io.pravega.controller.store.PravegaTablesStoreHelper.BYTES_TO_INTEGER_FUNCTION)2 INTEGER_TO_BYTES_FUNCTION (io.pravega.controller.store.PravegaTablesStoreHelper.INTEGER_TO_BYTES_FUNCTION)2 ZKHostIndex (io.pravega.controller.store.index.ZKHostIndex)2 NameUtils (io.pravega.shared.NameUtils)2 NameUtils.getQualifiedTableName (io.pravega.shared.NameUtils.getQualifiedTableName)2 UUID (java.util.UUID)2 CompletableFuture (java.util.concurrent.CompletableFuture)2 CompletionException (java.util.concurrent.CompletionException)2 Executor (java.util.concurrent.Executor)2 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)2 AccessLevel (lombok.AccessLevel)2