Skip to content

Commit 20e9ef6

Browse files
committed
Enable using Raft consensus in a cluster
Closes #42
1 parent cba5d2f commit 20e9ef6

File tree

3 files changed

+34
-29
lines changed

3 files changed

+34
-29
lines changed

resources/tarantool/jepsen.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ else
1313
box.cfg {
1414
listen = 3301;
1515
replication = { %TARANTOOL_REPLICATION% };
16-
read_only = %TARANTOOL_IS_READ_ONLY%;
16+
--read_only = %TARANTOOL_IS_READ_ONLY%;
1717
replication_synchro_quorum = 2;
1818
replication_synchro_timeout = 0.2;
1919
log_level = 6;

src/tarantool/client.clj

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,25 @@
2222
:connectTimeout (/ max-timeout 1000)
2323
:socketTimeout (/ max-timeout 1000)})
2424

25+
;(defn is-read-only
26+
; [conn]
27+
; (j/execute! conn ["SELECT lua('return box.info().ro') IS NOT NULL"]))
28+
29+
;(defn set-read-only-mode
30+
; "Disable and enable read only mode"
31+
; [conn mode]
32+
; (j/execute! conn ["SELECT LUA('box.cfg{read_only=true}; return true')"]))
33+
34+
(defn is-primary?
35+
[test node]
36+
(let [conn (cl/open node test)]
37+
(if (= node p) true false)))
38+
j/query conn ["box.info.election.state"]
39+
40+
(defn primary
41+
[nodes]
42+
(doseq [n nodes] (println n))
43+
2544
(defn open
2645
"Opens a connection to the given node."
2746
[node test]

src/tarantool/db.clj

Lines changed: 14 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
(:require [clojure.tools.logging :refer :all]
33
[clojure.string :as str]
44
[clojure.java.io :as io]
5-
[next.jdbc :as j]
6-
[next.jdbc.connection :as connection]
5+
;[next.jdbc :as j]
6+
;[next.jdbc.connection :as connection]
7+
[tarantool.client :as cl]
78
[jepsen.os.debian :as debian]
89
[jepsen.control.util :as cu]
910
[jepsen [core :as jepsen]
@@ -191,11 +192,6 @@
191192
[b]
192193
(if (true? b) "true" "false"))
193194

194-
(defn is-primary?
195-
[test node]
196-
(let [p (jepsen/primary test)]
197-
(if (= node p) true false)))
198-
199195
(defn is-single-mode?
200196
[test]
201197
(let [n (count (:nodes test))]
@@ -206,27 +202,17 @@
206202
(defn configure!
207203
"Configure instance"
208204
[test node]
209-
(let [read-only (not (is-primary? test node))]
210-
(info "Joining" node "as" (if (true? read-only) "replica" "leader"))
211-
(c/exec :mkdir :-p "/etc/tarantool/instances.available")
212-
(c/exec :mkdir :-p "/etc/tarantool/instances.enabled")
213-
(c/exec :usermod :-a :-G :tarantool :ubuntu)
214-
(c/exec :echo (-> "tarantool/jepsen.lua" io/resource slurp
215-
(str/replace #"%TARANTOOL_REPLICATION%" (replica-set test))
216-
(str/replace #"%TARANTOOL_IS_READ_ONLY%" (boolean-to-str read-only))
217-
(str/replace #"%TARANTOOL_SINGLE_MODE%" (boolean-to-str (is-single-mode? test)))
218-
(str/replace #"%TARANTOOL_DATA_ENGINE%" (:engine test)))
219-
:> "/etc/tarantool/instances.enabled/jepsen.lua")
220-
(c/exec :cp "/etc/tarantool/instances.enabled/jepsen.lua" "/etc/tarantool/instances.available")))
221-
222-
(defn is-read-only
223-
[conn]
224-
(j/execute! conn ["SELECT lua('return box.info().ro') IS NOT NULL"]))
225-
226-
(defn set-read-only-mode
227-
"Disable and enable read only mode"
228-
[conn mode]
229-
(j/execute! conn ["SELECT LUA('box.cfg{read_only=true}; return true')"]))
205+
(info "Joining" node "as" (if (true? read-only) "replica" "leader"))
206+
(c/exec :mkdir :-p "/etc/tarantool/instances.available")
207+
(c/exec :mkdir :-p "/etc/tarantool/instances.enabled")
208+
(c/exec :usermod :-a :-G :tarantool :ubuntu)
209+
(c/exec :echo (-> "tarantool/jepsen.lua" io/resource slurp
210+
(str/replace #"%TARANTOOL_REPLICATION%" (replica-set test))
211+
;(str/replace #"%TARANTOOL_IS_READ_ONLY%" (boolean-to-str read-only))
212+
(str/replace #"%TARANTOOL_SINGLE_MODE%" (boolean-to-str (is-single-mode? test)))
213+
(str/replace #"%TARANTOOL_DATA_ENGINE%" (:engine test)))
214+
:> "/etc/tarantool/instances.enabled/jepsen.lua")
215+
(c/exec :cp "/etc/tarantool/instances.enabled/jepsen.lua" "/etc/tarantool/instances.available"))
230216

231217
(defn db
232218
"Tarantool DB for a particular version."

0 commit comments

Comments
 (0)