default CompletableFuture<Void> put(K key, V value) { if (value == null) { return delete(key).thenApply(ignored -> null); } return put(key, value, Options.blindPut()) .thenApply(result -> { try { return (Void) null; } finally { result.close(); } }); }
private void applyPutOp(long revision, PutOp<byte[], byte[]> op, boolean ignoreSmallerRevision, MVCCStoreImpl<byte[], byte[]> localStore) { try (PutResult<byte[], byte[]> result = localStore.put(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()); } }
@Override default CompletableFuture<Void> put(K k, V v) { if (v == null) { return delete(k).thenApply(ignored -> null); } PutOp<K, V> op = newPut(k, v); return put(op).thenCompose(result -> { try { if (Code.OK == result.code()) { return FutureUtils.Void(); } else { return failWithCode(result.code(), "Failed to put (" + k + ", " + v + ") to store " + name()); } } finally { result.close(); } }); }
default CompletableFuture<Void> put(K pKey, K lKey, V value) { if (value == null) { return delete(pKey, lKey).thenApply(ignored -> null); } return put(pKey, lKey, value, Options.blindPut()) .thenApply(result -> { try { return (Void) null; } finally { result.close(); } }); }
void put(K key, V value, long revision) { try (PutOp<K, V> op = opFactory.newPut( key, value, Options.blindPut())) { try (PutResult<K, V> result = put(revision, op)) { if (Code.OK != result.code()) { throw new MVCCStoreException(result.code(), "Failed to put (" + key + ", " + value + ", " + revision + ") to state store " + name); } } } }
synchronized PutResult<K, V> processPut(long revision, PutOp<K, V> op) { checkStoreOpen(); WriteBatch batch = new WriteBatch(); PutResult<K, V> result = null; try { result = put(revision, batch, op); executeBatch(batch); return result; } catch (StateStoreRuntimeException e) { if (null != result) { result.close(); } throw e; } finally { RocksUtils.close(batch); } }