Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Protecting non replicated FLUSH session from brute force aborts
  • Loading branch information
sjaakola authored and Nirbhay Choubey committed Sep 10, 2015
1 parent 045b31c commit c666090
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 4 deletions.
1 change: 1 addition & 0 deletions sql/sql_class.cc
Original file line number Diff line number Diff line change
Expand Up @@ -861,6 +861,7 @@ extern "C" const char *wsrep_thd_exec_mode_str(THD *thd)
return
(!thd) ? "void" :
(thd->wsrep_exec_mode == LOCAL_STATE) ? "local" :
(thd->wsrep_exec_mode == LOCAL_FLUSH) ? "flush" :
(thd->wsrep_exec_mode == REPL_RECV) ? "applier" :
(thd->wsrep_exec_mode == TOTAL_ORDER) ? "total order" :
(thd->wsrep_exec_mode == LOCAL_COMMIT) ? "local commit" : "void";
Expand Down
17 changes: 17 additions & 0 deletions sql/sql_parse.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4165,6 +4165,11 @@ case SQLCOM_PREPARE:
}

case SQLCOM_UNLOCK_TABLES:
#ifdef WITH_WSREP
mysql_mutex_lock(&thd->LOCK_wsrep_thd);
if (thd->wsrep_exec_mode == LOCAL_FLUSH) thd->wsrep_exec_mode = LOCAL_STATE;
mysql_mutex_unlock(&thd->LOCK_wsrep_thd);
#endif /* WITH_WSREP */
/*
It is critical for mysqldump --single-transaction --master-data that
UNLOCK TABLES does not implicitely commit a connection which has only
Expand Down Expand Up @@ -4667,6 +4672,12 @@ case SQLCOM_PREPARE:
FALSE, UINT_MAX, FALSE))
goto error;

#ifdef WITH_WSREP
mysql_mutex_lock(&thd->LOCK_wsrep_thd);
thd->wsrep_exec_mode = LOCAL_FLUSH;
mysql_mutex_unlock(&thd->LOCK_wsrep_thd);
#endif /* WITH_WSREP */

if (flush_tables_with_read_lock(thd, all_tables))
goto error;

Expand All @@ -4687,6 +4698,12 @@ case SQLCOM_PREPARE:
{
WSREP_TO_ISOLATION_BEGIN(WSREP_MYSQL_DB, NULL, NULL)
}
else
{
mysql_mutex_lock(&thd->LOCK_wsrep_thd);
thd->wsrep_exec_mode = LOCAL_FLUSH;
mysql_mutex_unlock(&thd->LOCK_wsrep_thd);
}
#endif /* WITH_WSREP*/

/*
Expand Down
2 changes: 1 addition & 1 deletion sql/wsrep_hton.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ void wsrep_cleanup_transaction(THD *thd)
thd->wsrep_ws_handle.trx_id= WSREP_UNDEFINED_TRX_ID;
thd->wsrep_trx_meta.gtid= WSREP_GTID_UNDEFINED;
thd->wsrep_trx_meta.depends_on= WSREP_SEQNO_UNDEFINED;
thd->wsrep_exec_mode= LOCAL_STATE;
if (thd->wsrep_exec_mode != LOCAL_FLUSH) thd->wsrep_exec_mode= LOCAL_STATE;
return;
}

Expand Down
7 changes: 4 additions & 3 deletions sql/wsrep_mysqld.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1499,12 +1499,13 @@ wsrep_grant_mdl_exception(MDL_context *requestor_ctx,
mysql_mutex_unlock(&granted_thd->LOCK_wsrep_thd);
ret = TRUE;
}
else if (granted_thd->lex->sql_command == SQLCOM_FLUSH)
else if (granted_thd->lex->sql_command == SQLCOM_FLUSH ||
granted_thd->wsrep_exec_mode == LOCAL_FLUSH)
{
WSREP_DEBUG("mdl granted over FLUSH BF");
WSREP_DEBUG("BF thread waiting for FLUSH");
ticket->wsrep_report(wsrep_debug);
mysql_mutex_unlock(&granted_thd->LOCK_wsrep_thd);
ret = TRUE;
ret = FALSE;
}
else if (request_thd->lex->sql_command == SQLCOM_DROP_TABLE)
{
Expand Down
2 changes: 2 additions & 0 deletions sql/wsrep_mysqld.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ class THD;
enum wsrep_exec_mode {
/* Transaction processing before replication. */
LOCAL_STATE,
/* Local flush. */
LOCAL_FLUSH,
/* Slave thread applying write sets from other nodes or replaying thread. */
REPL_RECV,
/* Total-order-isolation mode */
Expand Down

0 comments on commit c666090

Please sign in to comment.