private void applyIncrOp(long revision, IncrementOp<byte[], byte[]> op, boolean ignoreSmallerRevision, MVCCStoreImpl<byte[], byte[]> localStore) { try (IncrementResult<byte[], byte[]> result = localStore.increment(revision, op)) { if (Code.OK == result.code() || (ignoreSmallerRevision && Code.SMALLER_REVISION == result.code())) { return; } throw new MVCCStoreException(result.code(), "Failed to apply command " + op + " at revision " + revision + " to the state store " + localStore.name()); } }
void increment(K key, long amount, long revision) { try (IncrementOp<K, V> op = opFactory.newIncrement(key, amount, Options.blindIncrement())) { try (IncrementResult<K, V> result = increment(revision, op)) { if (Code.OK != result.code()) { throw new MVCCStoreException(result.code(), "Failed to increment (" + key + ", " + amount + ") to state store " + name); } } } }
@Override default CompletableFuture<Void> increment(K k, long amount) { IncrementOp<K, V> op = getOpFactory().newIncrement( k, amount, Options.blindIncrement()); return increment(op).thenCompose(result -> { try { Code code = result.code(); if (Code.OK == code) { return FutureUtils.Void(); } else { return failWithCode(code, "Failed to increment(" + k + ", " + amount + ") to store " + name()); } } finally { result.close(); } }); }
@Override default CompletableFuture<Long> incrementAndGet(K k, long amount) { IncrementOp<K, V> op = getOpFactory().newIncrement( k, amount, Options.incrementAndGet()); return increment(op).thenCompose(result -> { try { Code code = result.code(); if (Code.OK == code) { return FutureUtils.value(result.totalAmount()); } else { return failWithCode(code, "Failed to increment(" + k + ", " + amount + ") to store " + name()); } } finally { result.close(); } }); }
@Override default CompletableFuture<Long> getAndIncrement(K k, long amount) { IncrementOp<K, V> op = getOpFactory().newIncrement( k, amount, Options.incrementAndGet()); return increment(op).thenCompose(result -> { try { Code code = result.code(); if (Code.OK == code) { return FutureUtils.value(result.totalAmount() - amount); } else { return failWithCode(code, "Failed to increment(" + k + ", " + amount + ") to store " + name()); } } finally { result.close(); } }); } }