From a87900843c41fceeeb8d65db21cd161bcaa8929b Mon Sep 17 00:00:00 2001 From: Lixun Peng Date: Thu, 29 Dec 2016 15:31:12 +0800 Subject: MDEV-10644 One of parallel replication threads remains active after STOP SLAVE SQL_THREAD completes Using mysql_mutex_trylock() instead of mysql_mutex_lock() for LOCK_active_mi in function show_slave_received_heartbeats() and show_heartbeat_period(). If can't aquire LOCK_active_mi lock after 1 seconds, then give up and just show SHOW_UNDEF. This is a temporary fix. If want to solve related problems completely, should change the LOCK_active_mi to mysql_rwlock_t. --- sql/mysqld.cc | 44 ++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 40 insertions(+), 4 deletions(-) diff --git a/sql/mysqld.cc b/sql/mysqld.cc index fda4fab9d26..0fbf1be942c 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -7329,11 +7329,29 @@ static int show_slave_received_heartbeats(THD *thd, SHOW_VAR *var, char *buff) Master_info *mi= NULL; longlong tmp; LINT_INIT(tmp); + int count; var->type= SHOW_LONGLONG; var->value= buff; - mysql_mutex_lock(&LOCK_active_mi); - if (master_info_index) + + count= 0; + while (count < 10) + { + if (mysql_mutex_trylock(&LOCK_active_mi) == EBUSY) + /* If can't get LOCK_active_mi, sleep 0.1 second and try again. */ + my_sleep(100000); + else + break; + + count++; + } + /* It means we can't get the lock, then just show SHOW_UNDEF */ + if (count >= 10) + { + var->type= SHOW_UNDEF; + return 0; + } + if (master_info_index) { mi= master_info_index-> get_master_info(&thd->variables.default_master_connection, @@ -7355,11 +7373,29 @@ static int show_heartbeat_period(THD *thd, SHOW_VAR *var, char *buff) Master_info *mi= NULL; float tmp; LINT_INIT(tmp); + int count; var->type= SHOW_CHAR; var->value= buff; - mysql_mutex_lock(&LOCK_active_mi); - if (master_info_index) + + count= 0; + while (count < 10) + { + if (mysql_mutex_trylock(&LOCK_active_mi) == EBUSY) + /* If can't get LOCK_active_mi, sleep 0.1 second and try again. */ + my_sleep(100000); + else + break; + + count++; + } + /* It means we can't get the lock, then just show SHOW_UNDEF */ + if (count >= 10) + { + var->type= SHOW_UNDEF; + return 0; + } + if (master_info_index) { mi= master_info_index-> get_master_info(&thd->variables.default_master_connection, -- cgit v1.2.1