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");