Skip to content

Commit 811ee62

Browse files
authored
Use include_metadata configuration in Consensus Commit (#152)
1 parent 5d40176 commit 811ee62

File tree

5 files changed

+13
-43
lines changed

5 files changed

+13
-43
lines changed

scalardb/src/scalardb/db/cluster.clj

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,10 @@
3939
"scalar.db.storage=jdbc"
4040
"scalar.db.contact_points=jdbc:postgresql://postgresql-scalardb-cluster.default.svc.cluster.local:5432/postgres"
4141
"scalar.db.username=postgres"
42-
"scalar.db.password=postgres"])
42+
"scalar.db.password=postgres"
43+
""
44+
;; Set to true to include transaction metadata in the records
45+
"scalar.db.consensus_commit.include_metadata.enabled=true"])
4346

4447
:imagePullSecrets [{:name "scalardb-ghcr-secret"}]}})
4548

scalardb/src/scalardb/db_extend.clj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@
3131
(.setProperty "scalar.db.consensus_commit.coordinator.group_commit.slot_capacity" "4")
3232
(.setProperty "scalar.db.consensus_commit.coordinator.group_commit.old_group_abort_timeout_millis" "15000")
3333
(.setProperty "scalar.db.consensus_commit.coordinator.group_commit.delayed_slot_move_timeout_millis" "400")
34-
(.setProperty "scalar.db.consensus_commit.coordinator.group_commit.metrics_monitor_log_enabled" "true")))
34+
(.setProperty "scalar.db.consensus_commit.coordinator.group_commit.metrics_monitor_log_enabled" "true")
35+
(.setProperty "scalar.db.consensus_commit.include_metadata.enabled" "true")))
3536

3637
(defprotocol DbExtension
3738
(get-db-type [this])

scalardb/src/scalardb/transfer.clj

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -132,13 +132,11 @@
132132
[test n]
133133
(try
134134
(let [tx (scalar/start-transaction test)
135-
tx-results (map #(.get tx (prepare-get %)) (range n))
136-
;; Need Storage API to read the transaction metadata
137-
results (mapv #(.get @(:storage test) (prepare-get %)) (range n))]
135+
results (map #(.get tx (prepare-get %)) (range n))]
138136
;; Put the same balance to check conflicts with in-flight transactions
139137
(mapv #(->> (calc-new-balance %2 0) (prepare-put %1) (.put tx))
140138
(range n)
141-
tx-results)
139+
results)
142140
(.commit tx)
143141
results)
144142
(catch Exception e
@@ -148,11 +146,9 @@
148146
(defn read-all-with-retry
149147
[test n]
150148
(scalar/check-transaction-connection! test)
151-
(scalar/check-storage-connection! test)
152149
(scalar/with-retry
153150
(fn [test]
154-
(scalar/prepare-transaction-service! test)
155-
(scalar/prepare-storage-service! test))
151+
(scalar/prepare-transaction-service! test))
156152
test
157153
(read-all test n)))
158154

scalardb/test/scalardb/transfer_2pc_test.clj

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
[scalardb.transfer-2pc :as transfer-2pc]
99
[spy.core :as spy])
1010
(:import (com.scalar.db.api DistributedTransaction
11-
DistributedStorage
1211
TwoPhaseCommitTransaction
1312
Get
1413
Put
@@ -63,12 +62,6 @@
6362
(^void put [_ ^Put p] (mock-put p))
6463
(^void commit [_] (swap! commit-count inc))))
6564

66-
(def mock-storage
67-
(reify
68-
DistributedStorage
69-
(^Optional get [_ ^Get g] (mock-get g))
70-
(^void put [_ ^Put p] (mock-put p))))
71-
7265
(def mock-transaction-throws-exception
7366
(reify
7467
DistributedTransaction
@@ -206,38 +199,30 @@
206199
(deftest transfer-client-get-all-test
207200
(binding [test-records (atom {0 1000 1 100 2 10 3 1 4 0})]
208201
(with-redefs [scalar/check-transaction-connection! (spy/spy)
209-
scalar/check-storage-connection! (spy/spy)
210202
scalar/start-transaction (spy/stub mock-transaction)]
211203
(let [client (client/open! (transfer-2pc/->TransferClient (atom false) 5 100 1)
212204
nil nil)
213-
result (client/invoke! client {:db mock-db
214-
:storage (ref mock-storage)}
205+
result (client/invoke! client {:db mock-db}
215206
(#'transfer/get-all {:client client}
216207
nil))]
217208
(is (spy/called-once? scalar/check-transaction-connection!))
218-
(is (spy/called-once? scalar/check-storage-connection!))
219209
(is (= :ok (:type result)))
220210
(is (= [1000 100 10 1 0] (get-in result [:value :balance])))
221211
(is (= [1000 100 10 1 0] (get-in result [:value :version])))))))
222212

223213
(deftest transfer-client-get-all-fail-test
224214
(with-redefs [scalar/exponential-backoff (spy/spy)
225215
scalar/check-transaction-connection! (spy/spy)
226-
scalar/check-storage-connection! (spy/spy)
227216
scalar/prepare-transaction-service! (spy/spy)
228-
scalar/prepare-storage-service! (spy/spy)
229217
scalar/start-transaction (spy/stub mock-transaction-throws-exception)]
230218
(let [client (client/open! (transfer-2pc/->TransferClient (atom false) 5 100 1)
231219
nil nil)]
232220
(is (thrown? clojure.lang.ExceptionInfo
233-
(client/invoke! client {:db mock-db
234-
:storage (ref mock-storage)}
221+
(client/invoke! client {:db mock-db}
235222
(#'transfer/get-all {:client client}
236223
nil))))
237224
(is (spy/called-n-times? scalar/exponential-backoff scalar/RETRIES))
238225
(is (spy/called-n-times? scalar/prepare-transaction-service!
239-
(+ (quot scalar/RETRIES scalar/RETRIES_FOR_RECONNECTION) 1)))
240-
(is (spy/called-n-times? scalar/prepare-storage-service!
241226
(+ (quot scalar/RETRIES scalar/RETRIES_FOR_RECONNECTION) 1))))))
242227

243228
(deftest transfer-client-check-tx-test

scalardb/test/scalardb/transfer_test.clj

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
[scalardb.transfer :as transfer]
88
[spy.core :as spy])
99
(:import (com.scalar.db.api DistributedTransaction
10-
DistributedStorage
1110
Get
1211
Put
1312
Result)
@@ -57,12 +56,6 @@
5756
(^void put [_ ^Put p] (mock-put p))
5857
(^void commit [_] (swap! commit-count inc))))
5958

60-
(def mock-storage
61-
(reify
62-
DistributedStorage
63-
(^Optional get [_ ^Get g] (mock-get g))
64-
(^void put [_ ^Put p] (mock-put p))))
65-
6659
(def mock-transaction-throws-exception
6760
(reify
6861
DistributedTransaction
@@ -178,38 +171,30 @@
178171
(deftest transfer-client-get-all-test
179172
(binding [test-records (atom {0 1000 1 100 2 10 3 1 4 0})]
180173
(with-redefs [scalar/check-transaction-connection! (spy/spy)
181-
scalar/check-storage-connection! (spy/spy)
182174
scalar/start-transaction (spy/stub mock-transaction)]
183175
(let [client (client/open! (transfer/->TransferClient (atom false) 5 100 1)
184176
nil nil)
185-
result (client/invoke! client {:db mock-db
186-
:storage (ref mock-storage)}
177+
result (client/invoke! client {:db mock-db}
187178
(#'transfer/get-all {:client client}
188179
nil))]
189180
(is (spy/called-once? scalar/check-transaction-connection!))
190-
(is (spy/called-once? scalar/check-storage-connection!))
191181
(is (= :ok (:type result)))
192182
(is (= [1000 100 10 1 0] (get-in result [:value :balance])))
193183
(is (= [1000 100 10 1 0] (get-in result [:value :version])))))))
194184

195185
(deftest transfer-client-get-all-fail-test
196186
(with-redefs [scalar/exponential-backoff (spy/spy)
197187
scalar/check-transaction-connection! (spy/spy)
198-
scalar/check-storage-connection! (spy/spy)
199188
scalar/prepare-transaction-service! (spy/spy)
200-
scalar/prepare-storage-service! (spy/spy)
201189
scalar/start-transaction (spy/stub mock-transaction-throws-exception)]
202190
(let [client (client/open! (transfer/->TransferClient (atom false) 5 100 1)
203191
nil nil)]
204192
(is (thrown? clojure.lang.ExceptionInfo
205-
(client/invoke! client {:db mock-db
206-
:storage (ref mock-storage)}
193+
(client/invoke! client {:db mock-db}
207194
(#'transfer/get-all {:client client}
208195
nil))))
209196
(is (spy/called-n-times? scalar/exponential-backoff scalar/RETRIES))
210197
(is (spy/called-n-times? scalar/prepare-transaction-service!
211-
(+ (quot scalar/RETRIES scalar/RETRIES_FOR_RECONNECTION) 1)))
212-
(is (spy/called-n-times? scalar/prepare-storage-service!
213198
(+ (quot scalar/RETRIES scalar/RETRIES_FOR_RECONNECTION) 1))))))
214199

215200
(deftest transfer-client-check-tx-test

0 commit comments

Comments
 (0)