Skip to content

Commit

Permalink
add dummy writes for get-all (#126)
Browse files Browse the repository at this point in the history
  • Loading branch information
yito88 authored May 31, 2024
1 parent 06f9b5e commit b3d1e66
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 7 deletions.
20 changes: 16 additions & 4 deletions scalardb/src/scalardb/transfer.clj
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,14 @@
"Read a record with a transaction. If read fails, this function returns nil."
[tx storage i]
(try
(.get tx (prepare-get i))
(.get storage (prepare-get i))
;; Need Storage API to read the transaction metadata
(let [tx-result (.get tx (prepare-get i))
result (.get storage (prepare-get i))]
;; Put the same balance to check conflicts with in-flight transactions
(->> (calc-new-balance tx-result 0)
(prepare-put i)
(.put tx))
result)
(catch CrudException _ nil)
(catch ExecutionException _ nil)))

Expand All @@ -145,8 +151,14 @@
(scalar/prepare-storage-service! test))
test
(let [tx (scalar/start-transaction test)
results (map #(read-record tx @(:storage test) %) (range n))]
(if (some nil? results) nil results))))
results (doall (map #(read-record tx @(:storage test) %) (range n)))]
(try
(.commit tx)
(if (some nil? results) nil results)
(catch Exception e
;; The transaction conflicted
(warn (.getMessage e))
nil)))))

(defrecord TransferClient [initialized? n initial-balance max-txs]
client/Client
Expand Down
18 changes: 15 additions & 3 deletions scalardb/src/scalardb/transfer_append.clj
Original file line number Diff line number Diff line change
Expand Up @@ -131,16 +131,28 @@
(defn- scan-records
[tx id]
(try
(.scan tx (prepare-scan id))
(let [results (.scan tx (prepare-scan id))]
;; Put the same balance to check conflicts with in-flight transactions
(->> (prepare-put id
(-> results first calc-new-age)
(-> results first (calc-new-balance 0)))
(.put tx))
results)
(catch CrudException _ nil)))

(defn scan-all-records-with-retry
[test n]
(scalar/check-transaction-connection! test)
(scalar/with-retry scalar/prepare-transaction-service! test
(let [tx (scalar/start-transaction test)
results (map #(scan-records tx %) (range n))]
(if (some nil? results) nil results))))
results (doall (map #(scan-records tx %) (range n)))]
(try
(.commit tx)
(if (some nil? results) nil results)
(catch Exception e
;; The transaction conflicted
(warn (.getMessage e))
nil)))))

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

0 comments on commit b3d1e66

Please sign in to comment.