aboutsummaryrefslogtreecommitdiff
path: root/script/jepsen.garage/src/jepsen/garage.clj
blob: ce02b7f7b5b20a6e310fb871cdff38593fe7ec61 (plain) (blame)
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
92
93
94
(ns jepsen.garage
  (:require
    [clojure.string :as str]
    [jepsen
     [checker :as checker]
     [cli :as cli]
     [generator :as gen]
     [nemesis :as nemesis]
     [tests :as tests]]
    [jepsen.os.debian :as debian]
    [jepsen.garage
     [daemon :as grg]
     [reg :as reg]
     [set :as set]]))

(def workloads
  "A map of workload names to functions that construct workloads, given opts."
  {"reg1" reg/workload1
   "reg2" reg/workload2
   "set1" set/workload1
   "set2" set/workload2})

(def patches
  "A map of patch names to Garage builds"
  {"default" "v0.9.0"
   "tsfix1" "d146cdd5b66ca1d3ed65ce93ca42c6db22defc09"})

(def cli-opts
  "Additional command line options."
  [["-p" "--patch NAME" "Garage patch to use"
    :default "default"
    :validate [patches (cli/one-of patches)]]
   ["-r" "--rate HZ" "Approximate number of requests per second, per thread."
    :default  10
    :parse-fn read-string
    :validate [#(and (number? %) (pos? %)) "Must be a positive number"]]
   [nil "--ops-per-key NUM" "Maximum number of operations on any given key."
    :default  100
    :parse-fn parse-long
    :validate [pos? "Must be a positive integer."]]
   ["-w" "--workload NAME" "Workload of test to run"
    :default "reg"
    :validate [workloads (cli/one-of workloads)]]])

(defn garage-test
  "Given an options map from the command line runner (e.g. :nodes, :ssh,
  :concurrency, ...), constructs a test map."
  [opts]
  (let [workload ((get workloads (:workload opts)) opts)
        garage-version (get patches (:patch opts))]
    (merge tests/noop-test
           opts
           {:pure-generators  true
            :name             (str "garage " (name (:workload opts)))
            :os               debian/os
            :db               (grg/db garage-version)
            :client           (:client workload)
            :generator        (gen/phases
                                (->>
                                  (:generator workload)
                                  (gen/stagger (/ (:rate opts)))
                                  (gen/nemesis
                                    (cycle [(gen/sleep 5)
                                            {:type :info, :f :partition-start}
                                            (gen/sleep 5)
                                            {:type :info, :f :clock-scramble}
                                            (gen/sleep 5)
                                            {:type :info, :f :partition-stop}
                                            (gen/sleep 5)
                                            {:type :info, :f :clock-scramble}]))
                                  (gen/time-limit (:time-limit opts)))
                                (gen/log "Healing cluster")
                                (gen/nemesis (gen/once {:type :info, :f :partition-stop}))
                                (gen/log "Waiting for recovery")
                                (gen/sleep 10)
                                (gen/clients (:final-generator workload)))
            :nemesis          (nemesis/compose
                                {{:partition-start :start
                                  :partition-stop :stop} (nemesis/partition-random-halves)
                                 {:clock-scramble :scramble} (nemesis/clock-scrambler 20.0)})
            :checker          (checker/compose
                                {:perf (checker/perf)
                                 :workload (:checker workload)})
            })))


(defn -main
  "Handles command line arguments. Can either run a test, or a web server for
  browsing results."
  [& args]
  (cli/run! (merge (cli/single-test-cmd {:test-fn garage-test
                                         :opt-spec cli-opts})
                   (cli/serve-cmd))
            args))