Unified behaviour when calling "plugin->deinit" for all plugin's types #521
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Changes
This patch ensures that MySQL calls
plugin->deinit
with a valid plugin struct as argument no matter the plugin's type.There is no reasons not to pass the
plugin struct
for all the extensible plugin's types.Rationale
Plugins usually implement
"deinit"
and"deinit"
functions.Those functions are called only once during the plugin lifecycle, "init" when installing a plugin and "deinit" when uninstalling a plugin (or something went wrong during the init phase).
The following code shows how MySQL decides to call
deinit
From sql/sql_plugin.cc
Code explanation
Before calling
plugin->deinit
, MySQL verifies if for the given plugin's type there is a special function that handles the deinit phase. This is achieved by searching (using the plugin's type as index) in the arrayplugin_type_deinitialize
insql/sql_plugin.cc
.Currently, there are 3 special functions:
"ha_finalize_handlerton"
(MYSQL_STORAGE_PLUGIN),"finalize_schema_table"
(MYSQL_INFORMATION_SCHEMA_PLUGIN) and"finalize_audit_plugin"
(MYSQL_AUDIT_PLUGIN).If there is not a special function then MySQL check if the plugin exposes a "deinit" function and executes it passing the "plugin struct" as argument. Otherwise, MySQL calls the "special function" passing the plugin as argument. Then the special function check if the plugin exposes a "deinit" function and then calls it but it always passes
nullptr
as argument rather than the "plugin struct".Note: In case of
"init"
the code is similar but looks for special functions in the array"plugin_type_initialize"
The documentation says:
Doc does not explain that MySQL will always pass
nullptr
instead of the "plugin struct" for those plugin's types. Also it does not mention that it is plugin responsibility to check that pointer, using that pointer trusting it is not nullptr could crash MySQL.Because of that, plugins of type "MYSQL_STORAGE_PLUGIN", "MYSQL_INFORMATION_SCHEMA_PLUGIN" and "MYSQL_AUDIT_PLUGIN" need to do something similar to the code below: