From 068a6819eb63bcb01fdfa037c9bf3bf63c33ee42 Mon Sep 17 00:00:00 2001 From: Yuchen Pei Date: Mon, 12 Feb 2024 21:08:22 +1100 Subject: [PATCH] MDEV-33441 Do not deinit plugin variables when retry requested After MDEV-31400, plugins are allowed to ask for retries when failing initialisation. However, such failures also cause plugin system variables to be deleted (plugin_variables_deinit()) before retrying and are not re-added during retry. We fix this by checking that if the plugin has requested a retry the variables are not deleted. Because plugin_deinitialize() also calls plugin_variables_deinit(), if the retry fails, the variables will still be deleted. Alternatives considered: - remove the plugin_variables_deinit() from plugin_initialize() error handling altogether. We decide to take a more conservative approach here. - re-add the system variables during retry. It is more complicated than simply iterating over plugin->system_vars and call my_hash_insert(). For example we will need to assign values to the test_load field and extract more code from test_plugin_options(), if that is possible. --- sql/sql_plugin.cc | 3 ++- .../mysql-test/spider/bugfix/r/mdev_33441.result | 7 +++++++ .../mysql-test/spider/bugfix/r/mdev_33441_fail.result | 10 ++++++++++ .../spider/mysql-test/spider/bugfix/t/mdev_33441.opt | 1 + .../spider/mysql-test/spider/bugfix/t/mdev_33441.test | 10 ++++++++++ .../mysql-test/spider/bugfix/t/mdev_33441_fail.opt | 2 ++ .../mysql-test/spider/bugfix/t/mdev_33441_fail.test | 10 ++++++++++ 7 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 storage/spider/mysql-test/spider/bugfix/r/mdev_33441.result create mode 100644 storage/spider/mysql-test/spider/bugfix/r/mdev_33441_fail.result create mode 100644 storage/spider/mysql-test/spider/bugfix/t/mdev_33441.opt create mode 100644 storage/spider/mysql-test/spider/bugfix/t/mdev_33441.test create mode 100644 storage/spider/mysql-test/spider/bugfix/t/mdev_33441_fail.opt create mode 100644 storage/spider/mysql-test/spider/bugfix/t/mdev_33441_fail.test diff --git a/sql/sql_plugin.cc b/sql/sql_plugin.cc index 008aa2b5de1..fca16ffa369 100644 --- a/sql/sql_plugin.cc +++ b/sql/sql_plugin.cc @@ -1505,7 +1505,7 @@ static int plugin_initialize(MEM_ROOT *tmp_root, struct st_plugin_int *plugin, else ret= plugin_do_initialize(plugin, state); - if (ret) + if (ret && ret != HA_ERR_RETRY_INIT) plugin_variables_deinit(plugin); mysql_mutex_lock(&LOCK_plugin); @@ -1786,6 +1786,7 @@ int plugin_init(int *argc, char **argv, int flags) uint state= plugin_ptr->state; mysql_mutex_unlock(&LOCK_plugin); error= plugin_do_initialize(plugin_ptr, state); + DBUG_EXECUTE_IF("fail_spider_init_retry", error= 1;); mysql_mutex_lock(&LOCK_plugin); plugin_ptr->state= state; if (error == HA_ERR_RETRY_INIT) diff --git a/storage/spider/mysql-test/spider/bugfix/r/mdev_33441.result b/storage/spider/mysql-test/spider/bugfix/r/mdev_33441.result new file mode 100644 index 00000000000..b19194f13b5 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/r/mdev_33441.result @@ -0,0 +1,7 @@ +# +# MDEV-33441 No spider variables available is Spider is loaded upon server startup +# +set spider_same_server_link=0; +# +# end of test mdev_33441 +# diff --git a/storage/spider/mysql-test/spider/bugfix/r/mdev_33441_fail.result b/storage/spider/mysql-test/spider/bugfix/r/mdev_33441_fail.result new file mode 100644 index 00000000000..e6123ed429b --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/r/mdev_33441_fail.result @@ -0,0 +1,10 @@ +# +# MDEV-33441 No spider variables available is Spider is loaded upon server startup +# +select * from mysql.plugin; +name dl +show variables like 'spider%'; +Variable_name Value +# +# end of test mdev_33441_fail +# diff --git a/storage/spider/mysql-test/spider/bugfix/t/mdev_33441.opt b/storage/spider/mysql-test/spider/bugfix/t/mdev_33441.opt new file mode 100644 index 00000000000..924ea4e31ef --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/t/mdev_33441.opt @@ -0,0 +1 @@ +--plugin-load-add=ha_spider diff --git a/storage/spider/mysql-test/spider/bugfix/t/mdev_33441.test b/storage/spider/mysql-test/spider/bugfix/t/mdev_33441.test new file mode 100644 index 00000000000..a2e0ddafe01 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/t/mdev_33441.test @@ -0,0 +1,10 @@ +--echo # +--echo # MDEV-33441 No spider variables available is Spider is loaded upon server startup +--echo # + +# We test that at least one spider variable exists. +set spider_same_server_link=0; + +--echo # +--echo # end of test mdev_33441 +--echo # diff --git a/storage/spider/mysql-test/spider/bugfix/t/mdev_33441_fail.opt b/storage/spider/mysql-test/spider/bugfix/t/mdev_33441_fail.opt new file mode 100644 index 00000000000..28f1ce4825b --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/t/mdev_33441_fail.opt @@ -0,0 +1,2 @@ +--plugin-load-add=ha_spider +--debug-dbug=d,fail_spider_init_retry diff --git a/storage/spider/mysql-test/spider/bugfix/t/mdev_33441_fail.test b/storage/spider/mysql-test/spider/bugfix/t/mdev_33441_fail.test new file mode 100644 index 00000000000..6734b477583 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/t/mdev_33441_fail.test @@ -0,0 +1,10 @@ +--source include/have_debug.inc +--echo # +--echo # MDEV-33441 No spider variables available is Spider is loaded upon server startup +--echo # +# We test that when retry fails, spider variables are deleted. +select * from mysql.plugin; +show variables like 'spider%'; +--echo # +--echo # end of test mdev_33441_fail +--echo #