Skip to content

Commit

Permalink
fix to handle an exception for each record
Browse files Browse the repository at this point in the history
  • Loading branch information
yito88 committed Oct 29, 2024
1 parent 96b6a84 commit 40f5416
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions scalardb/src/scalardb/transfer.clj
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,12 @@
(defn- read-record
"Read and update the specified record with a transaction.
Return nil if the read fails or a conflict happens."
[test storage i]
[test i]
(try
(let [tx (scalar/start-transaction test)
tx-result (.get tx (prepare-get i))
;; Need Storage API to read the transaction metadata
result (.get storage (prepare-get i))]
result (.get @(:storage test) (prepare-get i))]
;; Put the same balance to check conflicts with in-flight transactions
(->> (calc-new-balance tx-result 0)
(prepare-put i)
Expand All @@ -144,18 +144,22 @@
(warn (.getMessage e))
nil)))

(defn read-all-with-retry
[test n]
(scalar/check-transaction-connection! test)
(scalar/check-storage-connection! test)
(defn- read-record-with-retry
[test i]
(scalar/with-retry
(fn [test]
(scalar/prepare-transaction-service! test)
(scalar/prepare-storage-service! test))
test
(let [results (pmap #(read-record test @(:storage test) %) (range n))]
(when (every? #(some? %) results)
results))))
(read-record test i)))

(defn read-all-with-retry
[test n]
(scalar/check-transaction-connection! test)
(scalar/check-storage-connection! test)
(try
(pmap #(read-record-with-retry test %) (range n))
(catch Exception _ nil)))

(defrecord TransferClient [initialized? n initial-balance max-txs]
client/Client
Expand Down

0 comments on commit 40f5416

Please sign in to comment.