From e022dde39c8ea00aef3754d57ef802cb1b25b285 Mon Sep 17 00:00:00 2001 From: Monty Date: Thu, 7 Sep 2017 15:43:45 +0300 Subject: [PATCH] Cleanups and fixes - Added missing delete thd in bootstrap() - Delete wrong 'delete thd' in start_wsrep_THD() - Added missing 'delete thd' in case of SCHEDULER_ONE_THREAD_PER_CONNECTION - Delete wrong dec_thread_running() in destroy_thd() as it caused thread_running to be wrong. - Moved reset_killed() to a normal function to make it easier to debug - Added check of mutex in wsrep_aborting_thd... functions --- sql/mysqld.cc | 1 + sql/sql_class.cc | 18 +++++++++++++++++- sql/sql_class.h | 15 +-------------- sql/wsrep_mysqld.cc | 12 +++--------- 4 files changed, 22 insertions(+), 24 deletions(-) diff --git a/sql/mysqld.cc b/sql/mysqld.cc index d3786cdd5f5..3bad009a8bc 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -6396,6 +6396,7 @@ static void bootstrap(MYSQL_FILE *file) sql_print_warning("Can't create thread to handle bootstrap (errno= %d)", error); bootstrap_error=-1; + delete thd; DBUG_VOID_RETURN; } /* Wait for thread to die */ diff --git a/sql/sql_class.cc b/sql/sql_class.cc index 9ce2cfb0a80..1af0b789c1f 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -2067,6 +2067,23 @@ int THD::killed_errno() } +void THD::reset_killed() +{ + /* + Resetting killed has to be done under a mutex to ensure + its not done during an awake() call. + */ + DBUG_ENTER("reset_killed"); + if (killed != NOT_KILLED) + { + mysql_mutex_lock(&LOCK_thd_kill); + killed= NOT_KILLED; + killed_err= 0; + mysql_mutex_unlock(&LOCK_thd_kill); + } + DBUG_VOID_RETURN; +} + /* Remember the location of thread info, the structure needed for the structure for the net buffer @@ -4630,7 +4647,6 @@ void destroy_thd(MYSQL_THD thd) thd->add_status_to_global(); unlink_not_visible_thd(thd); delete thd; - dec_thread_running(); } void reset_thd(MYSQL_THD thd) diff --git a/sql/sql_class.h b/sql/sql_class.h index 1cbe70b2d5e..92f28a4dc07 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -3737,20 +3737,7 @@ public: } } int killed_errno(); - inline void reset_killed() - { - /* - Resetting killed has to be done under a mutex to ensure - its not done during an awake() call. - */ - if (killed != NOT_KILLED) - { - mysql_mutex_lock(&LOCK_thd_kill); - killed= NOT_KILLED; - killed_err= 0; - mysql_mutex_unlock(&LOCK_thd_kill); - } - } + void reset_killed(); inline void reset_kill_query() { if (killed < KILL_CONNECTION) diff --git a/sql/wsrep_mysqld.cc b/sql/wsrep_mysqld.cc index 7caff913106..63d153a7af4 100644 --- a/sql/wsrep_mysqld.cc +++ b/sql/wsrep_mysqld.cc @@ -1935,7 +1935,6 @@ pthread_handler_t start_wsrep_THD(void *arg) close_connection(thd, ER_OUT_OF_RESOURCES); statistic_increment(aborted_connects,&LOCK_status); MYSQL_CALLBACK(thread_scheduler, end_thread, (thd, 0)); - goto error; } @@ -1958,7 +1957,6 @@ pthread_handler_t start_wsrep_THD(void *arg) close_connection(thd, ER_OUT_OF_RESOURCES); statistic_increment(aborted_connects,&LOCK_status); MYSQL_CALLBACK(thread_scheduler, end_thread, (thd, 0)); - delete thd; goto error; } @@ -2002,13 +2000,8 @@ pthread_handler_t start_wsrep_THD(void *arg) // at server shutdown } - if (thread_handling > SCHEDULER_ONE_THREAD_PER_CONNECTION) - { - mysql_mutex_lock(&LOCK_thread_count); - thd->unlink(); - mysql_mutex_unlock(&LOCK_thread_count); - delete thd; - } + unlink_not_visible_thd(thd); + delete thd; my_thread_end(); return(NULL); @@ -2733,6 +2726,7 @@ void wsrep_unlock_rollback() my_bool wsrep_aborting_thd_contains(THD *thd) { + mysql_mutex_assert_owner(&LOCK_wsrep_rollback); wsrep_aborting_thd_t abortees = wsrep_aborting_thd; while (abortees) {