Skip to content

Commit efc0002

Browse files
authored
Separate Cassandra deps (#151)
1 parent 9b97dbb commit efc0002

File tree

11 files changed

+214
-208
lines changed

11 files changed

+214
-208
lines changed

.github/workflows/build-test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ jobs:
4646
- name: Run test for ScalarDB
4747
run: |
4848
cd scalardb
49-
lein cloverage
49+
lein with-profile dev,cassandra cloverage
5050
5151
- name: Run test for ScalarDL
5252
run: |

.github/workflows/cluster-test.yml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -139,11 +139,6 @@ jobs:
139139
namespace: metallb-system
140140
EOF
141141
142-
- name: Install dependencies
143-
run: |
144-
cd cassandra
145-
lein install
146-
147142
- name: ScalarDB Cluster test
148143
run: |
149144
cd scalardb

.github/workflows/daily.yml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -135,11 +135,6 @@ jobs:
135135
namespace: metallb-system
136136
EOF
137137
138-
- name: Install dependencies
139-
run: |
140-
cd cassandra
141-
lein install
142-
143138
- name: ${{ matrix.tests.name }}
144139
run: |
145140
cd scalardb

.github/workflows/test.yml

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ jobs:
3535
- name: ScalarDB test
3636
run: |
3737
docker exec jepsen-control bash -c "cd /scalar-jepsen/cassandra && lein install"
38-
docker exec jepsen-control bash -c "cd /scalar-jepsen/scalardb && lein run test --workload transfer --nodes n1,n2,n3 --ssh-private-key ~/.ssh/id_rsa"
38+
docker exec jepsen-control bash -c "cd /scalar-jepsen/scalardb && lein with-profile cassandra run test --workload transfer --nodes n1,n2,n3 --ssh-private-key ~/.ssh/id_rsa"
3939
4040
cluster:
4141
runs-on: ubuntu-latest
@@ -118,11 +118,6 @@ jobs:
118118
namespace: metallb-system
119119
EOF
120120
121-
- name: Install dependencies
122-
run: |
123-
cd cassandra
124-
lein install
125-
126121
- name: ScalarDB Cluster test
127122
run: |
128123
cd scalardb

scalardb/project.clj

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
[net.java.dev.jna/jna "5.11.0"]
88
[net.java.dev.jna/jna-platform "5.11.0"]
99
[org.slf4j/slf4j-jdk14 "2.0.6"]
10-
[cassandra "0.1.0-SNAPSHOT" :exclusions [org.apache.commons/commons-lang3]]
1110
[cheshire "5.12.0"]
1211
[clj-commons/clj-yaml "1.0.29"]
1312
[com.scalar-labs/scalardb-schema-loader "4.0.0-SNAPSHOT"]
@@ -22,19 +21,22 @@
2221
com.azure/azure-cosmos
2322
io.grpc/grpc-core
2423
com.scalar-labs/scalardb-rpc]]]}
24+
:cassandra {:dependencies [[cassandra "0.1.0-SNAPSHOT"
25+
:exclusions [org.apache.commons/commons-lang3]]]
26+
:env {:cassandra? "true"}}
2527
:cluster {:dependencies [[com.scalar-labs/scalardb-cluster-java-client-sdk "4.0.0-SNAPSHOT"
2628
;; avoid the netty dependency issue
2729
:exclusions [software.amazon.awssdk/*
2830
com.oracle.database.jdbc/ojdbc8-production
2931
com.azure/azure-cosmos
3032
com.scalar-labs/scalardb-rpc]]]
3133
:env {:scalardb-cluster-version "4.0.0-SNAPSHOT"
32-
:helm-chart-version "1.7.2"}
33-
:plugins [[lein-environ "1.2.0"]]}
34+
:helm-chart-version "1.7.2"}}
3435
:use-jars {:dependencies [[com.google.guava/guava "31.1-jre"]
3536
[org.apache.commons/commons-text "1.13.0"]]
3637
:resource-paths ["resources/scalardb.jar"]}
3738
:default [:base :system :user :provided :dev :use-released]}
39+
:plugins [[lein-environ "1.2.0"]]
3840
:jvm-opts ["-Djava.awt.headless=true" "-Xmx4g"]
3941
:main scalardb.runner
4042
:aot [scalardb.runner])
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
(ns scalardb.db.cassandra
2+
(:require [cassandra.core :as cassandra]
3+
[cassandra.nemesis :as cn]
4+
[cassandra.runner :as cr]
5+
[clojure.string :as string]
6+
[scalardb.db-extend :as ext])
7+
(:import (com.scalar.db.storage.cassandra CassandraAdmin
8+
CassandraAdmin$ReplicationStrategy
9+
CassandraAdmin$CompactionStrategy)
10+
(java.util Properties)))
11+
12+
(defrecord ExtCassandra []
13+
ext/DbExtension
14+
(get-db-type [_] :cassandra)
15+
(live-nodes [_ test] (cassandra/live-nodes test))
16+
(wait-for-recovery [_ test] (cassandra/wait-rf-nodes test))
17+
(create-table-opts
18+
[_ test]
19+
{(keyword CassandraAdmin/REPLICATION_STRATEGY)
20+
(str CassandraAdmin$ReplicationStrategy/SIMPLE_STRATEGY)
21+
(keyword CassandraAdmin/COMPACTION_STRATEGY)
22+
(str CassandraAdmin$CompactionStrategy/LCS)
23+
(keyword CassandraAdmin/REPLICATION_FACTOR) (:rf test)})
24+
(create-properties
25+
[_ test]
26+
(or (ext/load-config test)
27+
(let [nodes (:nodes test)]
28+
(when (nil? nodes)
29+
(throw (ex-info "No living node" {:test test})))
30+
(->> (doto (Properties.)
31+
(.setProperty "scalar.db.storage" "cassandra")
32+
(.setProperty "scalar.db.contact_points"
33+
(string/join "," nodes))
34+
(.setProperty "scalar.db.username" "cassandra")
35+
(.setProperty "scalar.db.password" "cassandra"))
36+
(ext/set-common-properties test)))))
37+
(create-storage-properties [this test] (ext/create-properties this test)))
38+
39+
(defn gen-db
40+
[faults admin]
41+
(let [db (ext/extend-db (cassandra/db) (->ExtCassandra))
42+
;; replace :kill nemesis with :crash for Cassandra
43+
faults (mapv #(if (= % :kill) :crash %) faults)]
44+
(when-not (every? #(some? (get cr/nemeses (name %))) faults)
45+
(throw
46+
(ex-info
47+
(str "Invalid nemesis for Cassandra: " faults) {})))
48+
[db
49+
(cn/nemesis-package
50+
{:db db
51+
:faults faults
52+
:admin admin
53+
:partition {:targets [:one
54+
:primaries
55+
:majority
56+
:majorities-ring
57+
:minority-third]}})
58+
Integer/MAX_VALUE]))

scalardb/src/scalardb/db/cluster.clj

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@
66
[jepsen
77
[control :as c]
88
[db :as db]]
9+
[scalardb.db-extend :as ext]
910
[scalardb.nemesis.cluster :as n])
10-
(:import (java.io File)))
11+
(:import (java.io File)
12+
(java.util Properties)))
1113

1214
(def ^:private ^:const CLUSTER_VALUES_YAML "scalardb-cluster-custom-values.yaml")
1315
(def ^:private ^:const DEFAULT_SCALARDB_CLUSTER_VERSION "4.0.0-SNAPSHOT")
@@ -171,7 +173,7 @@
171173
(map #(nth (str/split % #"\s+") 3))
172174
first))
173175

174-
(defn running-pods?
176+
(defn- running-pods?
175177
"Check a live node."
176178
[test]
177179
(-> test
@@ -197,7 +199,7 @@
197199
(warn (.getMessage e))
198200
false))))
199201

200-
(defn wait-for-recovery
202+
(defn- wait-for-recovery
201203
"Wait for the node bootstrapping."
202204
([test]
203205
(wait-for-recovery TIMEOUT_SEC INTERVAL_SEC test))
@@ -246,3 +248,38 @@
246248
db/LogFiles
247249
(log-files [_ test _]
248250
(get-logs test))))
251+
252+
(defrecord ExtCluster []
253+
ext/DbExtension
254+
(get-db-type [_] :cluster)
255+
(live-nodes [_ test] (running-pods? test))
256+
(wait-for-recovery [_ test] (wait-for-recovery test))
257+
(create-table-opts [_ _] {})
258+
(create-properties
259+
[_ test]
260+
(or (ext/load-config test)
261+
(let [node (-> test :nodes first)
262+
ip (c/on node (get-load-balancer-ip))]
263+
(->> (doto (Properties.)
264+
(.setProperty "scalar.db.transaction_manager" "cluster")
265+
(.setProperty "scalar.db.contact_points"
266+
(str "indirect:" ip))
267+
(.setProperty "scalar.db.sql.connection_mode" "cluster")
268+
(.setProperty "scalar.db.sql.cluster_mode.contact_points"
269+
(str "indirect:" ip)))
270+
(ext/set-common-properties test)))))
271+
(create-storage-properties [_ _]
272+
(let [node (-> test :nodes first)
273+
ip (c/on node (get-postgres-ip))]
274+
(doto (Properties.)
275+
(.setProperty "scalar.db.storage" "jdbc")
276+
(.setProperty "scalar.db.contact_points"
277+
(str "jdbc:postgresql://" ip ":5432/postgres"))
278+
(.setProperty "scalar.db.username" "postgres")
279+
(.setProperty "scalar.db.password" "postgres")))))
280+
281+
(defn gen-db
282+
[faults admin]
283+
(when (seq admin)
284+
(warn "The admin operations are ignored:" admin))
285+
[(ext/extend-db (db) (->ExtCluster)) (n/nemesis-package db 60 faults) 1])

scalardb/src/scalardb/db/postgres.clj

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
(ns scalardb.db.postgres
2-
(:require [clojure.tools.logging :refer [info]]
2+
(:require [clojure.tools.logging :refer [info warn]]
33
[jepsen
44
[control :as c]
55
[db :as db]
66
[util :refer [meh]]]
77
[jepsen.control.util :as cu]
8-
[jepsen.os.debian :as debian]))
8+
[jepsen.os.debian :as debian]
9+
[jepsen.nemesis.combined :as jn]
10+
[scalardb.db-extend :as ext])
11+
(:import (java.util Properties)))
912

1013
(def ^:private ^:const DEFAULT_VERSION "15")
1114
(def ^:private ^:const TIMEOUT_SEC 600)
@@ -71,7 +74,7 @@
7174
(c/su (meh (c/exec :rm :-r (get-main-dir version))))
7275
(c/su (meh (c/exec :rm (get-log-path version)))))
7376

74-
(defn live-node?
77+
(defn- live-node?
7578
[test]
7679
(let [node (-> test :nodes first)]
7780
(try
@@ -81,7 +84,7 @@
8184
(info node "is down")
8285
false))))
8386

84-
(defn wait-for-recovery
87+
(defn- wait-for-recovery
8588
"Wait for the node bootstrapping."
8689
([test]
8790
(wait-for-recovery TIMEOUT_SEC INTERVAL_SEC test))
@@ -134,3 +137,37 @@
134137

135138
db/LogFiles
136139
(log-files [_ test _] [(get-log-path test)])))
140+
141+
(defrecord ExtPostgres []
142+
ext/DbExtension
143+
(get-db-type [_] :postgres)
144+
(live-nodes [_ test] (live-node? test))
145+
(wait-for-recovery [_ test] (wait-for-recovery test))
146+
(create-table-opts [_ _] {})
147+
(create-properties
148+
[_ test]
149+
(or (ext/load-config test)
150+
(let [node (-> test :nodes first)]
151+
;; We have only one node in this test
152+
(->> (doto (Properties.)
153+
(.setProperty "scalar.db.storage" "jdbc")
154+
(.setProperty "scalar.db.contact_points"
155+
(str "jdbc:postgresql://" node ":5432/"))
156+
(.setProperty "scalar.db.username" "postgres")
157+
(.setProperty "scalar.db.password" "postgres"))
158+
(ext/set-common-properties test)))))
159+
(create-storage-properties [this test] (ext/create-properties this test)))
160+
161+
(defn gen-db
162+
[faults admin]
163+
(when (seq admin)
164+
(warn "The admin operations are ignored:" admin))
165+
[(ext/extend-db (db) (->ExtPostgres))
166+
(jn/nemesis-package
167+
{:db db
168+
:interval 60
169+
:faults faults
170+
:partition {:targets [:one]}
171+
:kill {:targets [:one]}
172+
:pause {:targets [:one]}})
173+
1])

0 commit comments

Comments
 (0)