1# See if slave restarts the transaction after failing on an InnoDB deadlock error. 2 3# Note: testing what happens when too many retries is possible, but 4# needs large waits when running with --debug, so we don't do it. 5# The same way, this test may not test what is expected when run 6# under Valgrind, timings are too short then (with --valgrind I 7# (Guilhem) have seen the test manage to provoke lock wait timeout 8# error but not deadlock error; that is ok as code deals with the two 9# errors in exactly the same way. 10 11--source include/master-slave.inc 12 13#create a new connection to the slave 14--connect (slave2, 127.0.0.1, root, ,test, $SLAVE_MYPORT,) 15 16# 0) Prepare tables and data 17--echo *** Prepare tables and data *** 18 19connection master; 20eval CREATE TABLE t1 (a INT NOT NULL, KEY(a)) ENGINE=$engine_type; 21eval CREATE TABLE t2 (a INT) ENGINE=$engine_type; 22eval CREATE TABLE t3 (a INT NOT NULL, KEY(a)) ENGINE=$engine_type; 23sync_slave_with_master; 24 25SHOW CREATE TABLE t1; 26SHOW CREATE TABLE t2; 27SHOW CREATE TABLE t3; 28SELECT @@GLOBAL.slave_transaction_retries; 29SELECT @@GLOBAL.innodb_lock_wait_timeout; 30--source include/stop_slave.inc 31 32connection master; 33# Save position of BEGIN 34let $master_pos_begin= query_get_value(SHOW MASTER STATUS, Position, 1); 35BEGIN; 36INSERT INTO t1 VALUES (1); 37# We make a long transaction here 38INSERT INTO t2 VALUES (2), (2), (2), (2), (2), (2), (2), (2), (2), (2); 39INSERT INTO t3 VALUES (3); 40COMMIT; 41save_master_pos; 42--echo 43 44# 1) Test deadlock 45# Block slave SQL thread, wait retries of transaction, unlock slave before lock timeout 46--echo *** Test deadlock *** 47 48connection slave; 49BEGIN; 50SELECT * FROM t1 FOR UPDATE; 51# Save variable 'Slave_retried_transactions' before deadlock 52let $slave_retried_transactions= query_get_value(SHOW GLOBAL STATUS LIKE 'Slave_retried_transactions', Value, 1); 53--connection slave2 54--source include/start_slave.inc 55--connection slave 56# Wait until SQL thread blocked: variable 'Slave_retried_transactions' will incremented 57let $status_var= Slave_retried_transactions; 58let $status_var_value= $slave_retried_transactions; 59let $status_type= GLOBAL; 60let $status_var_comparsion= >; 61--source include/wait_for_status_var.inc 62SELECT COUNT(*) FROM t2; 63COMMIT; 64source include/check_slave_is_running.inc; 65sync_with_master; 66 67# Check the data 68SELECT * FROM t1; 69SELECT * FROM t3; 70--echo 71 72# 2) Test lock wait timeout 73# Block slave and wait lock timeout error 74--echo *** Test lock wait timeout *** 75 76connection slave; 77--source include/stop_slave.inc 78DELETE FROM t2; 79# Set slave position to the BEGIN log event 80RESET MASTER; 81--replace_result $master_pos_begin MASTER_POS_BEGIN 82eval CHANGE MASTER TO MASTER_LOG_POS=$master_pos_begin; 83BEGIN; 84# Hold lock 85SELECT * FROM t1 FOR UPDATE; 86# Wait until slave stopped with error 'Lock wait timeout exceeded' 87--connection slave2 88START SLAVE; 89--connection slave 90let $slave_sql_errno= 1205; 91--source include/wait_for_slave_sql_error.inc 92SELECT COUNT(*) FROM t2; 93COMMIT; 94--source include/start_slave.inc 95sync_with_master; 96# Check data from tables 97SELECT * FROM t1; 98SELECT * FROM t3; 99# Check that no error is reported 100source include/check_slave_is_running.inc; 101--echo 102 103# 3) Test lock wait timeout and purged relay log 104# Set max_relay_log_size=0, block slave and wait lock timeout error. 105# Restart slave and check that no erros appear 106--echo *** Test lock wait timeout and purged relay logs *** 107 108connection slave; 109SET @my_max_relay_log_size= @@global.max_relay_log_size; 110SET global max_relay_log_size=0; 111--source include/stop_slave.inc 112DELETE FROM t2; 113# Set slave position to the BEGIN log event 114RESET MASTER; 115--replace_result $master_pos_begin MASTER_POS_BEGIN 116eval CHANGE MASTER TO MASTER_LOG_POS=$master_pos_begin; 117BEGIN; 118# Hold lock 119SELECT * FROM t1 FOR UPDATE; 120# Wait until slave stopped with error 'Lock wait timeout exceeded' 121--connection slave2 122START SLAVE; 123--connection slave 124let $slave_sql_errno= 1205; 125--source include/wait_for_slave_sql_error.inc 126SELECT COUNT(*) FROM t2; 127COMMIT; 128--source include/start_slave.inc 129sync_with_master; 130# Check data from tables 131SELECT * FROM t1; 132SELECT * FROM t3; 133# Check that no error is reported 134source include/check_slave_is_running.inc; 135--echo 136 137# 138# bug#11748510/36524 incident of deadlock on slave is overdramatized 139# 140# Observe that the slave stopped when the number of transation retries 141# exceeds @@global.slave_transaction_retries 142# 143connection master; 144 145--echo *** Test the deadlock warning to be escalated into the error *** 146 147delete from t1; 148delete from t2; 149delete from t3; 150 151sync_slave_with_master; 152 153# make sure slave's unilateral row gone as well 154delete from t1; 155delete from t2; 156delete from t3; 157 158# the first attempt to run a deadlock scenario of p 1) leads to the error 159set @save.slave_transaction_retries= @@global.slave_transaction_retries; 160set @@global.slave_transaction_retries= 0; 161source include/stop_slave.inc; 162 163connection master; 164 165BEGIN; 166INSERT INTO t1 VALUES (1); 167# We make a long transaction here 168INSERT INTO t2 VALUES (2), (2), (2), (2), (2), (2), (2), (2), (2), (2); 169INSERT INTO t3 VALUES (3); 170COMMIT; 171 172connection slave; 173BEGIN; 174SELECT count(*) as zero FROM t1 FOR UPDATE; 175 176--connection slave2 177START SLAVE; 178--connection slave 179 180--echo *** Now the slave must be stopped due to timeout *** 181 182let $slave_sql_errno= 1205; # ER_LOCK_TIMEOUT 183let $show_slave_sql_error= 0; 184source include/wait_for_slave_sql_error.inc; 185 186rollback; 187 188set @@global.slave_transaction_retries= @save.slave_transaction_retries; 189source include/start_slave.inc; 190# Clean up 191--echo *** Clean up *** 192connection master; 193DROP TABLE t1,t2,t3; 194sync_slave_with_master; 195SET global max_relay_log_size= @my_max_relay_log_size; 196 197--echo End of 5.1 tests 198--source include/rpl_end.inc 199