/** * Similar to {@link RocksDB#get(byte[])} but will also * read writes from this batch. * * This function will query both this batch and the DB and then merge * the results using the DB's merge operator (if the batch contains any * merge requests). * * Setting {@link ReadOptions#setSnapshot(long, long)} will affect what is * read from the DB but will NOT change which keys are read from the batch * (the keys in this batch do not yet belong to any snapshot and will be * fetched regardless). * * @param db The Rocks database * @param options The read options to use * @param key The key to read the value for * * @return a byte array storing the value associated with the input key if * any. null if it does not find the specified key. * * @throws RocksDBException if the value for the key cannot be read */ public byte[] getFromBatchAndDB(final RocksDB db, final ReadOptions options, final byte[] key) throws RocksDBException { return getFromBatchAndDB(nativeHandle_, db.nativeHandle_, options.nativeHandle_, key, key.length); }
/** * Similar to {@link RocksDB#get(ColumnFamilyHandle, byte[])} but will also * read writes from this batch. * * This function will query both this batch and the DB and then merge * the results using the DB's merge operator (if the batch contains any * merge requests). * * Setting {@link ReadOptions#setSnapshot(long, long)} will affect what is * read from the DB but will NOT change which keys are read from the batch * (the keys in this batch do not yet belong to any snapshot and will be * fetched regardless). * * @param db The Rocks database * @param columnFamilyHandle The column family to retrieve the value from * @param options The read options to use * @param key The key to read the value for * * @return a byte array storing the value associated with the input key if * any. null if it does not find the specified key. * * @throws RocksDBException if the value for the key cannot be read */ public byte[] getFromBatchAndDB(final RocksDB db, final ColumnFamilyHandle columnFamilyHandle, final ReadOptions options, final byte[] key) throws RocksDBException { return getFromBatchAndDB(nativeHandle_, db.nativeHandle_, options.nativeHandle_, key, key.length, columnFamilyHandle.nativeHandle_); }
public Map<NodeId, DAGNode> getAll(Set<NodeId> nodeIds) { if (nodeIds.isEmpty()) { return ImmutableMap.of(); } Map<NodeId, DAGNode> res = new HashMap<>(); lock.readLock().lock(); try { for (NodeId id : nodeIds) { byte[] key = toKey(id); byte[] val; if (_db == null) { val = batch.getFromBatch(batchOptions, key); } else { val = batch.getFromBatchAndDB(db(), readOptions, key); } Preconditions.checkState(val != null); DAGNode node = decode(val); res.put(id, node); } } catch (RocksDBException e) { throw new RuntimeException(e); } finally { lock.readLock().unlock(); } return res; }
private NodeData getNodeInternal(final RocksDBReference dbRef, final ObjectId id, final boolean failIfNotFound, @Nullable WriteBatchWithIndex batch) { Preconditions.checkNotNull(id, "id"); byte[] key = id.getRawValue(); byte[] data; try (ReadOptions ro = new ReadOptions()) { final RocksDB db = dbRef.db(); if (batch == null) { data = db.get(key); } else { data = batch.getFromBatchAndDB(db, ro, key); } } catch (RocksDBException e) { throw propagate(e); } if (null == data) { if (failIfNotFound) { throw new IllegalArgumentException("Graph Object does not exist: " + id); } return null; } NodeData node = BINDING.entryToObject(data); return node; }
private NodeData getNodeInternal(final RocksDBReference dbRef, final ObjectId id, final boolean failIfNotFound, @Nullable WriteBatchWithIndex batch) { Preconditions.checkNotNull(id, "id"); byte[] key = id.getRawValue(); byte[] data; try (ReadOptions ro = new ReadOptions()) { final RocksDB db = dbRef.db(); if (batch == null) { data = db.get(key); } else { data = batch.getFromBatchAndDB(db, ro, key); } } catch (RocksDBException e) { throw new RuntimeException(e); } if (null == data) { if (failIfNotFound) { throw new IllegalArgumentException("Graph Object does not exist: " + id); } return null; } NodeData node = BINDING.entryToObject(data); return node; }