From 7e08dd85d6271be4750c5989ccd5053df281d2aa Mon Sep 17 00:00:00 2001 From: Vladislav Vaintroub Date: Tue, 29 Oct 2019 18:32:14 +0100 Subject: [PATCH] MDEV-16264 prerequisite patch, ha_preshutdown. This is a prerequisite patch required to remove Innodb's thd_destructor_proxy thread. The patch implement pre-shutdown functionality for handlers. A storage engine might need to perform some work after all user connections are shut down, but before killing off the plugins. The reason is that an SE could still be using some of the server infrastructure. In case of Innodb this would be purge threads, that call into the server to calculate results of virtual function, acquire MDL locks on tables, or possibly also use the audit plugins. --- sql/handler.cc | 27 +++++++++++++++++++++++++++ sql/handler.h | 4 ++++ sql/mysqld.cc | 2 +- 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/sql/handler.cc b/sql/handler.cc index 67abe2362a3..46a0c313c80 100644 --- a/sql/handler.cc +++ b/sql/handler.cc @@ -868,6 +868,33 @@ void ha_end_backup() } +/* + Inform plugin of the server shutdown. + Called after all connections are down. + + Under some circumstances, storage engine might need to + so some work, before deinit() can be safely called. + (an example is Innodb purge that might call into server + to calculate virtual columns, which might potentially also + invoke other plugins, such as audit +*/ +static my_bool plugin_pre_shutdown(THD *, plugin_ref plugin, void *) +{ + handlerton *hton= plugin_hton(plugin); + if (hton->pre_shutdown) + hton->pre_shutdown(); + return FALSE; +} + + +void ha_pre_shutdown() +{ + plugin_foreach_with_mask(0, plugin_pre_shutdown, + MYSQL_STORAGE_ENGINE_PLUGIN, + PLUGIN_IS_DELETED | PLUGIN_IS_READY, 0); +} + + /* ======================================================================== ======================= TRANSACTIONS ===================================*/ diff --git a/sql/handler.h b/sql/handler.h index f23476242a0..65dd31933cc 100644 --- a/sql/handler.h +++ b/sql/handler.h @@ -1656,6 +1656,9 @@ struct handlerton /* backup */ void (*prepare_for_backup)(void); void (*end_backup)(void); + + /* Server shutdown early notification.*/ + void (*pre_shutdown)(void); }; @@ -4909,6 +4912,7 @@ int ha_delete_table(THD *thd, handlerton *db_type, const char *path, const LEX_CSTRING *db, const LEX_CSTRING *alias, bool generate_warning); void ha_prepare_for_backup(); void ha_end_backup(); +void ha_pre_shutdown(); /* statistics and info */ bool ha_show_status(THD *thd, handlerton *db_type, enum ha_stat_type stat); diff --git a/sql/mysqld.cc b/sql/mysqld.cc index 62b6ad5c33b..b3fb330f13c 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -5743,7 +5743,7 @@ int mysqld_main(int argc, char **argv) #endif close_connections(); - + ha_pre_shutdown(); clean_up(1); sd_notify(0, "STATUS=MariaDB server is down");