Search in sources :

Example 1 with RocksIteratorAdapter

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);
        }
    };
}
Also used : ReadOptions(org.rocksdb.ReadOptions) Slice(org.rocksdb.Slice) VaultEntry(org.apache.ignite.internal.vault.VaultEntry) ByteArray(org.apache.ignite.lang.ByteArray) RocksIterator(org.rocksdb.RocksIterator) RocksIteratorAdapter(org.apache.ignite.internal.rocksdb.RocksIteratorAdapter) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with RocksIteratorAdapter

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);
        }
    };
}
Also used : ByteBufferRow(org.apache.ignite.internal.schema.ByteBufferRow) RocksIterator(org.rocksdb.RocksIterator) RocksIteratorAdapter(org.apache.ignite.internal.rocksdb.RocksIteratorAdapter)

Aggregations

RocksIteratorAdapter (org.apache.ignite.internal.rocksdb.RocksIteratorAdapter)2 RocksIterator (org.rocksdb.RocksIterator)2 ByteBufferRow (org.apache.ignite.internal.schema.ByteBufferRow)1 VaultEntry (org.apache.ignite.internal.vault.VaultEntry)1 ByteArray (org.apache.ignite.lang.ByteArray)1 NotNull (org.jetbrains.annotations.NotNull)1 ReadOptions (org.rocksdb.ReadOptions)1 Slice (org.rocksdb.Slice)1