From c66609017b25bf066008a3dec9e3ecd00fc5ce8b Mon Sep 17 00:00:00 2001 From: sjaakola Date: Tue, 21 Apr 2015 16:22:53 +0300 Subject: [PATCH] Refs codership/mysql-wsrep#113 Protecting non replicated FLUSH session from brute force aborts --- sql/sql_class.cc | 1 + sql/sql_parse.cc | 17 +++++++++++++++++ sql/wsrep_hton.cc | 2 +- sql/wsrep_mysqld.cc | 7 ++++--- sql/wsrep_mysqld.h | 2 ++ 5 files changed, 25 insertions(+), 4 deletions(-) diff --git a/sql/sql_class.cc b/sql/sql_class.cc index 4ce99da7c7d..af03a3b10b3 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -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"; diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index 42ad69d84ec..13646c3a0c6 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -4165,6 +4165,11 @@ end_with_restore_list: } 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 @@ -4667,6 +4672,12 @@ end_with_restore_list: 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; @@ -4687,6 +4698,12 @@ end_with_restore_list: { 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*/ /* diff --git a/sql/wsrep_hton.cc b/sql/wsrep_hton.cc index 03bf072edcc..9809b5d9550 100644 --- a/sql/wsrep_hton.cc +++ b/sql/wsrep_hton.cc @@ -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; } diff --git a/sql/wsrep_mysqld.cc b/sql/wsrep_mysqld.cc index 548db8245c3..1e46d577875 100644 --- a/sql/wsrep_mysqld.cc +++ b/sql/wsrep_mysqld.cc @@ -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) { diff --git a/sql/wsrep_mysqld.h b/sql/wsrep_mysqld.h index 414284f45fd..55323d68a48 100644 --- a/sql/wsrep_mysqld.h +++ b/sql/wsrep_mysqld.h @@ -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 */