mySQL 5.0.11 sources for tomato
[tomato.git] / release / src / router / mysql / mysql-test / extra / rpl_tests / rpl_deadlock.test
blobbd446c869431296cd8c19635af7cc2a805d9b3c0
1 # See if slave restarts the transaction after failing on an InnoDB deadlock error.
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.
11 --source include/master-slave.inc
13 # 0) Prepare tables and data
14 --echo *** Prepare tables and data ***
16 connection master;
17 eval CREATE TABLE t1 (a INT NOT NULL, KEY(a)) ENGINE=$engine_type;
18 eval CREATE TABLE t2 (a INT) ENGINE=$engine_type;
19 eval CREATE TABLE t3 (a INT NOT NULL, KEY(a)) ENGINE=$engine_type;
20 sync_slave_with_master;
22 SHOW CREATE TABLE t1;
23 SHOW CREATE TABLE t2;
24 SHOW CREATE TABLE t3;
25 SHOW VARIABLES LIKE 'slave_transaction_retries';
26 --source include/stop_slave.inc
28 connection master;
29 BEGIN;
30 INSERT INTO t1 VALUES (1);
31 # We make a long transaction here
32 INSERT INTO t2 VALUES (2), (2), (2), (2), (2), (2), (2), (2), (2), (2);
33 INSERT INTO t3 VALUES (3);
34 COMMIT;
35 save_master_pos;
36 # Save BEGIN event into variable
37 let $master_pos_begin= query_get_value(SHOW BINLOG EVENTS, Pos, 5);
38 --echo
40 # 1) Test deadlock
41 # Block slave SQL thread, wait retries of transaction, unlock slave before lock timeout
42 --echo *** Test deadlock ***
44 connection slave;
45 BEGIN;
46 SELECT * FROM t1 FOR UPDATE;
47 # Save variable 'Slave_retried_transactions' before deadlock
48 let $slave_retried_transactions= query_get_value(SHOW GLOBAL STATUS LIKE 'Slave_retried_transactions', Value, 1);
49 START SLAVE;
50 # Wait until SQL thread blocked: variable 'Slave_retried_transactions' will incremented
51 let $status_var= Slave_retried_transactions;
52 let $status_var_value= $slave_retried_transactions;
53 let $status_type= GLOBAL;
54 let $status_var_comparsion= >;
55 --source include/wait_for_status_var.inc
56 SELECT COUNT(*) FROM t2;
57 COMMIT;
58 sync_with_master;
60 # Check the data
61 SELECT * FROM t1;
62 SELECT * FROM t3;
63 # Check that no error is reported
64 source include/check_slave_is_running.inc;
65 --echo
67 # 2) Test lock wait timeout
68 # Block slave and wait lock timeout error
69 --echo *** Test lock wait timeout ***
71 connection slave;
72 --source include/stop_slave.inc
73 DELETE FROM t2;
74 # Set slave position to the BEGIN log event
75 --replace_result $master_pos_begin MASTER_POS_BEGIN
76 eval CHANGE MASTER TO MASTER_LOG_POS=$master_pos_begin; 
77 BEGIN;
78 # Hold lock
79 SELECT * FROM t1 FOR UPDATE;
80 # Wait until slave stopped with error 'Lock wait timeout exceeded'
81 START SLAVE;
82 let $slave_sql_errno= 1205;
83 --source include/wait_for_slave_sql_error.inc
84 SELECT COUNT(*) FROM t2;
85 COMMIT;
86 --source include/start_slave.inc
87 sync_with_master;
88 # Check data from tables
89 SELECT * FROM t1;
90 SELECT * FROM t3;
91 # Check that no error is reported
92 source include/check_slave_is_running.inc;
93 --echo
95 # 3) Test lock wait timeout and purged relay log
96 # Set max_relay_log_size=0, block slave and wait lock timeout error.
97 # Restart slave and check that no erros appear
98 --echo *** Test lock wait timeout and purged relay logs ***
100 connection slave;
101 SET @my_max_relay_log_size= @@global.max_relay_log_size;
102 SET global max_relay_log_size=0;
103 --source include/stop_slave.inc
104 DELETE FROM t2;
105 # Set slave position to the BEGIN log event
106 --replace_result $master_pos_begin MASTER_POS_BEGIN
107 eval CHANGE MASTER TO MASTER_LOG_POS=$master_pos_begin; 
108 BEGIN;
109 # Hold lock
110 SELECT * FROM t1 FOR UPDATE;
111 # Wait until slave stopped with error 'Lock wait timeout exceeded'
112 START SLAVE;
113 let $slave_sql_errno= 1205;
114 --source include/wait_for_slave_sql_error.inc
115 SELECT COUNT(*) FROM t2;
116 COMMIT;
117 --source include/start_slave.inc
118 sync_with_master;
119 # Check data from tables
120 SELECT * FROM t1;
121 SELECT * FROM t3;
122 # Check that no error is reported
123 source include/check_slave_is_running.inc;
124 --echo
126 # Clean up
127 --echo *** Clean up ***
128 connection master;
129 DROP TABLE t1,t2,t3;
130 sync_slave_with_master;
131 SET global max_relay_log_size= @my_max_relay_log_size;
133 --echo End of 5.1 tests
134 --source include/rpl_end.inc