Skip to content

Commit e0fbef0

Browse files
committed
Enable Raft consensus and primary discovery in workloads
- Raft will work only when quorum is >= N / 2, therefore automatic quorum calculation was added, it depends on initial cluster size; - Raft manage read-only status automatically, so setting `read_only` has been removed in an instance file; - Enable primary instance discovery in workloads; Closes #42
1 parent 3587db0 commit e0fbef0

File tree

5 files changed

+30
-31
lines changed

5 files changed

+30
-31
lines changed

resources/tarantool/jepsen.lua

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,11 @@ else
1414
box.cfg {
1515
listen = '%TARANTOOL_IP_ADDRESS%:3301';
1616
replication = { %TARANTOOL_REPLICATION% };
17-
read_only = %TARANTOOL_IS_READ_ONLY%;
18-
replication_synchro_quorum = 2;
17+
replication_synchro_quorum = %TARANTOOL_QUORUM%;
1918
replication_synchro_timeout = 0.2;
19+
replication_timeout = 1;
20+
election_mode = 'candidate';
21+
election_timeout = 0.5;
2022
log_level = 6;
2123
log_nonblock = false;
2224
too_long_threshold = 0.5;

src/tarantool/counter.clj

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
[clojure.tools.logging :refer [debug info warn]]
99
[next.jdbc :as j]
1010
[next.jdbc.sql :as sql]
11-
[tarantool.client :as cl]
11+
[tarantool [client :as cl]
12+
[db :as db]]
1213
[jepsen.core :as jepsen]
1314
[knossos.model :as model]
1415
[knossos.op :as op]))
@@ -26,7 +27,8 @@
2627
(setup! [this test node]
2728
(let [conn (cl/open node test)]
2829
(assert conn)
29-
(when (= node (jepsen/primary test))
30+
(Thread/sleep 10000) ; wait for leader election and joining to a cluster
31+
(when (= node (first (db/primaries test)))
3032
(cl/with-conn-failure-retry conn
3133
(j/execute! conn [(str "CREATE TABLE IF NOT EXISTS " table-name
3234
" (id INT NOT NULL PRIMARY KEY,
@@ -40,7 +42,7 @@
4042
(cl/with-error-handling op
4143
(cl/with-txn-aborts op
4244
(case (:f op)
43-
:add (let [con (cl/open (jepsen/primary test) test)]
45+
:add (let [con (cl/open (first (db/primaries test)) test)]
4446
(do (j/execute! con
4547
[(str "UPDATE " table-name " SET count = count + ? WHERE id = 0") (:value op)]))
4648
(assoc op :type :ok))

src/tarantool/db.clj

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -192,11 +192,6 @@
192192
[b]
193193
(if (true? b) "true" "false"))
194194

195-
(defn is-primary?
196-
[test node]
197-
(let [p (jepsen/primary test)]
198-
(if (= node p) true false)))
199-
200195
(defn is-single-mode?
201196
[test]
202197
(let [n (count (:nodes test))]
@@ -214,32 +209,29 @@
214209
(into [])
215210
(remove nil?))))
216211

212+
(defn calculate-quorum
213+
"Calculate quorum for a given number of nodes."
214+
[test]
215+
(->> (/ (count (:nodes test)) 2)
216+
(double)
217+
(Math/round)))
218+
217219
(defn configure!
218220
"Configure instance"
219221
[test node]
220-
(let [read-only (not (is-primary? test node))]
221-
(info "Joining" node "as" (if (true? read-only) "replica" "leader"))
222+
(info "Configure instance on" node)
222223
(c/exec :mkdir :-p "/etc/tarantool/instances.available")
223224
(c/exec :mkdir :-p "/etc/tarantool/instances.enabled")
224225
(c/exec :usermod :-a :-G :tarantool :ubuntu)
225226
(c/exec :echo (-> "tarantool/jepsen.lua" io/resource slurp
227+
(str/replace #"%TARANTOOL_QUORUM%" (str (calculate-quorum test)))
226228
(str/replace #"%TARANTOOL_IP_ADDRESS%" node)
227229
(str/replace #"%TARANTOOL_REPLICATION%" (replica-set test))
228-
(str/replace #"%TARANTOOL_IS_READ_ONLY%" (boolean-to-str read-only))
229230
(str/replace #"%TARANTOOL_MVCC%" (boolean-to-str (:mvcc test)))
230231
(str/replace #"%TARANTOOL_SINGLE_MODE%" (boolean-to-str (is-single-mode? test)))
231232
(str/replace #"%TARANTOOL_DATA_ENGINE%" (:engine test)))
232233
:> "/etc/tarantool/instances.enabled/jepsen.lua")
233-
(c/exec :cp "/etc/tarantool/instances.enabled/jepsen.lua" "/etc/tarantool/instances.available")))
234-
235-
(defn is-read-only
236-
[conn]
237-
(j/execute! conn ["SELECT lua('return box.info().ro') IS NOT NULL"]))
238-
239-
(defn set-read-only-mode
240-
"Disable and enable read only mode"
241-
[conn mode]
242-
(j/execute! conn ["SELECT LUA('box.cfg{read_only=true}; return true')"]))
234+
(c/exec :cp "/etc/tarantool/instances.enabled/jepsen.lua" "/etc/tarantool/instances.available"))
243235

244236
(defn db
245237
"Tarantool DB for a particular version."

src/tarantool/register.clj

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
[knossos.model :as model]
1818
[jepsen.checker.timeline :as timeline]
1919
[jepsen.os.ubuntu :as ubuntu]
20-
[tarantool.client :as cl]
21-
[tarantool.db :as db]))
20+
[tarantool [client :as cl]
21+
[db :as db]]))
2222

2323
(def table-name "register")
2424

@@ -37,7 +37,8 @@
3737
(setup! [this test node]
3838
(let [conn (cl/open node test)]
3939
(assert conn)
40-
(if (= node (jepsen/primary test))
40+
(Thread/sleep 10000) ; wait for leader election and joining to a cluster
41+
(if (= node (first (db/primaries test)))
4142
(cl/with-conn-failure-retry conn
4243
(j/execute! conn [(str "CREATE TABLE IF NOT EXISTS " table-name
4344
" (id INT NOT NULL PRIMARY KEY,
@@ -54,7 +55,7 @@
5455
v (:value r)]
5556
(assoc op :type :ok, :value (independent/tuple k v)))
5657

57-
:write (do (let [con (cl/open (jepsen/primary test) test)
58+
:write (do (let [con (cl/open (first (db/primaries test)) test)
5859
table (clojure.string/upper-case table-name)]
5960
(j/execute! con
6061
[(str "SELECT _UPSERT(" k ", " value ", '" table "')")])
@@ -63,7 +64,7 @@
6364
:value (independent/tuple k value))))
6465

6566
:cas (do (let [[old new] value
66-
con (cl/open (jepsen/primary test) test)
67+
con (cl/open (first (db/primaries test)) test)
6768
table (clojure.string/upper-case table-name)
6869
r (->> (j/execute! con
6970
[(str "SELECT _CAS(" k ", " old ", " new ", '" table "')")])

src/tarantool/sets.clj

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
[clojure.tools.logging :refer [info warn]]
1010
[next.jdbc :as j]
1111
[next.jdbc.sql :as sql]
12-
[tarantool.client :as cl]
12+
[tarantool [client :as cl]
13+
[db :as db]]
1314
[jepsen.core :as jepsen]
1415
[knossos.model :as model]
1516
[knossos.op :as op]))
@@ -27,7 +28,8 @@
2728
(setup! [this test node]
2829
(let [conn (cl/open node test)]
2930
(assert conn)
30-
(if (= node (jepsen/primary test))
31+
(Thread/sleep 10000) ; wait for leader election and joining to a cluster
32+
(if (= node (first (db/primaries test)))
3133
(cl/with-conn-failure-retry conn
3234
(j/execute! conn [(str "CREATE TABLE IF NOT EXISTS " table-name
3335
" (id INT NOT NULL PRIMARY KEY AUTOINCREMENT,
@@ -41,7 +43,7 @@
4143
(cl/with-error-handling op
4244
(cl/with-txn-aborts op
4345
(case (:f op)
44-
:add (let [con (cl/open (jepsen/primary test) test)]
46+
:add (let [con (cl/open (first (db/primaries test)) test)]
4547
(do (sql/insert! con table-name {:value v})
4648
(assoc op :type :ok)))
4749

0 commit comments

Comments
 (0)