summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpukkamustard <pukkamustard@posteo.net>2021-01-12 11:19:10 +0100
committerpukkamustard <pukkamustard@posteo.net>2021-01-12 11:19:10 +0100
commit617a31003623bce844cb077cdec45cfb7b604f7f (patch)
tree399cc7a1239e0335bab7868261ec609eec86b034
parent55944bb4bd6535936ab8c939ae10da196779d1c7 (diff)
(lmdb): use MDB_NOTLS and MDB_RDONLY flags
-rw-r--r--lmdb.scm13
1 files changed, 8 insertions, 5 deletions
diff --git a/lmdb.scm b/lmdb.scm
index 8495c8a..39d3846 100644
--- a/lmdb.scm
+++ b/lmdb.scm
@@ -49,7 +49,7 @@
(dbi lmdb-db-dbi)
(closed? lmdb-db-closed? set-lmdb-db-closed?))
-(define* (lmdb-open path #:key db-name)
+(define* (lmdb-open path #:key (db-name #f))
;; create environment
(define env (mdb-env-create))
@@ -57,7 +57,8 @@
(raise-lmdb-error env))
;; open environment
- (define mdb-env-open-return-code (mdb-env-open env path))
+ (define mdb-env-open-return-code (mdb-env-open env path
+ #:flags (logior MDB_NOTLS)))
(unless (eqv? MDB_SUCCESS mdb-env-open-return-code)
(raise-lmdb-error mdb-env-open-return-code))
@@ -85,10 +86,11 @@
(define lmdb-transaction?
mdb-txn?)
-(define (call-with-txn db-or-txn proc)
+(define* (call-with-txn db-or-txn proc #:key (read-only #f))
(if (mdb-txn? db-or-txn)
(proc db-or-txn)
- (let* ((txn (mdb-txn-begin (lmdb-db-env db-or-txn)))
+ (let* ((txn-flags (if read-only MDB_RDONLY 0))
+ (txn (mdb-txn-begin (lmdb-db-env db-or-txn) #:flags txn-flags))
(return-value (proc txn)))
(mdb-txn-commit txn)
return-value)))
@@ -106,7 +108,8 @@
(let ((return-value
(call-with-txn db (lambda (txn)
(mdb-get txn (lmdb-db-dbi db)
- (make-mdb-val key))))))
+ (make-mdb-val key)))
+ #:read-only #t)))
(cond
((mdb-val? return-value) (mdb-val-data return-value))
((eqv? return-value MDB_NOTFOUND) #f)