use of org.apache.ignite.internal.rocksdb.RocksIteratorAdapter in project ignite-3 by apache.
the class PersistentVaultService method range.
/**
* {@inheritDoc}
*/
@Override
@NotNull
public Cursor<VaultEntry> range(@NotNull ByteArray fromKey, @NotNull ByteArray toKey) {
var readOpts = new ReadOptions();
var upperBound = new Slice(toKey.bytes());
readOpts.setIterateUpperBound(upperBound);
RocksIterator it = db.newIterator(readOpts);
it.seek(fromKey.bytes());
return new RocksIteratorAdapter<>(it) {
@Override
protected VaultEntry decodeEntry(byte[] key, byte[] value) {
return new VaultEntry(new ByteArray(key), value);
}
@Override
public void close() throws Exception {
super.close();
IgniteUtils.closeAll(upperBound, readOpts);
}
};
}
use of org.apache.ignite.internal.rocksdb.RocksIteratorAdapter in project ignite-3 by apache.
the class RocksDbSortedIndexStorage method range.
@Override
public Cursor<IndexRow> range(IndexRowPrefix lowerBound, IndexRowPrefix upperBound) {
RocksIterator iter = indexCf.newIterator();
iter.seekToFirst();
return new RocksIteratorAdapter<>(iter) {
@Nullable
private PrefixComparator lowerBoundComparator = new PrefixComparator(descriptor, lowerBound);
private final PrefixComparator upperBoundComparator = new PrefixComparator(descriptor, upperBound);
@Override
public boolean hasNext() {
while (super.hasNext()) {
var row = new ByteBufferRow(it.key());
if (lowerBoundComparator != null) {
// if lower comparator is not null, then the lower bound has not yet been reached
if (lowerBoundComparator.compare(row) < 0) {
it.next();
continue;
} else {
// once the lower bound is reached, we no longer need to check it
lowerBoundComparator = null;
}
}
return upperBoundComparator.compare(row) <= 0;
}
return false;
}
@Override
protected IndexRow decodeEntry(byte[] key, byte[] value) {
return new BinaryIndexRow(key, value);
}
};
}
Aggregations