diff options
Diffstat (limited to 'mysql-test')
-rw-r--r-- | mysql-test/r/rpl_deadlock.result | 81 | ||||
-rw-r--r-- | mysql-test/t/rpl_deadlock-slave.opt | 1 | ||||
-rw-r--r-- | mysql-test/t/rpl_deadlock.test | 107 |
3 files changed, 189 insertions, 0 deletions
diff --git a/mysql-test/r/rpl_deadlock.result b/mysql-test/r/rpl_deadlock.result new file mode 100644 index 00000000000..366d18f3e05 --- /dev/null +++ b/mysql-test/r/rpl_deadlock.result @@ -0,0 +1,81 @@ +stop slave; +drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9; +reset master; +reset slave; +drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9; +start slave; +create table t1 (a int not null, key(a)) engine=innodb; +create table t2 (a int not null, key(a)) engine=innodb; +create table t3 (a int) engine=innodb; +create table t4 (a int) engine=innodb; +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` int(11) NOT NULL default '0', + KEY `a` (`a`) +) ENGINE=InnoDB DEFAULT CHARSET=latin1 +show create table t2; +Table Create Table +t2 CREATE TABLE `t2` ( + `a` int(11) NOT NULL default '0', + KEY `a` (`a`) +) ENGINE=InnoDB DEFAULT CHARSET=latin1 +stop slave; +begin; +insert into t3 select * from t2 for update; +insert into t1 values(1); +commit; +begin; +select * from t1 for update; +a +start slave; +insert into t2 values(22); +commit; +select * from t1; +a +1 +select * from t2; +a +22 +show slave status; +Slave_IO_State Master_Host Master_User Master_Port Connect_Retry Master_Log_File Read_Master_Log_Pos Relay_Log_File Relay_Log_Pos Relay_Master_Log_File Slave_IO_Running Slave_SQL_Running Replicate_Do_DB Replicate_Ignore_DB Replicate_Do_Table Replicate_Ignore_Table Replicate_Wild_Do_Table Replicate_Wild_Ignore_Table Last_Errno Last_Error Skip_Counter Exec_Master_Log_Pos Relay_Log_Space Until_Condition Until_Log_File Until_Log_Pos Master_SSL_Allowed Master_SSL_CA_File Master_SSL_CA_Path Master_SSL_Cert Master_SSL_Cipher Master_SSL_Key Seconds_Behind_Master +# 127.0.0.1 root MASTER_MYPORT 1 master-bin.000001 13110 # # master-bin.000001 Yes Yes 0 0 13110 # None 0 No # +stop slave; +change master to master_log_pos=401; +begin; +select * from t2 for update; +a +22 +start slave; +commit; +select * from t1; +a +1 +1 +select * from t2; +a +22 +show slave status; +Slave_IO_State Master_Host Master_User Master_Port Connect_Retry Master_Log_File Read_Master_Log_Pos Relay_Log_File Relay_Log_Pos Relay_Master_Log_File Slave_IO_Running Slave_SQL_Running Replicate_Do_DB Replicate_Ignore_DB Replicate_Do_Table Replicate_Ignore_Table Replicate_Wild_Do_Table Replicate_Wild_Ignore_Table Last_Errno Last_Error Skip_Counter Exec_Master_Log_Pos Relay_Log_Space Until_Condition Until_Log_File Until_Log_Pos Master_SSL_Allowed Master_SSL_CA_File Master_SSL_CA_Path Master_SSL_Cert Master_SSL_Cipher Master_SSL_Key Seconds_Behind_Master +# 127.0.0.1 root MASTER_MYPORT 1 master-bin.000001 13110 # # master-bin.000001 Yes Yes 0 0 13110 # None 0 No # +set global max_relay_log_size=0; +stop slave; +change master to master_log_pos=401; +begin; +select * from t2 for update; +a +22 +start slave; +commit; +select * from t1; +a +1 +1 +1 +select * from t2; +a +22 +show slave status; +Slave_IO_State Master_Host Master_User Master_Port Connect_Retry Master_Log_File Read_Master_Log_Pos Relay_Log_File Relay_Log_Pos Relay_Master_Log_File Slave_IO_Running Slave_SQL_Running Replicate_Do_DB Replicate_Ignore_DB Replicate_Do_Table Replicate_Ignore_Table Replicate_Wild_Do_Table Replicate_Wild_Ignore_Table Last_Errno Last_Error Skip_Counter Exec_Master_Log_Pos Relay_Log_Space Until_Condition Until_Log_File Until_Log_Pos Master_SSL_Allowed Master_SSL_CA_File Master_SSL_CA_Path Master_SSL_Cert Master_SSL_Cipher Master_SSL_Key Seconds_Behind_Master +# 127.0.0.1 root MASTER_MYPORT 1 master-bin.000001 13110 # # master-bin.000001 Yes Yes 0 0 13110 # None 0 No # +drop table t1,t2; diff --git a/mysql-test/t/rpl_deadlock-slave.opt b/mysql-test/t/rpl_deadlock-slave.opt new file mode 100644 index 00000000000..f4a8c640458 --- /dev/null +++ b/mysql-test/t/rpl_deadlock-slave.opt @@ -0,0 +1 @@ +--innodb --loose-innodb_lock_wait_timeout=4 --slave-transaction-retries=2 --max-relay-log-size=4096 diff --git a/mysql-test/t/rpl_deadlock.test b/mysql-test/t/rpl_deadlock.test new file mode 100644 index 00000000000..82470e8ebd0 --- /dev/null +++ b/mysql-test/t/rpl_deadlock.test @@ -0,0 +1,107 @@ +# See if slave restarts the transaction after failing on an InnoDB deadlock error. + +# Note: testing what happens when too many retries is possible, but +# needs large waits when running with --debug, so we don't do it. +# The same way, this test may not test what is expected when run +# under Valgrind, timings are too short then (with --valgrind I +# (Guilhem) have seen the test manage to provoke lock wait timeout +# error but not deadlock error; that is ok as code deals with the two +# errors in exactly the same way. + +source include/have_innodb.inc; +source include/master-slave.inc; + +connection master; +create table t1 (a int not null, key(a)) engine=innodb; +create table t2 (a int not null, key(a)) engine=innodb; +create table t3 (a int) engine=innodb; +create table t4 (a int) engine=innodb; +sync_slave_with_master; + +show create table t1; +show create table t2; +stop slave; + +# 1) Test deadlock + +connection master; +begin; +# Let's keep BEGIN and the locked statement in two different relay logs. +let $1=200; +disable_query_log; +while ($1) +{ + eval insert into t3 values( $1 ); + dec $1; +} +enable_query_log; +insert into t3 select * from t2 for update; +insert into t1 values(1); +commit; +save_master_pos; + +connection slave; +begin; +# Let's make our transaction large so that it's slave who is chosen as +# victim +let $1=1000; +disable_query_log; +while ($1) +{ + eval insert into t4 values( $1 ); + dec $1; +} +enable_query_log; +select * from t1 for update; +start slave; +--sleep 3; # hope that slave is blocked now +insert into t2 values(22); # provoke deadlock, slave should be victim +commit; +sync_with_master; +select * from t1; # check that slave succeeded finally +select * from t2; +# check that no error is reported +--replace_column 1 # 8 # 9 # 23 # 33 # +--replace_result $MASTER_MYPORT MASTER_MYPORT +show slave status; + +# 2) Test lock wait timeout + +stop slave; +change master to master_log_pos=401; # the BEGIN log event +begin; +select * from t2 for update; # hold lock +start slave; +--sleep 10; # slave should have blocked, and be retrying +commit; +sync_with_master; +select * from t1; # check that slave succeeded finally +select * from t2; +# check that no error is reported +--replace_column 1 # 8 # 9 # 23 # 33 # +--replace_result $MASTER_MYPORT MASTER_MYPORT +show slave status; + +# Now we repeat 2), but with BEGIN in the same relay log as +# COMMIT (to see if seeking into hot log is ok). + +set global max_relay_log_size=0; + +# This is really copy-paste of 2) of above +stop slave; +change master to master_log_pos=401; +begin; +select * from t2 for update; +start slave; +--sleep 10; +commit; +sync_with_master; +select * from t1; +select * from t2; +--replace_column 1 # 8 # 9 # 23 # 33 # +--replace_result $MASTER_MYPORT MASTER_MYPORT +show slave status; + +connection master; +drop table t1,t2; +sync_slave_with_master; |