@Override public Iterator<Block> iterator() { RocksIterator iter = mDb.newIterator(mBlockMetaColumn, new ReadOptions().setPrefixSameAsStart(true)); iter.seekToFirst(); return new Iterator<Block>() { @Override public boolean hasNext() { return iter.isValid(); } @Override public Block next() { try { return new Block(Longs.fromByteArray(iter.key()), BlockMeta.parseFrom(iter.value())); } catch (Exception e) { throw new RuntimeException(e); } finally { iter.next(); } } }; }
ReadOptions ro = new ReadOptions(); ro.setTotalOrderSeek(true); ro.close();
readOpts = new ReadOptions(); readOpts = readOpts.setPrefixSameAsStart(true) .setVerifyChecksums(false);
void scanRange(RocksDbKey start, RocksDbKey end, RocksDbScanCallback fn) { try (ReadOptions ro = new ReadOptions()) { ro.setTotalOrderSeek(true); RocksIterator iterator = db.newIterator(ro); for (iterator.seek(start.getRaw()); iterator.isValid(); iterator.next()) { RocksDbKey key = new RocksDbKey(iterator.key()); if (key.compareTo(end) >= 0) { // past limit, quit return; } RocksDbValue val = new RocksDbValue(iterator.value()); if (!fn.cb(key, val)) { // if cb returns false, we are done with this section of rows return; } } } }
private RocksDB db() { if (_db == null) { writeOptions = new WriteOptions(); writeOptions.setDisableWAL(true); writeOptions.setSync(false); readOptions = new ReadOptions(); readOptions.setFillCache(false).setVerifyChecksums(false); _db = _dbSupplier.get(); } return _db; }
private RocksDBIterator() { this.it = db.newIterator(new ReadOptions().setFillCache(false)); it.seekToFirst(); }
/** * Constructor. * * <p> * The caller is responsible for invoking {@link org.rocksdb.RocksObject#close close()} on any supplied * {@code readOptions} and/or {@code writeBatch}, after this instance is {@link #close}'d of course. * * @param db database * @param readOptions read options, or null for the default * @param writeBatch batch for write operations, or null for none * @throws IllegalArgumentException if {@code db} is null */ public RocksDBKVStore(RocksDB db, ReadOptions readOptions, WriteBatch writeBatch) { this(db, readOptions != null ? readOptions : new ReadOptions(), readOptions == null, writeBatch); }
private SnapshotRocksDBKVStore(RocksDB db, Snapshot snapshot) { super(db, new ReadOptions().setSnapshot(snapshot), true, null); this.snapshot = snapshot; }
@Override public void close() { resetDbLock.writeLock().lock(); try { if (!isAlive()) return; logger.debug("Close db: {}", name); db.close(); readOpts.close(); alive = false; } catch (Exception e) { logger.error("Error closing db '{}'", name, e); } finally { resetDbLock.writeLock().unlock(); } }
/** * Builds RocksDb {@link ReadOptions}. * * @param isTailing * @return */ public static ReadOptions buildReadOptions(boolean isTailing) { ReadOptions readOptions = new ReadOptions(); readOptions.setTailing(isTailing); return readOptions; }
public synchronized CloseableIterator<GeoWaveRow> iterator(final ByteArrayRange range) { final RocksDB readDb = getReadDb(); if (readDb == null) { return new CloseableIterator.Empty<>(); } final ReadOptions options; final RocksIterator it; if (range.getEnd() == null) { options = null; it = readDb.newIterator(); } else { options = new ReadOptions().setIterateUpperBound(new Slice(range.getEndAsNextPrefix())); it = readDb.newIterator(options); } if (range.getStart() == null) { it.seekToFirst(); } else { it.seek(range.getStart()); } return new RocksDBRowIterator( options, it, adapterId, partition, requiresTimestamp, visibilityEnabled); } }
/** * Fill the cache when loading the block-based sst formatted db. * Callers may wish to set this field to false for bulk scans. * Default: true * * @param fillCache if true, then fill-cache behavior will be * performed. * @return the reference to the current ReadOptions. */ public ReadOptions setFillCache(final boolean fillCache) { assert(isOwningHandle()); setFillCache(nativeHandle_, fillCache); return this; }
@Override public RocksDbReadOptions setFillCache(boolean fillCache) { super.setFillCache(fillCache); return this; }
/** * If true, all data read from underlying storage will be * verified against corresponding checksums. * Default: true * * @param verifyChecksums if true, then checksum verification * will be performed on every read. * @return the reference to the current ReadOptions. */ public ReadOptions setVerifyChecksums( final boolean verifyChecksums) { assert(isOwningHandle()); setVerifyChecksums(nativeHandle_, verifyChecksums); return this; }
/** * Enforce that the iterator only iterates over the same prefix as the seek. * This option is effective only for prefix seeks, i.e. prefix_extractor is * non-null for the column family and {@link #totalOrderSeek()} is false. * Unlike iterate_upper_bound, {@link #setPrefixSameAsStart(boolean)} only * works within a prefix but in both directions. * * @param prefixSameAsStart if true, then the iterator only iterates over the * same prefix as the seek * @return the reference to the current ReadOptions. */ public ReadOptions setPrefixSameAsStart(final boolean prefixSameAsStart) { assert(isOwningHandle()); setPrefixSameAsStart(nativeHandle_, prefixSameAsStart); return this; }
@Override public RocksDbReadOptions setPrefixSameAsStart(boolean prefixSameAsStart) { super.setPrefixSameAsStart(prefixSameAsStart); return this; }
@Override public RocksDbReadOptions setVerifyChecksums(boolean verifyChecksums) { super.setVerifyChecksums(verifyChecksums); return this; }
/** * Enable a total order seek regardless of index format (e.g. hash index) * used in the table. Some table format (e.g. plain table) may not support * this option. * * @param totalOrderSeek if true, then total order seek will be enabled. * @return the reference to the current ReadOptions. */ public ReadOptions setTotalOrderSeek(final boolean totalOrderSeek) { assert(isOwningHandle()); setTotalOrderSeek(nativeHandle_, totalOrderSeek); return this; }
/** * <p>If "snapshot" is non-nullptr, read as of the supplied snapshot * (which must belong to the DB that is being read and which must * not have been released). If "snapshot" is nullptr, use an implicit * snapshot of the state at the beginning of this read operation.</p> * <p>Default: null</p> * * @param snapshot {@link Snapshot} instance * @return the reference to the current ReadOptions. */ public ReadOptions setSnapshot(final Snapshot snapshot) { assert(isOwningHandle()); if (snapshot != null) { setSnapshot(nativeHandle_, snapshot.nativeHandle_); } else { setSnapshot(nativeHandle_, 0l); } return this; }
@Override public RocksDbReadOptions setSnapshot(Snapshot snapshot) { super.setSnapshot(snapshot); return this; }