Search in sources :

Example 1 with RocksBiPredicate

use of org.apache.ignite.internal.rocksdb.RocksBiPredicate in project ignite-3 by apache.

the class RocksDbKeyValueStorage method higherOrCeiling.

/**
 * Gets an entry from the keys index with the least key greater than or equal to the specified key, depending on the strictlyHigher
 * parameter.
 *
 * @param key Key.
 * @param strictlyHigher {@code true} for a strictly higher entry, {@code false} for a ceiling one.
 * @return Entry for the least key greater than or equal to the specified key. If no such entry exists returns {@code null}.
 */
@Nullable
private IgniteBiTuple<byte[], long[]> higherOrCeiling(byte[] key, boolean strictlyHigher) {
    try (RocksIterator iterator = index.newIterator()) {
        iterator.seek(key);
        RocksBiPredicate predicate = strictlyHigher ? (k, v) -> CMP.compare(k, key) > 0 : (k, v) -> CMP.compare(k, key) >= 0;
        boolean found = find(iterator, predicate);
        if (!found) {
            return null;
        }
        return new IgniteBiTuple<>(iterator.key(), getAsLongs(iterator.value()));
    } catch (RocksDBException e) {
        throw new IgniteInternalException(e);
    }
}
Also used : RocksDBException(org.rocksdb.RocksDBException) RocksBiPredicate(org.apache.ignite.internal.rocksdb.RocksBiPredicate) IgniteBiTuple(org.apache.ignite.lang.IgniteBiTuple) IgniteInternalException(org.apache.ignite.lang.IgniteInternalException) RocksIterator(org.rocksdb.RocksIterator) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

RocksBiPredicate (org.apache.ignite.internal.rocksdb.RocksBiPredicate)1 IgniteBiTuple (org.apache.ignite.lang.IgniteBiTuple)1 IgniteInternalException (org.apache.ignite.lang.IgniteInternalException)1 Nullable (org.jetbrains.annotations.Nullable)1 RocksDBException (org.rocksdb.RocksDBException)1 RocksIterator (org.rocksdb.RocksIterator)1