Skip to content

Commit fd203d3

Browse files
authored
Enable to Switch a DB in ScalarDB Cluster test (#169)
1 parent 60b5f05 commit fd203d3

File tree

10 files changed

+91
-96
lines changed

10 files changed

+91
-96
lines changed

.github/workflows/cluster-test.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ jobs:
9494
- name: Setup Java
9595
uses: actions/setup-java@v5
9696
with:
97-
java-version: '11'
97+
java-version: '21'
9898
distribution: 'temurin'
9999

100100
- name: Install leiningen
@@ -194,7 +194,7 @@ jobs:
194194
195195
lein with-profile cluster run test \
196196
--nodes localhost \
197-
--db cluster \
197+
--db postgres \
198198
--concurrency 5 \
199199
--username runner \
200200
--ssh-private-key ~/.ssh/id_rsa \

.github/workflows/daily.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,15 +191,15 @@ jobs:
191191
if [ "${{ matrix.tests.enable_group_commit }}" = "true" ]; then
192192
OPTS+=" --enable-group-commit"
193193
fi
194+
DOCKER_USERNAME=${{ github.repository_owner }} \
195+
DOCKER_ACCESS_TOKEN=${{ secrets.CR_PAT }} \
194196
lein with-profile cluster run test \
195197
--time-limit ${{ matrix.tests.time_limit }} \
196198
--nodes localhost \
197-
--db cluster \
199+
--db postgres \
198200
--concurrency 5 \
199201
--username runner \
200202
--ssh-private-key ~/.ssh/id_rsa \
201-
--docker-username ${{ github.repository_owner }} \
202-
--docker-access-token ${{ secrets.CR_PAT }} \
203203
${OPTS} > /dev/null 2>&1
204204
205205
- name: Record result

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ jobs:
121121
- name: ScalarDB Cluster test
122122
run: |
123123
cd scalardb
124-
lein with-profile cluster run test --workload transfer --nodes localhost --db cluster --username runner --ssh-private-key ~/.ssh/id_rsa --docker-username ${{ github.repository_owner }} --docker-access-token ${{ secrets.CR_PAT }} --nemesis crash
124+
DOCKER_USERNAME=${{ github.repository_owner }} DOCKER_ACCESS_TOKEN=${{ secrets.CR_PAT }} lein with-profile cluster run test --workload transfer --nodes localhost --db postgres --username runner --ssh-private-key ~/.ssh/id_rsa --nemesis crash
125125
126126
- name: Check test result
127127
run: |

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,11 @@ The test will attempt to SSH into a machine where the Kubernetes cluster is depl
6868

6969
Below is an example command to run the ScalarDB Cluster test:
7070
```sh
71-
lein with-profile cluster run test --workload transfer --db cluster \
71+
DOCKER_USERNAME=${GITHUB_USER} \
72+
DOCKER_ACCESS_TOKEN=${GITHUB_ACCESS_TOKEN} \
73+
lein with-profile cluster run test --workload transfer --db postgres \
7274
--nodes ${KUBERNETES_CLUSTER_HOST} \
73-
--username ${USER} \
74-
--docker-username ${GITHUB_USER} \
75-
--docker-access-token ${GITHUB_ACCESS_TOKEN}
75+
--username ${USER}
7676
```
7777
- `KUBERNETES_CLUSTER_HOST`: The IP address or hostname of the machine running the Kubernetes cluster.
7878
- `USER`: The SSH username used to connect to the Kubernetes cluster host. If needed, `--password` or `--ssh-private-key` can be added.

scalardb/project.clj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@
3636
com.azure/azure-cosmos
3737
com.datastax.cassandra/cassandra-driver-core
3838
com.google.cloud/alloydb-jdbc-connector]]]
39-
:env {:scalardb-cluster-version "4.0.0-SNAPSHOT"
39+
:env {:cluster? "true"
40+
:scalardb-cluster-version "4.0.0-SNAPSHOT"
4041
:helm-chart-version "1.7.2"}}
4142
:use-jars {:dependencies [[com.google.guava/guava "31.1-jre"]
4243
[org.apache.commons/commons-text "1.13.0"]]

scalardb/src/scalardb/db/cassandra.clj

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
(defrecord ExtCassandra []
1313
ext/DbExtension
14-
(get-db-type [_] :cassandra)
1514
(live-nodes [_ test] (cassandra/live-nodes test))
1615
(wait-for-recovery [_ test] (cassandra/wait-rf-nodes test))
1716
(create-table-opts
@@ -37,7 +36,7 @@
3736
(create-storage-properties [this test] (ext/create-properties this test)))
3837

3938
(defn gen-db
40-
[faults admin]
39+
[faults admin & _]
4140
(let [db (ext/extend-db (cassandra/db) (->ExtCassandra))
4241
;; replace :kill nemesis with :crash for Cassandra
4342
faults (mapv #(if (= % :kill) :crash %) faults)]

scalardb/src/scalardb/db/cluster.clj

Lines changed: 58 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@
5353

5454
:imagePullSecrets [{:name "scalardb-ghcr-secret"}]}})
5555

56+
(defn- throw-unsupported-db-error
57+
[db-type]
58+
(throw (ex-info "Unsupported DB for ScalarDB Cluster test" {:db db-type})))
59+
5660
(defn- update-cluster-values
5761
[test values]
5862
(let [path [:scalardbCluster :scalardbClusterNodeProperties]
@@ -87,9 +91,11 @@
8791
(defn- install!
8892
"Install prerequisites.
8993
You should already have installed kind (or similar tool), kubectl and helm."
90-
[]
91-
;; postgre
92-
(c/exec :helm :repo :add "bitnami" "https://charts.bitnami.com/bitnami")
94+
[db-type]
95+
(case db-type
96+
:postgres (c/exec :helm :repo :add
97+
"bitnami" "https://charts.bitnami.com/bitnami")
98+
(throw-unsupported-db-error db-type))
9399
;; ScalarDB cluster
94100
(c/exec :helm :repo :add
95101
"scalar-labs" "https://scalar-labs.github.io/helm-charts")
@@ -99,17 +105,17 @@
99105
(c/exec :helm :repo :update))
100106

101107
(defn- configure!
102-
[test]
103-
(binding [c/*dir* (System/getProperty "user.dir")]
104-
(try
105-
(c/exec :kubectl :delete :secret "scalardb-ghcr-secret")
108+
[]
109+
(when (and (seq (env :docker-username)) (seq (env :docker-access-token)))
110+
(binding [c/*dir* (System/getProperty "user.dir")]
111+
(try
112+
(c/exec :kubectl :delete :secret "scalardb-ghcr-secret")
106113
;; ignore the failure when the secret doesn't exist
107-
(catch Exception _))
108-
(when-let [docker-username (:docker-username test)]
114+
(catch Exception _))
109115
(c/exec :kubectl :create :secret :docker-registry "scalardb-ghcr-secret"
110116
"--docker-server=ghcr.io"
111-
(str "--docker-username=" docker-username)
112-
(str "--docker-password=" (:docker-access-token test)))))
117+
(str "--docker-username=" (env :docker-username))
118+
(str "--docker-password=" (env :docker-access-token)))))
113119

114120
;; Chaos Mesh
115121
(try
@@ -118,21 +124,22 @@
118124
(c/exec :kubectl :create :ns "chaos-mesh"))))
119125

120126
(defn- start!
121-
[test]
122-
;; postgresql
123-
(c/exec
124-
:helm :install POSTGRESQL_NAME "bitnami/postgresql"
125-
:--set "auth.postgresPassword=postgres"
126-
:--set "primary.persistence.enabled=true"
127-
;; Need an external IP for storage APIs
128-
:--set "service.type=LoadBalancer"
129-
:--set "primary.service.type=LoadBalancer"
130-
;; Use legacy images
131-
:--set "image.repository=bitnamilegacy/postgresql"
132-
:--set "volumePermissions.image.repository=bitnamilegacy/os-shell"
133-
:--set "metrics.image.repository=bitnamilegacy/postgres-exporter"
134-
:--set "global.security.allowInsecureImages=true"
135-
:--version "16.7.0")
127+
[test db-type]
128+
(case db-type
129+
:postgres (c/exec
130+
:helm :install POSTGRESQL_NAME "bitnami/postgresql"
131+
:--set "auth.postgresPassword=postgres"
132+
:--set "primary.persistence.enabled=true"
133+
;; Need an external IP for storage APIs
134+
:--set "service.type=LoadBalancer"
135+
:--set "primary.service.type=LoadBalancer"
136+
;; Use legacy images
137+
:--set "image.repository=bitnamilegacy/postgresql"
138+
:--set "volumePermissions.image.repository=bitnamilegacy/os-shell"
139+
:--set "metrics.image.repository=bitnamilegacy/postgres-exporter"
140+
:--set "global.security.allowInsecureImages=true"
141+
:--version "16.7.0")
142+
(throw-unsupported-db-error db-type))
136143

137144
;; ScalarDB Cluster
138145
(let [chart-version (or (some-> (env :helm-chart-version) not-empty)
@@ -168,14 +175,13 @@
168175
(apply c/exec :rm :-f))
169176
(catch Exception _ nil)))
170177
(info "wiping the pods...")
171-
(try (c/exec :helm :uninstall POSTGRESQL_NAME) (catch Exception _ nil))
172-
(try (c/exec :kubectl :delete
173-
:pvc :-l "app.kubernetes.io/instance=postgresql-scalardb-cluster")
174-
(catch Exception _ nil))
175-
(try (c/exec :helm :uninstall CLUSTER_NAME) (catch Exception _ nil))
176-
(try (c/exec :helm :uninstall CLUSTER2_NAME) (catch Exception _ nil))
177-
(try (c/exec :helm :uninstall "chaos-mesh" :-n "chaos-mesh")
178-
(catch Exception _ nil)))
178+
(doseq [cmd [[:helm :uninstall POSTGRESQL_NAME]
179+
[:kubectl :delete
180+
:pvc :-l "app.kubernetes.io/instance=postgresql-scalardb-cluster"]
181+
[:helm :uninstall CLUSTER_NAME]
182+
[:helm :uninstall CLUSTER2_NAME]
183+
[:helm :uninstall "chaos-mesh" :-n "chaos-mesh"]]]
184+
(try (apply c/exec cmd) (catch Exception _ nil))))
179185

180186
(defn- get-pod-list
181187
[name]
@@ -245,15 +251,15 @@
245251

246252
(defn db
247253
"Setup ScalarDB Cluster."
248-
[]
254+
[db-type]
249255
(reify
250256
db/DB
251257
(setup! [_ test _]
252258
(when-not (:leave-db-running? test)
253259
(wipe!))
254-
(install!)
255-
(configure! test)
256-
(start! test)
260+
(install! db-type)
261+
(configure!)
262+
(start! test db-type)
257263
;; wait for the pods
258264
(wait-for-recovery test))
259265

@@ -281,9 +287,8 @@
281287
(log-files [_ test _]
282288
(get-logs test))))
283289

284-
(defrecord ExtCluster []
290+
(defrecord ExtCluster [db-type]
285291
ext/DbExtension
286-
(get-db-type [_] :cluster)
287292
(live-nodes [_ test] (running-pods? test))
288293
(wait-for-recovery [_ test] (wait-for-recovery test))
289294
(create-table-opts [_ _] {})
@@ -303,17 +308,20 @@
303308
(mapv create-fn [ip ip2])
304309
(create-fn ip)))))
305310
(create-storage-properties [_ _]
306-
(let [node (-> test :nodes first)
307-
ip (c/on node (get-load-balancer-ip POSTGRESQL_NAME))]
308-
(doto (Properties.)
309-
(.setProperty "scalar.db.storage" "jdbc")
310-
(.setProperty "scalar.db.contact_points"
311-
(str "jdbc:postgresql://" ip ":5432/postgres"))
312-
(.setProperty "scalar.db.username" "postgres")
313-
(.setProperty "scalar.db.password" "postgres")))))
311+
(let [node (-> test :nodes first)]
312+
(case db-type
313+
:postgres (let [ip (c/on node (get-load-balancer-ip POSTGRESQL_NAME))]
314+
(doto (Properties.)
315+
(.setProperty "scalar.db.storage" "jdbc")
316+
(.setProperty "scalar.db.contact_points"
317+
(str "jdbc:postgresql://" ip ":5432/postgres"))
318+
(.setProperty "scalar.db.username" "postgres")
319+
(.setProperty "scalar.db.password" "postgres")))
320+
(throw-unsupported-db-error db-type)))))
314321

315322
(defn gen-db
316-
[faults admin]
323+
[faults admin db-type]
317324
(when (seq admin)
318325
(warn "The admin operations are ignored: " admin))
319-
[(ext/extend-db (db) (->ExtCluster)) (n/nemesis-package db 60 faults) 1])
326+
(let [db (ext/extend-db (db db-type) (->ExtCluster db-type))]
327+
[db (n/nemesis-package db 60 faults) 1]))

scalardb/src/scalardb/db/postgres.clj

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,6 @@
140140

141141
(defrecord ExtPostgres []
142142
ext/DbExtension
143-
(get-db-type [_] :postgres)
144143
(live-nodes [_ test] (live-node? test))
145144
(wait-for-recovery [_ test] (wait-for-recovery test))
146145
(create-table-opts [_ _] {})
@@ -159,7 +158,7 @@
159158
(create-storage-properties [this test] (ext/create-properties this test)))
160159

161160
(defn gen-db
162-
[faults admin]
161+
[faults admin & _]
163162
(when (seq admin)
164163
(warn "The admin operations are ignored: " admin))
165164
[(ext/extend-db (db) (->ExtPostgres))

scalardb/src/scalardb/db_extend.clj

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
(.setProperty "scalar.db.consensus_commit.include_metadata.enabled" "true")))
2929

3030
(defprotocol DbExtension
31-
(get-db-type [this])
3231
(live-nodes [this test])
3332
(wait-for-recovery [this test])
3433
(create-table-opts [this test])
@@ -53,7 +52,6 @@
5352
db/LogFiles
5453
(log-files [_ test node] (db/log-files db test node))
5554
DbExtension
56-
(get-db-type [_] (get-db-type ext-db))
5755
(live-nodes [_ test] (live-nodes ext-db test))
5856
(wait-for-recovery [_ test] (wait-for-recovery ext-db test))
5957
(create-table-opts [_ test] (create-table-opts ext-db test))

scalardb/src/scalardb/runner.clj

Lines changed: 19 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,10 @@
1919
[elle-write-read-2pc]]
2020
[clojure.core :as c]))
2121

22-
(def db-keys
22+
(def supported-dbs
2323
"The map of test DBs."
2424
{"cassandra" :cassandra
25-
"postgres" :postgres
26-
"cluster" :cluster})
25+
"postgres" :postgres})
2726

2827
(def workload-keys
2928
"A map of test workload keys."
@@ -58,7 +57,7 @@
5857

5958
(def test-opt-spec
6059
[(cli/repeated-opt nil "--db NAME" "DB(s) on which the test is run"
61-
[:cassandra] db-keys)
60+
[:cassandra] supported-dbs)
6261

6362
(cli/repeated-opt nil "--workload NAME" "Test(s) to run" [] workload-keys)
6463

@@ -84,15 +83,7 @@
8483

8584
[nil "--config-file CONFIG_FILE"
8685
"ScalarDB config file. When this is given, other configuration options are ignored."
87-
:default ""]
88-
89-
[nil "--docker-username DOCKER_USERNAME"
90-
"Username to pull ScalarDB Cluster node image in ghcr.io."
91-
:default nil]
92-
93-
[nil "--docker-access-token DOCKER_ACCESS_TOKEN"
94-
"Access token to pull ScalarDB Cluster node image in ghcr.io."
95-
:default nil]])
86+
:default ""]])
9687

9788
(defn- test-name
9889
[workload-key faults admin]
@@ -101,21 +92,20 @@
10192
(into (map name admin))
10293
(->> (remove nil?) (string/join "-"))))
10394

104-
(defn- load-module
105-
[db-key]
106-
(case db-key
107-
:cassandra (require 'scalardb.db.cassandra)
108-
:postgres (require 'scalardb.db.postgres)
109-
:cluster (require 'scalardb.db.cluster)
110-
(throw (ex-info "Unsupported DB" {:db db-key}))))
111-
11295
(defn- gen-db
11396
"Returns [extended-db constructed-nemesis num-max-nodes]."
114-
[db-key faults admin]
115-
(load-module db-key)
116-
(let [gen-db-sym (symbol (str "scalardb.db." (name db-key)) "gen-db")
97+
[db-type faults admin]
98+
(let [gen-db-sym (if (= (env :cluster?) "true")
99+
(do (require 'scalardb.db.cluster)
100+
'scalardb.db.cluster/gen-db)
101+
(case db-type
102+
:cassandra (do (require 'scalardb.db.cassandra)
103+
'scalardb.db.cassandra/gen-db)
104+
:postgres (do (require 'scalardb.db.postgres)
105+
'scalardb.db.postgres/gen-db)
106+
(throw (ex-info "Unsupported DB" {:db db-type}))))
117107
gen-db-fn (resolve gen-db-sym)]
118-
(gen-db-fn faults admin)))
108+
(gen-db-fn faults admin db-type)))
119109

120110
(defn- gen-test-opt-spec
121111
[]
@@ -136,8 +126,8 @@
136126
:decommissioned (atom #{})})
137127

138128
(defn scalardb-test
139-
[base-opts db-key workload-key faults admin]
140-
(let [[db nemesis max-nodes] (gen-db db-key faults admin)
129+
[base-opts db-type workload-key faults admin]
130+
(let [[db nemesis max-nodes] (gen-db db-type faults admin)
141131
consistency-model (->> base-opts :consistency-model (mapv keyword))
142132
workload-opts (merge base-opts
143133
scalardb-opts
@@ -169,12 +159,12 @@
169159
:usage (cli/test-usage)
170160
:run (fn [{:keys [options]}]
171161
(doseq [_ (range (:test-count options))
172-
db-key (:db options)
162+
db-type (:db options)
173163
workload-key (:workload options)
174164
faults (:nemesis options)
175165
admin (or (:admin options) [[]])]
176166
(let [test (-> options
177-
(scalardb-test db-key
167+
(scalardb-test db-type
178168
workload-key
179169
faults
180170
admin)

0 commit comments

Comments
 (0)