Skip to content

Commit

Permalink
Set custom properties and add --enable-group-commit (#130)
Browse files Browse the repository at this point in the history
  • Loading branch information
yito88 authored Aug 28, 2024
1 parent 08c19ef commit 9ff6675
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 39 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
- name: docker-compose up
run: |
cd docker
docker-compose up -d
docker compose up -d
- name: Cassandra test
run: |
Expand Down
16 changes: 3 additions & 13 deletions scalardb/src/scalardb/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@
(com.scalar.db.schemaloader SchemaLoader)
(com.scalar.db.service TransactionFactory
StorageFactory)
(com.scalar.db.transaction.consensuscommit Coordinator)
(java.io FileInputStream)
(java.util Properties)))
(com.scalar.db.transaction.consensuscommit Coordinator)))

(def ^:const RETRIES 8)
(def ^:const RETRIES_FOR_RECONNECTION 3)
Expand Down Expand Up @@ -75,23 +73,15 @@
(cassandra/create-my-table session {:keyspace "coordinator"
:table "state"
:schema {:tx_id :text
:tx_child_ids :text
:tx_state :int
:tx_created_at :bigint
:primary-key [:tx_id]}})
(cassandra/close-cassandra cluster session)))

(defn- load-config
[test]
(when-let [path (and (seq (:config-file test)) (:config-file test))]
(let [props (Properties.)]
(with-open [stream (FileInputStream. path)]
(.load props stream))
props)))

(defn setup-transaction-tables
[test schemata]
(let [properties (or (load-config test)
(ext/create-properties (:db test) test))
(let [properties (ext/create-properties (:db test) test)
options (ext/create-table-opts (:db test) test)]
(if (= (.getProperty properties "scalar.db.username") "cassandra")
;; Workaround the issue of the schema loader for Cassandra
Expand Down
68 changes: 44 additions & 24 deletions scalardb/src/scalardb/db_extend.clj
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
(:import (com.scalar.db.storage.cassandra CassandraAdmin
CassandraAdmin$ReplicationStrategy
CassandraAdmin$CompactionStrategy)
(java.io FileInputStream)
(java.util Properties)))

(def ^:private ISOLATION_LEVELS {:snapshot "SNAPSHOT"
Expand All @@ -14,6 +15,28 @@
(def ^:private SERIALIZABLE_STRATEGIES {:extra-read "EXTRA_READ"
:extra-write "EXTRA_WRITE"})

(defn- load-config
[test]
(when-let [path (and (seq (:config-file test)) (:config-file test))]
(let [props (Properties.)]
(with-open [stream (FileInputStream. path)]
(.load props stream))
props)))

(defn- set-common-properties
[test properties]
(doto properties
(.setProperty "scalar.db.consensus_commit.isolation_level"
((:isolation-level test) ISOLATION_LEVELS))
(.setProperty "scalar.db.consensus_commit.serializable_strategy"
((:serializable-strategy test) SERIALIZABLE_STRATEGIES))
(.setProperty "scalar.db.consensus_commit.coordinator.group_commit.enabled"
(str (:enable-group-commit test)))
(.setProperty "scalar.db.consensus_commit.coordinator.group_commit.slot_capacity" "4")
(.setProperty "scalar.db.consensus_commit.coordinator.group_commit.old_group_abort_timeout_millis" "15000")
(.setProperty "scalar.db.consensus_commit.coordinator.group_commit.delayed_slot_move_timeout_millis" "400")
(.setProperty "scalar.db.consensus_commit.coordinator.group_commit.metrics_monitor_log_enabled" "true")))

(defprotocol DbExtension
(live-nodes [this test])
(wait-for-recovery [this test])
Expand All @@ -33,18 +56,17 @@
(keyword CassandraAdmin/REPLICATION_FACTOR) (:rf test)})
(create-properties
[_ test]
(let [nodes (:nodes test)]
(when (nil? nodes)
(throw (ex-info "No living node" {:test test})))
(doto (Properties.)
(.setProperty "scalar.db.storage" "cassandra")
(.setProperty "scalar.db.contact_points" (string/join "," nodes))
(.setProperty "scalar.db.username" "cassandra")
(.setProperty "scalar.db.password" "cassandra")
(.setProperty "scalar.db.consensus_commit.isolation_level"
((:isolation-level test) ISOLATION_LEVELS))
(.setProperty "scalar.db.consensus_commit.serializable_strategy"
((:serializable-strategy test) SERIALIZABLE_STRATEGIES))))))
(or (load-config test)
(let [nodes (:nodes test)]
(when (nil? nodes)
(throw (ex-info "No living node" {:test test})))
(->> (doto (Properties.)
(.setProperty "scalar.db.storage" "cassandra")
(.setProperty "scalar.db.contact_points"
(string/join "," nodes))
(.setProperty "scalar.db.username" "cassandra")
(.setProperty "scalar.db.password" "cassandra"))
(set-common-properties test))))))

(defrecord ExtPostgres []
DbExtension
Expand All @@ -53,18 +75,16 @@
(create-table-opts [_ _] {})
(create-properties
[_ test]
(let [node (-> test :nodes first)]
;; We have only one node in this test
(doto (Properties.)
(.setProperty "scalar.db.storage" "jdbc")
(.setProperty "scalar.db.contact_points"
(str "jdbc:postgresql://" node ":5432/"))
(.setProperty "scalar.db.username" "postgres")
(.setProperty "scalar.db.password" "postgres")
(.setProperty "scalar.db.consensus_commit.isolation_level"
((:isolation-level test) ISOLATION_LEVELS))
(.setProperty "scalar.db.consensus_commit.serializable_strategy"
((:serializable-strategy test) SERIALIZABLE_STRATEGIES))))))
(or (load-config test)
(let [node (-> test :nodes first)]
;; We have only one node in this test
(->> (doto (Properties.)
(.setProperty "scalar.db.storage" "jdbc")
(.setProperty "scalar.db.contact_points"
(str "jdbc:postgresql://" node ":5432/"))
(.setProperty "scalar.db.username" "postgres")
(.setProperty "scalar.db.password" "postgres"))
(set-common-properties test))))))

(def ^:private ext-dbs
{:cassandra (->ExtCassandra)
Expand Down
6 changes: 5 additions & 1 deletion scalardb/src/scalardb/runner.clj
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,11 @@
"consistency model to be checked"
["snapshot-isolation"])

[nil "--config-file CONFIG_FILE" "ScalarDB config file. When this is given, other configuration options are ignored."
[nil "--enable-group-commit" "if set, group commit is enabled"
:default false]

[nil "--config-file CONFIG_FILE"
"ScalarDB config file. When this is given, other configuration options are ignored."
:default ""]])

(defn- test-name
Expand Down

0 comments on commit 9ff6675

Please sign in to comment.