@@ -1271,9 +1271,9 @@ bool dispatch_command(enum enum_server_command command, THD *thd,
12711271 if (thd->wsrep_conflict_state == ABORTED &&
12721272 command != COM_STMT_CLOSE && command != COM_QUIT)
12731273 {
1274+ mysql_mutex_unlock (&thd->LOCK_thd_data );
12741275 my_error (ER_LOCK_DEADLOCK, MYF (0 ), " wsrep aborted transaction" );
12751276 WSREP_DEBUG (" Deadlock error for: %s" , thd->query ());
1276- mysql_mutex_unlock (&thd->LOCK_thd_data );
12771277 thd->reset_killed ();
12781278 thd->mysys_var ->abort = 0 ;
12791279 thd->wsrep_conflict_state = NO_CONFLICT;
@@ -7290,34 +7290,44 @@ static void wsrep_mysql_parse(THD *thd, char *rawbuf, uint length,
72907290 thd->lex ->sql_command != SQLCOM_SELECT &&
72917291 (thd->wsrep_retry_counter < thd->variables .wsrep_retry_autocommit ))
72927292 {
7293- WSREP_DEBUG (" wsrep retrying AC query: %s" ,
7293+ mysql_mutex_unlock (&thd->LOCK_thd_data );
7294+ WSREP_DEBUG (" wsrep retrying AC query: %s" ,
72947295 (thd->query ()) ? thd->query () : " void" );
72957296
72967297 /* Performance Schema Interface instrumentation, end */
72977298 MYSQL_END_STATEMENT (thd->m_statement_psi , thd->get_stmt_da ());
72987299 thd->m_statement_psi = NULL ;
72997300 thd->m_digest = NULL ;
7301+ // Released thd->LOCK_thd_data above as below could end up
7302+ // close_thread_tables()/close_open_tables()/close_thread_table()/mysql_mutex_lock(&thd->LOCK_thd_data)
73007303 close_thread_tables (thd);
73017304
7305+ mysql_mutex_lock (&thd->LOCK_thd_data );
73027306 thd->wsrep_conflict_state = RETRY_AUTOCOMMIT;
73037307 thd->wsrep_retry_counter ++; // grow
73047308 wsrep_copy_query (thd);
73057309 thd->set_time ();
73067310 parser_state->reset (rawbuf, length);
7311+ mysql_mutex_unlock (&thd->LOCK_thd_data );
73077312 }
73087313 else
73097314 {
7310- WSREP_DEBUG (" %s, thd: %lu is_AC: %d, retry: %lu - %lu SQL: %s" ,
7311- (thd->wsrep_conflict_state == ABORTED) ?
7315+ mysql_mutex_unlock (&thd->LOCK_thd_data );
7316+ // This does dirty read to wsrep variables but it is only a debug code
7317+ WSREP_DEBUG (" %s, thd: %lu is_AC: %d, retry: %lu - %lu SQL: %s" ,
7318+ (thd->wsrep_conflict_state == ABORTED) ?
73127319 " BF Aborted" : " cert failure" ,
7313- thd->thread_id , is_autocommit, thd->wsrep_retry_counter ,
7320+ thd->thread_id , is_autocommit, thd->wsrep_retry_counter ,
73147321 thd->variables .wsrep_retry_autocommit , thd->query ());
73157322 my_error (ER_LOCK_DEADLOCK, MYF (0 ), " wsrep aborted transaction" );
7323+
7324+ mysql_mutex_lock (&thd->LOCK_thd_data );
73167325 thd->wsrep_conflict_state = NO_CONFLICT;
73177326 if (thd->wsrep_conflict_state != REPLAYING)
73187327 thd->wsrep_retry_counter = 0 ; // reset
7328+ mysql_mutex_unlock (&thd->LOCK_thd_data );
73197329 }
7320- mysql_mutex_unlock (&thd-> LOCK_thd_data );
7330+
73217331 thd->reset_killed ();
73227332 }
73237333 else
@@ -7353,6 +7363,7 @@ static void wsrep_mysql_parse(THD *thd, char *rawbuf, uint length,
73537363#endif /* WITH_WSREP */
73547364}
73557365
7366+
73567367/*
73577368 When you modify mysql_parse(), you may need to modify
73587369 mysql_test_parse_for_slave() in this same file.
0 commit comments