1
0
mirror of https://github.com/MariaDB/server.git synced 2025-08-08 11:22:35 +03:00

MDEV-22530: Aborting OPTIMIZE TABLE still logs in binary log and replicates to the Slave server.

Problem:
========
Aborting OPTIMIZE TABLE still logs in binary logs and replicates to the
Slave server. "Optimize table" command under execution, is killed by using
"Ctrl-C" as shown below.

MariaDB [test]> optimize table t2;
^CCtrl-C -- query killed. Continuing normally.

In spite of query execution being interrupted the query gets written to
binary log.

Analysis:
========
Admin command execution logic is not handling KILL command, hence it
ignores the KILL command and completes its execution.

Fix:
===
Check for thread killed notification, during admin command execution and
handle it. If thread kill occurs prior to any table modification the query
will not be written to binary log. If kill happens after at least one table
is modified then the query will be written to binary log. Ex: command in
execution is 'OPTIMIZE TABLE t1,t2' and the thread kill happens after t1
table is modified then 'OPTIMIZE TABLE t1,t2' will be written to binary log
as admin commands will not make the slave to diverge from master.
This commit is contained in:
Sujatha
2021-05-12 18:03:45 +05:30
parent 410e3c1a9a
commit 88c7a58ecf
3 changed files with 144 additions and 1 deletions

View File

@@ -0,0 +1,40 @@
#
# Kill OPTIMIZE command prior to table modification
#
RESET MASTER;
CREATE TABLE t1 (f INT) ENGINE=INNODB;
CREATE TABLE t2 (f INT) ENGINE=INNODB;
connect con1,127.0.0.1,root,,test,$MASTER_MYPORT,;
connection con1;
SET debug_sync='admin_command_kill_before_modify SIGNAL ready_to_be_killed WAIT_FOR master_cont';
OPTIMIZE TABLE t1,t2;
connection default;
SET debug_sync='now WAIT_FOR ready_to_be_killed';
KILL THD_ID;
SET debug_sync = 'reset';
disconnect con1;
include/show_binlog_events.inc
Log_name Pos Event_type Server_id End_log_pos Info
master-bin.000001 # Gtid # # GTID #-#-#
master-bin.000001 # Query # # use `test`; CREATE TABLE t1 (f INT) ENGINE=INNODB
master-bin.000001 # Gtid # # GTID #-#-#
master-bin.000001 # Query # # use `test`; CREATE TABLE t2 (f INT) ENGINE=INNODB
DROP TABLE t1,t2;
FLUSH LOGS;
#
# Kill OPTIMIZE command after table modification
#
CREATE TABLE t1 (f INT) ENGINE=INNODB;
CREATE TABLE t2 (f INT) ENGINE=INNODB;
connect con1,127.0.0.1,root,,test,$MASTER_MYPORT,;
connection con1;
SET debug_sync='admin_command_kill_after_modify SIGNAL ready_to_be_killed WAIT_FOR master_cont';
OPTIMIZE TABLE t1,t2;
connection default;
SET debug_sync='now WAIT_FOR ready_to_be_killed';
KILL THD_ID;
SET debug_sync = 'reset';
disconnect con1;
DROP TABLE t1,t2;
FLUSH LOGS;
FOUND 1 /OPTIMIZE TABLE t1,t2/ in mysqlbinlog.out