Skip to content

Commit 978dd81

Browse files
committed
Fix test bank with accounts in separate tables
Test "bank-multitable-lua" fetched balances from different tables in separate requests and so in different transactions. When we run it on synchronous cluster it led to incorrect sum on all bank accounts. Now test fetches all balances in an SQL transaction. Closes tarantool/tarantool#5848 Closes tarantool/tarantool#5513 Test passed on cluster with three nodes with and wo MVCC: lein run test --workload bank-multitable-lua --nodes-file nodes --username ubuntu --version 2.8 --leave-db-running --mvcc lein run test --workload bank-multitable-lua --nodes-file nodes --username ubuntu --version 2.8 --leave-db-running Test passed on a single instance with and wo MVCC: lein run test --workload bank-multitable-lua --nodes-file node --username ubuntu --version 2.8 --mvcc --leave-db-running lein run test --workload bank-multitable-lua --nodes-file node --username ubuntu --version 2.8 --mvcc --leave-db-running --mvcc
1 parent a376afe commit 978dd81

File tree

2 files changed

+20
-16
lines changed

2 files changed

+20
-16
lines changed

resources/tarantool/jepsen.lua

+4-4
Original file line numberDiff line numberDiff line change
@@ -137,13 +137,13 @@ box.schema.func.create('_WITHDRAW_MULTITABLE',
137137
local space_from = box.space[table_from]
138138
local space_to = box.space[table_to]
139139
box.begin()
140-
local bal_from = space_from:get(0)[2] - amount
141-
local bal_to = space_to:get(0)[2] + amount
140+
local bal_from = space_from:get(0).BALANCE - amount
141+
local bal_to = space_to:get(0).BALANCE + amount
142142
if bal_from < 0 or bal_to < 0 then
143143
return false
144144
end
145-
space_from:update(0, {{'-', 2, amount}})
146-
space_to:update(0, {{'+', 2, amount}})
145+
space_from:update(0, {{'-', 'BALANCE', amount}})
146+
space_to:update(0, {{'+', 'BALANCE', amount}})
147147
box.commit()
148148
149149
return true

src/tarantool/bank.clj

+16-12
Original file line numberDiff line numberDiff line change
@@ -87,29 +87,33 @@
8787
(doseq [a (:accounts test)]
8888
(info "Creating table" table-name a)
8989
(j/execute! conn [(str "CREATE TABLE IF NOT EXISTS " table-name a
90-
"(id INT NOT NULL PRIMARY KEY,"
90+
"(id INT NOT NULL PRIMARY KEY,"
91+
"account_id INT NOT NULL,"
9192
"balance INT NOT NULL)")])
9293
(info "Populating account" a)
9394
(sql/insert! conn (str table-name a)
9495
{:id 0
95-
:balance (if (= a (first (:accounts test)))
96-
(:total-amount test)
97-
0)})))))
96+
:account_id a
97+
:balance 10})))))
9898
(assoc this :conn conn :node node))))
9999

100100
(invoke! [this test op]
101101
(try
102+
; op struct example: {:type :invoke, :f :read, :process 0, :time 65183208864}
102103
(case (:f op)
103104
:read
104-
(->> (:accounts test)
105-
(map (fn [x]
106-
[x (->> (sql/query conn [(str "SELECT balance FROM " table-name
107-
x)]
108-
{:row-fn :BALANCE})
109-
first)]))
105+
(->> (sql/query conn ["SELECT ACCOUNT_ID, BALANCE FROM ACCOUNTS0 UNION
106+
SELECT ACCOUNT_ID, BALANCE FROM ACCOUNTS1 UNION
107+
SELECT ACCOUNT_ID, BALANCE FROM ACCOUNTS2 UNION
108+
SELECT ACCOUNT_ID, BALANCE FROM ACCOUNTS3 UNION
109+
SELECT ACCOUNT_ID, BALANCE FROM ACCOUNTS4 UNION
110+
SELECT ACCOUNT_ID, BALANCE FROM ACCOUNTS5 UNION
111+
SELECT ACCOUNT_ID, BALANCE FROM ACCOUNTS6 UNION
112+
SELECT ACCOUNT_ID, BALANCE FROM ACCOUNTS7 UNION
113+
SELECT ACCOUNT_ID, BALANCE FROM ACCOUNTS8 UNION
114+
SELECT ACCOUNT_ID, BALANCE FROM ACCOUNTS9"])
115+
(map (juxt :ACCOUNT_ID :BALANCE))
110116
(into (sorted-map))
111-
(map (fn [[k {b :BALANCE}]] [k b]))
112-
(into {})
113117
(assoc op :type :ok, :value))
114118

115119
:transfer

0 commit comments

Comments
 (0)