| 1 |
# ==== Purpose ==== |
| 2 |
# |
| 3 |
# Test verifies that when an admin command execution is interrupted by KILL |
| 4 |
# command it should stop its execution. The admin command in binary log should |
| 5 |
# contain only the list of tables which have successfully executed admin |
| 6 |
# command prior to kill. |
| 7 |
# |
| 8 |
# ==== Implementation ==== |
| 9 |
# |
| 10 |
# Steps: |
| 11 |
# 0 - Create two table t1,t2. |
| 12 |
# 1 - Execute OPTIMIZE TABLE t1,t2 command. |
| 13 |
# 2 - Using debug sync mechanism kill OPTIMIZE TABLE command at a stage |
| 14 |
# where it has not optimized any table. |
| 15 |
# 3 - Check that OPTIMIZE TABLE command is not written to binary log. |
| 16 |
# 4 - Using debug sync mechanism hold the execution of OPTIMIZE TABLE after |
| 17 |
# t1 table optimization. Now kill the OPTIMIZE TABLE command. |
| 18 |
# 5 - Observe the binlog output, the OPTIMIZE TABLE command should display `t1,t2`. |
| 19 |
# 6 - Please note that, we binlog the entire query even if at least one |
| 20 |
# table is modified as admin commands are safe to replicate and they will |
| 21 |
# not make the slave to diverge. |
| 22 |
# |
| 23 |
# ==== References ==== |
| 24 |
# |
| 25 |
# MDEV-22530: Aborting OPTIMIZE TABLE still logs in binary log and replicates to the Slave server. |
| 26 |
# |
| 27 |
--source include/have_log_bin.inc |
| 28 |
--source include/have_debug.inc |
| 29 |
--source include/have_debug_sync.inc |
| 30 |
--source include/have_innodb.inc |
| 31 |
|
| 32 |
--echo # |
| 33 |
--echo # Kill OPTIMIZE command prior to table modification |
| 34 |
--echo # |
| 35 |
RESET MASTER; |
| 36 |
|
| 37 |
CREATE TABLE t1 (f INT) ENGINE=INNODB; |
| 38 |
CREATE TABLE t2 (f INT) ENGINE=INNODB; |
| 39 |
|
| 40 |
--connect(con1,127.0.0.1,root,,test,$MASTER_MYPORT,) |
| 41 |
--connection con1 |
| 42 |
SET debug_sync='admin_command_kill_before_modify SIGNAL ready_to_be_killed WAIT_FOR master_cont'; |
| 43 |
--send OPTIMIZE TABLE t1,t2 |
| 44 |
|
| 45 |
--connection default |
| 46 |
SET debug_sync='now WAIT_FOR ready_to_be_killed'; |
| 47 |
--let $thd_id= `SELECT ID FROM INFORMATION_SCHEMA.PROCESSLIST WHERE INFO LIKE '%OPTIMIZE TABLE %'` |
| 48 |
|
| 49 |
# Now kill. |
| 50 |
--replace_result $thd_id THD_ID |
| 51 |
eval KILL $thd_id; |
| 52 |
|
| 53 |
SET debug_sync = 'reset'; |
| 54 |
--disconnect con1 |
| 55 |
|
| 56 |
--source include/show_binlog_events.inc |
| 57 |
DROP TABLE t1,t2; |
| 58 |
|
| 59 |
RESET MASTER; |
| 60 |
|
| 61 |
--echo # |
| 62 |
--echo # Kill OPTIMIZE command after table modification |
| 63 |
--echo # |
| 64 |
|
| 65 |
CREATE TABLE t1 (f INT) ENGINE=INNODB; |
| 66 |
CREATE TABLE t2 (f INT) ENGINE=INNODB; |
| 67 |
|
| 68 |
--connect(con1,127.0.0.1,root,,test,$MASTER_MYPORT,) |
| 69 |
--connection con1 |
| 70 |
SET debug_sync='admin_command_kill_after_modify SIGNAL ready_to_be_killed WAIT_FOR master_cont'; |
| 71 |
--send OPTIMIZE TABLE t1,t2 |
| 72 |
|
| 73 |
--connection default |
| 74 |
SET debug_sync='now WAIT_FOR ready_to_be_killed'; |
| 75 |
--let $thd_id= `SELECT ID FROM INFORMATION_SCHEMA.PROCESSLIST WHERE INFO LIKE '%OPTIMIZE TABLE %'` |
| 76 |
|
| 77 |
# Now kill. |
| 78 |
--replace_result $thd_id THD_ID |
| 79 |
eval KILL $thd_id; |
| 80 |
|
| 81 |
SET debug_sync = 'reset'; |
| 82 |
--disconnect con1 |
| 83 |
|
| 84 |
--let $wait_binlog_event= OPTIMIZE |
| 85 |
--source include/wait_for_binlog_event.inc |
| 86 |
|
| 87 |
DROP TABLE t1,t2; |
| 88 |
let $binlog_file= query_get_value(SHOW MASTER STATUS, File, 1); |
| 89 |
FLUSH LOGS; |
| 90 |
|
| 91 |
--let $MYSQLD_DATADIR= `select @@datadir` |
| 92 |
--exec $MYSQL_BINLOG $MYSQLD_DATADIR/$binlog_file > $MYSQLTEST_VARDIR/tmp/mysqlbinlog.out |
| 93 |
|
| 94 |
--let SEARCH_PATTERN= OPTIMIZE TABLE t1,t2 |
| 95 |
--let SEARCH_FILE= $MYSQLTEST_VARDIR/tmp/mysqlbinlog.out |
| 96 |
--source include/search_pattern_in_file.inc |
| 97 |
|
| 98 |
--remove_file $MYSQLTEST_VARDIR/tmp/mysqlbinlog.out |