-
Notifications
You must be signed in to change notification settings - Fork 160
/
kv.clj
53 lines (45 loc) · 2.08 KB
/
kv.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
(ns crux.fixtures.kv
(:require [clojure.java.io :as io]
[crux.fixtures :as fix]
[crux.system :as sys]))
(def ^:dynamic *kv-opts* {})
(defn with-kv-store* [f]
(fix/with-tmp-dirs #{db-dir}
(with-open [sys (-> (sys/prep-system
{:kv-store (merge (when-let [db-dir-suffix (:db-dir-suffix *kv-opts*)]
{:db-dir (io/file db-dir db-dir-suffix)})
*kv-opts*)})
(sys/start-system))]
(f (:kv-store sys)))))
(defmacro with-kv-store [bindings & body]
`(with-kv-store* (fn [~@bindings] ~@body)))
(def rocks-dep {:crux/module 'crux.rocksdb/->kv-store, :db-dir-suffix "rocksdb"})
(def lmdb-dep {:crux/module 'crux.lmdb/->kv-store, :db-dir-suffix "lmdb", :env-mapsize 4096})
(def memkv-dep {:crux/module 'crux.mem-kv/->kv-store})
(def mutablekv-dep {:crux/module 'crux.kv.mutable-kv/->mutable-kv-store})
(defn with-each-kv-store* [f]
(doseq [kv-opts [memkv-dep
mutablekv-dep
rocks-dep
{:crux/module `crux.rocksdb.jnr/->kv-store
:db-dir-suffix "rocksdb-jnr"}
lmdb-dep
{:crux/module `crux.lmdb.jnr/->kv-store
:db-dir-suffix "lmdb-jnr"
:env-mapsize 4096}]]
(binding [*kv-opts* (merge *kv-opts* kv-opts)]
(f))))
(defmacro with-each-kv-store [& body]
`(with-each-kv-store* (fn [] ~@body)))
(defn with-kv-store-opts* [kv-opts f]
(fix/with-tmp-dirs #{db-dir}
(letfn [(->kv-opts [module]
(merge (when-let [db-dir-suffix (:db-dir-suffix kv-opts)]
{:db-dir (io/file db-dir db-dir-suffix module)})
kv-opts))]
(fix/with-opts {:crux/tx-log {:kv-store (->kv-opts "tx-log")}
:crux/document-store {:kv-store (->kv-opts "doc-store")}
:crux/index-store {:kv-store (->kv-opts "index-store")}}
f))))
(defmacro with-kv-store-opts [kv-dep & body]
`(with-kv-store-opts* ~kv-dep (fn [] ~@body)))