| 1 |
############################################################################### |
| 2 |
# Bug#20369401: MTS STOP SLAVE TAKES WAY TOO LONG(WHEN WORKER THREADS ARE SLOW) |
| 3 |
# |
| 4 |
# Problem: |
| 5 |
# ======== |
| 6 |
# TOP SLAVE waits workers to catch up the queue, which may |
| 7 |
# take a lot of time for the command to finish. STOP SLAVE |
| 8 |
# must be executed quickly, even if workers are slow. |
| 9 |
############################################################################### |
| 10 |
# Following test demonstrates that STOP SLAVE command will not leave any gaps. |
| 11 |
# It first creates two databases (d1 and d2) and setup slave to use two parallel |
| 12 |
# workers. The test case then insert on the slave a tuple that will block |
| 13 |
# writes on d2 and generate gaps. Finally, the test case executes "STOP SLAVE" |
| 14 |
# and verify that the SQL thread was properly stopped and left no gaps. |
| 15 |
|
| 16 |
--source include/have_binlog_format_statement.inc |
| 17 |
--source include/only_mts_replica_parallel_workers.inc |
| 18 |
--source include/only_mts_replica_parallel_type_database.inc |
| 19 |
--source include/master-slave.inc |
| 20 |
|
| 21 |
--let $slave_stop_wait=5 |
| 22 |
|
| 23 |
--echo #### I. Initialize #### |
| 24 |
|
| 25 |
--source include/rpl_connection_slave.inc |
| 26 |
--source include/stop_slave.inc |
| 27 |
SET @save.innodb_lock_wait_timeout= @@global.innodb_lock_wait_timeout; |
| 28 |
--eval set @@global.innodb_lock_wait_timeout=$slave_stop_wait + 1000 |
| 29 |
|
| 30 |
--source include/start_slave.inc |
| 31 |
|
| 32 |
--source include/rpl_connection_master.inc |
| 33 |
CREATE DATABASE d1; |
| 34 |
CREATE DATABASE d2; |
| 35 |
CREATE TABLE d1.t (a INT PRIMARY KEY, name text) ENGINE=INNODB; |
| 36 |
CREATE TABLE d2.t (a INT PRIMARY KEY, name text) ENGINE=INNODB; |
| 37 |
|
| 38 |
--echo #### II. Prepare test scenario #### |
| 39 |
|
| 40 |
--source include/sync_slave_sql_with_master.inc |
| 41 |
BEGIN; |
| 42 |
INSERT INTO d2.t VALUES (2, 'Slave local'); # Hold T3 |
| 43 |
INSERT INTO d1.t VALUES (3, 'Slave local'); # Hold T6 |
| 44 |
|
| 45 |
--source include/rpl_connection_master.inc |
| 46 |
INSERT INTO d1.t VALUES (1, 'T1'); |
| 47 |
INSERT INTO d2.t VALUES (1, 'T2'); |
| 48 |
INSERT INTO d2.t VALUES (2, 'T3'); # This will be a gap when executed on slave |
| 49 |
INSERT INTO d2.t VALUES (3, 'T4'); # This will be a gap when executed on slave |
| 50 |
INSERT INTO d1.t VALUES (2, 'T5'); |
| 51 |
INSERT INTO d1.t VALUES (3, 'T6'); |
| 52 |
INSERT INTO d2.t VALUES (4, 'T7'); # This should not be executed after STOP SLAVE |
| 53 |
INSERT INTO d2.t VALUES (5, 'T8'); # This should not be executed after STOP SLAVE |
| 54 |
INSERT INTO d1.t VALUES (4, 'T9'); # This should not be executed after STOP SLAVE |
| 55 |
|
| 56 |
--source include/rpl_connection_slave1.inc |
| 57 |
--let $table=d2.t |
| 58 |
--let $count=1 |
| 59 |
--source include/wait_until_rows_count.inc |
| 60 |
|
| 61 |
--let $table=d1.t |
| 62 |
--let $count=2 |
| 63 |
--source include/wait_until_rows_count.inc |
| 64 |
|
| 65 |
--echo # Now d1.t has two rows and d2.t has one row. |
| 66 |
|
| 67 |
# Wait for coordinator to populate worker's queues. |
| 68 |
--let $show_statement= SHOW PROCESSLIST |
| 69 |
--let $field= State |
| 70 |
--let $condition= = 'Replica has read all relay log; waiting for more updates' |
| 71 |
--source include/wait_show_condition.inc |
| 72 |
|
| 73 |
--echo # Now coordinator has read the entire relay log and populated workers' queues. |
| 74 |
|
| 75 |
# There is now a gap at T3,T4 |
| 76 |
SELECT * FROM d2.t; |
| 77 |
SELECT * FROM d1.t; |
| 78 |
|
| 79 |
--echo #### Verify that STOP SLAVE stops at gap less state #### |
| 80 |
|
| 81 |
--send STOP SLAVE |
| 82 |
|
| 83 |
--source include/rpl_connection_slave.inc |
| 84 |
# Despite time elapsed, the slave should still be running, waiting for the |
| 85 |
# queue to be completed. |
| 86 |
--sleep $slave_stop_wait |
| 87 |
--let $show_statement= SHOW PROCESSLIST |
| 88 |
--let $field= State |
| 89 |
--let $condition= = 'Waiting for workers to exit' |
| 90 |
--source include/wait_show_condition.inc |
| 91 |
|
| 92 |
--echo # Now coordinator is waiting for the worker to consume its queue. |
| 93 |
ROLLBACK; |
| 94 |
--source include/wait_for_slave_sql_to_stop.inc |
| 95 |
|
| 96 |
|
| 97 |
--echo # III. Now all slave threads have stopped. Verify that worker completed its queue: |
| 98 |
--echo # d2 should contain Т2, Т3, Т4. |
| 99 |
--let $assert_cond= MAX(a)=3 FROM d2.t; |
| 100 |
--let $assert_text= Rows until T3 in d2.t must be replicated now |
| 101 |
--source include/assert.inc |
| 102 |
|
| 103 |
--echo # d1 should contain Т1, Т5, T6. |
| 104 |
--let $assert_cond= MAX(a)=3 FROM d1.t; |
| 105 |
--let $assert_text= Rows until 2 in d1.t must be replicated now |
| 106 |
--source include/assert.inc |
| 107 |
--source include/start_slave.inc |
| 108 |
|
| 109 |
--source include/rpl_connection_slave1.inc |
| 110 |
--reap |
| 111 |
|
| 112 |
# |
| 113 |
# Cleanup |
| 114 |
# |
| 115 |
--source include/rpl_connection_slave.inc |
| 116 |
SET @@global.innodb_lock_wait_timeout= @save.innodb_lock_wait_timeout; |
| 117 |
--source include/rpl_connection_master.inc |
| 118 |
DROP DATABASE d1; |
| 119 |
DROP DATABASE d2; |
| 120 |
--source include/sync_slave_sql_with_master.inc |
| 121 |
|
| 122 |
--source include/rpl_end.inc |