Skip to content

Commit a691e56

Browse files
author
VadimTk
committed
Better sync between creating tables and loading data
1 parent 2d2fac0 commit a691e56

File tree

1 file changed

+38
-3
lines changed

1 file changed

+38
-3
lines changed

tpcc_common.lua

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,23 +74,54 @@ function cmd_prepare()
7474

7575
if drv:name() == "mysql" then
7676
con:query("SET FOREIGN_KEY_CHECKS=0")
77+
query = string.format([[
78+
CREATE TABLE IF NOT EXISTS aux_sync (
79+
table_id int not null,
80+
active smallint not null default 1 ,
81+
primary key (table_id)
82+
)]])
83+
84+
con:query(query)
7785
end
86+
7887
-- create tables in parallel table per thread
7988
for i = sysbench.tid % sysbench.opt.threads + 1, sysbench.opt.tables,
8089
sysbench.opt.threads do
90+
if drv:name() == "mysql" then
91+
con:query("INSERT INTO aux_sync (table_id) VALUES ("..i..") ON DUPLICATE KEY UPDATE active=1")
92+
end
8193
create_tables(drv, con, i)
8294
end
8395

8496
-- make sure all tables are created before we load data
8597

86-
if drv:name() == "pgsql" then
87-
show_query="select * from pg_catalog.pg_tables where schemaname != 'information_schema' and schemaname != 'pg_catalog'"
98+
print("Waiting on tables\n")
99+
100+
if drv:name() == "mysql" then
101+
102+
local aux_cnt
103+
local aux_active
104+
while (true)
105+
do
106+
aux_cnt, aux_active= con:query_row("SELECT COUNT(*), SUM(active) FROM aux_sync")
107+
ffi.C.usleep(10000)
108+
--print(sysbench.tid..": got "..aux_cnt.." and "..aux_active.."\n")
109+
if (tonumber(aux_active) == 0 and tonumber(aux_cnt)==sysbench.opt.tables) then
110+
-- print ("!!!!!!!!!!!!!!!")
111+
break
112+
end
113+
end
114+
88115
end
89116

117+
if drv:name() == "pgsql" then
118+
show_query="select * from pg_catalog.pg_indexes where schemaname != 'information_schema' and schemaname != 'pg_catalog'"
119+
90120
repeat
91121
rs= con:query(show_query)
92122
ffi.C.usleep(1000)
93-
until rs.nrows == sysbench.opt.tables * 9
123+
until rs.nrows == sysbench.opt.tables * 14
124+
end
94125

95126
for i = sysbench.tid % sysbench.opt.threads + 1, sysbench.opt.scale,
96127
sysbench.opt.threads do
@@ -346,6 +377,10 @@ function create_tables(drv, con, table_num)
346377
con:query("ALTER TABLE stock"..i.." ADD CONSTRAINT fkey_stock_1_"..table_num.." FOREIGN KEY(s_w_id) REFERENCES warehouse"..i.."(w_id)")
347378
con:query("ALTER TABLE stock"..i.." ADD CONSTRAINT fkey_stock_2_"..table_num.." FOREIGN KEY(s_i_id) REFERENCES item"..i.."(i_id)")
348379
end
380+
381+
if drv:name() == "mysql" then
382+
con:query("UPDATE aux_sync SET active=0 WHERE table_id="..table_num)
383+
end
349384
end
350385

351386

0 commit comments

Comments
 (0)