Skip to content

Commit 29afb2f

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: I58333a9a941b772805e3e09dfcced57788c66c66
2 parents 519f351 + 4b58949 commit 29afb2f

File tree

6 files changed

+80
-12
lines changed

6 files changed

+80
-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,35 @@
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+
--source include/wait_until_connected_again.inc
26+
27+
INSTALL COMPONENT "file://component_test_sys_var_service";
28+
SELECT @@test_component.str_sys_var;
29+
UNINSTALL COMPONENT "file://component_test_sys_var_service";
30+
31+
let $MYSQLD_DATADIR= `SELECT @@datadir`;
32+
--remove_file $MYSQLD_DATADIR/test_component_sys_var_service.log
33+
let $restart_parameters = restart:;
34+
--source include/restart_mysqld.inc
35+
--remove_file $MYSQLTEST_VARDIR/tmp/sys_reg.cnf

sql/mysqld.cc

+7
Original file line numberDiff line numberDiff line change
@@ -1226,6 +1226,8 @@ ulong log_error_verbosity = 3; // have a non-zero value during early start-up
12261226
bool opt_keyring_migration_to_component = false;
12271227
bool opt_keyring_migration_from_component = false;
12281228
bool opt_persist_sensitive_variables_in_plaintext{true};
1229+
int argc_cached;
1230+
char **argv_cached;
12291231

12301232
#if defined(_WIN32)
12311233
/*
@@ -8907,6 +8909,11 @@ int mysqld_main(int argc, char **argv)
89078909
return 1;
89088910
}
89098911

8912+
argc_cached = argc;
8913+
argv_cached = new (&argv_alloc) char *[argc_cached + 1];
8914+
memcpy(argv_cached, argv, argc_cached * sizeof(char *));
8915+
argv_cached[argc_cached] = nullptr;
8916+
89108917
/* Set data dir directory paths */
89118918
strmake(mysql_real_data_home, get_relative_path(MYSQL_DATADIR),
89128919
sizeof(mysql_real_data_home) - 1);

sql/mysqld.h

+18
Original file line numberDiff line numberDiff line change
@@ -826,4 +826,22 @@ extern Deployed_components *g_deployed_components;
826826
extern bool opt_persist_sensitive_variables_in_plaintext;
827827

828828
void persisted_variables_refresh_keyring_support();
829+
830+
/**
831+
Stores the value of argc during server start up that contains
832+
the count of arguments specified by the user in the
833+
configuration files and command line.
834+
The server refers the cached argument count during
835+
plugin and component installation.
836+
*/
837+
extern int argc_cached;
838+
/**
839+
Stores the value of argv during server start up that contains
840+
the vector of arguments specified by the user in the
841+
configuration files and command line.
842+
The server refers the cached argument vector during
843+
plugin and component installation.
844+
*/
845+
extern char **argv_cached;
846+
829847
#endif /* MYSQLD_INCLUDED */

sql/server_component/component_sys_var_service.cc

+2-3
Original file line numberDiff line numberDiff line change
@@ -353,10 +353,9 @@ DEFINE_BOOL_METHOD(mysql_component_sys_variable_imp::register_variable,
353353
if (mysqld_server_started) {
354354
Persisted_variables_cache *pv =
355355
Persisted_variables_cache::get_instance();
356-
argc_copy = orig_argc;
356+
argc_copy = argc_cached;
357357
argv_copy = new (&local_root) char *[argc_copy + 1];
358-
memcpy(argv_copy, orig_argv, argc_copy * sizeof(char *));
359-
argv_copy[argc_copy] = nullptr;
358+
memcpy(argv_copy, argv_cached, (argc_copy + 1) * sizeof(char *));
360359
argc = &argc_copy;
361360
argv = &argv_copy;
362361
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
@@ -36,7 +36,6 @@
3636
#include "my_base.h"
3737
#include "my_compiler.h"
3838
#include "my_dbug.h"
39-
#include "my_default.h" // free_defaults
4039
#include "my_getopt.h"
4140
#include "my_inttypes.h"
4241
#include "my_list.h"
@@ -2239,8 +2238,9 @@ static bool mysql_install_plugin(THD *thd, LEX_CSTRING name,
22392238
const LEX_STRING *dl) {
22402239
TABLE *table;
22412240
bool error = true;
2242-
int argc = orig_argc;
2243-
char **argv = orig_argv;
2241+
int argc;
2242+
char **argv;
2243+
char **argv_copy;
22442244
st_plugin_int *tmp = nullptr;
22452245
bool store_infoschema_metadata = false;
22462246
dd::Schema_MDL_locker mdl_handler(thd);
@@ -2312,16 +2312,18 @@ static bool mysql_install_plugin(THD *thd, LEX_CSTRING name,
23122312
mysql_mutex_lock(&LOCK_plugin);
23132313

23142314
{
2315-
MEM_ROOT alloc{PSI_NOT_INSTRUMENTED, 512};
2316-
my_getopt_use_args_separator = true;
2317-
if (my_load_defaults(MYSQL_CONFIG_NAME, load_default_groups, &argc, &argv,
2318-
&alloc, nullptr)) {
2315+
argc = argc_cached;
2316+
if (!(argv_copy =
2317+
(char **)my_memdup(PSI_NOT_INSTRUMENTED, argv_cached,
2318+
(argc + 1) * sizeof(char *), MYF(0)))) {
23192319
mysql_mutex_unlock(&LOCK_plugin);
23202320
mysql_rwlock_unlock(&LOCK_system_variables_hash);
2321-
report_error(REPORT_TO_USER, ER_PLUGIN_IS_NOT_LOADED, name.str);
2321+
report_error(REPORT_TO_USER, ER_OUTOFMEMORY,
2322+
static_cast<int>((argc + 1) * sizeof(char *)));
23222323
goto err;
23232324
}
2324-
my_getopt_use_args_separator = false;
2325+
argv = argv_copy;
2326+
23252327
/*
23262328
Append parse early and static variables present in mysqld-auto.cnf file
23272329
for the newly installed plugin to process those options which are specific
@@ -2457,6 +2459,7 @@ static bool mysql_install_plugin(THD *thd, LEX_CSTRING name,
24572459
}
24582460

24592461
err:
2462+
my_free(argv_copy);
24602463
mysql_mutex_unlock(&LOCK_plugin_install);
24612464
return end_transaction(thd, error);
24622465
}

0 commit comments

Comments
 (0)