Skip to content

Commit 025cbde

Browse files
committed
Added purge transaction
1 parent f703637 commit 025cbde

File tree

3 files changed

+78
-2
lines changed

3 files changed

+78
-2
lines changed

tpcc.lua

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ end
3737

3838
function event()
3939
-- print( NURand (1023,1,3000))
40-
local trx_type = sysbench.rand.uniform(1,23)
40+
local max_trx = sysbench.opt.enable_purge == "yes" and 24 or 23
41+
local trx_type = sysbench.rand.uniform(1,max_trx)
4142
if trx_type <= 10 then
4243
trx="new_order"
4344
elseif trx_type <= 20 then
@@ -48,6 +49,8 @@ function event()
4849
trx="delivery"
4950
elseif trx_type <= 23 then
5051
trx="stocklevel"
52+
elseif trx_type <= 24 then
53+
trx="purge"
5154
end
5255

5356
-- Execute transaction
@@ -61,7 +64,11 @@ end
6164

6265
function sysbench.hooks.report_intermediate(stat)
6366
-- -- print("my stat: ", val)
64-
sysbench.report_csv(stat)
67+
if sysbench.opt.report_csv == "yes" then
68+
sysbench.report_csv(stat)
69+
else
70+
sysbench.report_default(stat)
71+
end
6572
end
6673

6774

tpcc_common.lua

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ sysbench.cmdline.options = {
5151
{"Use foreign keys", 1},
5252
trx_level =
5353
{"Transaction isolation level (RC, RR or SER)", "RR"},
54+
enable_purge =
55+
{"Use purge transaction (yes, no)", "no"},
56+
report_csv =
57+
{"Report output in csv (yes, no)", "no"},
5458
mysql_storage_engine =
5559
{"Storage engine, if MySQL is used", "innodb"},
5660
mysql_table_options =

tpcc_run.lua

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,7 @@ function orderstatus()
501501
ORDER BY o_id DESC;
502502
-]]
503503
local o_id
504+
504505
o_id = con:query_row(([[SELECT o_id, o_carrier_id, o_entry_d
505506
FROM orders%d
506507
WHERE o_w_id = %d
@@ -509,6 +510,21 @@ function orderstatus()
509510
ORDER BY o_id DESC]]):
510511
format(table_num, w_id, d_id, c_id))
511512

513+
-- rs = con:query(([[SELECT o_id, o_carrier_id, o_entry_d
514+
-- FROM orders%d
515+
-- WHERE o_w_id = %d
516+
-- AND o_d_id = %d
517+
-- AND o_c_id = %d
518+
-- ORDER BY o_id DESC]]):
519+
-- format(table_num, w_id, d_id, c_id))
520+
-- if rs.nrows == 0 then
521+
-- print(string.format("Error o_id %d, %d, %d, %d\n", table_num , w_id , d_id , c_id))
522+
-- end
523+
-- for i = 1, rs.nrows do
524+
-- row = rs:fetch_row()
525+
-- o_id= row[1]
526+
-- end
527+
512528
-- SELECT ol_i_id, ol_supply_w_id, ol_quantity, ol_amount,
513529
-- ol_delivery_d
514530
-- FROM order_line
@@ -727,4 +743,53 @@ function stocklevel()
727743

728744
end
729745

746+
-- function purge to remove all orders, this is useful if we want to limit data directory in size
747+
748+
function purge()
749+
for i = 1, 10 do
750+
local table_num = sysbench.rand.uniform(1, sysbench.opt.tables)
751+
local w_id = sysbench.rand.uniform(1, sysbench.opt.scale)
752+
local d_id = sysbench.rand.uniform(1, DIST_PER_WARE)
753+
754+
con:query("BEGIN")
755+
756+
local m_o_id
757+
758+
rs = con:query(([[SELECT min(no_o_id) mo
759+
FROM new_orders%d
760+
WHERE no_w_id = %d AND no_d_id = %d]])
761+
:format(table_num, w_id, d_id))
762+
763+
if (rs.nrows > 0) then
764+
m_o_id=unpack(rs:fetch_row(), 1, rs.nfields)
765+
end
766+
767+
if (m_o_id ~= nil ) then
768+
-- select o_id,o.o_d_id from orders2 o, (select o_c_id,o_w_id,o_d_id,count(distinct o_id) from orders2 where o_w_id=1 and o_id > 2100 and o_id < 11153 group by o_c_id,o_d_id,o_w_id having count( distinct o_id) > 1 limit 1) t where t.o_w_id=o.o_w_id and t.o_d_id=o.o_d_id and t.o_c_id=o.o_c_id limit 1;
769+
-- find an order to delete
770+
rs = con:query(([[SELECT o_id FROM orders%d o, (SELECT o_c_id,o_w_id,o_d_id,count(distinct o_id) FROM orders%d WHERE o_w_id=%d AND o_d_id=%d AND o_id > 2100 AND o_id < %d GROUP BY o_c_id,o_d_id,o_w_id having count( distinct o_id) > 1 limit 1) t WHERE t.o_w_id=o.o_w_id and t.o_d_id=o.o_d_id and t.o_c_id=o.o_c_id limit 1 ]])
771+
:format(table_num, table_num, w_id, d_id, m_o_id))
772+
773+
local del_o_id
774+
if (rs.nrows > 0) then
775+
del_o_id=unpack(rs:fetch_row(), 1, rs.nfields)
776+
end
777+
778+
if (del_o_id ~= nil ) then
779+
780+
con:query(([[DELETE FROM order_line%d where ol_w_id=%d AND ol_d_id=%d AND ol_o_id=%d]])
781+
:format(table_num, w_id, d_id, del_o_id))
782+
con:query(([[DELETE FROM orders%d where o_w_id=%d AND o_d_id=%d and o_id=%d]])
783+
:format(table_num, w_id, d_id, del_o_id))
784+
con:query(([[DELETE FROM history%d where h_w_id=%d AND h_d_id=%d LIMIT 10]])
785+
:format(table_num, w_id, d_id ))
786+
787+
end
788+
789+
end
790+
791+
con:query("COMMIT")
792+
end
793+
end
794+
730795
-- vim:ts=4 ss=4 sw=4 expandtab

0 commit comments

Comments
 (0)