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