Refine search
@Override public Collection<K> listKeys() { Collection<K> keys = new ArrayList<>(); RocksIterator itr = rocksDb.newIterator(columnFamily); itr.seekToFirst(); while (itr.isValid()) { keys.add((K) serializer.deserialize(itr.key())); itr.next(); } return keys; }
@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 void close() { iterator.close(); } }
protected boolean makeMore() { if(innerIterator.isValid()) { byte[] keyEntry = innerIterator.key(); byte[] valueEntry = innerIterator.value(); innerIterator.next(); if (RocksDbStorageEngine.this.isPartitionScanSupported()) { keyEntry = StoreBinaryFormat.extractKey(keyEntry); } ByteArray key = new ByteArray(keyEntry); for(Versioned<byte[]> val: StoreBinaryFormat.fromByteArray(valueEntry)) { cache.add(new Pair<ByteArray, Versioned<byte[]>>(key, val)); } return true; } return false; }
@Override public <T> List<Pair<String, T>> fetchTop(int size, Type type) throws FailStoreException { RocksIterator iterator = null; try { List<Pair<String, T>> list = new ArrayList<Pair<String, T>>(size); iterator = db.newIterator(); for (iterator.seekToFirst(); iterator.isValid(); iterator.next()) { iterator.status(); String key = new String(iterator.key(), "UTF-8"); T value = JSON.parse(new String(iterator.value(), "UTF-8"), type); Pair<String, T> pair = new Pair<String, T>(key, value); list.add(pair); if (list.size() >= size) { break; } } return list; } catch (Exception e) { throw new FailStoreException(e); } finally { if (iterator != null) { iterator.dispose(); } } }
@Override public void clearIndex(IndexInfo index) { checkOpen(); byte[] mappingKey = computeIndexTreePrefixLookupKey(index.getId()); try (RocksDBReference dbRef = dbhandle.getReference()) { try (RocksIterator it = dbRef.db().newIterator(indexMappingsColumn)) { it.seek(mappingKey); while (it.isValid()) { byte[] key = it.key(); for (int i = 0; i < mappingKey.length; i++) { if (mappingKey[i] != key[i]) { return; } } it.next(); dbRef.db().delete(indexMappingsColumn, key); } } catch (RocksDBException e) { throw new RuntimeException(e); } } }
@Override public ByteArray next() { if(!this.innerIterator.isValid()) { throw new NoSuchElementException("Iterate to end"); } byte[] keyEntry = this.innerIterator.key(); this.innerIterator.next(); if (RocksDbStorageEngine.this.isPartitionScanSupported()) { keyEntry = StoreBinaryFormat.extractKey(keyEntry); } return new ByteArray(keyEntry); }
@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(); } } }; }
@Benchmark public void readRev(final Reader r, final Blackhole bh) { final RocksIterator iterator = r.db.newIterator(); iterator.seekToLast(); while (iterator.isValid()) { bh.consume(iterator.value()); iterator.prev(); } }
@Override public boolean hasChildren(InodeDirectoryView inode) { RocksIterator iter = mDb.newIterator(mEdgesColumn, mReadPrefixSameAsStart); iter.seek(Longs.toByteArray(inode.getId())); return iter.isValid(); }
public Map.Entry<byte[], byte[]> peekPrev() { iterator.prev(); try { return peekNext(); } finally { if (iterator.isValid()) { iterator.next(); } else { iterator.seekToFirst(); } } }
public RocksdbKeysIterator(RocksIterator innerIterator) { this.innerIterator = innerIterator; // Caller of the RocksIterator should seek it before the first use. this.innerIterator.seekToFirst(); }
@Override public synchronized KVIterator<K, V> range(K from, K to) { checkStoreOpen(); RocksIterator rocksIter = db.newIterator(dataCfHandle); if (null == from) { rocksIter.seekToFirst(); } else { byte[] fromBytes = keyCoder.encode(from); rocksIter.seek(fromBytes); } KVIterator<K, V> kvIter; if (null == to) { kvIter = new RocksdbKVIterator(name, rocksIter, keyCoder, valCoder); } else { kvIter = new RocksdbRangeIterator(name, rocksIter, keyCoder, valCoder, to); } kvIters.add(kvIter); return kvIter; }
@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 boolean isEmpty() { putAll(); boolean empty = true; try (RocksIterator it = db.newIterator()) { empty = it.isValid(); } return empty; }
@Override public boolean hasNext() { this.matched = this.itor.isOwningHandle(); if (!this.matched) { // Maybe closed return this.matched; } this.matched = this.itor.isValid(); if (this.matched) { // Update position for paging this.position = this.itor.key(); // Do filter if not SCAN_ANY if (!this.match(Session.SCAN_ANY)) { this.matched = this.filter(this.position); } } if (!this.matched) { // The end this.position = null; // Free the iterator if finished this.close(); } return this.matched; }