From 63f91927870b41b8965e2a2a868abcc2b3672f68 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Thu, 7 Jan 2021 19:37:47 +0100 Subject: MDEV-17251 SHOW STATUS unnecessary calls calc_sum_of_all_status 1. only call calc_sum_of_all_status() if a global SHOW_xxx_STATUS variable is to be returned 2. only lock LOCK_status when copying global_status_var, but not when iterating all threads --- sql/sql_parse.cc | 1 + 1 file changed, 1 insertion(+) (limited to 'sql/sql_parse.cc') diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index 54937116383..131ba4a86c5 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -2179,6 +2179,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd, break; general_log_print(thd, command, NullS); status_var_increment(thd->status_var.com_stat[SQLCOM_SHOW_STATUS]); + *current_global_status_var= global_status_var; calc_sum_of_all_status(current_global_status_var); if (!(uptime= (ulong) (thd->start_time - server_start_time))) queries_per_second1000= 0; -- cgit v1.2.1 From 259a1902a066d01547e5d70ba0e4837d1be62e7b Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Fri, 5 Feb 2021 15:00:38 +0100 Subject: cleanup: THD::abort_current_cond_wait() * reuse the loop in THD::abort_current_cond_wait, don't duplicate it * find_thread_by_id should return whatever it has found, it's the caller's task not to kill COM_DAEMON (if the caller's a killer) and other minor changes --- sql/sql_parse.cc | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) (limited to 'sql/sql_parse.cc') diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index de96f0c8924..7b90bac2a42 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -9079,10 +9079,9 @@ struct find_thread_callback_arg }; -my_bool find_thread_callback(THD *thd, find_thread_callback_arg *arg) +static my_bool find_thread_callback(THD *thd, find_thread_callback_arg *arg) { - if (thd->get_command() != COM_DAEMON && - arg->id == (arg->query_id ? thd->query_id : (longlong) thd->thread_id)) + if (arg->id == (arg->query_id ? thd->query_id : (longlong) thd->thread_id)) { mysql_mutex_lock(&thd->LOCK_thd_kill); // Lock from delete arg->thd= thd; @@ -9100,10 +9099,9 @@ THD *find_thread_by_id(longlong id, bool query_id) } #ifdef WITH_WSREP -my_bool find_thread_with_thd_data_lock_callback(THD *thd, find_thread_callback_arg *arg) +static my_bool find_thread_with_thd_data_lock_callback(THD *thd, find_thread_callback_arg *arg) { - if (thd->get_command() != COM_DAEMON && - arg->id == (arg->query_id ? thd->query_id : (longlong) thd->thread_id)) + if (arg->id == (arg->query_id ? thd->query_id : (longlong) thd->thread_id)) { if (WSREP(thd)) mysql_mutex_lock(&thd->LOCK_thd_data); mysql_mutex_lock(&thd->LOCK_thd_kill); // Lock from delete @@ -9137,10 +9135,14 @@ kill_one_thread(THD *thd, longlong id, killed_state kill_signal, killed_type typ DBUG_ENTER("kill_one_thread"); DBUG_PRINT("enter", ("id: %lld signal: %u", id, (uint) kill_signal)); #ifdef WITH_WSREP - if (id && (tmp= find_thread_by_id_with_thd_data_lock(id, type == KILL_TYPE_QUERY))) + tmp= find_thread_by_id_with_thd_data_lock(id, type == KILL_TYPE_QUERY); #else - if (id && (tmp= find_thread_by_id(id, type == KILL_TYPE_QUERY))) + tmp= find_thread_by_id(id, type == KILL_TYPE_QUERY); #endif + if (!tmp) + DBUG_RETURN(error); + + if (tmp->get_command() != COM_DAEMON) { /* If we're SUPER, we can KILL anything, including system-threads. @@ -9194,11 +9196,11 @@ kill_one_thread(THD *thd, longlong id, killed_state kill_signal, killed_type typ else error= (type == KILL_TYPE_QUERY ? ER_KILL_QUERY_DENIED_ERROR : ER_KILL_DENIED_ERROR); + } #ifdef WITH_WSREP - if (WSREP(tmp)) mysql_mutex_unlock(&tmp->LOCK_thd_data); + if (WSREP(tmp)) mysql_mutex_unlock(&tmp->LOCK_thd_data); #endif - mysql_mutex_unlock(&tmp->LOCK_thd_kill); - } + mysql_mutex_unlock(&tmp->LOCK_thd_kill); DBUG_PRINT("exit", ("%d", error)); DBUG_RETURN(error); } -- cgit v1.2.1 From 9703cffa8cb57e2fe29719f4aae3282bfae82878 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Fri, 5 Feb 2021 14:59:27 +0100 Subject: don't take mutexes conditionally --- sql/sql_parse.cc | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) (limited to 'sql/sql_parse.cc') diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index 7b90bac2a42..dd0e5cfa34e 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -9098,12 +9098,11 @@ THD *find_thread_by_id(longlong id, bool query_id) return arg.thd; } -#ifdef WITH_WSREP static my_bool find_thread_with_thd_data_lock_callback(THD *thd, find_thread_callback_arg *arg) { if (arg->id == (arg->query_id ? thd->query_id : (longlong) thd->thread_id)) { - if (WSREP(thd)) mysql_mutex_lock(&thd->LOCK_thd_data); + mysql_mutex_lock(&thd->LOCK_thd_data); mysql_mutex_lock(&thd->LOCK_thd_kill); // Lock from delete arg->thd= thd; return 1; @@ -9116,7 +9115,6 @@ THD *find_thread_by_id_with_thd_data_lock(longlong id, bool query_id) server_threads.iterate(find_thread_with_thd_data_lock_callback, &arg); return arg.thd; } -#endif /** kill one thread. @@ -9134,11 +9132,7 @@ kill_one_thread(THD *thd, longlong id, killed_state kill_signal, killed_type typ uint error= (type == KILL_TYPE_QUERY ? ER_NO_SUCH_QUERY : ER_NO_SUCH_THREAD); DBUG_ENTER("kill_one_thread"); DBUG_PRINT("enter", ("id: %lld signal: %u", id, (uint) kill_signal)); -#ifdef WITH_WSREP tmp= find_thread_by_id_with_thd_data_lock(id, type == KILL_TYPE_QUERY); -#else - tmp= find_thread_by_id(id, type == KILL_TYPE_QUERY); -#endif if (!tmp) DBUG_RETURN(error); @@ -9197,10 +9191,8 @@ kill_one_thread(THD *thd, longlong id, killed_state kill_signal, killed_type typ error= (type == KILL_TYPE_QUERY ? ER_KILL_QUERY_DENIED_ERROR : ER_KILL_DENIED_ERROR); } -#ifdef WITH_WSREP - if (WSREP(tmp)) mysql_mutex_unlock(&tmp->LOCK_thd_data); -#endif mysql_mutex_unlock(&tmp->LOCK_thd_kill); + mysql_mutex_unlock(&tmp->LOCK_thd_data); DBUG_PRINT("exit", ("%d", error)); DBUG_RETURN(error); } @@ -9246,7 +9238,7 @@ static my_bool kill_threads_callback(THD *thd, kill_threads_callback_arg *arg) return 1; if (!arg->threads_to_kill.push_back(thd, arg->thd->mem_root)) { - if (WSREP(thd)) mysql_mutex_lock(&thd->LOCK_thd_data); + mysql_mutex_lock(&thd->LOCK_thd_data); mysql_mutex_lock(&thd->LOCK_thd_kill); // Lock from delete } } @@ -9290,7 +9282,7 @@ static uint kill_threads_for_user(THD *thd, LEX_USER *user, */ next_ptr= it2++; mysql_mutex_unlock(&ptr->LOCK_thd_kill); - if (WSREP(ptr)) mysql_mutex_unlock(&ptr->LOCK_thd_data); + mysql_mutex_unlock(&ptr->LOCK_thd_data); (*rows)++; } while ((ptr= next_ptr)); } -- cgit v1.2.1 From eac8341df4c3c7b98360f4e9498acf393dc055e3 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Sun, 7 Feb 2021 17:48:58 +0100 Subject: MDEV-23328 Server hang due to Galera lock conflict resolution adaptation of 29bbcac0ee8 for 10.4 --- sql/sql_parse.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'sql/sql_parse.cc') diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index dd0e5cfa34e..d71d29bc85a 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -9102,8 +9102,8 @@ static my_bool find_thread_with_thd_data_lock_callback(THD *thd, find_thread_cal { if (arg->id == (arg->query_id ? thd->query_id : (longlong) thd->thread_id)) { - mysql_mutex_lock(&thd->LOCK_thd_data); mysql_mutex_lock(&thd->LOCK_thd_kill); // Lock from delete + mysql_mutex_lock(&thd->LOCK_thd_data); // XXX DELME arg->thd= thd; return 1; } @@ -9238,8 +9238,8 @@ static my_bool kill_threads_callback(THD *thd, kill_threads_callback_arg *arg) return 1; if (!arg->threads_to_kill.push_back(thd, arg->thd->mem_root)) { - mysql_mutex_lock(&thd->LOCK_thd_data); mysql_mutex_lock(&thd->LOCK_thd_kill); // Lock from delete + mysql_mutex_lock(&thd->LOCK_thd_data); } } } -- cgit v1.2.1 From 259b945204eec0dc623fd861c0f83fcb2b3bd763 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Fri, 12 Feb 2021 15:05:24 +0100 Subject: remove find_thread_with_thd_data_lock_callback let the caller take the lock if needed --- sql/sql_parse.cc | 27 +++++---------------------- 1 file changed, 5 insertions(+), 22 deletions(-) (limited to 'sql/sql_parse.cc') diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index d71d29bc85a..9d9831d9209 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -9098,24 +9098,6 @@ THD *find_thread_by_id(longlong id, bool query_id) return arg.thd; } -static my_bool find_thread_with_thd_data_lock_callback(THD *thd, find_thread_callback_arg *arg) -{ - if (arg->id == (arg->query_id ? thd->query_id : (longlong) thd->thread_id)) - { - mysql_mutex_lock(&thd->LOCK_thd_kill); // Lock from delete - mysql_mutex_lock(&thd->LOCK_thd_data); // XXX DELME - arg->thd= thd; - return 1; - } - return 0; -} -THD *find_thread_by_id_with_thd_data_lock(longlong id, bool query_id) -{ - find_thread_callback_arg arg(id, query_id); - server_threads.iterate(find_thread_with_thd_data_lock_callback, &arg); - return arg.thd; -} - /** kill one thread. @@ -9132,7 +9114,7 @@ kill_one_thread(THD *thd, longlong id, killed_state kill_signal, killed_type typ uint error= (type == KILL_TYPE_QUERY ? ER_NO_SUCH_QUERY : ER_NO_SUCH_THREAD); DBUG_ENTER("kill_one_thread"); DBUG_PRINT("enter", ("id: %lld signal: %u", id, (uint) kill_signal)); - tmp= find_thread_by_id_with_thd_data_lock(id, type == KILL_TYPE_QUERY); + tmp= find_thread_by_id(id, type == KILL_TYPE_QUERY); if (!tmp) DBUG_RETURN(error); @@ -9159,6 +9141,7 @@ kill_one_thread(THD *thd, longlong id, killed_state kill_signal, killed_type typ faster and do a harder kill than KILL_SYSTEM_THREAD; */ + mysql_mutex_lock(&tmp->LOCK_thd_data); // for various wsrep* checks below #ifdef WITH_WSREP if (((thd->security_ctx->master_access & SUPER_ACL) || thd->security_ctx->user_matches(tmp->security_ctx)) && @@ -9180,8 +9163,8 @@ kill_one_thread(THD *thd, longlong id, killed_state kill_signal, killed_type typ else #endif /* WITH_WSREP */ { - WSREP_DEBUG("kill_one_thread %llu, victim: %llu wsrep_aborter %llu by signal %d", - thd->thread_id, id, tmp->wsrep_aborter, kill_signal); + WSREP_DEBUG("kill_one_thread %llu, victim: %llu wsrep_aborter %llu by signal %d", + thd->thread_id, id, tmp->wsrep_aborter, kill_signal); tmp->awake_no_mutex(kill_signal); WSREP_DEBUG("victim: %llu taken care of", id); error= 0; @@ -9190,9 +9173,9 @@ kill_one_thread(THD *thd, longlong id, killed_state kill_signal, killed_type typ else error= (type == KILL_TYPE_QUERY ? ER_KILL_QUERY_DENIED_ERROR : ER_KILL_DENIED_ERROR); + mysql_mutex_unlock(&tmp->LOCK_thd_data); } mysql_mutex_unlock(&tmp->LOCK_thd_kill); - mysql_mutex_unlock(&tmp->LOCK_thd_data); DBUG_PRINT("exit", ("%d", error)); DBUG_RETURN(error); } -- cgit v1.2.1