From 3dd91241cbe926be949a46809428e86dce47c362 Mon Sep 17 00:00:00 2001 From: Vladislav Vaintroub Date: Tue, 1 Jun 2021 10:25:27 +0200 Subject: [PATCH] MDEV-24985 Shutdown fails to abort current InnoDB lock waits On shutdown, to kill remaining connections, do the same thing that server does during KILL CONNECTION, i.e thd->awake(). The stripped-down KILL version, that was used prior to this patch for shutdown, missed the engine specific part (ha_kill_query) --- sql/mysqld.cc | 7 +++---- sql/sql_class.cc | 4 ++-- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/sql/mysqld.cc b/sql/mysqld.cc index 491931b4732..dcddb157cda 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -660,6 +660,7 @@ SHOW_COMP_OPTION have_openssl; #ifndef EMBEDDED_LIBRARY static std::atomic shutdown_user; #endif //EMBEDDED_LIBRARY +std::atomic shutdown_thread_id; /* Thread specific variables */ @@ -1532,10 +1533,7 @@ static my_bool kill_thread_phase_1(THD *thd, void *) if (DBUG_EVALUATE_IF("only_kill_system_threads", !thd->system_thread, 0)) return 0; - - thd->set_killed(KILL_SERVER_HARD); - MYSQL_CALLBACK(thread_scheduler, post_kill_notification, (thd)); - kill_thread(thd); + thd->awake(KILL_SERVER_HARD); return 0; } @@ -1666,6 +1664,7 @@ void kill_mysql(THD *thd) my_free(user); } + shutdown_thread_id= thd->thread_id; DBUG_EXECUTE_IF("mysql_admin_shutdown_wait_for_slaves", thd->lex->is_shutdown_wait_for_slaves= true;); DBUG_EXECUTE_IF("simulate_delay_at_shutdown", diff --git a/sql/sql_class.cc b/sql/sql_class.cc index 7c2014fe4b0..017ae3c5eff 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -1869,7 +1869,7 @@ void add_diff_to_status(STATUS_VAR *to_var, STATUS_VAR *from_var, @note Do always call this while holding LOCK_thd_kill. NOT_KILLED is used to awake a thread for a slave */ - +extern std::atomic shutdown_thread_id; void THD::awake_no_mutex(killed_state state_to_set) { DBUG_ENTER("THD::awake"); @@ -1893,7 +1893,7 @@ void THD::awake_no_mutex(killed_state state_to_set) if (state_to_set >= KILL_CONNECTION || state_to_set == NOT_KILLED) { #ifdef SIGNAL_WITH_VIO_CLOSE - if (this != current_thd) + if (this != current_thd && thread_id != shutdown_thread_id) { if(active_vio) vio_shutdown(active_vio, SHUT_RDWR);