diff --git a/cockroachdb/src/jepsen/cockroach.clj b/cockroachdb/src/jepsen/cockroach.clj index 1859ff7c9..4d5dd576f 100644 --- a/cockroachdb/src/jepsen/cockroach.clj +++ b/cockroachdb/src/jepsen/cockroach.clj @@ -70,6 +70,10 @@ (auto/start! test node) (Thread/sleep 5000)) ; Give it time to join + (when (= node (jepsen/primary test)) + (auto/init! node) + (Thread/sleep 5000)) + (jepsen/synchronize test) (when (= node (jepsen/primary test)) (auto/set-replication-zone! ".default" diff --git a/cockroachdb/src/jepsen/cockroach/auto.clj b/cockroachdb/src/jepsen/cockroach/auto.clj index f2c5b34e3..e1049ebc9 100644 --- a/cockroachdb/src/jepsen/cockroach/auto.clj +++ b/cockroachdb/src/jepsen/cockroach/auto.clj @@ -53,6 +53,13 @@ ] (if insecure [:--insecure] []))) +;; Extra command-line arguments to give to `cockroach init` +(def cockroach-init-arguments + (concat [:init + ;; ... other arguments here ... + ] + (if insecure [:--insecure] []))) + (defn control-addr "Address of the Jepsen control node, as seen by the local node. Used to filter packet captures." @@ -174,16 +181,21 @@ extra-args [:--logtostderr :>> errlog (c/lit "2>&1")])) -(defn runcmd - "The command to run cockroach for a given test" - [test node joining?] - (let [join (if joining? - [(->> (:nodes test) +(defn cockroach-init-cmdline + "Construct the command line to initialize a CockroachDB cluster." + [] + (concat + [(c/expand-path cockroach)] + cockroach-init-arguments)) + +(defn startcmd + "The command to start cockroach for a given test" + [test node] + (let [join [(->> (:nodes test) (remove #{node}) (map name) (str/join ",") - (str "--join="))] - [])] + (str "--join="))]] (wrap-env [(str "COCKROACH_LINEARIZABLE=" (if (:linearizable test) "true" "false")) (str "COCKROACH_MAX_OFFSET=" "250ms")] @@ -198,11 +210,24 @@ (catch RuntimeException e ""))) (info node "Cockroach already running.") (do (info node "Starting CockroachDB...") - (c/trace (c/exec (runcmd test node - (not= node (jepsen/primary test))))) + (c/trace (c/exec (startcmd test node))) (info node "Cockroach started")))) :started) +(defn initcmd + "The command to initialize cockroach for a given test" + [] + (cockroach-init-cmdline)) + +(defn init! + "Initialize cockroachdb cluster" + [node] + (c/sudo cockroach-user + (do (info node "Initializing CockroachDB...") + (c/trace (c/exec (initcmd))) + (info node "Cockroach initialized"))) + :initialized) + (defn kill! "Kills cockroach on node." [test node]