Skip to content

Commit c603e7a

Browse files
committed
added check script
1 parent 2e3ed2a commit c603e7a

File tree

4 files changed

+178
-4
lines changed

4 files changed

+178
-4
lines changed

tpcc.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
require("tpcc_common")
2222
require("tpcc_run")
23+
require("tpcc_check")
2324

2425

2526
function event()

tpcc_check.lua

Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
-- Copyright (C) 2006-2017 Vadim Tkachenko, Percona
2+
3+
-- This program is free software; you can redistribute it and/or modify
4+
-- it under the terms of the GNU General Public License as published by
5+
-- the Free Software Foundation; either version 2 of the License, or
6+
-- (at your option) any later version.
7+
8+
-- This program is distributed in the hope that it will be useful,
9+
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
10+
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+
-- GNU General Public License for more details.
12+
13+
-- You should have received a copy of the GNU General Public License
14+
-- along with this program; if not, write to the Free Software
15+
-- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16+
17+
-- -----------------------------------------------------------------------------
18+
-- Check data code for TPCC benchmarks.
19+
-- -----------------------------------------------------------------------------
20+
21+
22+
require("tpcc_common")
23+
24+
25+
function check_tables(drv, con, warehouse_num)
26+
27+
local pass1 = 1
28+
for table_num = 1, sysbench.opt.tables do
29+
-- print(string.format("Checking tables: %d for warehouse: %d\n", table_num, warehouse_num))
30+
rs = con:query("SELECT d_w_id,sum(d_ytd)-w_ytd diff FROM district"..table_num..",warehouse"..table_num.." where d_w_id=w_id AND w_id="..warehouse_num.." group by d_w_id")
31+
32+
for i = 1, rs.nrows do
33+
row = rs:fetch_row()
34+
local d_tax = tonumber(row[2])
35+
if d_tax ~= 0 then
36+
pass1=0
37+
end
38+
end
39+
end
40+
41+
if pass1 == 1 then
42+
print(string.format("Check 1, warehouse: %d PASSED", warehouse_num))
43+
else
44+
print(string.format("Check 1, warehouse: %d FAILED!!!", warehouse_num))
45+
end
46+
47+
-- CHECK 2
48+
-- select dis.d_id, d_next_o_id-1,mo,mno from district1 dis, (select o_d_id,max(o_id) mo from orders1 where o_w_id=1 group by o_d_id) q, (select no_d_id,max(no_o_id) mno from new_orders1 where no_w_id=1 group by no_d_id) no where d_w_id=1 and q.o_d_id=dis.d_id and no.no_d_id=dis.d_id
49+
50+
51+
local pass2 = 1
52+
for table_num = 1, sysbench.opt.tables do
53+
-- print(string.format("Checking tables: %d for warehouse: %d\n", table_num, warehouse_num))
54+
rs = con:query(string.format("SELECT dis.d_id, d_next_o_id-1,mo,mno FROM district%d dis, (SELECT o_d_id,max(o_id) mo FROM orders%d WHERE o_w_id=%d GROUP BY o_d_id) q, (select no_d_id,max(no_o_id) mno from new_orders%d where no_w_id=%d group by no_d_id) no where d_w_id=%d and q.o_d_id=dis.d_id and no.no_d_id=dis.d_id", table_num,table_num,warehouse_num, table_num, warehouse_num, warehouse_num))
55+
56+
for i = 1, rs.nrows do
57+
row = rs:fetch_row()
58+
local d1 = tonumber(row[2])
59+
local d2 = tonumber(row[3])
60+
local d3 = tonumber(row[4])
61+
if d1 ~= d2 then
62+
pass2=0
63+
end
64+
if d1 ~= d3 then
65+
pass2=0
66+
end
67+
end
68+
end
69+
70+
if pass2 == 1 then
71+
print(string.format("Check 2, warehouse: %d PASSED", warehouse_num))
72+
else
73+
print(string.format("Check 2, warehouse: %d FAILED!!!", warehouse_num))
74+
end
75+
76+
local pass3 = 1
77+
for table_num = 1, sysbench.opt.tables do
78+
-- print(string.format("Checking tables: %d for warehouse: %d\n", table_num, warehouse_num))
79+
rs = con:query(string.format("select no_d_id,max(no_o_id)-min(no_o_id)+1,count(*) from new_orders%d where no_w_id=%d group by no_d_id",table_num, warehouse_num))
80+
81+
for i = 1, rs.nrows do
82+
row = rs:fetch_row()
83+
local d1 = tonumber(row[2])
84+
local d2 = tonumber(row[3])
85+
if d1 ~= d2 then
86+
pass3=0
87+
end
88+
end
89+
end
90+
91+
if pass3 == 1 then
92+
print(string.format("Check 3, warehouse: %d PASSED", warehouse_num))
93+
else
94+
print(string.format("Check 3, warehouse: %d FAILED!!!", warehouse_num))
95+
end
96+
97+
local pass4 = 1
98+
for table_num = 1, sysbench.opt.tables do
99+
-- print(string.format("Checking tables: %d for warehouse: %d\n", table_num, warehouse_num))
100+
rs = con:query(string.format("SELECT count(*) FROM (SELECT o_d_id, SUM(o_ol_cnt) sm1, cn FROM orders%d,(SELECT ol_d_id, COUNT(*) cn FROM order_line%d WHERE ol_w_id=%d GROUP BY ol_d_id) ol WHERE O_w_id=%d AND ol_d_id=o_d_id GROUP BY o_d_id) t1 WHERE sm1<>cn",table_num, table_num, warehouse_num, warehouse_num))
101+
102+
for i = 1, rs.nrows do
103+
row = rs:fetch_row()
104+
local d1 = tonumber(row[1])
105+
if d1 ~= 0 then
106+
pass4=0
107+
end
108+
end
109+
end
110+
111+
if pass4 == 1 then
112+
print(string.format("Check 4, warehouse: %d PASSED", warehouse_num))
113+
else
114+
print(string.format("Check 4, warehouse: %d FAILED!!!", warehouse_num))
115+
end
116+
117+
local pass8 = 1
118+
for table_num = 1, sysbench.opt.tables do
119+
-- print(string.format("Checking tables: %d for warehouse: %d\n", table_num, warehouse_num))
120+
rs = con:query(string.format("SELECT count(*) cn FROM (SELECT w_id,w_ytd,SUM(h_amount) sm FROM history%d,warehouse%d WHERE h_w_id=w_id GROUP BY w_id) t1 WHERE w_ytd<>sm",table_num, table_num))
121+
122+
for i = 1, rs.nrows do
123+
row = rs:fetch_row()
124+
local d1 = tonumber(row[1])
125+
if d1 ~= 0 then
126+
pass8=0
127+
end
128+
end
129+
end
130+
131+
if pass8 == 1 then
132+
print(string.format("Check 8, warehouse: %d PASSED", warehouse_num))
133+
else
134+
print(string.format("Check 8, warehouse: %d FAILED!!!", warehouse_num))
135+
end
136+
137+
local pass9 = 1
138+
for table_num = 1, sysbench.opt.tables do
139+
-- print(string.format("Checking tables: %d for warehouse: %d\n", table_num, warehouse_num))
140+
rs = con:query(string.format("SELECT COUNT(*) FROM (select d_id,d_w_id,sum(d_ytd) s1 from district%d group by d_id,d_w_id) d,(select h_d_id,h_w_id,sum(h_amount) s2 from history%d group by h_d_id, h_w_id) h WHERE h_d_id=d_id AND d_w_id=h_w_id and s1<>s2",table_num, table_num))
141+
142+
for i = 1, rs.nrows do
143+
row = rs:fetch_row()
144+
local d1 = tonumber(row[1])
145+
if d1 ~= 0 then
146+
pass9=0
147+
end
148+
end
149+
end
150+
151+
if pass9 == 1 then
152+
print(string.format("Check 9, warehouse: %d PASSED", warehouse_num))
153+
else
154+
print(string.format("Check 9, warehouse: %d FAILED!!!", warehouse_num))
155+
end
156+
end
157+
158+
159+
-- vim:ts=4 ss=4 sw=4 expandtab

tpcc_common.lua

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,23 @@ function cmd_prepare()
7474

7575
end
7676

77+
-- Check consistency
78+
-- benefit from executing with --threads > 1 as long as --scale > 1
79+
function cmd_check()
80+
local drv = sysbench.sql.driver()
81+
local con = drv:connect()
82+
83+
for i = sysbench.tid % sysbench.opt.threads + 1, sysbench.opt.scale,
84+
sysbench.opt.threads do
85+
check_tables(drv, con, i)
86+
end
87+
88+
end
89+
7790
-- Implement parallel prepare and prewarm commands
7891
sysbench.cmdline.commands = {
7992
prepare = {cmd_prepare, sysbench.cmdline.PARALLEL_COMMAND},
93+
check = {cmd_check, sysbench.cmdline.PARALLEL_COMMAND}
8094
}
8195

8296

tpcc_run.lua

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,15 +132,15 @@ function new_order()
132132
con:query("INSERT INTO orders".. table_num ..
133133
"(o_id, o_d_id, o_w_id, o_c_id, o_entry_d, o_ol_cnt, o_all_local)"..
134134
string.format(" VALUES (%d,%d,%d,%d,NOW(),%d,%d)",
135-
d_next_o_id+1, d_id, w_id, c_id, ol_cnt, all_local))
135+
d_next_o_id, d_id, w_id, c_id, ol_cnt, all_local))
136136

137137
-- INSERT INTO new_orders (no_o_id, no_d_id, no_w_id)
138138
-- VALUES (:o_id,:d_id,:w_id); */
139139

140140
con:query("INSERT INTO new_orders".. table_num ..
141141
"(no_o_id, no_d_id, no_w_id)"..
142142
string.format(" VALUES (%d,%d,%d)",
143-
d_next_o_id+1, d_id, w_id))
143+
d_next_o_id, d_id, w_id))
144144

145145
for ol_number=1, ol_cnt do
146146
local ol_supply_w_id = supware[ol_number]
@@ -226,7 +226,7 @@ function new_order()
226226
" (ol_o_id, ol_d_id, ol_w_id, ol_number, ol_i_id, ol_supply_w_id, ol_quantity, ol_amount, ol_dist_info)"..
227227
" VALUES "..
228228
string.format("(%d,%d,%d,%d,%d,%d,%d,%d,'%s')",
229-
d_next_o_id+1, d_id, w_id, ol_number, ol_i_id, ol_supply_w_id, ol_quantity, ol_amount, ol_dist_info)
229+
d_next_o_id, d_id, w_id, ol_number, ol_i_id, ol_supply_w_id, ol_quantity, ol_amount, ol_dist_info)
230230
)
231231

232232
end
@@ -638,7 +638,7 @@ function delivery()
638638
-- SET ol_delivery_d = :datetime
639639
-- WHERE ol_o_id = :no_o_id AND ol_d_id = :d_id AND
640640
-- ol_w_id = :w_id;*/
641-
641+
print("Update ol_delivery_d"..table_num.." no_o_id: "..no_o_id )
642642
con:query(string.format([[UPDATE order_line%d SET ol_delivery_d = NOW()
643643
WHERE ol_o_id = %d AND ol_d_id = %d AND ol_w_id = %d]],
644644
table_num, no_o_id, d_id, w_id))

0 commit comments

Comments
 (0)