Search in sources :

Example 1 with KeyValueTable

use of io.pravega.controller.store.kvtable.KeyValueTable 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)

Example 2 with KeyValueTable

use of io.pravega.controller.store.kvtable.KeyValueTable in project pravega by pravega.

the class CreateTableTask method execute.

@Override
public CompletableFuture<Void> execute(final CreateTableEvent request) {
    String scope = request.getScopeName();
    String kvt = request.getKvtName();
    int partitionCount = request.getPartitionCount();
    int primaryKeyLength = request.getPrimaryKeyLength();
    int secondaryKeyLength = request.getSecondaryKeyLength();
    long creationTime = request.getTimestamp();
    long requestId = request.getRequestId();
    long rolloverSize = request.getRolloverSizeBytes();
    String kvTableId = request.getTableId().toString();
    KeyValueTableConfiguration config = KeyValueTableConfiguration.builder().partitionCount(partitionCount).primaryKeyLength(primaryKeyLength).secondaryKeyLength(secondaryKeyLength).rolloverSizeBytes(rolloverSize).build();
    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 create event for KeyValueTable {}/{} with Id:{} as UUIDs did not match.", scope, kvt, id);
            return CompletableFuture.completedFuture(null);
        } else {
            return kvtMetadataStore.isScopeSealed(scope, context, executor).thenCompose(isScopeSealed -> {
                if (isScopeSealed) {
                    log.warn(requestId, "Scope {} is in sealed state: ", scope);
                    throw new IllegalStateException("Scope in sealed state: " + scope);
                }
                return this.kvtMetadataStore.createKeyValueTable(scope, kvt, config, creationTime, context, executor).thenComposeAsync(response -> {
                    // segments and change the state of the kvtable to active.
                    if (response.getStatus().equals(CreateKVTableResponse.CreateStatus.NEW) || response.getStatus().equals(CreateKVTableResponse.CreateStatus.EXISTS_CREATING)) {
                        final int startingSegmentNumber = response.getStartingSegmentNumber();
                        final int minNumSegments = response.getConfiguration().getPartitionCount();
                        final int keyLength = response.getConfiguration().getPrimaryKeyLength() + response.getConfiguration().getSecondaryKeyLength();
                        List<Long> newSegments = IntStream.range(startingSegmentNumber, startingSegmentNumber + minNumSegments).boxed().map(x -> NameUtils.computeSegmentId(x, 0)).collect(Collectors.toList());
                        kvtMetadataTasks.createNewSegments(scope, kvt, newSegments, keyLength, requestId, config.getRolloverSizeBytes()).thenCompose(y -> {
                            kvtMetadataStore.getVersionedState(scope, kvt, context, executor).thenCompose(state -> {
                                if (state.getObject().equals(KVTableState.CREATING)) {
                                    kvtMetadataStore.updateVersionedState(scope, kvt, KVTableState.ACTIVE, state, context, executor);
                                }
                                return CompletableFuture.completedFuture(null);
                            });
                            return CompletableFuture.completedFuture(null);
                        });
                    }
                    return CompletableFuture.completedFuture(null);
                }, executor);
            });
        }
    }), e -> Exceptions.unwrap(e) instanceof RetryableException, Integer.MAX_VALUE, executor);
}
Also used : OperationContext(io.pravega.controller.store.stream.OperationContext) IntStream(java.util.stream.IntStream) OperationContext(io.pravega.controller.store.stream.OperationContext) NameUtils(io.pravega.shared.NameUtils) KeyValueTable(io.pravega.controller.store.kvtable.KeyValueTable) Exceptions(io.pravega.common.Exceptions) LoggerFactory(org.slf4j.LoggerFactory) CompletableFuture(java.util.concurrent.CompletableFuture) CreateKVTableResponse(io.pravega.controller.store.kvtable.CreateKVTableResponse) KeyValueTableConfiguration(io.pravega.client.tables.KeyValueTableConfiguration) TableMetadataTasks(io.pravega.controller.task.KeyValueTable.TableMetadataTasks) Collectors(java.util.stream.Collectors) KVTableMetadataStore(io.pravega.controller.store.kvtable.KVTableMetadataStore) CreateTableEvent(io.pravega.shared.controller.event.kvtable.CreateTableEvent) List(java.util.List) TagLogger(io.pravega.common.tracing.TagLogger) RetryableException(io.pravega.controller.retryable.RetryableException) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) Preconditions(com.google.common.base.Preconditions) KVTableState(io.pravega.controller.store.kvtable.KVTableState) RetryHelper(io.pravega.controller.util.RetryHelper) KeyValueTableConfiguration(io.pravega.client.tables.KeyValueTableConfiguration) RetryableException(io.pravega.controller.retryable.RetryableException) List(java.util.List)

Aggregations

Preconditions (com.google.common.base.Preconditions)2 Exceptions (io.pravega.common.Exceptions)2 TagLogger (io.pravega.common.tracing.TagLogger)2 RetryableException (io.pravega.controller.retryable.RetryableException)2 KVTableMetadataStore (io.pravega.controller.store.kvtable.KVTableMetadataStore)2 KeyValueTable (io.pravega.controller.store.kvtable.KeyValueTable)2 OperationContext (io.pravega.controller.store.stream.OperationContext)2 TableMetadataTasks (io.pravega.controller.task.KeyValueTable.TableMetadataTasks)2 RetryHelper (io.pravega.controller.util.RetryHelper)2 CompletableFuture (java.util.concurrent.CompletableFuture)2 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)2 LoggerFactory (org.slf4j.LoggerFactory)2 KeyValueTableConfiguration (io.pravega.client.tables.KeyValueTableConfiguration)1 Futures (io.pravega.common.concurrent.Futures)1 CreateKVTableResponse (io.pravega.controller.store.kvtable.CreateKVTableResponse)1 KVTableState (io.pravega.controller.store.kvtable.KVTableState)1 StoreException (io.pravega.controller.store.stream.StoreException)1 NameUtils (io.pravega.shared.NameUtils)1 CreateTableEvent (io.pravega.shared.controller.event.kvtable.CreateTableEvent)1 DeleteTableEvent (io.pravega.shared.controller.event.kvtable.DeleteTableEvent)1