diff options
author | Sujatha <sujatha.sivakumar@mariadb.com> | 2021-05-12 18:03:45 +0530 |
---|---|---|
committer | Sujatha <sujatha.sivakumar@mariadb.com> | 2021-05-17 16:38:58 +0530 |
commit | 88c7a58ecf231865492729f892f6aafe72cafdad (patch) | |
tree | 0f0bb7b84f180ffcff1ed5c2e0d9ea9dc5609ce1 /sql/sql_admin.cc | |
parent | 410e3c1a9a364219481392a408f12a432d83b2f2 (diff) | |
download | mariadb-git-88c7a58ecf231865492729f892f6aafe72cafdad.tar.gz |
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.
Diffstat (limited to 'sql/sql_admin.cc')
-rw-r--r-- | sql/sql_admin.cc | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/sql/sql_admin.cc b/sql/sql_admin.cc index 2b3593388bb..21afa1154f6 100644 --- a/sql/sql_admin.cc +++ b/sql/sql_admin.cc @@ -446,6 +446,7 @@ static bool mysql_admin_table(THD* thd, TABLE_LIST* tables, int compl_result_code; bool need_repair_or_alter= 0; wait_for_commit* suspended_wfc; + bool is_table_modified= false; DBUG_ENTER("mysql_admin_table"); DBUG_PRINT("enter", ("extra_open_options: %u", extra_open_options)); @@ -496,6 +497,10 @@ static bool mysql_admin_table(THD* thd, TABLE_LIST* tables, bool open_for_modify= org_open_for_modify; DBUG_PRINT("admin", ("table: '%s'.'%s'", table->db, table->table_name)); + DEBUG_SYNC(thd, "admin_command_kill_before_modify"); + + if (thd->is_killed()) + break; strxmov(table_name, db, ".", table->table_name, NullS); thd->open_options|= extra_open_options; table->lock_type= lock_type; @@ -1192,6 +1197,8 @@ send_result_message: { if (trans_commit_stmt(thd)) goto err; + if (!is_table_modified) + is_table_modified= true; } close_thread_tables(thd); thd->release_transactional_locks(); @@ -1214,8 +1221,9 @@ send_result_message: if (protocol->write()) goto err; + DEBUG_SYNC(thd, "admin_command_kill_after_modify"); } - if (is_cmd_replicated && !thd->lex->no_write_to_binlog) + if (is_table_modified && is_cmd_replicated && !thd->lex->no_write_to_binlog) { if (write_bin_log(thd, TRUE, thd->query(), thd->query_length())) goto err; |