| 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/have_perfschema.inc |
| 12 |
--source include/master-slave.inc |
| 13 |
|
| 14 |
# 0) Prepare tables and data |
| 15 |
--echo *** Prepare tables and data *** |
| 16 |
|
| 17 |
connection master; |
| 18 |
eval CREATE TABLE t1 (a INT NOT NULL, KEY(a)) ENGINE=$engine_type; |
| 19 |
eval CREATE TABLE t2 (a INT) ENGINE=$engine_type; |
| 20 |
eval CREATE TABLE t3 (a INT NOT NULL, KEY(a)) ENGINE=$engine_type; |
| 21 |
sync_slave_with_master; |
| 22 |
|
| 23 |
SHOW CREATE TABLE t1; |
| 24 |
SHOW CREATE TABLE t2; |
| 25 |
SHOW CREATE TABLE t3; |
| 26 |
SHOW VARIABLES LIKE 'slave_transaction_retries'; |
| 27 |
--source include/stop_slave.inc |
| 28 |
|
| 29 |
connection master; |
| 30 |
BEGIN; |
| 31 |
INSERT INTO t1 VALUES (1); |
| 32 |
# We make a long transaction here |
| 33 |
INSERT INTO t2 VALUES (2), (2), (2), (2), (2), (2), (2), (2), (2), (2); |
| 34 |
INSERT INTO t3 VALUES (3); |
| 35 |
COMMIT; |
| 36 |
save_master_pos; |
| 37 |
# Save BEGIN event into variable |
| 38 |
let $master_pos_begin= query_get_value(SHOW BINLOG EVENTS, Pos, 10); |
| 39 |
--echo |
| 40 |
|
| 41 |
# 1) Test deadlock |
| 42 |
# Block slave SQL thread, wait retries of transaction, unlock slave before lock timeout |
| 43 |
--echo *** Test deadlock *** |
| 44 |
|
| 45 |
connection slave; |
| 46 |
BEGIN; |
| 47 |
SELECT * FROM t1 FOR UPDATE; |
| 48 |
# Save variable 'Slave_retried_transactions' before deadlock |
| 49 |
let $slave_retried_transactions= query_get_value(SHOW GLOBAL STATUS LIKE 'Slave_retried_transactions', Value, 1); |
| 50 |
# Run the START SLAVE in a separate connection. Otherwise it terminates |
| 51 |
# the SELECT FOR UPDATE transaction (START SLAVE does implicit COMMIT!). |
| 52 |
connection slave1; |
| 53 |
START SLAVE; |
| 54 |
# Wait until SQL thread blocked: variable 'Slave_retried_transactions' will incremented |
| 55 |
let $status_var= Slave_retried_transactions; |
| 56 |
let $status_var_value= $slave_retried_transactions; |
| 57 |
let $status_type= GLOBAL; |
| 58 |
let $status_var_comparsion= >; |
| 59 |
--source include/wait_for_status_var.inc |
| 60 |
connection slave; |
| 61 |
SELECT COUNT(*) FROM t2; |
| 62 |
COMMIT; |
| 63 |
|
| 64 |
--echo |
| 65 |
--echo # Test that the performance schema coulumn shows > 0 values. |
| 66 |
--echo |
| 67 |
|
| 68 |
--let $assert_text= current number of retries should be more than the value saved before deadlock. |
| 69 |
--let $assert_cond= [SELECT COUNT_TRANSACTIONS_RETRIES FROM performance_schema.replication_applier_status, COUNT_TRANSACTIONS_RETRIES, 1] > "$slave_retried_transactions" |
| 70 |
--source include/assert.inc |
| 71 |
|
| 72 |
source include/check_slave_is_running.inc; |
| 73 |
sync_with_master; |
| 74 |
|
| 75 |
# Check the data |
| 76 |
SELECT * FROM t1; |
| 77 |
SELECT * FROM t3; |
| 78 |
# Check that no error is reported |
| 79 |
source include/check_slave_is_running.inc; |
| 80 |
--echo |
| 81 |
|
| 82 |
# 2) Test lock wait timeout |
| 83 |
# Block slave and wait lock timeout error |
| 84 |
--echo *** Test lock wait timeout *** |
| 85 |
|
| 86 |
connection slave; |
| 87 |
--source include/stop_slave.inc |
| 88 |
DELETE FROM t2; |
| 89 |
# Set slave position to the BEGIN log event |
| 90 |
--replace_result $master_pos_begin <master_pos_begin> |
| 91 |
eval CHANGE MASTER TO MASTER_LOG_POS=$master_pos_begin, MASTER_USE_GTID=NO; |
| 92 |
BEGIN; |
| 93 |
# Hold lock |
| 94 |
SELECT * FROM t1 FOR UPDATE; |
| 95 |
# Wait until slave stopped with error 'Lock wait timeout exceeded' |
| 96 |
connection slave1; |
| 97 |
START SLAVE; |
| 98 |
let $slave_sql_errno= 1205; |
| 99 |
--source include/wait_for_slave_sql_error.inc |
| 100 |
connection slave; |
| 101 |
SELECT COUNT(*) FROM t2; |
| 102 |
COMMIT; |
| 103 |
--source include/start_slave.inc |
| 104 |
sync_with_master; |
| 105 |
# Check data from tables |
| 106 |
SELECT * FROM t1; |
| 107 |
SELECT * FROM t3; |
| 108 |
# Check that no error is reported |
| 109 |
source include/check_slave_is_running.inc; |
| 110 |
--echo |
| 111 |
|
| 112 |
# 3) Test lock wait timeout and purged relay log |
| 113 |
# Set max_relay_log_size=0, block slave and wait lock timeout error. |
| 114 |
# Restart slave and check that no erros appear |
| 115 |
--echo *** Test lock wait timeout and purged relay logs *** |
| 116 |
|
| 117 |
connection slave; |
| 118 |
SET @my_max_relay_log_size= @@global.max_relay_log_size; |
| 119 |
SET global max_relay_log_size=0; |
| 120 |
--source include/stop_slave.inc |
| 121 |
DELETE FROM t2; |
| 122 |
# Set slave position to the BEGIN log event |
| 123 |
--replace_result $master_pos_begin <master_pos_begin> |
| 124 |
eval CHANGE MASTER TO MASTER_LOG_POS=$master_pos_begin, MASTER_USE_GTID=NO; |
| 125 |
BEGIN; |
| 126 |
# Hold lock |
| 127 |
SELECT * FROM t1 FOR UPDATE; |
| 128 |
# Wait until slave stopped with error 'Lock wait timeout exceeded' |
| 129 |
connection slave1; |
| 130 |
START SLAVE; |
| 131 |
let $slave_sql_errno= 1205; |
| 132 |
--source include/wait_for_slave_sql_error.inc |
| 133 |
connection slave; |
| 134 |
SELECT COUNT(*) FROM t2; |
| 135 |
COMMIT; |
| 136 |
--source include/start_slave.inc |
| 137 |
sync_with_master; |
| 138 |
# Check data from tables |
| 139 |
SELECT * FROM t1; |
| 140 |
SELECT * FROM t3; |
| 141 |
# Check that no error is reported |
| 142 |
source include/check_slave_is_running.inc; |
| 143 |
--echo |
| 144 |
|
| 145 |
# Clean up |
| 146 |
--echo *** Clean up *** |
| 147 |
connection master; |
| 148 |
DROP TABLE t1,t2,t3; |
| 149 |
sync_slave_with_master; |
| 150 |
SET global max_relay_log_size= @my_max_relay_log_size; |
| 151 |
|
| 152 |
--echo End of 5.1 tests |
| 153 |
--source include/rpl_end.inc |