Skip to content

Commit 4b58949

Browse files
author
Omar Sharieff
committed
Bug#28341329 : COMPONENT OPTIONS WITH --LOOSE PREFIX AREN'T CONSIDERED
AFTER INSTALLATION Description: Server does not load component variables specified in the configuration file when the component is installed after server start up. Cache plugin and component variables specified in the configuration file. Fix: Added functionality to load component variables specified in the configuration file during component installation. Added functionality to cache plugin and component variables specified in the configuration file during server start up. The server loads the cached variable values instead of rereading the configuration file during plugin and component installation. Change-Id: I5c1633b70daee536d9522692bde38909df894a84
1 parent 4d365aa commit 4b58949

File tree

6 files changed

+81
-12
lines changed

6 files changed

+81
-12
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
INSTALL COMPONENT "file://component_test_sys_var_service";
2+
SELECT @@test_component.str_sys_var;
3+
@@test_component.str_sys_var
4+
12
5+
UNINSTALL COMPONENT "file://component_test_sys_var_service";
6+
# restart:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
--source ../include/have_component_test_sys_var_service.inc
2+
3+
--disable_query_log
4+
call mtr.add_suppression("duplicate variable name");
5+
--enable_query_log
6+
7+
let $MYSQLD_DATADIR= `SELECT @@datadir`;
8+
let $MYSQL_BASEDIR= `SELECT @@basedir`;
9+
let $MYSQL_SOCKET= `SELECT @@socket`;
10+
let $MYSQL_PIDFILE= `SELECT @@pid_file`;
11+
let $MYSQL_PORT= `SELECT @@port`;
12+
let $MYSQL_MESSAGESDIR= `SELECT @@lc_messages_dir`;
13+
let $MYSQL_SERVER_ID= `SELECT @@server_id`;
14+
15+
--exec echo "wait" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect
16+
--shutdown_server
17+
--source include/wait_until_disconnected.inc
18+
19+
--write_file $MYSQLTEST_VARDIR/tmp/sys_reg.cnf
20+
[mysqld]
21+
loose-test_component.str_sys_var=12
22+
EOF
23+
24+
--exec echo "restart:--defaults-file=$MYSQLTEST_VARDIR/tmp/sys_reg.cnf" --basedir=$MYSQL_BASEDIR --datadir=$MYSQLD_DATADIR --socket=$MYSQL_SOCKET --pid-file=$MYSQL_PIDFILE --port=$MYSQL_PORT --lc-messages-dir=$MYSQL_MESSAGESDIR --server-id=$MYSQL_SERVER_ID --secure-file-priv="" --innodb_dedicated_server=OFF --skip-mysqlx > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect
25+
--enable_reconnect
26+
--source include/wait_until_connected_again.inc
27+
28+
INSTALL COMPONENT "file://component_test_sys_var_service";
29+
SELECT @@test_component.str_sys_var;
30+
UNINSTALL COMPONENT "file://component_test_sys_var_service";
31+
32+
let $MYSQLD_DATADIR= `SELECT @@datadir`;
33+
--remove_file $MYSQLD_DATADIR/test_component_sys_var_service.log
34+
let $restart_parameters = restart:;
35+
--source include/restart_mysqld.inc
36+
--remove_file $MYSQLTEST_VARDIR/tmp/sys_reg.cnf

sql/mysqld.cc

+7
Original file line numberDiff line numberDiff line change
@@ -1208,6 +1208,8 @@ uint host_cache_size;
12081208
ulong log_error_verbosity = 3; // have a non-zero value during early start-up
12091209
bool opt_keyring_migration_to_component = false;
12101210
bool opt_persist_sensitive_variables_in_plaintext{true};
1211+
int argc_cached;
1212+
char **argv_cached;
12111213

12121214
#if defined(_WIN32)
12131215
/*
@@ -7308,6 +7310,11 @@ int mysqld_main(int argc, char **argv)
73087310
return 1;
73097311
}
73107312

7313+
argc_cached = argc;
7314+
argv_cached = new (&argv_alloc) char *[argc_cached + 1];
7315+
memcpy(argv_cached, argv, argc_cached * sizeof(char *));
7316+
argv_cached[argc_cached] = nullptr;
7317+
73117318
/* Set data dir directory paths */
73127319
strmake(mysql_real_data_home, get_relative_path(MYSQL_DATADIR),
73137320
sizeof(mysql_real_data_home) - 1);

sql/mysqld.h

+18
Original file line numberDiff line numberDiff line change
@@ -847,4 +847,22 @@ extern Deployed_components *g_deployed_components;
847847
extern bool opt_persist_sensitive_variables_in_plaintext;
848848

849849
void persisted_variables_refresh_keyring_support();
850+
851+
/**
852+
Stores the value of argc during server start up that contains
853+
the count of arguments specified by the user in the
854+
configuration files and command line.
855+
The server refers the cached argument count during
856+
plugin and component installation.
857+
*/
858+
extern int argc_cached;
859+
/**
860+
Stores the value of argv during server start up that contains
861+
the vector of arguments specified by the user in the
862+
configuration files and command line.
863+
The server refers the cached argument vector during
864+
plugin and component installation.
865+
*/
866+
extern char **argv_cached;
867+
850868
#endif /* MYSQLD_INCLUDED */

sql/server_component/component_sys_var_service.cc

+2-3
Original file line numberDiff line numberDiff line change
@@ -351,10 +351,9 @@ DEFINE_BOOL_METHOD(mysql_component_sys_variable_imp::register_variable,
351351
if (mysqld_server_started) {
352352
Persisted_variables_cache *pv =
353353
Persisted_variables_cache::get_instance();
354-
argc_copy = orig_argc;
354+
argc_copy = argc_cached;
355355
argv_copy = new (&local_root) char *[argc_copy + 1];
356-
memcpy(argv_copy, orig_argv, argc_copy * sizeof(char *));
357-
argv_copy[argc_copy] = nullptr;
356+
memcpy(argv_copy, argv_cached, (argc_copy + 1) * sizeof(char *));
358357
argc = &argc_copy;
359358
argv = &argv_copy;
360359
if (pv && pv->append_read_only_variables(argc, argv, true, true,

sql/sql_plugin.cc

+12-9
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
#include "my_base.h"
3939
#include "my_compiler.h"
4040
#include "my_dbug.h"
41-
#include "my_default.h" // free_defaults
4241
#include "my_getopt.h"
4342
#include "my_inttypes.h"
4443
#include "my_list.h"
@@ -2254,8 +2253,9 @@ static bool mysql_install_plugin(THD *thd, LEX_CSTRING name,
22542253
const LEX_STRING *dl) {
22552254
TABLE *table;
22562255
bool error = true;
2257-
int argc = orig_argc;
2258-
char **argv = orig_argv;
2256+
int argc;
2257+
char **argv;
2258+
char **argv_copy;
22592259
st_plugin_int *tmp = nullptr;
22602260
bool store_infoschema_metadata = false;
22612261
dd::Schema_MDL_locker mdl_handler(thd);
@@ -2327,16 +2327,18 @@ static bool mysql_install_plugin(THD *thd, LEX_CSTRING name,
23272327
mysql_mutex_lock(&LOCK_plugin);
23282328

23292329
{
2330-
MEM_ROOT alloc{PSI_NOT_INSTRUMENTED, 512};
2331-
my_getopt_use_args_separator = true;
2332-
if (my_load_defaults(MYSQL_CONFIG_NAME, load_default_groups, &argc, &argv,
2333-
&alloc, nullptr)) {
2330+
argc = argc_cached;
2331+
if (!(argv_copy =
2332+
(char **)my_memdup(PSI_NOT_INSTRUMENTED, argv_cached,
2333+
(argc + 1) * sizeof(char *), MYF(0)))) {
23342334
mysql_mutex_unlock(&LOCK_plugin);
23352335
mysql_rwlock_unlock(&LOCK_system_variables_hash);
2336-
report_error(REPORT_TO_USER, ER_PLUGIN_IS_NOT_LOADED, name.str);
2336+
report_error(REPORT_TO_USER, ER_OUTOFMEMORY,
2337+
static_cast<int>((argc + 1) * sizeof(char *)));
23372338
goto err;
23382339
}
2339-
my_getopt_use_args_separator = false;
2340+
argv = argv_copy;
2341+
23402342
/*
23412343
Append parse early and static variables present in mysqld-auto.cnf file
23422344
for the newly installed plugin to process those options which are specific
@@ -2472,6 +2474,7 @@ static bool mysql_install_plugin(THD *thd, LEX_CSTRING name,
24722474
}
24732475

24742476
err:
2477+
my_free(argv_copy);
24752478
mysql_mutex_unlock(&LOCK_plugin_install);
24762479
return end_transaction(thd, error);
24772480
}

0 commit comments

Comments
 (0)