Skip to content

Bump Jepsen version to 2.3.0 #86

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
:url "https://www.eclipse.org/legal/epl-2.0/"}
:main tarantool.runner
:dependencies [[org.clojure/clojure "1.10.1"]
[jepsen "0.1.18"]
[jepsen "0.2.3"]
[expound "0.8.5"]
[seancorfield/next.jdbc "1.1.582"]
[org.tarantool/connector "1.9.4"]
Expand Down
2 changes: 1 addition & 1 deletion resources/tarantool/jepsen.lua
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ box.schema.func.create('_UPSERT',
of synchronous cluster with enabled Raft consensus protocol is started.
Returns nil when Raft is disabled. Example: SELECT _LEADER()
]]
box.schema.func.create('_LEADER',
box.schema.func.create('_LEADER_IPADDR',
{language = 'LUA',
returns = 'string',
body = [[function()
Expand Down
80 changes: 37 additions & 43 deletions src/tarantool/bank.clj
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,25 @@
(let [conn (cl/open node test)]
(assoc this :conn conn :node node)))

(setup! [this test node]
(setup! [this test]
(locking BankClientWithLua
(let [conn (cl/open node test)]
(Thread/sleep 10000) ; wait for leader election and joining to a cluster
(when (= node (first (db/primaries test)))
;(when (= (:node conn) (first (db/primaries test)))
(cl/with-conn-failure-retry conn
(info (str "Creating table " table-name))
(j/execute! conn [(str "CREATE TABLE IF NOT EXISTS " table-name
"(id INT NOT NULL PRIMARY KEY,
balance INT NOT NULL)")])
(j/execute! conn [(str "SELECT LUA('return box.space."
(clojure.string/upper-case table-name)
":alter{ is_sync = true } or 1')")])
(doseq [a (:accounts test)]
(info "Populating account")
(sql/insert! conn table-name {:id a
:balance (if (= a (first (:accounts test)))
(:total-amount test)
0)}))))
(assoc this :conn conn :node node))))
0)})))
(assoc this :conn conn :node (:node conn))))

(invoke! [this test op]
(try
Expand All @@ -63,25 +65,24 @@
(assoc op :type :fail, :value {:from from :to to :amount amount})
(assoc op :type :ok))))))

(teardown! [_ test]
(when-not (:leave-db-running? test)
(info (str "Drop table" table-name))
(cl/with-conn-failure-retry conn
(j/execute! conn [(str "DROP TABLE IF EXISTS " table-name)]))))
(teardown! [_ test])

(close! [_ test]))

; One bank account per table
(defrecord MultiBankClientWithLua [conn tbl-created?]
client/Client
(open! [this test node]
(assoc this :conn (cl/open node test)))
(let [c (cl/open node test)]
(assoc this
:node node
:conn c
:initialized? (atom false))))

(setup! [this test node]
(setup! [this test]
(locking tbl-created?
(let [conn (cl/open node test)]
(Thread/sleep 10000) ; wait for leader election and joining to a cluster
(when (= node (first (db/primaries test)))
;(when (= (:node conn) (first (db/primaries test)))
(when (compare-and-set! tbl-created? false true)
(cl/with-conn-failure-retry conn
(doseq [a (:accounts test)]
Expand All @@ -90,12 +91,15 @@
"(id INT NOT NULL PRIMARY KEY,"
"account_id INT NOT NULL,"
"balance INT NOT NULL)")])
(j/execute! conn [(str "SELECT LUA('return box.space."
(clojure.string/upper-case (str table-name a))
":alter{ is_sync = true } or 1')")])
(info "Populating account" a)
(sql/insert! conn (str table-name a)
{:id 0
:account_id a
:balance 10})))))
(assoc this :conn conn :node node))))
:balance 10}))))
(assoc this :conn conn :node (:node conn))))

(invoke! [this test op]
(try
Expand Down Expand Up @@ -129,12 +133,7 @@
(assoc op :type :fail)
(assoc op :type :ok))))))

(teardown! [_ test]
(when-not (:leave-db-running? test)
(cl/with-conn-failure-retry conn
(doseq [a (:accounts test)]
(info "Drop table" table-name a)
(j/execute! conn [(str "DROP TABLE IF EXISTS " table-name a)])))))
(teardown! [_ test])

(close! [_ test]))

Expand All @@ -145,23 +144,25 @@
(let [conn (cl/open node test)]
(assoc this :conn conn :node node)))

(setup! [this test node]
(setup! [this test]
(locking BankClient
(let [conn (cl/open node test)]
(Thread/sleep 10000) ; wait for leader election and joining to a cluster
(when (= node (first (db/primaries test)))
;(when (= (:node conn) (first (db/primaries test)))
(cl/with-conn-failure-retry conn
(info (str "Creating table " table-name))
(j/execute! conn [(str "CREATE TABLE IF NOT EXISTS " table-name
"(id INT NOT NULL PRIMARY KEY,
balance INT NOT NULL)")])
(j/execute! conn [(str "SELECT LUA('return box.space."
(clojure.string/upper-case table-name)
":alter{ is_sync = true } or 1')")])
(doseq [a (:accounts test)]
(info "Populating account")
(sql/insert! conn table-name {:id a
:balance (if (= a (first (:accounts test)))
(:total-amount test)
0)}))))
(assoc this :conn conn :node node))))
0)})))
(assoc this :conn conn :node (:node conn))))

(invoke! [this test op]
(try
Expand Down Expand Up @@ -193,11 +194,7 @@
(j/execute! con [(str "UPDATE " table-name " SET balance = balance + ? WHERE id = ?") amount to])
(assoc op :type :ok)))))))

(teardown! [_ test]
(when-not (:leave-db-running? test)
(info (str "Drop table" table-name))
(cl/with-conn-failure-retry conn
(j/execute! conn [(str "DROP TABLE IF EXISTS " table-name)]))))
(teardown! [_ test])

(close! [_ test]))

Expand All @@ -207,25 +204,27 @@
(open! [this test node]
(assoc this :conn (cl/open node test)))

(setup! [this test node]
(setup! [this test]
(locking tbl-created?
(let [conn (cl/open node test)]
(Thread/sleep 10000) ; wait for leader election and joining to a cluster
(when (= node (first (db/primaries test)))
;(when (= (:node conn) (first (db/primaries test)))
(when (compare-and-set! tbl-created? false true)
(cl/with-conn-failure-retry conn
(doseq [a (:accounts test)]
(info "Creating table" table-name a)
(j/execute! conn [(str "CREATE TABLE IF NOT EXISTS " table-name a
"(id INT NOT NULL PRIMARY KEY,"
"balance INT NOT NULL)")])
(j/execute! conn [(str "SELECT LUA('return box.space."
(clojure.string/upper-case (str table-name a))
":alter{ is_sync = true } or 1')")])
(info "Populating account" a)
(sql/insert! conn (str table-name a)
{:id 0
:balance (if (= a (first (:accounts test)))
(:total-amount test)
0)})))))
(assoc this :conn conn :node node))))
0)})))
(assoc this :conn conn :node (:node conn)))))

(invoke! [this test op]
(try
Expand Down Expand Up @@ -268,12 +267,7 @@
(j/execute! con [(str "UPDATE " to " SET balance = balance + ? WHERE id = 0") amount])
(assoc op :type :ok)))))))

(teardown! [_ test]
(when-not (:leave-db-running? test)
(cl/with-conn-failure-retry conn
(doseq [a (:accounts test)]
(info "Drop table" table-name a)
(j/execute! conn [(str "DROP TABLE IF EXISTS " table-name a)])))))
(teardown! [_ test])

(close! [_ test]))

Expand Down
16 changes: 15 additions & 1 deletion src/tarantool/client.clj
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,24 @@
(defn primary
[node]
(let [conn (open node test)
leader (:COLUMN_1 (first (sql/query conn ["SELECT _LEADER()"])))]
leader (:COLUMN_1 (first (sql/query conn ["SELECT _LEADER_IPADDR()"])))]
;(assert leader)
leader))

(defn is-ro?
[conn]
(let [r (-> conn
(sql/query ["SELECT lua('return box.cfg.read_only or false')"])
first
:COLUMN_1
Boolean/valueOf
boolean)]
r))

(defn is-rw?
[conn]
(not (is-ro? conn)))

(defmacro with-txn-aborts
"Aborts body on rollbacks."
[op & body]
Expand Down
14 changes: 5 additions & 9 deletions src/tarantool/counter.clj
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,18 @@
(assert conn)
(assoc this :conn conn :node node)))

(setup! [this test node]
(let [conn (cl/open node test)]
(setup! [this test]
(assert conn)
(Thread/sleep 10000) ; wait for leader election and joining to a cluster
(when (= node (first (db/primaries test)))
;(when (= (:node conn) (first (db/primaries test)))
(cl/with-conn-failure-retry conn
(j/execute! conn [(str "CREATE TABLE IF NOT EXISTS " table-name
" (id INT NOT NULL PRIMARY KEY,
count INT NOT NULL)")]))
(sql/insert! conn table-name {:id 0 :count 0})
(let [table (clojure.string/upper-case table-name)]
(j/execute! conn [(str "SELECT LUA('return box.space." table ":alter{ is_sync = true } or 1')")])))
(assoc this :conn conn :node node)))
(j/execute! conn [(str "SELECT LUA('return box.space." table ":alter{ is_sync = true } or 1')")]))
(assoc this :conn conn :node (:node conn)))

(invoke! [this test op]
(cl/with-error-handling op
Expand All @@ -50,10 +49,7 @@
[(str "SELECT count FROM " table-name " WHERE id = 0")])))]
(assoc op :type :ok :value value))))))

(teardown! [_ test]
(when-not (:leave-db-running? test)
(cl/with-conn-failure-retry conn
(j/execute! conn [(str "DROP TABLE IF EXISTS " table-name)]))))
(teardown! [_ test])

(close! [_ test]))

Expand Down
23 changes: 13 additions & 10 deletions src/tarantool/db.clj
Original file line number Diff line number Diff line change
Expand Up @@ -204,12 +204,14 @@
(into [])
(remove nil?))))

(defn calculate-quorum
"Calculate quorum for a given number of nodes."
(defn majority
"returns majority (n/2 + 1) for a given number of nodes."
[test]
(->> (/ (count (:nodes test)) 2)
(double)
(Math/round)))
(-> (:nodes test)
count
(/ 2)
inc
Math/floor long))

(defn configure!
"Configure instance"
Expand All @@ -219,7 +221,7 @@
(c/exec :mkdir :-p "/etc/tarantool/instances.enabled")
(c/exec :usermod :-a :-G :tarantool :ubuntu)
(c/exec :echo (-> "tarantool/jepsen.lua" io/resource slurp
(str/replace #"%TARANTOOL_QUORUM%" (str (calculate-quorum test)))
(str/replace #"%TARANTOOL_QUORUM%" (str (majority test)))
(str/replace #"%TARANTOOL_IP_ADDRESS%" node)
(str/replace #"%TARANTOOL_REPLICATION%" (replica-set test))
(str/replace #"%TARANTOOL_MVCC%" (str (:mvcc test)))
Expand All @@ -246,11 +248,12 @@
(stop! test node)
(wipe! test node))

db/Primary
(setup-primary! [_ test node])
;db/Primary
;(setup-primary! [db test node])

(primaries [_ test]
(primaries test))
;(primaries [db test]
; "Return a seq of primaries in a cluster."
; ["84.23.53.151"]) ; FIXME

db/Process
(start! [_ test node]
Expand Down
22 changes: 9 additions & 13 deletions src/tarantool/register.clj
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,17 @@
(assert conn)
(assoc this :conn conn :node node)))

(setup! [this test node]
(let [conn (cl/open node test)]
(setup! [this test]
(assert conn)
(Thread/sleep 10000) ; wait for leader election and joining to a cluster
(if (= node (first (db/primaries test)))
(Thread/sleep 30000) ; wait for leader election and joining to a cluster
(if (true? (cl/is-rw? conn))
(cl/with-conn-failure-retry conn
(j/execute! conn [(str "CREATE TABLE IF NOT EXISTS " table-name
" (id INT NOT NULL PRIMARY KEY,
value INT NOT NULL)")])
(let [table (clojure.string/upper-case table-name)]
(j/execute! conn [(str "SELECT LUA('return box.space." table ":alter{ is_sync = true } or 1')")]))))
(assoc this :conn conn :node node)))
(assoc this :conn conn))

(invoke! [this test op]
(let [[k value] (:value op)]
Expand All @@ -52,13 +51,13 @@
v (:value r)]
(assoc op :type :ok, :value (independent/tuple k v)))

:write (do (let [con (cl/open (first (db/primaries test)) test)
table (clojure.string/upper-case table-name)]
(j/execute! con
:write (do (let [table (clojure.string/upper-case table-name)]
(if (true? (cl/is-ro? conn))
(j/execute! conn
[(str "SELECT _UPSERT(" k ", " value ", '" table "')")])
(assoc op
:type :ok
:value (independent/tuple k value))))
:value (independent/tuple k value)))))

:cas (do (let [[old new] value
con (cl/open (first (db/primaries test)) test)
Expand All @@ -74,10 +73,7 @@
:value (independent/tuple k value))
(assoc op :type :fail)))))))

(teardown! [_ test]
(when-not (:leave-db-running? test)
(cl/with-conn-failure-retry conn
(j/execute! conn [(str "DROP TABLE IF EXISTS " table-name)]))))
(teardown! [_ test])

(close! [_ test]))

Expand Down
Loading