use of org.apache.bookkeeper.api.kv.result.DeleteResult in project bookkeeper by apache.
the class TableWriteView method rDelete.
default CompletableFuture<KeyValue<K, V>> rDelete(K key, long expectedRevision) {
Txn<K, V> txn = txn(key);
txn.If(opFactory().compareModRevision(CompareResult.EQUAL, key, expectedRevision)).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 rDelete key " + key + " (mod_rev = " + expectedRevision + ")"));
}
} finally {
result.close();
}
});
}
use of org.apache.bookkeeper.api.kv.result.DeleteResult in project bookkeeper by apache.
the class MVCCAsyncStore method rDelete.
@Override
default CompletableFuture<KeyValue<K, V>> rDelete(K k, long expectedRevision) {
TxnOp<K, V> op = getOpFactory().newTxn().If(newCompareModRevision(CompareResult.EQUAL, k, expectedRevision)).Then(getOpFactory().newDelete(k, Options.deleteAndGet())).build();
return txn(op).thenCompose(result -> {
try {
Code code = result.code();
if (Code.OK == code && !result.isSuccess()) {
code = Code.BAD_REVISION;
}
if (Code.OK == code) {
List<Result<K, V>> subResults = result.results();
DeleteResult<K, V> deleteResult = (DeleteResult<K, V>) subResults.get(0);
List<KeyValue<K, V>> prevKvs = deleteResult.getPrevKvsAndClear();
if (prevKvs.isEmpty()) {
return FutureUtils.value(null);
} else {
return FutureUtils.value(prevKvs.get(0));
}
} else {
return failWithCode(code, "Failed to rDelete key " + k + " (mod_rev=" + expectedRevision + ") to store " + name());
}
} finally {
result.close();
}
});
}
use of org.apache.bookkeeper.api.kv.result.DeleteResult in project bookkeeper by apache.
the class MVCCAsyncStore method vDelete.
@Override
default CompletableFuture<KeyValue<K, V>> vDelete(K k, long expectedVersion) {
TxnOp<K, V> op = getOpFactory().newTxn().If(newCompareVersion(CompareResult.EQUAL, k, expectedVersion)).Then(getOpFactory().newDelete(k, Options.deleteAndGet())).build();
return txn(op).thenCompose(result -> {
try {
Code code = result.code();
if (Code.OK == code && !result.isSuccess()) {
code = Code.BAD_REVISION;
}
if (Code.OK == code) {
List<Result<K, V>> subResults = result.results();
DeleteResult<K, V> deleteResult = (DeleteResult<K, V>) subResults.get(0);
List<KeyValue<K, V>> prevKvs = deleteResult.getPrevKvsAndClear();
if (prevKvs.isEmpty()) {
return FutureUtils.value(null);
} else {
return FutureUtils.value(prevKvs.get(0));
}
} else {
return failWithCode(code, "Failed to vDelete key " + k + " (version=" + expectedVersion + ") to store " + name());
}
} finally {
result.close();
}
});
}
use of org.apache.bookkeeper.api.kv.result.DeleteResult in project bookkeeper by apache.
the class PTableWriteView method vDelete.
default CompletableFuture<KeyValue<K, V>> vDelete(K pKey, K lKey, long expectedVersion) {
Txn<K, V> txn = txn(pKey);
txn.If(opFactory().compareVersion(CompareResult.EQUAL, lKey, expectedVersion)).Then(opFactory().newDelete(lKey, 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 " + lKey + " (version = " + expectedVersion + ")"));
}
} finally {
result.close();
}
});
}
use of org.apache.bookkeeper.api.kv.result.DeleteResult in project bookkeeper by apache.
the class PTableWriteView method rDelete.
default CompletableFuture<KeyValue<K, V>> rDelete(K pKey, K lKey, long expectedRevision) {
Txn<K, V> txn = txn(pKey);
txn.If(opFactory().compareModRevision(CompareResult.EQUAL, lKey, expectedRevision)).Then(opFactory().newDelete(lKey, 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 rDelete key " + lKey + " (mod_rev = " + expectedRevision + ")"));
}
} finally {
result.close();
}
});
}
Aggregations