~ubuntu-branches/ubuntu/trusty/mariadb-5.5/trusty-proposed

« back to all changes in this revision

Viewing changes to mysql-test/suite/binlog/t/binlog_killed.test

  • Committer: Package Import Robot
  • Author(s): Otto Kekäläinen
  • Date: 2013-12-22 10:27:05 UTC
  • Revision ID: package-import@ubuntu.com-20131222102705-mndw7s12mz0szrcn
Tags: upstream-5.5.32
Import upstream version 5.5.32

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
-- source include/have_innodb.inc
 
2
-- source include/have_binlog_format_statement.inc
 
3
-- source include/binlog_start_pos.inc
 
4
 
 
5
call mtr.add_suppression("Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT");
 
6
 
 
7
# You cannot use `KILL' with the Embedded MySQL Server library,
 
8
# because the embedded server merely runs inside the threads of the host
 
9
# application. -- the docs
 
10
 
 
11
-- source include/not_embedded.inc
 
12
 
 
13
###
 
14
### bug#22725 : incorrect killed error in binlogged query
 
15
###
 
16
 
 
17
connect (con1, localhost, root,,);
 
18
connect (con2, localhost, root,,);
 
19
 
 
20
create table t1 (a int auto_increment, b int, PRIMARY KEY (a)) ENGINE=InnoDB;
 
21
create table t2 (a int auto_increment, b int, PRIMARY KEY (a)) ENGINE=MyISAM;
 
22
create table t3 (a int auto_increment, b int, PRIMARY KEY (a)) ENGINE=InnoDB;
 
23
 
 
24
#
 
25
# effective test for bug#22725
 
26
#
 
27
 
 
28
connection con1;
 
29
select get_lock("a", 20);
 
30
 
 
31
connection con2;
 
32
let $ID= `select connection_id()`;
 
33
 
 
34
#
 
35
# reset master does not reset binlogging on the embedded server.
 
36
# the test is not run on the embedded for reason of using KILL query.
 
37
# `reset master' problem is to be addressed by bug#15580 fixes.
 
38
#
 
39
reset master;
 
40
send insert into t2 values (null, null), (null, get_lock("a", 10));
 
41
 
 
42
 
 
43
connection con1;
 
44
 
 
45
--disable_abort_on_error
 
46
--disable_warnings
 
47
 
 
48
let $wait_condition=
 
49
  select count(*) = 1 from information_schema.processlist
 
50
  where info like "%insert into t2 values%" and state like 'User lock';
 
51
--source include/wait_condition.inc
 
52
 
 
53
--replace_regex /[0-9]+/ID/
 
54
eval kill query $ID;
 
55
 
 
56
connection con2;
 
57
--error 0,ER_QUERY_INTERRUPTED
 
58
reap;
 
59
let $rows= `select count(*) from t2  /* must be 2 or 0 */`;
 
60
 
 
61
let $MYSQLD_DATADIR= `select @@datadir`;
 
62
--let $binlog_killed_pos=query_get_value(SHOW BINLOG EVENTS, Pos, 4)
 
63
--let $binlog_killed_end_log_pos=query_get_value(SHOW BINLOG EVENTS, End_log_pos, 4)
 
64
--exec $MYSQL_BINLOG --force-if-open --start-position=$binlog_killed_pos --stop-position=$binlog_killed_end_log_pos $MYSQLD_DATADIR/master-bin.000001 > $MYSQLTEST_VARDIR/tmp/kill_query_calling_sp.binlog
 
65
--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
 
66
--disable_result_log
 
67
eval select
 
68
(@a:=load_file("$MYSQLTEST_VARDIR/tmp/kill_query_calling_sp.binlog"))
 
69
is not null;
 
70
--enable_result_log
 
71
--replace_result $MYSQL_TEST_DIR MYSQL_TEST_DIR
 
72
let $error_code= `select @a like "%#%error_code=0%" /* must return 1 or 0*/`;
 
73
let $insert_binlogged= `select @a like "%insert into%" /* must return 1 or 0 */`;
 
74
eval set @result= $rows - $error_code - $insert_binlogged;
 
75
 
 
76
--enable_warnings
 
77
--enable_abort_on_error
 
78
 
 
79
select @result /* must be zero either way */;
 
80
 
 
81
 
 
82
--remove_file $MYSQLTEST_VARDIR/tmp/kill_query_calling_sp.binlog
 
83
connection con1;
 
84
select RELEASE_LOCK("a");
 
85
 
 
86
#
 
87
# bug#27571 asynchronous setting mysql_`query`::error and Query_log_e::error_code
 
88
#
 
89
 
 
90
# checking that killing inside of select loops is safe as before
 
91
# killing after the loop can be only simulated - another test
 
92
 
 
93
delete from t1;
 
94
delete from t2;
 
95
insert into t1 values (1,1),(2,2);
 
96
 
 
97
#
 
98
# simple update
 
99
#
 
100
connection con1;
 
101
begin; update t1 set b=11 where a=2;
 
102
 
 
103
connection con2;
 
104
let $ID= `select connection_id()`;
 
105
begin;
 
106
send update t1 set b=b+10;
 
107
 
 
108
connection con1;
 
109
--replace_result $ID ID
 
110
eval kill query $ID;
 
111
rollback;
 
112
 
 
113
# Bug #32148    killi query may be ineffective 
 
114
# forced to comment out the test's outcome 
 
115
# and mask out ineffective ER_QUERY_INTERRUPTED
 
116
# todo1: revert back upon fixing bug#32148
 
117
# todo2: the tests need refining in that
 
118
#        killing should wait till the victim requested
 
119
#        its lock (wait_condition available in 5.1 tests)
 
120
 
 
121
connection con2;
 
122
--error 0,ER_QUERY_INTERRUPTED
 
123
reap;
 
124
rollback;
 
125
select * from t1  order by a /* must be the same as before (1,1),(2,2) */;
 
126
 
 
127
#
 
128
# multi update
 
129
# commented out as Bug #31807 multi-update,delete killing does not report with ER_QUERY_INTERRUPTED
 
130
# in the way
 
131
#
 
132
# connection con1;
 
133
# begin; update t1 set b=b+10;
 
134
 
 
135
# connection con2;
 
136
# send update t1 as t_1,t1 as t_2 set t_1.b=11 where t_2.a=2;
 
137
 
 
138
# connection con1;
 
139
# --replace_result $ID ID
 
140
# eval kill query $ID;
 
141
# rollback;
 
142
 
 
143
# disable_abort_on_error;
 
144
 
 
145
# connection con2;
 
146
# --error HY000,ER_QUERY_INTERRUPTED
 
147
# reap;
 
148
# select * from t1 /* must be the same as before (1,1),(2,2) */;
 
149
 
 
150
# enable_abort_on_error;
 
151
#
 
152
# simple delete
 
153
#
 
154
connection con1;
 
155
begin; delete from t1 where a=2;
 
156
 
 
157
connection con2;
 
158
let $ID= `select connection_id()`;
 
159
begin;
 
160
send delete from t1 where a=2;
 
161
 
 
162
connection con1;
 
163
--replace_result $ID ID
 
164
eval kill query $ID;
 
165
rollback;
 
166
 
 
167
connection con2;
 
168
--error 0,ER_QUERY_INTERRUPTED
 
169
reap;
 
170
rollback;
 
171
# todo1,2 above
 
172
select * from t1 order by a /* must be the same as before (1,1),(2,2) */;
 
173
 
 
174
 
 
175
#
 
176
# multi delete
 
177
# the same as for multi-update
 
178
#
 
179
# connection con1;
 
180
# begin; delete from t1 where a=2;
 
181
 
 
182
# connection con2;
 
183
# send delete t1 from t1 where t1.a=2;
 
184
 
 
185
# connection con1;
 
186
# --replace_result $ID ID
 
187
# eval kill query $ID;
 
188
# rollback;
 
189
 
 
190
# connection con2;
 
191
# --error 0,ER_QUERY_INTERRUPTED
 
192
# reap;
 
193
# select * from t1 /* must be the same as before (1,1),(2,2) */;
 
194
#
 
195
# insert select
 
196
#
 
197
connection con1;
 
198
--disable_warnings
 
199
drop table if exists t4;
 
200
--enable_warnings
 
201
create table t4 (a int, b int) engine=innodb;
 
202
insert into t4 values (3, 3);
 
203
begin; insert into t1 values (3, 3);
 
204
 
 
205
connection con2;
 
206
let $ID= `select connection_id()`;
 
207
begin;
 
208
send insert into t1 select * from t4 for update;
 
209
 
 
210
connection con1;
 
211
--replace_result $ID ID
 
212
eval kill query $ID;
 
213
rollback;
 
214
 
 
215
connection con2;
 
216
--error 0,ER_QUERY_INTERRUPTED,ER_LOCK_WAIT_TIMEOUT
 
217
reap;
 
218
# todo 1,2 above
 
219
rollback;
 
220
select * from t1 /* must be the same as before (1,1),(2,2) */;
 
221
 
 
222
drop table t4; # cleanup for the sub-case
 
223
 
 
224
###
 
225
## non-ta table case: killing must be recorded in binlog
 
226
###
 
227
create table t4 (a int, b int) ENGINE=MyISAM /* for killing update and delete */;
 
228
 
 
229
delimiter |;
 
230
create function bug27563(n int) 
 
231
RETURNS int(11)
 
232
NOT DETERMINISTIC
 
233
begin
 
234
  if @b > 0 then
 
235
     select get_lock("a", 20)  into @a;
 
236
  else 
 
237
     set @b= 1;
 
238
  end if;
 
239
  return n;
 
240
end|
 
241
delimiter ;|
 
242
 
 
243
#
 
244
# update
 
245
#
 
246
 
 
247
delete from t4;
 
248
insert into t4 values (1,1), (1,1);
 
249
reset master;
 
250
connection con1;
 
251
select get_lock("a", 20);
 
252
 
 
253
connection con2;
 
254
let $ID= `select connection_id()`;
 
255
set @b= 0;
 
256
send update t4 set b=b + bug27563(b);
 
257
 
 
258
connection con1;
 
259
let $wait_condition= select count(*) = 1 FROM INFORMATION_SCHEMA.PROCESSLIST where state='User lock';
 
260
source include/wait_condition.inc;
 
261
select count(*) FROM INFORMATION_SCHEMA.PROCESSLIST where state='User lock';
 
262
 
 
263
--replace_result $ID ID
 
264
eval kill query $ID;
 
265
 
 
266
connection con2;
 
267
--error ER_QUERY_INTERRUPTED
 
268
reap;
 
269
select * from t4 order by b /* must be (1,1), (1,2) */;
 
270
select @b  /* must be 1 at the end of a stmt calling bug27563() */;
 
271
--echo must have the update query event on the 4th line
 
272
source include/show_binlog_events.inc;
 
273
--let $binlog_killed_pos= query_get_value(SHOW BINLOG EVENTS, Pos, 4)
 
274
--let $binlog_killed_end_log_pos= query_get_value(SHOW BINLOG EVENTS, End_log_pos, 4)
 
275
 
 
276
--echo *** a proof the query is binlogged with an error ***
 
277
 
 
278
--exec $MYSQL_BINLOG --force-if-open --start-position=$binlog_killed_pos --stop-position=$binlog_killed_end_log_pos $MYSQLD_DATADIR/master-bin.000001 > $MYSQLTEST_VARDIR/tmp/binlog_killed_bug27571.binlog
 
279
--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
 
280
eval select
 
281
(@a:=load_file("$MYSQLTEST_VARDIR/tmp/binlog_killed_bug27571.binlog"))
 
282
is not null;
 
283
--replace_result $MYSQL_TEST_DIR MYSQL_TEST_DIR
 
284
let $error_code= `select @a like "%#%error_code=0%" /* must return 0*/`;
 
285
eval select $error_code /* must return 0 to mean the killed update is in */;
 
286
 
 
287
# cleanup for the sub-case
 
288
connection con1;
 
289
select RELEASE_LOCK("a");
 
290
--remove_file $MYSQLTEST_VARDIR/tmp/binlog_killed_bug27571.binlog
 
291
 
 
292
#
 
293
# delete
 
294
#
 
295
 
 
296
delete from t4;
 
297
insert into t4 values (1,1), (2,2);
 
298
reset master;
 
299
connection con1;
 
300
select get_lock("a", 20);
 
301
 
 
302
connection con2;
 
303
let $ID= `select connection_id()`;
 
304
set @b= 0;
 
305
send delete from t4 where b=bug27563(1) or b=bug27563(2);
 
306
 
 
307
connection con1;
 
308
let $wait_condition= select count(*) = 1 FROM INFORMATION_SCHEMA.PROCESSLIST where state='User lock';
 
309
source include/wait_condition.inc;
 
310
select count(*) FROM INFORMATION_SCHEMA.PROCESSLIST where state='User lock';
 
311
--replace_result $ID ID
 
312
eval kill query $ID;
 
313
 
 
314
connection con2;
 
315
--error ER_QUERY_INTERRUPTED
 
316
reap;
 
317
select count(*) from t4 /* must be 1 */;
 
318
select @b  /* must be 1 at the end of a stmt calling bug27563() */;
 
319
--echo must have the delete query event on the 4th line
 
320
source include/show_binlog_events.inc;
 
321
--let $binlog_killed_pos= query_get_value(SHOW BINLOG EVENTS, Pos, 4)
 
322
--let $binlog_killed_end_log_pos= query_get_value(SHOW BINLOG EVENTS, End_log_pos, 4)
 
323
 
 
324
# a proof the query is binlogged with an error
 
325
 
 
326
--exec $MYSQL_BINLOG --force-if-open --start-position=$binlog_killed_pos --stop-position=$binlog_killed_end_log_pos $MYSQLD_DATADIR/master-bin.000001 > $MYSQLTEST_VARDIR/tmp/binlog_killed_bug27571.binlog
 
327
--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
 
328
eval select
 
329
(@a:=load_file("$MYSQLTEST_VARDIR/tmp/binlog_killed_bug27571.binlog"))
 
330
is not null;
 
331
--replace_result $MYSQL_TEST_DIR MYSQL_TEST_DIR
 
332
let $error_code= `select @a like "%#%error_code=0%" /* must return 0*/`;
 
333
eval select $error_code /* must return 0 to mean the killed delete is in */;
 
334
 
 
335
# cleanup for the sub-case
 
336
connection con1;
 
337
select RELEASE_LOCK("a");
 
338
--remove_file $MYSQLTEST_VARDIR/tmp/binlog_killed_bug27571.binlog
 
339
 
 
340
drop table t4;
 
341
 
 
342
#
 
343
# load data - see simulation tests
 
344
#
 
345
 
 
346
 
 
347
# bug#27571 cleanup
 
348
 
 
349
drop function bug27563;
 
350
 
 
351
 
 
352
#
 
353
# common cleanup 
 
354
#
 
355
 
 
356
drop table t1,t2,t3;
 
357
 
 
358
--echo end of the tests