1

How do I tell a RocksDB iterator to seek until the last matching prefix?

In Clojure using the RocksDB Java API:

(import '(org.rocksdb RocksDB Options ReadOptions RocksIterator Slice))
(let [opts (-> (ReadOptions.)
               (.setPrefixSameAsStart true)
               (.setTotalOrderSeek true))
      iter (.newIterator db)]
  (.seek iter (.getBytes ("some-prefix:"))
  (.key iter))
=> "not-matching-prefix"

Do I have to manually check if the next key matches the prefix? This seems suboptimal because I have to stream in the whole key to check it, when RocksDB could eject early.

Petrus Theron
  • 27,855
  • 36
  • 153
  • 287

1 Answers1

4

Yes, you can provide RocksDB the upper bound to optimize it - by using setIterateUpperBound in ReadOptions.

rmcv
  • 1,956
  • 1
  • 9
  • 8