use of io.pravega.controller.store.PravegaTablesStoreHelper.BYTES_TO_INTEGER_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);
}
use of io.pravega.controller.store.PravegaTablesStoreHelper.BYTES_TO_INTEGER_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);
}
Aggregations