Skip to content

Commit 63c5bee

Browse files
sjaakolaNirbhay Choubey
authored andcommitted
Refs codership/mysql-wsrep#113 - Extended the protection of local FLUSH
sessions to cover all exclusive MDL locks
1 parent 417f778 commit 63c5bee

File tree

8 files changed

+26
-23
lines changed

8 files changed

+26
-23
lines changed

sql/mdl.cc

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3373,4 +3373,21 @@ void MDL_ticket::wsrep_report(bool debug)
33733373
psi_stage->m_name);
33743374
}
33753375
}
3376+
bool MDL_context::wsrep_has_explicit_locks()
3377+
{
3378+
MDL_ticket *ticket = NULL;
3379+
3380+
Ticket_iterator it(m_tickets[MDL_EXPLICIT]);
3381+
3382+
while ((ticket = it++))
3383+
{
3384+
if (ticket->m_type == MDL_EXCLUSIVE)
3385+
{
3386+
return true;
3387+
}
3388+
}
3389+
3390+
return false;
3391+
}
3392+
33763393
#endif /* WITH_WSREP */

sql/mdl.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -934,7 +934,8 @@ class MDL_context
934934
public:
935935
#ifdef WITH_WSREP
936936
THD *wsrep_get_thd() const { return get_thd(); }
937-
#endif
937+
bool wsrep_has_explicit_locks();
938+
#endif /* WITH_WSREP */
938939
void find_deadlock();
939940

940941
ulong get_thread_id() const { return thd_get_thread_id(get_thd()); }

sql/sql_class.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -861,7 +861,6 @@ extern "C" const char *wsrep_thd_exec_mode_str(THD *thd)
861861
return
862862
(!thd) ? "void" :
863863
(thd->wsrep_exec_mode == LOCAL_STATE) ? "local" :
864-
(thd->wsrep_exec_mode == LOCAL_FLUSH) ? "flush" :
865864
(thd->wsrep_exec_mode == REPL_RECV) ? "applier" :
866865
(thd->wsrep_exec_mode == TOTAL_ORDER) ? "total order" :
867866
(thd->wsrep_exec_mode == LOCAL_COMMIT) ? "local commit" : "void";

sql/sql_parse.cc

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4165,11 +4165,6 @@ case SQLCOM_PREPARE:
41654165
}
41664166

41674167
case SQLCOM_UNLOCK_TABLES:
4168-
#ifdef WITH_WSREP
4169-
mysql_mutex_lock(&thd->LOCK_wsrep_thd);
4170-
if (thd->wsrep_exec_mode == LOCAL_FLUSH) thd->wsrep_exec_mode = LOCAL_STATE;
4171-
mysql_mutex_unlock(&thd->LOCK_wsrep_thd);
4172-
#endif /* WITH_WSREP */
41734168
/*
41744169
It is critical for mysqldump --single-transaction --master-data that
41754170
UNLOCK TABLES does not implicitely commit a connection which has only
@@ -4672,12 +4667,6 @@ case SQLCOM_PREPARE:
46724667
FALSE, UINT_MAX, FALSE))
46734668
goto error;
46744669

4675-
#ifdef WITH_WSREP
4676-
mysql_mutex_lock(&thd->LOCK_wsrep_thd);
4677-
thd->wsrep_exec_mode = LOCAL_FLUSH;
4678-
mysql_mutex_unlock(&thd->LOCK_wsrep_thd);
4679-
#endif /* WITH_WSREP */
4680-
46814670
if (flush_tables_with_read_lock(thd, all_tables))
46824671
goto error;
46834672

@@ -4698,12 +4687,6 @@ case SQLCOM_PREPARE:
46984687
{
46994688
WSREP_TO_ISOLATION_BEGIN(WSREP_MYSQL_DB, NULL, NULL)
47004689
}
4701-
else
4702-
{
4703-
mysql_mutex_lock(&thd->LOCK_wsrep_thd);
4704-
thd->wsrep_exec_mode = LOCAL_FLUSH;
4705-
mysql_mutex_unlock(&thd->LOCK_wsrep_thd);
4706-
}
47074690
#endif /* WITH_WSREP*/
47084691

47094692
/*

sql/wsrep_hton.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ void wsrep_cleanup_transaction(THD *thd)
4040
thd->wsrep_ws_handle.trx_id= WSREP_UNDEFINED_TRX_ID;
4141
thd->wsrep_trx_meta.gtid= WSREP_GTID_UNDEFINED;
4242
thd->wsrep_trx_meta.depends_on= WSREP_SEQNO_UNDEFINED;
43-
if (thd->wsrep_exec_mode != LOCAL_FLUSH) thd->wsrep_exec_mode= LOCAL_STATE;
43+
thd->wsrep_exec_mode= LOCAL_STATE;
4444
return;
4545
}
4646

sql/wsrep_mysqld.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1500,7 +1500,7 @@ wsrep_grant_mdl_exception(MDL_context *requestor_ctx,
15001500
ret = TRUE;
15011501
}
15021502
else if (granted_thd->lex->sql_command == SQLCOM_FLUSH ||
1503-
granted_thd->wsrep_exec_mode == LOCAL_FLUSH)
1503+
granted_thd->mdl_context.wsrep_has_explicit_locks())
15041504
{
15051505
WSREP_DEBUG("BF thread waiting for FLUSH");
15061506
ticket->wsrep_report(wsrep_debug);

sql/wsrep_mysqld.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@ class THD;
3030
enum wsrep_exec_mode {
3131
/* Transaction processing before replication. */
3232
LOCAL_STATE,
33-
/* Local flush. */
34-
LOCAL_FLUSH,
3533
/* Slave thread applying write sets from other nodes or replaying thread. */
3634
REPL_RECV,
3735
/* Total-order-isolation mode */

sql/wsrep_thd.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -611,3 +611,8 @@ int wsrep_thd_in_locking_session(void *thd_ptr)
611611
return 0;
612612
}
613613

614+
bool wsrep_thd_has_explicit_locks(THD *thd)
615+
{
616+
assert(thd);
617+
return (thd->mdl_context.wsrep_has_explicit_locks());
618+
}

0 commit comments

Comments
 (0)