From 9ff6675da34a1121c3277868577470e4b21dd58b Mon Sep 17 00:00:00 2001 From: Yuji Ito Date: Wed, 28 Aug 2024 02:29:29 +0200 Subject: [PATCH] Set custom properties and add `--enable-group-commit` (#130) --- .github/workflows/test.yml | 2 +- scalardb/src/scalardb/core.clj | 16 ++----- scalardb/src/scalardb/db_extend.clj | 68 +++++++++++++++++++---------- scalardb/src/scalardb/runner.clj | 6 ++- 4 files changed, 53 insertions(+), 39 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index bb83bb1..0930304 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -26,7 +26,7 @@ jobs: - name: docker-compose up run: | cd docker - docker-compose up -d + docker compose up -d - name: Cassandra test run: | diff --git a/scalardb/src/scalardb/core.clj b/scalardb/src/scalardb/core.clj index 44d7564..2ebd860 100644 --- a/scalardb/src/scalardb/core.clj +++ b/scalardb/src/scalardb/core.clj @@ -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) @@ -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 diff --git a/scalardb/src/scalardb/db_extend.clj b/scalardb/src/scalardb/db_extend.clj index cbfb409..07a1567 100644 --- a/scalardb/src/scalardb/db_extend.clj +++ b/scalardb/src/scalardb/db_extend.clj @@ -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" @@ -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]) @@ -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 @@ -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) diff --git a/scalardb/src/scalardb/runner.clj b/scalardb/src/scalardb/runner.clj index b175cc0..4aab195 100644 --- a/scalardb/src/scalardb/runner.clj +++ b/scalardb/src/scalardb/runner.clj @@ -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