use of org.apache.bookkeeper.api.kv.result.DeleteResult in project bookkeeper by apache.
the class TableWriteView method vDelete.
default CompletableFuture<KeyValue<K, V>> vDelete(K key, long expectedVersion) {
Txn<K, V> txn = txn(key);
txn.If(opFactory().compareVersion(CompareResult.EQUAL, key, expectedVersion)).Then(opFactory().newDelete(key, Options.deleteAndGet()));
return txn.commit().thenCompose(result -> {
try {
if (result.isSuccess()) {
DeleteResult<K, V> deleteResult = (DeleteResult<K, V>) result.results().get(0);
if (deleteResult.prevKvs().isEmpty()) {
return FutureUtils.value(null);
} else {
List<KeyValue<K, V>> prevKvs = deleteResult.getPrevKvsAndClear();
return FutureUtils.value(prevKvs.get(0));
}
} else {
return FutureUtils.exception(new KvApiException(Code.BAD_REVISION, "Failed to vDelete key " + key + " (version = " + expectedVersion + ")"));
}
} finally {
result.close();
}
});
}
Aggregations