1#
2# This is a load generator to call from rpl_parallel and rpl_sequential tests
3
4#
5#
6# load volume parameter
7#
8
9let $iter = 20;
10let $init_rows= 50;
11
12#
13# Distribution of queries within an iteration:
14# legends:
15# auto = auto_increment=1, trans = inside BEGIN-COMMIT,
16# del = Delete, ins =- Insert, upd = Update
17#
18let $ins_auto_wk= 1;
19let $ins_auto_nk= 1;
20let $ins_trans_wk= 1;
21let $ins_trans_nk= 1;
22let $upd_trans_nk= 0;
23let $upd_trans_wk= 1;
24let $del_trans_nk= 0;
25let $del_trans_wk= 1;
26
27# windows run on PB2 is too slow to time out
28disable_query_log;
29if (`select convert(@@version_compile_os using latin1) IN ("Win32","Win64","Windows") as "TRUE"`)
30{
31  let $iter = 10;
32}
33enable_query_log;
34
35let $databases = 16;
36
37connection slave;
38--source include/only_mts_slave_parallel_workers.inc
39
40call mtr.add_suppression('Slave: Error dropping database'); ## todo: fix
41
42source include/stop_slave.inc;
43start slave;
44
45connection master;
46
47--disable_query_log
48--disable_result_log
49
50
51let $i = $databases + 1;
52while($i)
53{
54  let $i1 = $i;
55  dec $i1;
56
57  eval create database test$i1;
58  eval use test$i1;
59  create table ti_nk (a int, b int, c text) engine=tokudb;
60  create table ti_wk (a int auto_increment primary key, b int, c text) engine=tokudb;
61  let $l1= $init_rows;
62  while($l1)
63  {
64       	eval insert into ti_nk values($l1, $i1, uuid());
65	dec $l1;
66  }
67
68  # this table is special - just for timing. It's more special on test0 db
69  # where it contains master timing of the load as well.
70  create table benchmark (state text) engine=myisam; # timestamp keep on the slave side
71
72  dec $i;
73}
74
75--enable_result_log
76--enable_query_log
77
78
79--source include/sync_slave_sql_with_master.inc
80#connection slave;
81
82--disable_query_log
83--disable_result_log
84
85let $i = $databases + 1;
86while($i)
87{
88  let $i1 = $i;
89  dec $i1;
90  eval use test$i1;
91  alter table benchmark add ts timestamp not null default current_timestamp;
92
93  dec $i;
94}
95--enable_result_log
96--enable_query_log
97
98
99# not gather events into relay log w/o executing yet
100stop slave sql_thread;
101
102##call p1(1);
103
104connection master;
105
106--disable_query_log
107--disable_result_log
108
109#
110# Load producer
111#
112
113# initial timestamp to record
114
115# the extra ts col on slave is effective only with the STMT format (todo: bug-report)
116set @save.binlog_format= @@session.binlog_format;
117set @@session.binlog_format=STATEMENT;
118let $i = $databases + 1;
119while($i)
120{
121  let $i1 = $i;
122  dec $i1;
123  eval use test$i1;
124
125  insert into benchmark set state='slave takes on load';
126
127  dec $i;
128}
129set @@session.binlog_format= @save.binlog_format;
130
131connection slave;
132
133use test0;
134insert into benchmark set state='master started load';
135
136
137connection master;
138
139while ($iter)
140{
141    let $i = $databases + 1;
142
143    while ($i)
144    {
145	let $i1 = $i;
146	dec $i1;
147
148	eval use test$i1;
149
150        let $ins= $ins_auto_nk;
151	while ($ins)
152	{
153	    eval insert into ti_nk values($iter, $i1, uuid());
154	    dec $ins;
155	}
156
157        let $ins= $ins_auto_wk;
158	while ($ins)
159	{
160	    eval insert into ti_wk values(null,  $i1, uuid());
161	    dec $ins;
162	}
163
164	begin;
165
166        let $ins= $ins_trans_nk;
167	while ($ins)
168	{
169	    eval insert into ti_nk values($iter, $i1, uuid());
170	    dec $ins;
171	}
172
173        let $ins= $ins_trans_wk;
174	while ($ins)
175	{
176	    eval insert into ti_wk values(null,  $i1, repeat('a', round(rand()*10)));
177	    dec $ins;
178	}
179
180	let $min=`select min(a) from ti_nk`;
181        let $del= $del_trans_nk;
182	while ($del)
183	{
184	    eval delete from ti_nk where a= $min + $del;
185	    dec $del;
186	}
187
188	let $min=`select min(a) from ti_nk`;
189        let $del= $del_trans_wk;
190	while ($del)
191	{
192	    eval delete from ti_wk where a= $min + $del;
193	    dec $del;
194	}
195
196        let $upd= $upd_trans_nk;
197	while ($upd)
198	{
199	    update ti_nk set c= uuid();
200	    dec $upd;
201	}
202
203        let $upd= $upd_trans_wk;
204	while ($upd)
205	{
206	    update ti_wk set c= uuid();
207	    dec $upd;
208	}
209
210	commit;
211	dec $i;
212    }
213
214    dec $iter;
215}
216
217connection slave;
218
219use test0;
220insert into benchmark set state='master ends load';
221
222connection master;
223
224# terminal timestamp to record
225
226let $i = $databases + 1;
227set @save.binlog_format= @@session.binlog_format;
228set @@session.binlog_format=STATEMENT;
229while($i)
230{
231  let $i1 = $i;
232  dec $i1;
233  eval use test$i1;
234
235  insert into benchmark set state='slave is supposed to finish with load';
236
237  dec $i;
238}
239set @@session.binlog_format= @save.binlog_format;
240
241--enable_result_log
242--enable_query_log
243
244connection slave;
245
246## todo: record start and end time of appying to compare times of
247#  parallel and sequential execution.
248
249--disable_result_log
250
251insert into test0.benchmark set state='slave is processing load';
252
253# To force filling timestamp cols with the slave local clock values
254# to implement benchmarking.
255
256# TODO: replace with another algorithm
257#set @save.mts_exp_slave_local_timestamp=@@global.mts_exp_slave_local_timestamp;
258#set @@global.mts_exp_slave_local_timestamp=1;
259start slave sql_thread;
260
261let $wait_timeout= 600;
262let $wait_condition= SELECT count(*)+sleep(1) = 5 FROM test0.benchmark;
263source include/wait_condition.inc;
264
265use test0;
266insert into benchmark set state='slave ends load';
267
268# cleanup for files that could not be removed in the end of previous invocation.
269let $MYSQLD_DATADIR= `select @@datadir`;
270--remove_files_wildcard $MYSQLD_DATADIR *.out
271
272use test;
273let $benchmark_file= `select replace(concat("benchmark_",uuid(),".out"),"-","_")`;
274--replace_regex /benchmark_.*.out/benchmark.out/
275eval select * from test1.benchmark into outfile  '$benchmark_file';
276select ts from test0.benchmark where state like 'master started load' into @m_0;
277select ts from test0.benchmark where state like 'master ends load' into @m_1;
278select ts from test0.benchmark where state like 'slave takes on load' into @s_m0;
279select ts from test0.benchmark where state like 'slave is supposed to finish with load' into @s_m1;
280
281select ts from test0.benchmark where state like 'slave ends load' into @s_1;
282select ts from test0.benchmark where state like 'slave is processing load' into @s_0;
283let $delta_file= `select replace(concat("delta_",uuid(),".out"),"-","_")`;
284--replace_regex /delta_.*.out/delta.out/
285eval select time_to_sec(@m_1) - time_to_sec(@m_0) as 'delta_m',
286       time_to_sec(@s_1) - time_to_sec(@s_0) as 'delta_s',
287       time_to_sec(@s_m1) - time_to_sec(@s_m0) as 'delta_sm'  into outfile '$delta_file';
288
289
290#
291# Consistency verification
292#
293let $i = $databases + 1;
294while($i)
295{
296  let $i1 = $i;
297  dec $i1;
298
299  # removing uuid() non-deterministic last collumn with statement format
300  connection master;
301
302  --disable_query_log
303  if (`select @@global.binlog_format like 'statement'`)
304  {
305    eval alter table test$i1.ti_nk drop c;
306    eval alter table test$i1.ti_wk drop c;
307  }
308  --disable_query_log
309
310  --source include/sync_slave_sql_with_master.inc
311  let $diff_tables=master:test$i1.ti_nk, slave:test$i1.ti_nk;
312  source include/diff_tables.inc;
313
314  let $diff_tables=master:test$i1.ti_wk, slave:test$i1.ti_wk;
315  source include/diff_tables.inc;
316
317  dec $i;
318}
319--enable_result_log
320--enable_query_log
321
322
323connection master;
324
325--disable_query_log
326--disable_result_log
327
328let $i = $databases + 1;
329while($i)
330{
331  let $i1 = $i;
332  dec $i1;
333
334  eval drop database test$i1;
335  dec $i;
336}
337
338--enable_result_log
339--enable_query_log
340
341--source include/sync_slave_sql_with_master.inc
342
343