From 6b685ea7b0776430d45b095cb4be3ef0739a3c04 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Wed, 28 Sep 2022 18:55:15 +0200 Subject: correctness assert thd_get_ha_data() can be used without a lock, but only from the current thd thread, when calling from anoher thread it *must* be protected by thd->LOCK_thd_data * fix group commit code to take thd->LOCK_thd_data * remove innobase_close_connection() from the innodb background thread, it's not needed after 87775402cd0c and was failing the assert with current_thd==0 --- include/my_pthread.h | 1 + sql/log.cc | 4 ++++ sql/sql_class.cc | 1 + storage/innobase/handler/ha_innodb.cc | 4 ---- 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/include/my_pthread.h b/include/my_pthread.h index f5bfda49a28..1c83e77a41b 100644 --- a/include/my_pthread.h +++ b/include/my_pthread.h @@ -437,6 +437,7 @@ void safe_mutex_free_deadlock_data(safe_mutex_t *mp); #define my_cond_wait(A,B) safe_cond_wait((A), (B), __FILE__, __LINE__) #else +#define safe_mutex_is_owner(mp) (1) #define safe_mutex_assert_owner(mp) do {} while (0) #define safe_mutex_assert_not_owner(mp) do {} while (0) #define safe_mutex_setflags(mp, F) do {} while (0) diff --git a/sql/log.cc b/sql/log.cc index c679e8f5111..ec212825787 100644 --- a/sql/log.cc +++ b/sql/log.cc @@ -8512,7 +8512,11 @@ MYSQL_BIN_LOG::trx_group_commit_leader(group_commit_entry *leader) ++num_commits; if (current->cache_mngr->using_xa && likely(!current->error) && DBUG_EVALUATE_IF("skip_commit_ordered", 0, 1)) + { + mysql_mutex_lock(¤t->thd->LOCK_thd_data); run_commit_ordered(current->thd, current->all); + mysql_mutex_unlock(¤t->thd->LOCK_thd_data); + } current->thd->wakeup_subsequent_commits(current->error); /* diff --git a/sql/sql_class.cc b/sql/sql_class.cc index 87f5262f9ce..cd80602a9f2 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -462,6 +462,7 @@ void thd_storage_lock_wait(THD *thd, long long value) extern "C" void *thd_get_ha_data(const THD *thd, const struct handlerton *hton) { + DBUG_ASSERT(thd == current_thd || mysql_mutex_is_owner(&thd->LOCK_thd_data)); return thd->ha_data[hton->slot].ha_ptr; } diff --git a/storage/innobase/handler/ha_innodb.cc b/storage/innobase/handler/ha_innodb.cc index 4a710a5c384..a3184abd2d3 100644 --- a/storage/innobase/handler/ha_innodb.cc +++ b/storage/innobase/handler/ha_innodb.cc @@ -1484,10 +1484,6 @@ innobase_destroy_background_thd( /*============================*/ MYSQL_THD thd) { - /* need to close the connection explicitly, the server won't do it - if innodb is in the PLUGIN_IS_DYING state */ - innobase_close_connection(innodb_hton_ptr, thd); - thd_set_ha_data(thd, innodb_hton_ptr, NULL); destroy_background_thd(thd); } -- cgit v1.2.1