Skip to content

Commit

Permalink
reset transaction after obtaining entries
Browse files Browse the repository at this point in the history
  • Loading branch information
huahaiy committed Jul 21, 2020
1 parent 1444fc5 commit ebe0eb6
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 4 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
All notable changes to this project will be documented in this file. This change log follows the conventions of [keepachangelog.com](http://keepachangelog.com/).

## WIP
## Fixed
- Reset transaction after getting entries
- Only use 24 reader slots

## 0.2.4
## Fixed
Expand Down
2 changes: 1 addition & 1 deletion src/datalevin/constants.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

(def ^:const +max-dbs+ 128)
(def ^:const +max-readers+ 126)
(def ^:const +use-readers+ 64) ; leave the rest to others
(def ^:const +use-readers+ 24) ; leave the rest to others
(def ^:const +init-db-size+ 100) ; in megabytes
(def ^:const +default-val-size+ 16384) ; in bytes
(def ^:const +max-key-size+ 511) ; in bytes
Expand Down
10 changes: 7 additions & 3 deletions src/datalevin/lmdb.clj
Original file line number Diff line number Diff line change
Expand Up @@ -559,9 +559,13 @@
(entries [this dbi-name]
(assert (not (closed? this)) "LMDB env is closed.")
(let [^DBI dbi (get-dbi this dbi-name)
^Rtx rtx (get-rtx pool)
^Stat stat (.stat ^Dbi (.-db dbi) (.-txn rtx))]
(.-entries stat)))
^Rtx rtx (get-rtx pool)]
(try
(.-entries ^Stat (.stat ^Dbi (.-db dbi) (.-txn rtx)))
(catch Exception e
(raise "Fail to get entries: " (ex-message e)
{:dbi dbi-name}))
(finally (reset rtx)))))

(transact [this txs]
(assert (not (closed? this)) "LMDB env is closed.")
Expand Down
8 changes: 8 additions & 0 deletions test/datalevin/lmdb_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@
[:put "b" :long 1 :data :long]
[:put "b" 2 3 :long :long]]))

(testing "entries"
(is (= 6 (sut/entries lmdb "a")))
(is (= 9 (sut/entries lmdb "b"))))

(testing "get-value"
(is (= 2 (sut/get-value lmdb "a" 1)))
(is (= [1 2] (sut/get-value lmdb "a" 1 :data :data false)))
Expand All @@ -71,6 +75,10 @@
[:del "a" :non-exist]])
(is (nil? (sut/get-value lmdb "a" 1))))

(testing "entries-again"
(is (= 5 (sut/entries lmdb "a")))
(is (= 9 (sut/entries lmdb "b"))))

(testing "non-existent dbi"
(is (thrown-with-msg? Exception #"open-dbi" (sut/get-value lmdb "z" 1))))

Expand Down

0 comments on commit ebe0eb6

Please sign in to comment.