Skip to content

Commit ba700ef

Browse files
committed
Add nemeses support
Write via leader only Closes #16 Closes #17 Closes #21 Closes #25 Closes #34
1 parent 91046d0 commit ba700ef

File tree

5 files changed

+116
-9
lines changed

5 files changed

+116
-9
lines changed

src/tarantool/counter.clj

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,9 @@
3838
(cl/with-error-handling op
3939
(cl/with-txn-aborts op
4040
(case (:f op)
41-
:add (do (j/execute! conn
42-
[(str "UPDATE " table-name " SET count = count + ? WHERE id = 0") (:value op)])
41+
:add (let [con (cl/open (jepsen/primary test) test)]
42+
(do (j/execute! con
43+
[(str "UPDATE " table-name " SET count = count + ? WHERE id = 0") (:value op)]))
4344
(assoc op :type :ok))
4445

4546
:read (let [value (:COUNT

src/tarantool/db.clj

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,31 @@
247247
(stop! test node)
248248
(wipe! test node))
249249

250+
;db/Primary
251+
;(setup-primary! [_ test node])
252+
253+
;(primaries [_ test]
254+
; (->> (node-state test)
255+
; (filter (comp #{:leader} :role))
256+
; (map :node)))
257+
258+
db/Process
259+
(start! [_ test node]
260+
(start! node {}))
261+
;{:initial-cluster-state (if @(:initialized? test)
262+
; :existing
263+
; :new)
264+
; :nodes @(:members test)}))
265+
266+
(kill! [_ test node]
267+
(c/su
268+
;(cu/stop-daemon! binary pidfile)))
269+
(cu/grepkill! :kill "tarantool")))
270+
271+
db/Pause
272+
(pause! [_ test node] (c/su (cu/grepkill! :stop "tarantool")))
273+
(resume! [_ test node] (c/su (cu/grepkill! :cont "tarantool")))
274+
250275
db/LogFiles
251276
(log-files [_ test node]
252277
[logfile])))

src/tarantool/nemesis.clj

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
(ns tarantool.nemesis
2+
"Nemeses for Tarantool"
3+
(:require [clojure.pprint :refer [pprint]]
4+
[clojure.tools.logging :refer [info warn]]
5+
[dom-top.core :refer [real-pmap]]
6+
[jepsen [nemesis :as n]
7+
[net :as net]
8+
[util :as util]]
9+
[jepsen.generator :as gen]
10+
[jepsen.nemesis [combined :as nc]
11+
[time :as nt]]))
12+
13+
(defn nemesis-package
14+
"Constructs a nemesis and generators for Tarantool"
15+
[opts]
16+
(let [opts (update opts :faults set)]
17+
(nc/nemesis-package opts)))

src/tarantool/runner.clj

Lines changed: 65 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@
1212
[control :as c]
1313
[independent :as independent]
1414
[generator :as gen]
15-
[nemesis :as nemesis]
1615
[tests :as tests]
1716
[util :refer [timeout meh]]]
1817
[jepsen.checker.timeline :as timeline]
1918
;[knossos.model :as model]
2019
[jepsen.os.ubuntu :as ubuntu]
2120
[tarantool [db :as db]
21+
[nemesis :as nemesis]
2222
[register :as register]
2323
[sets :as sets]
2424
[counter :as counter]]))
@@ -48,6 +48,10 @@
4848
;:pages pages/workload
4949
:register register/workload})
5050

51+
(def standard-workloads
52+
"The workload names we run for test-all by default."
53+
(keys workloads))
54+
5155
(def workload-options
5256
"For each workload, a map of workload options to all the values that option
5357
supports."
@@ -64,6 +68,32 @@
6468
;:pages {:serialized-indices [true false]}
6569
:register {}})
6670

71+
(def nemeses
72+
"Types of faults a nemesis can create."
73+
#{:pause :kill :partition :clock})
74+
75+
(def standard-nemeses
76+
"Combinations of nemeses for tests"
77+
[[]
78+
[:pause]
79+
[:kill]
80+
[:partition]
81+
[:pause :kill :partition :clock]])
82+
83+
(def special-nemeses
84+
"A map of special nemesis names to collections of faults"
85+
{:none []
86+
:standard [:pause :kill :partition :clock :member]
87+
:all [:pause :kill :partition :clock :member]})
88+
89+
(defn parse-nemesis-spec
90+
"Takes a comma-separated nemesis string and returns a collection of keyword
91+
faults."
92+
[spec]
93+
(->> (str/split spec #",")
94+
(map keyword)
95+
(mapcat #(get special-nemeses % [%]))))
96+
6797
(def cli-opts
6898
"Options for test runners."
6999
[["-v" "--version VERSION"
@@ -76,13 +106,22 @@
76106
:parse-fn keyword
77107
:missing (str "--workload " (cli/one-of workloads))
78108
:validate [workloads (cli/one-of workloads)]]
109+
[nil "--nemesis FAULTS" "A comma-separated list of nemesis faults to enable"
110+
:parse-fn parse-nemesis-spec
111+
:validate [(partial every? (into nemeses (keys special-nemeses)))
112+
(str "Faults must be one of " nemeses " or "
113+
(cli/one-of special-nemeses))]]
114+
[nil "--nemesis-interval SECONDS" "How long to wait between nemesis faults"
115+
:default 3
116+
:parse-fn read-string
117+
:validate [#(and (number? %) (pos? %)) "must be a positive number"]]
79118
["-e" "--engine NAME"
80119
"What Tarantool data engine should we use?"
81120
:default "memtx"]])
82121

83122
(def crash-pattern
84123
"An egrep pattern we use to find crashes in the Tarantool logs."
85-
"Segmentation fault|too long WAL write|F>")
124+
"Segmentation fault|too long WAL write|F>|ER_TUPLE_FOUND")
86125

87126
(defn logged-crashes
88127
"Takes a test, and returns a map of nodes to strings from their Tarantool logs
@@ -115,7 +154,15 @@
115154
(defn tarantool-test
116155
[opts]
117156
(let [workload ((get workloads (:workload opts)) opts)
118-
nemesis nemesis/noop
157+
nemesis (nemesis/nemesis-package
158+
{:db db/db
159+
:nodes (:nodes opts)
160+
:faults (:nemesis opts)
161+
:partition {:targets [:primaries]}
162+
:pause {:targets [nil :one :primaries :majority :all]}
163+
:kill {:targets [nil :one :primaries :majority :all]}
164+
:interval (:nemesis-interval opts)})
165+
_ (info (pr-str nemesis))
119166
gen (->> (:generator workload)
120167
(gen/nemesis (:generator nemesis))
121168
(gen/time-limit (:time-limit opts)))
@@ -129,26 +176,39 @@
129176
(merge tests/noop-test
130177
opts
131178
{:client (:client workload)
132-
:nemesis nemesis
179+
:nemesis (:nemesis nemesis)
133180
:name (str "tarantool-" (:version opts))
134181
:os ubuntu/os
135182
:db (db/db (:version opts))
136183
:engine (:engine opts)
137184
:mvcc (:mvcc opts)
138185
:pure-generators true
139186
:generator gen
140-
:checker (checker/compose {:perf (checker/perf)
187+
:checker (checker/compose {:perf (checker/perf {:nemeses (:perf nemesis)})
141188
:clock-skew (checker/clock-plot)
142189
:crash (crash-checker)
143190
:timeline (timeline/html)
144191
:stats (checker/stats)
145192
:exceptions (checker/unhandled-exceptions)
146193
:workload (:checker workload)})})))
147194

195+
(defn all-tests
196+
"Takes parsed CLI options and constructs a sequence of test options, by
197+
combining all workloads and nemeses."
198+
[opts]
199+
(let [nemeses (if-let [n (:nemesis opts)] [n] standard-nemeses)
200+
workloads (if-let [w (:workload opts)] [w] standard-workloads)
201+
counts (range (:test-count opts))]
202+
(->> (for [i counts, n nemeses, w workloads]
203+
(assoc opts :nemesis n :workload w))
204+
(map tarantool-test))))
205+
148206
(defn -main
149207
"Handles command line arguments."
150208
[& args]
151209
(cli/run! (merge (cli/single-test-cmd {:test-fn tarantool-test
152210
:opt-spec cli-opts})
211+
(cli/test-all-cmd {:test-fn all-tests
212+
:opt-spec cli-opts})
153213
(cli/serve-cmd))
154214
args))

src/tarantool/sets.clj

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
[checker :as checker]
77
[generator :as gen]
88
[independent :as independent]]
9+
[clojure.tools.logging :refer [info warn]]
910
[next.jdbc :as j]
1011
[next.jdbc.sql :as sql]
1112
[tarantool.client :as cl]
@@ -37,8 +38,11 @@
3738
(cl/with-error-handling op
3839
(cl/with-txn-aborts op
3940
(case (:f op)
40-
:add (do (sql/insert! conn table-name {:value v})
41-
(assoc op :type :ok))
41+
:add (let [con (cl/open (jepsen/primary test) test)]
42+
(info (jepsen/primary test))
43+
;(do (sql/insert! con table-name {:value v})
44+
(do (j/execute! con [(str "INSERT INTO " table-name "(value) VALUES (" v ")")])
45+
(assoc op :type :ok)))
4246

4347
:read (->> (sql/query conn [(str "SELECT * FROM " table-name)])
4448
(mapv :VALUE)

0 commit comments

Comments
 (0)