@Override public void seek(byte[] target) { iterator.seek(target); status(); }
private void seek() { if (this.keyBegin == null) { // Seek to the first if no `keyBegin` this.itor.seekToFirst(); } else { /* * Seek to `keyBegin`: * if set SCAN_GT_BEGIN/SCAN_GTE_BEGIN (key > / >= 'xx') * or if set SCAN_PREFIX_WITH_BEGIN (key prefix with 'xx') */ this.itor.seek(this.keyBegin); // Skip `keyBegin` if set SCAN_GT_BEGIN (key > 'xx') if (this.match(Session.SCAN_GT_BEGIN) && !this.match(Session.SCAN_GTE_BEGIN)) { while (this.itor.isValid() && Bytes.equals(this.itor.key(), this.keyBegin)) { this.itor.next(); } } } }
public RocksdbEntriesIterator(RocksIterator innerIterator, int partition) { this.innerIterator = innerIterator; this.partitionId = partition; // Caller of the RocksIterator should seek it before the first use. // seek to the prefix specified this.innerIterator.seek(StoreBinaryFormat.makePartitionKey(partition)); cache = new ArrayList<Pair<ByteArray, Versioned<byte[]>>>(); }
RangeIterator(ColumnFamily table, RocksIterator it, RangeRequest range, long maxTimestamp) { this.table = table; this.it = it; this.request = range; this.maxTimestamp = maxTimestamp; byte[] start = range.getStartInclusive(); if (start.length == 0) { it.seekToFirst(); } else { it.seek(RocksDbKeyValueServices.getKey(start, maxTimestamp - 1)); } }
public RocksdbKeysIterator(RocksIterator innerIterator, int partition) { this.innerIterator = innerIterator; this.partitionId = partition; // Caller of the RocksIterator should seek it to the prefix before // the first use. this.innerIterator.seek(StoreBinaryFormat.makePartitionKey(partition)); cache = null; }
@Override public Iterable<Long> getChildIds(Long inodeId) { RocksIterator iter = mDb.newIterator(mEdgesColumn, mReadPrefixSameAsStart); iter.seek(Longs.toByteArray(inodeId)); return () -> new Iterator<Long>() { @Override public boolean hasNext() { return iter.isValid(); } @Override public Long next() { try { return Longs.fromByteArray(iter.value()); } catch (Exception e) { throw new RuntimeException(e); } finally { iter.next(); } } }; }
@Override public byte[] prefixLookup(byte[] key, int prefixBytes) { if (prefixBytes != NodeKeyCompositor.PREFIX_BYTES) throw new RuntimeException("RocksDbDataSource.prefixLookup() supports only " + prefixBytes + "-bytes prefix"); resetDbLock.readLock().lock(); try { if (logger.isTraceEnabled()) logger.trace("~> RocksDbDataSource.prefixLookup(): " + name + ", key: " + toHexString(key)); // RocksDB sets initial position of iterator to the first key which is greater or equal to the seek key // since keys in RocksDB are ordered in asc order iterator must be initiated with the lowest key // thus bytes with indexes greater than PREFIX_BYTES must be nullified byte[] prefix = new byte[NodeKeyCompositor.PREFIX_BYTES]; arraycopy(key, 0, prefix, 0, NodeKeyCompositor.PREFIX_BYTES); byte[] ret = null; try (RocksIterator it = db.newIterator(readOpts)) { it.seek(prefix); if (it.isValid()) ret = it.value(); } catch (Exception e) { logger.error("Failed to seek by prefix in db '{}'", name, e); hintOnTooManyOpenFiles(e); throw new RuntimeException(e); } if (logger.isTraceEnabled()) logger.trace("<~ RocksDbDataSource.prefixLookup(): " + name + ", key: " + toHexString(key) + ", " + (ret == null ? "null" : ret.length)); return ret; } finally { resetDbLock.readLock().unlock(); } }
@Override public boolean hasChildren(InodeDirectoryView inode) { RocksIterator iter = mDb.newIterator(mEdgesColumn, mReadPrefixSameAsStart); iter.seek(Longs.toByteArray(inode.getId())); return iter.isValid(); }
@Override public List<BlockLocation> getLocations(long id) { RocksIterator iter = mDb.newIterator(mBlockLocationsColumn, new ReadOptions().setPrefixSameAsStart(true)); iter.seek(Longs.toByteArray(id)); List<BlockLocation> locations = new ArrayList<>(); for (; iter.isValid(); iter.next()) { try { locations.add(BlockLocation.parseFrom(iter.value())); } catch (Exception e) { throw new RuntimeException(e); } } return locations; }
@Override public Status scan(final String table, final String startkey, final int recordcount, final Set<String> fields, final Vector<HashMap<String, ByteIterator>> result) { try { if (!COLUMN_FAMILIES.containsKey(table)) { createColumnFamily(table); } final ColumnFamilyHandle cf = COLUMN_FAMILIES.get(table).getHandle(); try(final RocksIterator iterator = rocksDb.newIterator(cf)) { int iterations = 0; for (iterator.seek(startkey.getBytes(UTF_8)); iterator.isValid() && iterations < recordcount; iterator.next()) { final HashMap<String, ByteIterator> values = new HashMap<>(); deserializeValues(iterator.value(), fields, values); result.add(values); iterations++; } } return Status.OK; } catch(final RocksDBException e) { LOGGER.error(e.getMessage(), e); return Status.ERROR; } }
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; } } } }
for (iterator.seek(startKey.getRaw()); iterator.isValid(); iterator.next()) { RocksDbKey key = new RocksDbKey(iterator.key());
@Override public void seek(byte[] target) { iterator.seek(target); status(); }
@Override public void seek(byte[] target) { iterator.seek(target); status(); }
RocksDBRangeIterator(final String storeName, final RocksIterator iter, final Bytes from, final Bytes to) { super(storeName, iter); iter.seek(from.get()); rawToKey = to.get(); if (rawToKey == null) { throw new NullPointerException("RocksDBRangeIterator: RawToKey is null for key " + to); } }
private CloseableIterator<GeoWaveMetadata> prefixIterator(final byte[] prefix) { final ReadOptions options = new ReadOptions().setPrefixSameAsStart(true); final RocksIterator it = db.newIterator(options); it.seek(prefix); return new RocksDBMetadataIterator(options, it, requiresTimestamp, visibilityEnabled); }
@Override public Entry<byte[], byte[]> getCeil(byte[] key) throws IOException { try (RocksIterator iterator = db.newIterator(optionCache)) { // Position the iterator on the record whose key is >= to the supplied key iterator.seek(key); if (iterator.isValid()) { return new EntryWrapper(iterator.key(), iterator.value()); } else { return null; } } }
static Long getTimestamp(RocksIterator iter, Cell cell, long timestamp) { iter.seek(getKey(cell, timestamp - 1)); if (iter.isValid()) { Pair<Cell, Long> cellAndTs = parseCellAndTs(iter.key()); if (cellAndTs.lhSide.equals(cell)) { return cellAndTs.rhSide; } } return null; }
static void getTimestamps(RocksIterator iter, Cell cell, long timestamp, @Output Multimap<Cell, Long> results) { iter.seek(getKey(cell, timestamp - 1)); for (; iter.isValid(); iter.next()) { Pair<Cell, Long> cellAndTs = parseCellAndTs(iter.key()); if (!cell.equals(cellAndTs.lhSide)) { return; } results.put(cellAndTs.lhSide, cellAndTs.rhSide); } }
static Value getCell(RocksIterator iter, Cell cell, long timestamp) { iter.seek(getKey(cell, timestamp - 1)); if (iter.isValid()) { Pair<Cell, Long> cellAndTs = parseCellAndTs(iter.key()); if (cellAndTs.lhSide.equals(cell)) { return Value.create(iter.value(), cellAndTs.rhSide); } } return null; }