From a3ba3aab5ad62b03d58ab64b0e10679ae9f583c8 Mon Sep 17 00:00:00 2001 From: Daniele Sciascia Date: Thu, 8 Mar 2018 11:11:03 +0100 Subject: [PATCH] MDEV-13549 Wrong usage of mutex 'LOCK_wsrep_thd' and 'LOCK_thd_kill' test galera.MW-286 Test MW-286 occasionally failed with error the following message: ``` safe_mutex: Found wrong usage of mutex 'LOCK_wsrep_thd' and 'LOCK_thd_kill' Mutex currently locked (in reverse order): LOCK_thd_kill mariadb-server/sql/sql_class.h line 3535 LOCK_wsrep_thd mariadb-server/sql/wsrep_thd.cc line 88 ``` The fix consists in calling thd->reset_killed() in wsrep_mysql_parse() after LOCK_wsrep_thd is unlocked. Which avoids the taking locks LOCK_wsrep_thd and LOCK_thd_kill in reverse order. --- sql/sql_parse.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index 4dd8d9e124e..97d743d9a42 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -7193,7 +7193,6 @@ static void wsrep_mysql_parse(THD *thd, char *rawbuf, uint length, thd->wsrep_conflict_state == CERT_FAILURE) { thd->reset_for_next_command(); - thd->reset_killed(); if (is_autocommit && thd->lex->sql_command != SQLCOM_SELECT && (thd->wsrep_retry_counter < thd->variables.wsrep_retry_autocommit)) @@ -7221,17 +7220,18 @@ static void wsrep_mysql_parse(THD *thd, char *rawbuf, uint length, thd->thread_id, is_autocommit, thd->wsrep_retry_counter, thd->variables.wsrep_retry_autocommit, thd->query()); my_error(ER_LOCK_DEADLOCK, MYF(0), "wsrep aborted transaction"); - thd->reset_killed(); thd->wsrep_conflict_state= NO_CONFLICT; if (thd->wsrep_conflict_state != REPLAYING) thd->wsrep_retry_counter= 0; // reset } + mysql_mutex_unlock(&thd->LOCK_wsrep_thd); + thd->reset_killed(); } else { set_if_smaller(thd->wsrep_retry_counter, 0); // reset; eventually ok + mysql_mutex_unlock(&thd->LOCK_wsrep_thd); } - mysql_mutex_unlock(&thd->LOCK_wsrep_thd); } /* If retry is requested clean up explain structure */