Skip to content

Commit

Permalink
Fix bug setting end of range prefix scan
Browse files Browse the repository at this point in the history
  • Loading branch information
tnavatar committed Aug 5, 2024
1 parent 124e079 commit f6d394d
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions src/genegraph/framework/storage/rocksdb.clj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
[net.openhft.hashing LongHashFunction]
[com.google.common.primitives Longs]))


(defn k->long [k]
(if (instance? Long k)
k
Expand Down Expand Up @@ -137,9 +136,16 @@
"Return the key defining the (exclusive) upper bound of a scan,
as defined by RANGE-KEY"
[^bytes range-key]
(let [last-byte-idx (dec (alength range-key))]
(doto (Arrays/copyOf range-key (alength range-key))
(aset-byte last-byte-idx (inc (aget range-key last-byte-idx))))))
(let [key-length (alength range-key)
key-prefix-idx (- key-length 8)
bb (ByteBuffer/allocate key-length)]
(.put bb range-key 0 key-prefix-idx)
(.put bb
(-> (Arrays/copyOfRange range-key key-prefix-idx key-length)
Longs/fromByteArray
inc
Longs/toByteArray))
(.array bb)))

(defn destroy [path]
(with-open [opts (Options.)]
Expand Down Expand Up @@ -255,7 +261,13 @@
(storage/write db [:one :three] :onethree)
(storage/write db [:four :five] :fourfive)
(storage/scan db :one))


(with-open [db (open "/users/tristan/desktop/test-rocks")]
(storage/write db [127 :two] :onetwo)
(storage/write db [127 :three] :onethree)
(storage/write db [4 :five] :fourfive)
(storage/scan db 127))

(with-open [db (open "/users/tristan/desktop/test-rocks")]
(storage/write db [:one :two] :onetwo)
(storage/write db [:one :three] :onethree)
Expand All @@ -268,6 +280,10 @@
(storage/write db [:four :five] :fourfive)
(storage/range-delete db :one)
(storage/scan db :one))

)





0 comments on commit f6d394d

Please sign in to comment.