From ebe0eb6c2d19daa954ca5dd9f3781ed075ab62e2 Mon Sep 17 00:00:00 2001 From: Huahai Yang Date: Mon, 20 Jul 2020 23:44:34 -0700 Subject: [PATCH] reset transaction after obtaining entries --- CHANGELOG.md | 3 +++ src/datalevin/constants.cljc | 2 +- src/datalevin/lmdb.clj | 10 +++++++--- test/datalevin/lmdb_test.clj | 8 ++++++++ 4 files changed, 19 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cd0c192e..b5fd7162 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/src/datalevin/constants.cljc b/src/datalevin/constants.cljc index 32317690..094ee2ab 100644 --- a/src/datalevin/constants.cljc +++ b/src/datalevin/constants.cljc @@ -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 diff --git a/src/datalevin/lmdb.clj b/src/datalevin/lmdb.clj index b9651613..4ff8e912 100644 --- a/src/datalevin/lmdb.clj +++ b/src/datalevin/lmdb.clj @@ -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.") diff --git a/test/datalevin/lmdb_test.clj b/test/datalevin/lmdb_test.clj index d66854d1..e60fc2d9 100644 --- a/test/datalevin/lmdb_test.clj +++ b/test/datalevin/lmdb_test.clj @@ -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))) @@ -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))))