diff --git a/include/wsrep.h b/include/wsrep.h index 703b89f966a..835c8d77c72 100644 --- a/include/wsrep.h +++ b/include/wsrep.h @@ -25,41 +25,40 @@ #define DBUG_ASSERT_IF_WSREP(A) DBUG_ASSERT(A) #define WSREP_MYSQL_DB (char *)"mysql" -#define WSREP_TO_ISOLATION_BEGIN_IF(db_, table_, table_list_) \ - if (WSREP_ON && WSREP(thd) && wsrep_to_isolation_begin(thd, db_, table_, table_list_)) + +#define WSREP_TO_ISOLATION_BEGIN_IF(db_, table_, table_list_) \ + if (WSREP_ON && WSREP(thd) && \ + wsrep_to_isolation_begin(thd, db_, table_, table_list_)) #define WSREP_TO_ISOLATION_BEGIN(db_, table_, table_list_) \ - if (WSREP_ON && WSREP(thd) && wsrep_to_isolation_begin(thd, db_, table_, table_list_)) \ + if (WSREP_ON && WSREP(thd) && \ + wsrep_to_isolation_begin(thd, db_, table_, table_list_)) \ goto wsrep_error_label; #define WSREP_TO_ISOLATION_BEGIN_CREATE(db_, table_, table_list_, create_info_) \ - if (WSREP_ON && WSREP(thd) && \ - wsrep_to_isolation_begin(thd, db_, table_, \ - table_list_, nullptr, nullptr, create_info_))\ + if (WSREP_ON && WSREP(thd) && \ + wsrep_to_isolation_begin(thd, db_, table_, \ + table_list_, nullptr, nullptr, create_info_)) \ goto wsrep_error_label; #define WSREP_TO_ISOLATION_BEGIN_ALTER(db_, table_, table_list_, alter_info_, fk_tables_, create_info_) \ - if (WSREP(thd) && wsrep_thd_is_local(thd) && \ - wsrep_to_isolation_begin(thd, db_, table_, \ - table_list_, alter_info_, \ - fk_tables_, create_info_)) \ + if (WSREP(thd) && \ + wsrep_to_isolation_begin(thd, db_, table_, \ + table_list_, alter_info_, \ + fk_tables_, create_info_)) \ goto wsrep_error_label; -#define WSREP_TO_ISOLATION_END \ - if ((WSREP(thd) && wsrep_thd_is_local_toi(thd)) || \ - wsrep_thd_is_in_rsu(thd)) \ - wsrep_to_isolation_end(thd); - /* Checks if lex->no_write_to_binlog is set for statements that use LOCAL or NO_WRITE_TO_BINLOG. */ -#define WSREP_TO_ISOLATION_BEGIN_WRTCHK(db_, table_, table_list_) \ - if (WSREP(thd) && !thd->lex->no_write_to_binlog \ - && wsrep_to_isolation_begin(thd, db_, table_, table_list_)) goto wsrep_error_label; +#define WSREP_TO_ISOLATION_BEGIN_WRTCHK(db_, table_, table_list_) \ + if (WSREP(thd) && !thd->lex->no_write_to_binlog && \ + wsrep_to_isolation_begin(thd, db_, table_, table_list_)) \ + goto wsrep_error_label; #define WSREP_TO_ISOLATION_BEGIN_FK_TABLES(db_, table_, table_list_, fk_tables) \ - if (WSREP(thd) && !thd->lex->no_write_to_binlog \ + if (WSREP(thd) && !thd->lex->no_write_to_binlog \ && wsrep_to_isolation_begin(thd, db_, table_, table_list_, NULL, fk_tables)) #define WSREP_SYNC_WAIT(thd_, before_) \ @@ -77,7 +76,6 @@ #define WSREP_TO_ISOLATION_BEGIN(db_, table_, table_list_) do { } while(0) #define WSREP_TO_ISOLATION_BEGIN_ALTER(db_, table_, table_list_, alter_info_, fk_tables_, create_info_) #define WSREP_TO_ISOLATION_BEGIN_FK_TABLES(db_, table_, table_list_, fk_tables_) -#define WSREP_TO_ISOLATION_END #define WSREP_TO_ISOLATION_BEGIN_CREATE(db_, table_, table_list_, create_info_) #define WSREP_TO_ISOLATION_BEGIN_WRTCHK(db_, table_, table_list_) #define WSREP_SYNC_WAIT(thd_, before_) diff --git a/sql/event_data_objects.cc b/sql/event_data_objects.cc index a5e2326127c..50abb31721f 100644 --- a/sql/event_data_objects.cc +++ b/sql/event_data_objects.cc @@ -1545,7 +1545,9 @@ end: if (sql_command_set) { - WSREP_TO_ISOLATION_END; +#ifdef WITH_WSREP + wsrep_to_isolation_end(thd); +#endif thd->lex->sql_command = sql_command_save; } diff --git a/sql/sql_acl.cc b/sql/sql_acl.cc index 7b8b2a7ec55..723092d8aa0 100644 --- a/sql/sql_acl.cc +++ b/sql/sql_acl.cc @@ -4028,10 +4028,9 @@ end: #ifdef WITH_WSREP wsrep_error_label: - if (WSREP(thd) && !thd->wsrep_applier) + if (WSREP(thd)) { - WSREP_TO_ISOLATION_END; - + wsrep_to_isolation_end(thd); thd->set_query(query_save); } #endif /* WITH_WSREP */ @@ -4172,10 +4171,9 @@ int acl_set_default_role(THD *thd, const char *host, const char *user, #ifdef WITH_WSREP wsrep_error_label: - if (WSREP(thd) && !thd->wsrep_applier) + if (WSREP(thd)) { - WSREP_TO_ISOLATION_END; - + wsrep_to_isolation_end(thd); thd->set_query(query_save); } #endif /* WITH_WSREP */ diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index 98a437c5991..038b914b2fb 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -6114,7 +6114,8 @@ finish: #ifdef WITH_WSREP thd->wsrep_consistency_check= NO_CONSISTENCY_CHECK; - WSREP_TO_ISOLATION_END; + if (wsrep_thd_is_toi(thd) || wsrep_thd_is_in_rsu(thd)) + wsrep_to_isolation_end(thd); /* Force release of transactional locks if not in active MST and wsrep is on. */ diff --git a/sql/wsrep_mysqld.cc b/sql/wsrep_mysqld.cc index 6877b7c1a4d..64fa8db26fc 100644 --- a/sql/wsrep_mysqld.cc +++ b/sql/wsrep_mysqld.cc @@ -2697,6 +2697,17 @@ static void wsrep_RSU_end(THD *thd) thd->variables.wsrep_on= 1; } +static inline bool is_replaying_connection(THD *thd) +{ + bool ret; + + mysql_mutex_lock(&thd->LOCK_thd_data); + ret= (thd->wsrep_trx().state() == wsrep::transaction::s_replaying) ? true : false; + mysql_mutex_unlock(&thd->LOCK_thd_data); + + return ret; +} + int wsrep_to_isolation_begin(THD *thd, const char *db_, const char *table_, const TABLE_LIST* table_list, const Alter_info *alter_info, @@ -2706,9 +2717,18 @@ int wsrep_to_isolation_begin(THD *thd, const char *db_, const char *table_, /* No isolation for applier or replaying threads. */ - if (!wsrep_thd_is_local(thd)) return 0; + if (!wsrep_thd_is_local(thd)) + { + if (wsrep_OSU_method_get(thd) == WSREP_OSU_TOI) + WSREP_DEBUG("%s TOI Begin: %s", + is_replaying_connection(thd) ? "Replay" : "Apply", + wsrep_thd_query(thd)); + + return 0; + } int ret= 0; + mysql_mutex_lock(&thd->LOCK_thd_data); if (thd->wsrep_trx().state() == wsrep::transaction::s_must_abort) @@ -2791,25 +2811,32 @@ int wsrep_to_isolation_begin(THD *thd, const char *db_, const char *table_, void wsrep_to_isolation_end(THD *thd) { - DBUG_ASSERT(wsrep_thd_is_local_toi(thd) || - wsrep_thd_is_in_rsu(thd)); - - thd->variables.lock_wait_timeout= thd->variables.saved_lock_wait_timeout; - if (wsrep_thd_is_local_toi(thd)) { + thd->variables.lock_wait_timeout= thd->variables.saved_lock_wait_timeout; DBUG_ASSERT(wsrep_OSU_method_get(thd) == WSREP_OSU_TOI); wsrep_TOI_end(thd); } else if (wsrep_thd_is_in_rsu(thd)) { + thd->variables.lock_wait_timeout= thd->variables.saved_lock_wait_timeout; DBUG_ASSERT(wsrep_OSU_method_get(thd) == WSREP_OSU_RSU); wsrep_RSU_end(thd); } else { - DBUG_ASSERT(0); + /* Applier or replaying threads just output TO END */ + if (wsrep_debug) + { + wsrep::client_state& client_state(thd->wsrep_cs()); + WSREP_DEBUG("%s TO END: %lld: %s", + is_replaying_connection(thd) ? "Replay" : "Apply", + client_state.toi_meta().seqno().get(), + wsrep_thd_query(thd)); + } + return; } + if (wsrep_emulate_bin_log) wsrep_thd_binlog_trx_reset(thd); } @@ -2957,17 +2984,6 @@ static inline bool is_client_connection(THD *thd) return (thd->wsrep_client_thread && thd->variables.wsrep_on); } -static inline bool is_replaying_connection(THD *thd) -{ - bool ret; - - mysql_mutex_lock(&thd->LOCK_thd_data); - ret= (thd->wsrep_trx().state() == wsrep::transaction::s_replaying) ? true : false; - mysql_mutex_unlock(&thd->LOCK_thd_data); - - return ret; -} - static inline bool is_committing_connection(THD *thd) { bool ret;