From 7144f7f2d17bdf03fbd28dfdd6b4d6bf689e7aaa Mon Sep 17 00:00:00 2001 From: Seppo Jaakola Date: Sun, 17 Feb 2013 00:22:40 +0200 Subject: [PATCH] References https://mariadb.atlassian.net/browse/MDEV-4176 Avoiding ha_kill_query for aborts initiated by replicator --- sql/sql_class.cc | 11 ++++++++--- sql/sql_class.h | 1 + sql/sql_parse.cc | 4 ++++ sql/wsrep_mysqld.h | 2 +- storage/innobase/handler/ha_innodb.cc | 10 +++++----- storage/innobase/handler/ha_innodb.h | 2 +- storage/xtradb/handler/ha_innodb.cc | 10 +++++----- storage/xtradb/handler/ha_innodb.h | 2 +- 8 files changed, 26 insertions(+), 16 deletions(-) diff --git a/sql/sql_class.cc b/sql/sql_class.cc index 0cc3732806e..974ad8a2632 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -893,10 +893,11 @@ extern "C" void wsrep_thd_set_wsrep_last_query_id(THD *thd, query_id_t id) { thd->wsrep_last_query_id= id; } -extern "C" void wsrep_thd_awake(THD *thd, my_bool signal) +extern "C" void wsrep_thd_awake(THD* bf_thd, THD *thd, my_bool signal) { if (signal) { + thd->wsrep_bf_thd = bf_thd; mysql_mutex_lock(&thd->LOCK_thd_data); thd->awake(KILL_QUERY); mysql_mutex_unlock(&thd->LOCK_thd_data); @@ -1114,7 +1115,7 @@ THD::THD() wsrep_consistency_check = NO_CONSISTENCY_CHECK; wsrep_status_vars = 0; wsrep_mysql_replicated = 0; - + wsrep_bf_thd = NULL; #endif /* Call to init() below requires fully initialized Open_tables_state. */ reset_open_tables_state(this); @@ -1469,6 +1470,7 @@ void THD::init(void) wsrep_seqno_changed= false; wsrep_consistency_check = NO_CONSISTENCY_CHECK; wsrep_mysql_replicated = 0; + wsrep_bf_thd = NULL; #endif if (variables.sql_log_bin) variables.option_bits|= OPTION_BIN_LOG; @@ -1836,8 +1838,11 @@ void THD::awake(killed_state state_to_set) /* Interrupt target waiting inside a storage engine. */ if (state_to_set != NOT_KILLED) +#ifdef WITH_WSREP + if (!wsrep_bf_thd || wsrep_bf_thd->wsrep_exec_mode == LOCAL_STATE) +#else ha_kill_query(this, thd_kill_level(this)); - +#endif /* WITH_WSREP */ /* Broadcast a condition to kick the target if it is waiting on it. */ if (mysys_var) { diff --git a/sql/sql_class.h b/sql/sql_class.h index a216c2146fd..fc3d3087f2c 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -2376,6 +2376,7 @@ public: wsrep_consistency_check; wsrep_stats_var* wsrep_status_vars; int wsrep_mysql_replicated; + THD* wsrep_bf_thd; #endif /* WITH_WSREP */ /** Internal parser state. diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index 27f68698ef5..b21826d735f 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -786,6 +786,7 @@ bool do_command(THD *thd) else if (thd->wsrep_conflict_state == ABORTED) { thd->store_globals(); + thd->wsrep_bf_thd = NULL; } thd->wsrep_query_state= QUERY_EXEC; @@ -1059,6 +1060,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd, thd->mysys_var->abort = 0; thd->wsrep_conflict_state = NO_CONFLICT; thd->wsrep_retry_counter = 0; + thd->wsrep_bf_thd = NULL; /* Increment threads running to compensate dec_thread_running() called after dispatch_end label. @@ -6131,6 +6133,7 @@ static void wsrep_mysql_parse(THD *thd, char *rawbuf, uint length, my_error(ER_LOCK_DEADLOCK, MYF(0), "wsrep aborted transaction"); } thd->wsrep_conflict_state= ABORTED; + thd->wsrep_bf_thd = NULL; wsrep->post_rollback(wsrep, &thd->wsrep_trx_handle); break; default: @@ -7992,6 +7995,7 @@ static void wsrep_client_rollback(THD *thd) } mysql_mutex_lock(&thd->LOCK_wsrep_thd); thd->wsrep_conflict_state= ABORTED; + thd->wsrep_bf_thd = NULL; } static enum wsrep_status wsrep_apply_sql( diff --git a/sql/wsrep_mysqld.h b/sql/wsrep_mysqld.h index 0709a2c1f34..bb1695563cf 100644 --- a/sql/wsrep_mysqld.h +++ b/sql/wsrep_mysqld.h @@ -205,7 +205,7 @@ extern "C" query_id_t wsrep_thd_query_id(THD *thd); extern "C" char * wsrep_thd_query(THD *thd); extern "C" query_id_t wsrep_thd_wsrep_last_query_id(THD *thd); extern "C" void wsrep_thd_set_wsrep_last_query_id(THD *thd, query_id_t id); -extern "C" void wsrep_thd_awake(THD *thd, my_bool signal); +extern "C" void wsrep_thd_awake(THD* bf_thd, THD *thd, my_bool signal); diff --git a/storage/innobase/handler/ha_innodb.cc b/storage/innobase/handler/ha_innodb.cc index f0f889cad86..9c663dd5a33 100644 --- a/storage/innobase/handler/ha_innodb.cc +++ b/storage/innobase/handler/ha_innodb.cc @@ -12376,7 +12376,7 @@ wsrep_innobase_kill_one_trx(void *bf_thd_ptr, trx_t *bf_trx, trx_t *victim_trx, WSREP_DEBUG("victim %llu in MUST ABORT state", victim_trx->id); wsrep_thd_UNLOCK(thd); - wsrep_thd_awake(thd, signal); + wsrep_thd_awake(bf_thd, thd, signal); DBUG_RETURN(0); break; case ABORTED: @@ -12395,7 +12395,7 @@ wsrep_innobase_kill_one_trx(void *bf_thd_ptr, trx_t *bf_trx, trx_t *victim_trx, WSREP_DEBUG("kill query for: %ld", wsrep_thd_thread_id(thd)); - wsrep_thd_awake(thd, signal); + wsrep_thd_awake(bf_thd, thd, signal); WSREP_DEBUG("kill trx QUERY_COMMITTING for %llu", victim_trx->id); @@ -12448,14 +12448,14 @@ wsrep_innobase_kill_one_trx(void *bf_thd_ptr, trx_t *bf_trx, trx_t *victim_trx, lock_cancel_waiting_and_release(wait_lock); } - wsrep_thd_awake(thd, signal); + wsrep_thd_awake(bf_thd, thd, signal); } else { /* abort currently executing query */ DBUG_PRINT("wsrep",("sending KILL_QUERY to: %ld", wsrep_thd_thread_id(thd))); WSREP_DEBUG("kill query for: %ld", wsrep_thd_thread_id(thd)); - wsrep_thd_awake(thd, signal); + wsrep_thd_awake(bf_thd, thd, signal); /* for BF thd, we need to prevent him from committing */ if (wsrep_thd_exec_mode(thd) == REPL_RECV) { @@ -12546,7 +12546,7 @@ wsrep_abort_transaction(handlerton* hton, THD *bf_thd, THD *victim_thd, wsrep_thd_LOCK(victim_thd); wsrep_thd_set_conflict_state(victim_thd, MUST_ABORT); wsrep_thd_UNLOCK(victim_thd); - wsrep_thd_awake(victim_thd, signal); + wsrep_thd_awake(bf_thd, victim_thd, signal); } DBUG_RETURN(-1); } diff --git a/storage/innobase/handler/ha_innodb.h b/storage/innobase/handler/ha_innodb.h index 052e215deca..6777221ff13 100644 --- a/storage/innobase/handler/ha_innodb.h +++ b/storage/innobase/handler/ha_innodb.h @@ -328,7 +328,7 @@ extern "C" query_id_t wsrep_thd_query_id(THD *thd); extern "C" char * wsrep_thd_query(THD *thd); extern "C" query_id_t wsrep_thd_wsrep_last_query_id(THD *thd); extern "C" void wsrep_thd_set_wsrep_last_query_id(THD *thd, query_id_t id); -extern "C" void wsrep_thd_awake(THD *thd, my_bool signal); +extern "C" void wsrep_thd_awake(THD* bf_thd, THD *thd, my_bool signal); #endif typedef struct trx_struct trx_t; /********************************************************************//** diff --git a/storage/xtradb/handler/ha_innodb.cc b/storage/xtradb/handler/ha_innodb.cc index f931068404a..e0dbfcca737 100644 --- a/storage/xtradb/handler/ha_innodb.cc +++ b/storage/xtradb/handler/ha_innodb.cc @@ -13502,7 +13502,7 @@ wsrep_innobase_kill_one_trx(trx_t *bf_trx, trx_t *victim_trx, ibool signal) WSREP_DEBUG("victim %llu in MUST ABORT state", victim_trx->id); wsrep_thd_UNLOCK(thd); - wsrep_thd_awake(thd, signal); + wsrep_thd_awake(bf_thd, thd, signal); DBUG_RETURN(0); break; case ABORTED: @@ -13521,7 +13521,7 @@ wsrep_innobase_kill_one_trx(trx_t *bf_trx, trx_t *victim_trx, ibool signal) WSREP_DEBUG("kill query for: %ld", wsrep_thd_thread_id(thd)); - wsrep_thd_awake(thd, signal); + wsrep_thd_awake(bf_thd, thd, signal); WSREP_DEBUG("kill trx QUERY_COMMITTING for %llu", victim_trx->id); @@ -13574,14 +13574,14 @@ wsrep_innobase_kill_one_trx(trx_t *bf_trx, trx_t *victim_trx, ibool signal) lock_cancel_waiting_and_release(wait_lock); } - wsrep_thd_awake(thd, signal); + wsrep_thd_awake(bf_thd, thd, signal); } else { /* abort currently executing query */ DBUG_PRINT("wsrep",("sending KILL_QUERY to: %ld", wsrep_thd_thread_id(thd))); WSREP_DEBUG("kill query for: %ld", wsrep_thd_thread_id(thd)); - wsrep_thd_awake(thd, signal); + wsrep_thd_awake(bf_thd, thd, signal); /* for BF thd, we need to prevent him from committing */ if (wsrep_thd_exec_mode(thd) == REPL_RECV) { @@ -13672,7 +13672,7 @@ wsrep_abort_transaction(handlerton* hton, THD *bf_thd, THD *victim_thd, wsrep_thd_LOCK(victim_thd); wsrep_thd_set_conflict_state(victim_thd, MUST_ABORT); wsrep_thd_UNLOCK(victim_thd); - wsrep_thd_awake(victim_thd, signal); + wsrep_thd_awake(bf_thd, victim_thd, signal); } DBUG_RETURN(-1); } diff --git a/storage/xtradb/handler/ha_innodb.h b/storage/xtradb/handler/ha_innodb.h index fc10b0ca338..851fbb828e4 100644 --- a/storage/xtradb/handler/ha_innodb.h +++ b/storage/xtradb/handler/ha_innodb.h @@ -404,7 +404,7 @@ extern "C" query_id_t wsrep_thd_query_id(THD *thd); extern "C" char * wsrep_thd_query(THD *thd); extern "C" query_id_t wsrep_thd_wsrep_last_query_id(THD *thd); extern "C" void wsrep_thd_set_wsrep_last_query_id(THD *thd, query_id_t id); -extern "C" void wsrep_thd_awake(THD *thd, my_bool signal); +extern "C" void wsrep_thd_awake(THD* bf_thd, THD *thd, my_bool signal); #endif typedef struct trx_struct trx_t; /********************************************************************//**