Search in sources :

Example 1 with DeleteResult

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();
        }
    });
}
Also used : KeyValue(org.apache.bookkeeper.api.kv.result.KeyValue) KvApiException(org.apache.bookkeeper.api.kv.exceptions.KvApiException) DeleteResult(org.apache.bookkeeper.api.kv.result.DeleteResult)

Example 2 with DeleteResult

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();
        }
    });
}
Also used : KeyValue(org.apache.bookkeeper.api.kv.result.KeyValue) Code(org.apache.bookkeeper.api.kv.result.Code) DeleteResult(org.apache.bookkeeper.api.kv.result.DeleteResult) DeleteResult(org.apache.bookkeeper.api.kv.result.DeleteResult) Result(org.apache.bookkeeper.api.kv.result.Result) RangeResult(org.apache.bookkeeper.api.kv.result.RangeResult) CompareResult(org.apache.bookkeeper.api.kv.op.CompareResult)

Example 3 with DeleteResult

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();
        }
    });
}
Also used : KeyValue(org.apache.bookkeeper.api.kv.result.KeyValue) Code(org.apache.bookkeeper.api.kv.result.Code) DeleteResult(org.apache.bookkeeper.api.kv.result.DeleteResult) DeleteResult(org.apache.bookkeeper.api.kv.result.DeleteResult) Result(org.apache.bookkeeper.api.kv.result.Result) RangeResult(org.apache.bookkeeper.api.kv.result.RangeResult) CompareResult(org.apache.bookkeeper.api.kv.op.CompareResult)

Example 4 with DeleteResult

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();
        }
    });
}
Also used : KeyValue(org.apache.bookkeeper.api.kv.result.KeyValue) KvApiException(org.apache.bookkeeper.api.kv.exceptions.KvApiException) DeleteResult(org.apache.bookkeeper.api.kv.result.DeleteResult)

Example 5 with DeleteResult

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();
        }
    });
}
Also used : KeyValue(org.apache.bookkeeper.api.kv.result.KeyValue) KvApiException(org.apache.bookkeeper.api.kv.exceptions.KvApiException) DeleteResult(org.apache.bookkeeper.api.kv.result.DeleteResult)

Aggregations

DeleteResult (org.apache.bookkeeper.api.kv.result.DeleteResult)6 KeyValue (org.apache.bookkeeper.api.kv.result.KeyValue)6 KvApiException (org.apache.bookkeeper.api.kv.exceptions.KvApiException)4 CompareResult (org.apache.bookkeeper.api.kv.op.CompareResult)2 Code (org.apache.bookkeeper.api.kv.result.Code)2 RangeResult (org.apache.bookkeeper.api.kv.result.RangeResult)2 Result (org.apache.bookkeeper.api.kv.result.Result)2