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);
}
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);
}
Aggregations