Skip to content

Commit

Permalink
cockroachdb: Update clients and nemeses to non-deprecated interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
bdarnell committed May 17, 2018
1 parent 94a45aa commit 9e4a77e
Show file tree
Hide file tree
Showing 9 changed files with 244 additions and 236 deletions.
42 changes: 23 additions & 19 deletions cockroachdb/src/jepsen/cockroach/adya.clj
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,24 @@
; G2: Anti-dependency cycles
(defrecord G2Client [table-created? client]
client/Client
(setup! [this test node]
(let [client (c/client node)]
(locking table-created?
(when (compare-and-set! table-created? false true)
(c/with-conn [c client]
(c/with-timeout
(c/with-txn-retry
(j/execute! c "create table a (
(open! [this test node]
(assoc this :client (c/client node)))

(setup! [this test]
(locking table-created?
(when (compare-and-set! table-created? false true)
(c/with-conn [c client]
(c/with-timeout
(c/with-txn-retry
(j/execute! c "create table a (
id int primary key,
key int,
value int)"))
(c/with-txn-retry
(j/execute! c "create table b (
(c/with-txn-retry
(j/execute! c "create table b (
id int primary key,
key int,
value int)"))))))
(assoc this :client client)))
value int)")))))))

(invoke! [this test op]
(c/with-exception->op op
Expand All @@ -59,27 +60,30 @@
" where key = ? and value % 3 = 0")
k])
_ (when (or (seq as) (seq bs))
; Ah, the other txn has already committed
; Ah, the other txn has already committed
(return (assoc op :type :fail :error :too-late)))
table (if a-id "a" "b")
id (or a-id b-id)
r (c/insert! c table {:key k, :id id, :value 30})]
(assoc op :type :ok)))
(assoc op :type :ok)))

:read
(let [as (c/with-txn-retry
(c/query c ["select * from a where
(c/query c ["select * from a where
key = ? and value % 3 = 0" k]))
bs (c/with-txn-retry
(c/query c ["select * from b where
(c/query c ["select * from b where
key = ? and value % 3 = 0" k]))
values (->> (concat as bs)
(map :id))]
(assoc op
:type :ok
:value (independent/tuple k values)))))))))
(assoc op
:type :ok
:value (independent/tuple k values)))))))))

(teardown! [this test]
nil)

(close! [this test]
(rc/close! client)))

(defn g2-test
Expand Down
12 changes: 6 additions & 6 deletions cockroachdb/src/jepsen/cockroach/auto.clj
Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +144,12 @@
the tarball."
[test node]
(c/su
(debian/install [:tcpdump :ntpdate])
(cu/ensure-user! cockroach-user)
(cu/install-tarball! node (:tarball test) working-path false)
(c/exec :mkdir :-p working-path)
(c/exec :mkdir :-p log-path)
(c/exec :chown :-R (str cockroach-user ":" cockroach-user) working-path))
(debian/install [:tcpdump :ntpdate])
(cu/ensure-user! cockroach-user)
(cu/install-archive! (:tarball test) working-path false)
(c/exec :mkdir :-p working-path)
(c/exec :mkdir :-p log-path)
(c/exec :chown :-R (str cockroach-user ":" cockroach-user) working-path))
(install-bumptime!)
(nt/install!)
(info node "Cockroach installed"))
Expand Down
152 changes: 76 additions & 76 deletions cockroachdb/src/jepsen/cockroach/bank.clj
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
"Simulates transfers between bank accounts"
(:refer-clojure :exclude [test])
(:require [jepsen [cockroach :as cockroach]
[client :as client]
[checker :as checker]
[generator :as gen]
[independent :as independent]
[reconnect :as rc]
[util :as util :refer [meh]]]
[client :as client]
[checker :as checker]
[generator :as gen]
[independent :as independent]
[reconnect :as rc]
[util :as util :refer [meh]]]
[jepsen.checker.timeline :as timeline]
[jepsen.cockroach [client :as c]
[nemesis :as cln]]
[nemesis :as cln]]
[clojure.core.reducers :as r]
[clojure.java.jdbc :as j]
[clojure.tools.logging :refer :all]
Expand All @@ -19,27 +19,27 @@

(defrecord BankClient [tbl-created? n starting-balance conn]
client/Client
(setup! [this test node]
(let [conn (c/client node)]
(locking tbl-created?
(when (compare-and-set! tbl-created? false true)
(c/with-conn [c conn]
(Thread/sleep 1000)
(c/with-txn-retry
(j/execute! c ["drop table if exists accounts"]))
(Thread/sleep 1000)
(info "Creating table")
(c/with-txn-retry
(j/execute! c ["create table accounts
(open! [this test node]
(assoc this :conn (c/client node)))

(setup! [this test]
(locking tbl-created?
(when (compare-and-set! tbl-created? false true)
(c/with-conn [c conn]
(Thread/sleep 1000)
(c/with-txn-retry
(j/execute! c ["drop table if exists accounts"]))
(Thread/sleep 1000)
(info "Creating table")
(c/with-txn-retry
(j/execute! c ["create table accounts
(id int not null primary key,
balance bigint not null)"]))
(dotimes [i n]
(Thread/sleep 500)
(info "Creating account" i)
(c/with-txn-retry
(c/insert! c :accounts {:id i :balance starting-balance}))))))

(assoc this :conn conn)))
(dotimes [i n]
(Thread/sleep 500)
(info "Creating account" i)
(c/with-txn-retry
(c/insert! c :accounts {:id i :balance starting-balance})))))))

(invoke! [this test op]
(c/with-exception->op op
Expand All @@ -56,14 +56,14 @@
(let [{:keys [from to amount]} (:value op)
b1 (-> c
(c/query
["select balance from accounts where id = ?"
from] {:row-fn :balance})
["select balance from accounts where id = ?"
from] {:row-fn :balance})
first
(- amount))
b2 (-> c
(c/query
["select balance from accounts where id = ?" to]
{:row-fn :balance})
["select balance from accounts where id = ?" to]
{:row-fn :balance})
first
(+ amount))]
(cond
Expand All @@ -81,12 +81,12 @@
(assoc op :type :ok)))))))))))

(teardown! [this test]
(try
(c/with-timeout
(c/with-conn [c conn]
(j/execute! c ["drop table if exists accounts"])))
(finally
(rc/close! conn)))))
(c/with-timeout
(c/with-conn [c conn]
(j/execute! c ["drop table if exists accounts"]))))

(close! [this test]
(rc/close! conn)))

(defn bank-read
"Reads the current state of all accounts without any synchronization."
Expand Down Expand Up @@ -160,34 +160,34 @@
(defn test
[opts]
(bank-test-base
(merge {:name "bank"
:model {:n 5 :total 50}
:client (BankClient. (atom false) 5 10 nil)}
opts)))
(merge {:name "bank"
:model {:n 5 :total 50}
:client (BankClient. (atom false) 5 10 nil)}
opts)))

; One bank account per table
; One bank account per table
(defrecord MultiBankClient [tbl-created? n starting-balance conn]
client/Client
(setup! [this test node]
(let [conn (c/client node)]
(locking tbl-created?
(when (compare-and-set! tbl-created? false true)
(c/with-conn [c conn]
(dotimes [i n]
(Thread/sleep 500)
(c/with-txn-retry
(j/execute! c [(str "drop table if exists accounts" i)]))
(Thread/sleep 500)
(info "Creating table " i)
(c/with-txn-retry
(j/execute! c [(str "create table accounts" i
" (balance bigint not null)")]))
(Thread/sleep 500)
(info "Populating account" i)
(c/with-txn-retry
(c/insert! c (str "accounts" i) {:balance starting-balance}))))))

(assoc this :conn conn)))
(open! [this test node]
(assoc this :conn (c/client node)))

(setup! [this test]
(locking tbl-created?
(when (compare-and-set! tbl-created? false true)
(c/with-conn [c conn]
(dotimes [i n]
(Thread/sleep 500)
(c/with-txn-retry
(j/execute! c [(str "drop table if exists accounts" i)]))
(Thread/sleep 500)
(info "Creating table " i)
(c/with-txn-retry
(j/execute! c [(str "create table accounts" i
" (balance bigint not null)")]))
(Thread/sleep 500)
(info "Populating account" i)
(c/with-txn-retry
(c/insert! c (str "accounts" i) {:balance starting-balance})))))))

(invoke! [this test op]
(c/with-exception->op op
Expand All @@ -200,8 +200,8 @@
(->> (range n)
(mapv (fn [x]
(->> (c/query
c [(str "select balance from accounts" x)]
{:row-fn :balance})
c [(str "select balance from accounts" x)]
{:row-fn :balance})
first)))
(assoc op :type :ok, :value))

Expand All @@ -211,8 +211,8 @@
to (str "accounts" to)
b1 (-> c
(c/query
[(str "select balance from " from)]
{:row-fn :balance})
[(str "select balance from " from)]
{:row-fn :balance})
first
(- amount))
b2 (-> c
Expand All @@ -232,18 +232,18 @@
(assoc op :type :ok)))))))))))

(teardown! [this test]
(try
(c/with-conn [c conn]
(c/with-timeout
(dotimes [i n]
(j/execute! c [(str "drop table if exists accounts" i)]))))
(finally
(rc/close! conn)))))
(c/with-conn [c conn]
(c/with-timeout
(dotimes [i n]
(j/execute! c [(str "drop table if exists accounts" i)])))))

(close! [this test]
(rc/close! conn)))

(defn multitable-test
[opts]
(bank-test-base
(merge {:name "bank-multitable"
:model {:n 5 :total 50}
:client (MultiBankClient. (atom false) 5 10 nil)}
opts)))
(merge {:name "bank-multitable"
:model {:n 5 :total 50}
:client (MultiBankClient. (atom false) 5 10 nil)}
opts)))
29 changes: 16 additions & 13 deletions cockroachdb/src/jepsen/cockroach/comments.clj
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,21 @@
(defrecord Client [table-count table-created? client]
client/Client

(setup! [this test node]
(open! [this test node]
(assoc this :client (c/client node)))

(setup! [this test]
(Thread/sleep 2000)
(let [client (c/client node)]
(locking table-created?
(when (compare-and-set! table-created? false true)
(c/with-conn [c client]
(c/with-timeout
(info "Creating tables" (pr-str (table-names table-count)))
(doseq [t (table-names table-count)]
(j/execute! c [(str "create table " t
" (id int primary key,
(locking table-created?
(when (compare-and-set! table-created? false true)
(c/with-conn [c client]
(c/with-timeout
(info "Creating tables" (pr-str (table-names table-count)))
(doseq [t (table-names table-count)]
(j/execute! c [(str "create table " t
" (id int primary key,
key int)")])
(info "Created table" t))))))

(assoc this :client client)))
(info "Created table" t)))))))

(invoke! [this test op]
(c/with-exception->op op
Expand All @@ -82,6 +82,9 @@
(assoc op :type :ok, :value))))))))

(teardown! [this test]
nil)

(close! [this test]
(rc/close! client)))

(defn checker
Expand Down
Loading

0 comments on commit 9e4a77e

Please sign in to comment.