Skip to content

Commit ed8089c

Browse files
authored
Merge pull request #2 from Percona-Lab/extracheck
Extracheck
2 parents cd6e4b2 + d7d3956 commit ed8089c

File tree

4 files changed

+62
-12
lines changed

4 files changed

+62
-12
lines changed

tpcc.lua

+5-1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ function thread_init()
2727
con = drv:connect()
2828

2929
set_isolation_level(drv,con)
30+
con:query("SET autocommit=0")
3031

3132
end
3233

@@ -51,7 +52,9 @@ function event()
5152
end
5253

5354
-- Repeat transaction execution until success
54-
while not pcall(function () trx() end ) do end
55+
while not pcall(function () trx() end ) do
56+
con:query("ROLLBACK")
57+
end
5558

5659
end
5760

@@ -60,4 +63,5 @@ function sysbench.hooks.report_intermediate(stat)
6063
sysbench.report_csv(stat)
6164
end
6265

66+
6367
-- vim:ts=4 ss=4 sw=4 expandtab

tpcc_check.lua

+40
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,46 @@ function check_tables(drv, con, warehouse_num)
192192
else
193193
print(string.format("Check 9, warehouse: %d FAILED!!!", warehouse_num))
194194
end
195+
196+
local pass10 = 1
197+
for table_num = 1, sysbench.opt.tables do
198+
-- print(string.format("Checking tables: %d for warehouse: %d\n", table_num, warehouse_num))
199+
rs = con:query(string.format("SELECT count(*) FROM ( SELECT c.c_id, c.c_d_id, c.c_w_id, c.c_balance c1, (SELECT sum(ol_amount) FROM orders%d STRAIGHT_JOIN order_line%d WHERE OL_W_ID=O_W_ID AND OL_D_ID = O_D_ID AND OL_O_ID = O_ID AND OL_DELIVERY_D IS NOT NULL AND O_W_ID=c.c_w_id AND O_D_ID=c.C_D_ID AND O_C_ID=c.C_ID) sm, (SELECT sum(h_amount) from history%d WHERE H_C_W_ID=c.C_W_ID AND H_C_D_ID=c.C_D_ID AND H_C_ID=c.C_ID) smh FROM customer%d c WHERE c.c_w_id=%d ) t where c1<>sm-smh",table_num, table_num, table_num, table_num, warehouse_num))
200+
201+
for i = 1, rs.nrows do
202+
row = rs:fetch_row()
203+
local d1 = tonumber(row[1])
204+
if d1 ~= 0 then
205+
pass10=0
206+
end
207+
end
208+
end
209+
210+
if pass10 == 1 then
211+
print(string.format("Check 10, warehouse: %d PASSED", warehouse_num))
212+
else
213+
print(string.format("Check 10, warehouse: %d FAILED!!!", warehouse_num))
214+
end
215+
216+
local pass12 = 1
217+
for table_num = 1, sysbench.opt.tables do
218+
-- print(string.format("Checking tables: %d for warehouse: %d\n", table_num, warehouse_num))
219+
rs = con:query(string.format("SELECT count(*) FROM (SELECT c.c_id, c.c_d_id, c.c_balance c1, c_ytd_payment, (SELECT sum(ol_amount) FROM orders%d STRAIGHT_JOIN order_line%d WHERE OL_W_ID=O_W_ID AND OL_D_ID = O_D_ID AND OL_O_ID = O_ID AND OL_DELIVERY_D IS NOT NULL AND O_W_ID=c.c_w_id AND O_D_ID=c.C_D_ID AND O_C_ID=c.C_ID) sm FROM customer%d c WHERE c.c_w_id=%d) t1 WHERE c1+c_ytd_payment <> sm " ,table_num, table_num, table_num, warehouse_num))
220+
221+
for i = 1, rs.nrows do
222+
row = rs:fetch_row()
223+
local d1 = tonumber(row[1])
224+
if d1 ~= 0 then
225+
pass12=0
226+
end
227+
end
228+
end
229+
230+
if pass12 == 1 then
231+
print(string.format("Check 12, warehouse: %d PASSED", warehouse_num))
232+
else
233+
print(string.format("Check 12, warehouse: %d FAILED!!!", warehouse_num))
234+
end
195235
end
196236

197237

tpcc_common.lua

+6-5
Original file line numberDiff line numberDiff line change
@@ -469,9 +469,9 @@ function load_tables(drv, con, warehouse_num)
469469
-- 3,000 rows in the ORDER table with
470470
a_counts[warehouse_num][d_id][o_id] = sysbench.rand.uniform(5,15)
471471

472-
query = string.format([[(%d, %d, %d, %d, NOW(), %d, %d, 1 )]],
472+
query = string.format([[(%d, %d, %d, %d, NOW(), %s, %d, 1 )]],
473473
o_id, d_id, warehouse_num, tab[o_id],
474-
sysbench.rand.uniform(1,10),
474+
o_id < 2101 and sysbench.rand.uniform(1,10) or "NULL",
475475
a_counts[warehouse_num][d_id][o_id]
476476
)
477477
con:bulk_insert_next(query)
@@ -492,9 +492,10 @@ function load_tables(drv, con, warehouse_num)
492492
for o_id = 1 , 3000 do
493493
for ol_id = 1, a_counts[warehouse_num][d_id][o_id] do
494494

495-
query = string.format([[(%d, %d, %d, %d, %d, %d, NOW(), 5, %f, '%s' )]],
496-
o_id, d_id, warehouse_num, ol_id, sysbench.rand.uniform(1, MAXITEMS), warehouse_num,
497-
sysbench.rand.uniform_double()*9999.99,
495+
query = string.format([[(%d, %d, %d, %d, %d, %d, %s, 5, %f, '%s' )]],
496+
o_id, d_id, warehouse_num, ol_id, sysbench.rand.uniform(1, MAXITEMS), warehouse_num,
497+
o_id < 2101 and "NOW()" or "NULL",
498+
o_id < 2101 and 0 or sysbench.rand.uniform_double()*9999.99,
498499
string.rep(sysbench.rand.string("@"),24)
499500
)
500501
con:bulk_insert_next(query)

tpcc_run.lua

+11-6
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ function payment()
379379

380380
rs = con:query([[SELECT c_first, c_middle, c_last, c_street_1,
381381
c_street_2, c_city, c_state, c_zip, c_phone,
382-
c_credit, c_credit_lim, c_discount, c_balance, c_since
382+
c_credit, c_credit_lim, c_discount, c_balance, c_ytd_payment, c_since
383383
FROM customer]]..table_num..
384384
" WHERE c_w_id = ".. w_id.. " AND c_d_id="..c_d_id ..
385385
" AND c_id="..c_id.." FOR UPDATE")
@@ -396,6 +396,7 @@ function payment()
396396
local c_credit_lim
397397
local c_discount
398398
local c_balance
399+
local c_ytd_payment
399400
local c_since
400401
for i = 1, rs.nrows do
401402
row = rs:fetch_row()
@@ -412,11 +413,13 @@ function payment()
412413
c_credit_lim = row[11]
413414
c_discount = row[12]
414415
c_balance = row[13]
415-
c_since = row[14]
416+
c_ytd_payment = row[14]
417+
c_since = row[15]
416418
-- print(row[1], row[2], row[3], row[4])
417419
end
418420

419421
c_balance = tonumber(c_balance) - h_amount
422+
c_ytd_payment = tonumber(c_ytd_payment) + h_amount
420423

421424
if c_credit == "BC" then
422425
-- SELECT c_data
@@ -445,12 +448,12 @@ function payment()
445448
-- AND c_d_id = :c_d_id
446449
-- AND c_id = :c_id
447450
con:query("UPDATE customer"..table_num..
448-
" SET c_balance="..c_balance..", c_data='"..c_new_data.."'"..
451+
" SET c_balance="..c_balance..", c_ytd_payment="..c_ytd_payment..",c_data='"..c_new_data.."'"..
449452
" WHERE c_w_id = ".. w_id.. " AND c_d_id="..c_d_id ..
450453
" AND c_id="..c_id)
451454
else
452455
con:query("UPDATE customer"..table_num..
453-
" SET c_balance="..c_balance..
456+
" SET c_balance="..c_balance..", c_ytd_payment="..c_ytd_payment..
454457
" WHERE c_w_id = ".. w_id.. " AND c_d_id="..c_d_id ..
455458
" AND c_id="..c_id)
456459

@@ -596,8 +599,9 @@ function delivery()
596599
-- WHERE no_d_id = :d_id AND no_w_id = :w_id;*/
597600

598601
rs = con:query(string.format([[SELECT COALESCE(MIN(no_o_id),0) no_o_id
599-
FROM new_orders%d WHERE no_d_id = %d AND no_w_id = %d]],
602+
FROM new_orders%d WHERE no_d_id = %d AND no_w_id = %d FOR UPDATE]],
600603
table_num, d_id, w_id))
604+
-- FROM new_orders%d WHERE no_d_id = %d AND no_w_id = %d]],
601605
local no_o_id
602606
for i = 1, rs.nrows do
603607
row = rs:fetch_row()
@@ -662,7 +666,8 @@ function delivery()
662666
-- c_delivery_cnt = c_delivery_cnt + 1
663667
-- WHERE c_id = :c_id AND c_d_id = :d_id AND
664668
-- c_w_id = :w_id;*/
665-
con:query(string.format([[UPDATE customer%d SET c_balance = c_balance + %d,
669+
-- print(string.format("update customer table %d, cid %d, did %d, wid %d balance %f",table_num, o_c_id, d_id, w_id, sm_ol_amount))
670+
con:query(string.format([[UPDATE customer%d SET c_balance = c_balance + %f,
666671
c_delivery_cnt = c_delivery_cnt + 1
667672
WHERE c_id = %d AND c_d_id = %d AND c_w_id = %d]],
668673
table_num, sm_ol_amount, o_c_id, d_id, w_id))

0 commit comments

Comments
 (0)