-
Notifications
You must be signed in to change notification settings - Fork 160
/
db.clj
64 lines (54 loc) · 1.57 KB
/
db.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
54
55
56
57
58
59
60
61
62
63
64
(ns crux.db
(:import java.io.Closeable
java.util.Iterator
crux.api.ITxLog))
;; tag::Index[]
(defprotocol Index
(seek-values [this k])
(next-values [this]))
;; end::Index[]
;; tag::LayeredIndex[]
(defprotocol LayeredIndex
(open-level [this])
(close-level [this])
(max-depth [this]))
;; end::LayeredIndex[]
;; tag::Indexer[]
(defprotocol Indexer
(index-docs [this docs])
(index-tx [this tx tx-events])
(missing-docs [this content-hashes])
(store-index-meta [this k v])
(read-index-meta [this k])
(latest-completed-tx [this]))
;; end::Indexer[]
;; tag::TxLog[]
(defprotocol TxLog
(submit-tx [this tx-ops])
(open-tx-log ^crux.api.ITxLog [this from-tx-id])
(latest-submitted-tx [this]))
;; end::TxLog[]
(defprotocol DocumentStore
(submit-docs [this id-and-docs])
(fetch-docs [this ids]))
;; NOTE: The snapshot parameter here is an optimisation to avoid keep
;; opening snapshots and allow caching of iterators. A non-KV backed
;; object store could choose to ignore it, but it would be nice to
;; hide it.
;; tag::ObjectStore[]
(defprotocol ObjectStore
(get-single-object [this snapshot k])
(get-objects [this snapshot ks])
(missing-keys [this snapshot ks])
(put-objects [this kvs]))
;; end::ObjectStore[]
(defrecord CloseableTxLogIterator [close-fn ^Iterator lazy-seq-iterator]
ITxLog
(next [this]
(.next lazy-seq-iterator))
(hasNext [this]
(.hasNext lazy-seq-iterator))
(close [_]
(close-fn)))
(defn ->closeable-tx-log-iterator [close-fn ^Iterable sq]
(->CloseableTxLogIterator close-fn (.iterator (lazy-seq sq))))