mix_innodb_myisam_binlog.test 11.3 KB
Newer Older
guilhem@mysql.com's avatar
guilhem@mysql.com committed
1
# Check that binlog is ok when a transaction mixes updates to InnoDB and
2 3 4 5
# MyISAM.
# It would be nice to make this a replication test, but in 4.0 the
# slave is always with --skip-innodb in the testsuite. I (Guilhem) however
# did some tests manually on a slave; tables are replicated fine and
6
# Exec_Master_Log_Pos advances as expected.
guilhem@mysql.com's avatar
guilhem@mysql.com committed
7

8
-- source include/have_log_bin.inc
guilhem@mysql.com's avatar
guilhem@mysql.com committed
9 10
-- source include/have_innodb.inc

11 12 13 14
--disable_warnings
drop table if exists t1, t2;
--enable_warnings

guilhem@mysql.com's avatar
guilhem@mysql.com committed
15 16 17 18
connect (con1,localhost,root,,);
connect (con2,localhost,root,,);

connection con1;
19 20
create table t1 (a int) engine=innodb;
create table t2 (a int) engine=myisam;
guilhem@mysql.com's avatar
guilhem@mysql.com committed
21 22 23 24

reset master;

begin;
25 26
insert into t1 values(1);
insert into t2 select * from t1;
guilhem@mysql.com's avatar
guilhem@mysql.com committed
27 28
commit;

29
source include/show_binlog_events.inc;
guilhem@mysql.com's avatar
guilhem@mysql.com committed
30

31 32
delete from t1;
delete from t2;
guilhem@mysql.com's avatar
guilhem@mysql.com committed
33 34 35
reset master;

begin;
36 37 38
insert into t1 values(2);
insert into t2 select * from t1;
# should say some changes to non-transact1onal tables couldn't be rolled back
guilhem@mysql.com's avatar
guilhem@mysql.com committed
39 40
rollback;

41
source include/show_binlog_events.inc;
guilhem@mysql.com's avatar
guilhem@mysql.com committed
42

43 44
delete from t1;
delete from t2;
guilhem@mysql.com's avatar
guilhem@mysql.com committed
45 46 47
reset master;

begin;
48
insert into t1 values(3);
guilhem@mysql.com's avatar
guilhem@mysql.com committed
49
savepoint my_savepoint;
50 51
insert into t1 values(4);
insert into t2 select * from t1;
guilhem@mysql.com's avatar
guilhem@mysql.com committed
52 53 54
rollback to savepoint my_savepoint;
commit;

55
source include/show_binlog_events.inc;
guilhem@mysql.com's avatar
guilhem@mysql.com committed
56

57 58
delete from t1;
delete from t2;
guilhem@mysql.com's avatar
guilhem@mysql.com committed
59 60 61
reset master;

begin;
62
insert into t1 values(5);
guilhem@mysql.com's avatar
guilhem@mysql.com committed
63
savepoint my_savepoint;
64 65
insert into t1 values(6);
insert into t2 select * from t1;
guilhem@mysql.com's avatar
guilhem@mysql.com committed
66
rollback to savepoint my_savepoint;
67
insert into t1 values(7);
guilhem@mysql.com's avatar
guilhem@mysql.com committed
68
commit;
69
select a from t1 order by a; # check that savepoints work :)
guilhem@mysql.com's avatar
guilhem@mysql.com committed
70

71
source include/show_binlog_events.inc;
guilhem@mysql.com's avatar
guilhem@mysql.com committed
72 73

# and when ROLLBACK is not explicit?
74 75
delete from t1;
delete from t2;
guilhem@mysql.com's avatar
guilhem@mysql.com committed
76 77 78 79
reset master;

select get_lock("a",10);
begin;
80 81
insert into t1 values(8);
insert into t2 select * from t1;
guilhem@mysql.com's avatar
guilhem@mysql.com committed
82 83 84 85 86 87 88 89 90
disconnect con1;

connection con2;
# We want to SHOW BINLOG EVENTS, to know what was logged. But there is no
# guarantee that logging of the terminated con1 has been done yet (it may not
# even be started, so con1 may have not even attempted to lock the binlog yet;
# so SHOW BINLOG EVENTS may come before con1 does the loggin. To be sure that
# logging has been done, we use a user lock.
select get_lock("a",10);
91
source include/show_binlog_events.inc;
guilhem@mysql.com's avatar
guilhem@mysql.com committed
92

93 94 95
# and when not in a transact1on?
delete from t1;
delete from t2;
guilhem@mysql.com's avatar
guilhem@mysql.com committed
96 97
reset master;

98 99
insert into t1 values(9);
insert into t2 select * from t1;
guilhem@mysql.com's avatar
guilhem@mysql.com committed
100

101
source include/show_binlog_events.inc;
guilhem@mysql.com's avatar
guilhem@mysql.com committed
102

103
# Check that when the query updat1ng the MyISAM table is the first in the
guilhem@gbichot2's avatar
guilhem@gbichot2 committed
104
# transaction, we log it immediately.
105 106
delete from t1;
delete from t2;
guilhem@mysql.com's avatar
guilhem@mysql.com committed
107 108
reset master;

109
insert into t1 values(10); # first make t1 non-empty
guilhem@mysql.com's avatar
guilhem@mysql.com committed
110
begin;
111
insert into t2 select * from t1;
112
source include/show_binlog_events.inc;
113
insert into t1 values(11);
guilhem@mysql.com's avatar
guilhem@mysql.com committed
114 115
commit;

116
source include/show_binlog_events.inc;
guilhem@mysql.com's avatar
guilhem@mysql.com committed
117

118 119
# Check that things work like before this BEGIN/ROLLBACK code was added,
# when t2 is INNODB 
guilhem@mysql.com's avatar
guilhem@mysql.com committed
120

121
alter table t2 engine=INNODB;
guilhem@mysql.com's avatar
guilhem@mysql.com committed
122

123 124
delete from t1;
delete from t2;
guilhem@mysql.com's avatar
guilhem@mysql.com committed
125 126 127
reset master;

begin;
128 129
insert into t1 values(12);
insert into t2 select * from t1;
guilhem@mysql.com's avatar
guilhem@mysql.com committed
130 131
commit;

132
source include/show_binlog_events.inc;
guilhem@mysql.com's avatar
guilhem@mysql.com committed
133

134 135
delete from t1;
delete from t2;
guilhem@mysql.com's avatar
guilhem@mysql.com committed
136 137 138
reset master;

begin;
139 140
insert into t1 values(13);
insert into t2 select * from t1;
guilhem@mysql.com's avatar
guilhem@mysql.com committed
141 142
rollback;

143
source include/show_binlog_events.inc;
guilhem@mysql.com's avatar
guilhem@mysql.com committed
144

145 146
delete from t1;
delete from t2;
guilhem@mysql.com's avatar
guilhem@mysql.com committed
147 148 149
reset master;

begin;
150
insert into t1 values(14);
guilhem@mysql.com's avatar
guilhem@mysql.com committed
151
savepoint my_savepoint;
152 153
insert into t1 values(15);
insert into t2 select * from t1;
guilhem@mysql.com's avatar
guilhem@mysql.com committed
154 155 156
rollback to savepoint my_savepoint;
commit;

157
source include/show_binlog_events.inc;
guilhem@mysql.com's avatar
guilhem@mysql.com committed
158

159 160
delete from t1;
delete from t2;
guilhem@mysql.com's avatar
guilhem@mysql.com committed
161 162 163
reset master;

begin;
164
insert into t1 values(16);
guilhem@mysql.com's avatar
guilhem@mysql.com committed
165
savepoint my_savepoint;
166 167
insert into t1 values(17);
insert into t2 select * from t1;
guilhem@mysql.com's avatar
guilhem@mysql.com committed
168
rollback to savepoint my_savepoint;
169
insert into t1 values(18);
guilhem@mysql.com's avatar
guilhem@mysql.com committed
170
commit;
171
select a from t1 order by a; # check that savepoints work :)
guilhem@mysql.com's avatar
guilhem@mysql.com committed
172

173
source include/show_binlog_events.inc;
guilhem@mysql.com's avatar
guilhem@mysql.com committed
174

175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205
# Test for BUG#5714, where a MyISAM update in the transaction used to
# release row-level locks in InnoDB

connect (con3,localhost,root,,);

connection con3;
delete from t1;
delete from t2;
--disable_warnings
alter table t2 type=MyISAM;
--enable_warnings
insert into t1 values (1);
begin;
select * from t1 for update;

connection con2;
select (@before:=unix_timestamp())*0; # always give repeatable output
begin;
send select * from t1 for update;

connection con3;
insert into t2 values (20);

connection con2;
--error 1205
reap;
select (@after:=unix_timestamp())*0; # always give repeatable output
# verify that innodb_lock_wait_timeout was exceeded. When there was
# the bug, the reap would return immediately after the insert into t2.
select (@after-@before) >= 2;

206
drop table t1,t2;
207 208 209 210 211 212 213 214 215 216 217
commit;

# test for BUG#7947 - DO RELEASE_LOCK() not written to binlog on rollback in the middle
# of a transaction

connection con2;
begin;
create temporary table ti (a int) engine=innodb;
rollback;
insert into ti values(1);
set autocommit=0;
218 219 220 221
create temporary table t1 (a int) engine=myisam; 
commit;
insert t1 values (1); 
rollback;
222 223 224 225 226 227 228 229 230
create table t0 (n int);
insert t0 select * from t1;
set autocommit=1;
insert into t0 select GET_LOCK("lock1",null);
set autocommit=0;
create table t2 (n int) engine=innodb;
insert into t2 values (3); 
disconnect con2;
connection con3;
231
select get_lock("lock1",60);
232
source include/show_binlog_events.inc;
233 234 235
do release_lock("lock1");
drop table t0,t2;

236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257
# Test for BUG#16559 (ROLLBACK should always have a zero error code in
# binlog). Has to be here and not earlier, as the SELECTs influence
# XIDs differently between normal and ps-protocol (and SHOW BINLOG
# EVENTS above read XIDs).

connect (con4,localhost,root,,);
connection con3;
reset master;
create table t1 (a int) engine=innodb;
create table t2 (a int) engine=myisam;
select get_lock("a",10);
begin;
insert into t1 values(8);
insert into t2 select * from t1;
disconnect con3;

connection con4;
select get_lock("a",10); # wait for rollback to finish

# we check that the error code of the "ROLLBACK" event is 0 and not
# ER_SERVER_SHUTDOWN (i.e. disconnection just rolls back transaction
# and does not make slave to stop)
258 259
--exec $MYSQL_BINLOG --start-position=547 $MYSQLTEST_VARDIR/log/master-bin.000001 > $MYSQLTEST_VARDIR/tmp/mix_innodb_myisam_binlog.output
--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
260
eval select
261
(@a:=load_file("$MYSQLTEST_VARDIR/tmp/mix_innodb_myisam_binlog.output"))
262 263 264
is not null;
--replace_result $MYSQL_TEST_DIR MYSQL_TEST_DIR
eval select
265
@a like "%#%error_code=0%ROLLBACK/*!*/;%ROLLBACK /* added by mysqlbinlog */;%",
266
@a not like "%#%error_code=%error_code=%";
267
drop table t1, t2;
268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382

#
# Bug #27417  	thd->no_trans_update.stmt lost value inside of SF-exec-stack
# bug #28960    non-trans temp table changes with insert .. select
#               not binlogged after rollback
#
# testing appearence of insert into temp_table in binlog.
# There are two branches of execution that require different setup.

## send_eof() branch

# prepare

create temporary table tt (a int unique);
create table ti (a int) engine=innodb;
reset master;
show master status;

# action

begin; 
insert into ti values (1); 
insert into ti values (2) ; 
insert into tt select * from ti;
rollback;

# check

select count(*) from tt /* 2 */;
show master status;
--replace_column 2 # 5 #
show binlog events from 98;
select count(*) from ti /* zero */;
insert into ti select * from tt;
select * from ti /* that is what slave would miss - a bug */;


## send_error() branch
delete from ti;
delete from tt where a=1;
reset master;
show master status;

# action

begin; 
insert into ti values (1); 
insert into ti values (2) /* to make the dup error in the following */; 
--error ER_DUP_ENTRY
insert into tt select * from ti /* one affected and error */;
rollback;

# check

show master status;
--replace_column 2 # 5 #
show binlog events from 98;
select count(*) from ti /* zero */;
insert into ti select * from tt;
select * from tt /* that is what otherwise slave missed - the bug */;

drop table ti;


#
# Bug #27417 thd->no_trans_update.stmt lost value inside of SF-exec-stack
#
# Testing asserts: if there is a side effect of modifying non-transactional
# table thd->no_trans_update.stmt must be TRUE;
# the assert is active with debug build
#

--disable_warnings
drop function if exists bug27417;
drop table if exists t1,t2;
--enable_warnings
# side effect table
CREATE TABLE t1 (a int NOT NULL auto_increment primary key) ENGINE=MyISAM;
# target tables
CREATE TABLE t2 (a int NOT NULL auto_increment, PRIMARY KEY (a));

delimiter |;
create function bug27417(n int) 
RETURNS int(11)
begin
  insert into t1 values (null);
  return n;
end|
delimiter ;|

reset master;

# execute

insert into t2 values (bug27417(1));
insert into t2 select bug27417(2);
reset master;

--error ER_DUP_ENTRY
insert into t2 values (bug27417(2)); 
show master status; /* only (!) with fixes for #23333 will show there is the query */;
select count(*) from t1 /* must be 3 */;

reset master;
select count(*) from t2;
delete from t2 where a=bug27417(3);
select count(*) from t2 /* nothing got deleted */; 
show master status; /* the query must be in regardless of #23333 */;
select count(*) from t1 /* must be 5 */;

--enable_info
delete t2 from t2 where t2.a=bug27417(100) /* must not affect t2 */;
--disable_info
select count(*) from t1 /* must be 7 */;

383
# function bug27417 remains for the following testing of bug#23333
384 385
drop table t1,t2;

386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499
#
# Bug#23333 using the patch (and the test) for bug#27471
# throughout the bug tests 
# t1 - non-trans side effects gatherer;
# t2 - transactional table;
#
CREATE TABLE t1 (a int  NOT NULL auto_increment primary key) ENGINE=MyISAM;
CREATE TABLE t2 (a int, PRIMARY KEY (a)) ENGINE=InnoDB;
CREATE TABLE t3 (a int, PRIMARY KEY (a), b int unique);


#
# INSERT
#

# prepare
  
 insert into t2 values (1);
 reset master;

# execute

 --error ER_DUP_ENTRY
 insert into t2 values (bug27417(1)); 
  
# check

 show master status /* the offset must denote there is the query */;
 select count(*) from t1 /* must be 1 */;

#
# INSERT SELECT
#

# prepare
 delete from t1;
 delete from t2;
 insert into t2 values (2);
 reset master;

# execute

 --error ER_DUP_ENTRY
 insert into t2 select bug27417(1) union select bug27417(2); 
  
# check

 show master status /* the offset must denote there is the query */;
 select count(*) from t1 /* must be 2 */;

#
# UPDATE (multi-update see bug#27716)
#

# prepare
 delete from t1;
 insert into t3 values (1,1),(2,3),(3,4);
 reset master;

# execute
 --error ER_DUP_ENTRY
 update t3 set b=b+bug27417(1);

# check
 show master status /* the offset must denote there is the query */;
 select count(*) from t1 /* must be 2 */;


#
# DELETE (for multi-delete see Bug #29136)
#

# prepare
 delete from t1;
 delete from t2;
 delete from t3;
 insert into t2 values (1);
 insert into t3 values (1,1);
 create trigger trg_del before delete on t2 for each row 
   insert into t3 values (bug27417(1), 2);
 reset master;

# execute
 --error ER_DUP_ENTRY
 delete from t2;
# check
 show master status /* the offset must denote there is the query */;
 select count(*) from t1 /* must be 1 */;


#
# LOAD DATA
#

# prepare
 delete from t1;
 create table t4 (a int default 0, b int primary key) engine=innodb;
 insert into t4 values (0, 17);
 reset master;

# execute
 --error ER_DUP_ENTRY
 load data infile '../std_data_ln/rpl_loaddata.dat' into table t4 (a, @b) set b= @b + bug27417(2);
# check
 select * from t4;
 select count(*) from t1 /* must be 2 */;
 show master status /* the offset must denote there is the query */;

#
# bug#23333 cleanup
#


drop trigger trg_del;
500
drop table t1,t2,t3,t4;
501 502 503
drop function bug27417;


504 505
--echo end of tests