-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathmap.clj
91 lines (81 loc) · 3.75 KB
/
map.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
(ns scylla.collections.map
"A test for sets backed by CQL maps."
(:require [clojure [pprint :refer :all]]
[clojure.tools.logging :refer [info]]
[jepsen
[client :as client]
[checker :as checker]
[generator :as gen]]
[qbits.alia :as alia]
[qbits.hayt :refer :all]
[scylla [client :as c]
[db :as db]])
(:import (clojure.lang ExceptionInfo)
(com.datastax.driver.core.exceptions UnavailableException
WriteTimeoutException
ReadTimeoutException
NoHostAvailableException)))
(defrecord CQLMapClient [tbl-created? conn]
client/Client
(open! [this test node]
(assoc this :conn (c/open test node)))
(setup! [_ test]
(let [s (:session conn)]
(locking tbl-created?
(when (compare-and-set! tbl-created? false true)
(c/retry-each
(alia/execute s (create-keyspace :jepsen_keyspace
(if-exists false)
(with {:replication {:class :SimpleStrategy
:replication_factor 3}})))
(alia/execute s (use-keyspace :jepsen_keyspace))
(alia/execute s (create-table :maps
(if-exists false)
(column-definitions {:id :int
:elements (map-type :int :int)
:primary-key [:id]})
(with {:compaction {:class (:compaction-strategy test)}}))))))))
(invoke! [_ test op]
(let [s (:session conn)]
(c/with-errors op #{:read}
(alia/execute s (use-keyspace :jepsen_keyspace))
(case (:f op)
:add (do (alia/execute s
(update :maps
(set-columns {:elements [+ {(:value op) (:value op)}]})
(where [[= :id 0]]))
(merge {:consistency :one}
(c/write-opts test)))
(assoc op :type :ok))
:read (do (db/wait-for-recovery 30 s)
(let [value (->> (alia/execute s
(select :maps (where [[= :id 0]]))
(merge
; TODO: do we really want
; ALL?
{:consistency :all
:retry-policy c/aggressive-read}
(c/read-opts test)))
first
:elements
vals
(into (sorted-set)))]
(assoc op :type :ok :value value)))))))
(close! [_ _]
(c/close! conn))
(teardown! [_ _])
client/Reusable
(reusable? [_ _] true))
(defn cql-map-client
"A set implemented using CQL maps"
[]
(->CQLMapClient (atom false) nil))
(defn workload
[opts]
{:client (cql-map-client)
:generator (map (fn [x] {:f :add, :value x}) (range))
:final-generator (->> {:f :read}
gen/repeat
(gen/stagger 1)
gen/until-ok)
:checker (checker/set)})