Skip to content

Commit 0c86267

Browse files
committed
Bug #20581228: MYSQLD --HELP --VERBOSE TRIES TO LOCK FILES
Various issues are relevant to consider when running mysqld with options --help --verbose: 1. On a loaded system, mysqld --help --verbose will initialize InnoDB in the same way as for an ordinary start. It will try to lock the system files present, and keeps trying for a hardcoded number of times, with a hardcoded sleep inbetween. It will eventually fail, and this will also make mysqld --help --verbose fail and report an error. 2. On an existing but empty datadir, InnoDB will create the system files while initializing. These files will be left behind after mysqld --help --verbose is finished, and will make a subsequent mysqld --initialize fail due to the datadir not being empty. 3. On a non-existing datadir, the plugin table will not be found, and mysqld --help --verbose will fail too. InnoDB is initialized in order to enable reading the plugin table, which contains the dynamic plugins. However, this is relevant only in issue 1 above. For issue 2 and 3, there is no point in initializing InnoDB since only the builtin plugins will be listed anyway. This patch applies the same constraint also in the first situation above. Thus, we let mysqld --help --verbose only list options belonging to the builtin plugins, and skip the dynamic ones. This allows us to execute mysqld --help --verbose without initializing InnoDB and without opening the plugin table, and this solves all three issues listed above.
1 parent 94ea2b6 commit 0c86267

File tree

4 files changed

+113
-6
lines changed

4 files changed

+113
-6
lines changed

mysql-test/r/help_verbose.result

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# There should be no errors or warnings
2+
Pattern "ERROR" not found
3+
Pattern "WARNING" not found
4+
# There should be no errors or warnings
5+
Pattern "ERROR" not found
6+
Pattern "WARNING" not found
7+
# There should be no leftovers in the datadir.
8+
# There should be no errors or warnings
9+
Pattern "ERROR" not found
10+
Pattern "WARNING" not found

mysql-test/t/help_verbose.test

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
###########################################################################
2+
# Global settings
3+
###########################################################################
4+
5+
--let $MESSAGES_DIR= `select @@lc_messages_dir`
6+
7+
###########################################################################
8+
# 1. Run --help --verbose on a writable datadir with another
9+
# server already running.
10+
###########################################################################
11+
12+
--let $BUGDIR= $MYSQL_TMP_DIR/help_verbose_tc1
13+
--let $LOG_FILE = $BUGDIR/mysqld.log
14+
--let $TEST_DATADIR= `select @@datadir`
15+
16+
--mkdir $BUGDIR
17+
18+
--exec $MYSQLD --no-defaults --help --verbose --datadir=$TEST_DATADIR --lc-messages-dir=$MESSAGES_DIR --secure-file-priv="" > $LOG_FILE 2>&1
19+
20+
--echo # There should be no errors or warnings
21+
--let SEARCH_FILE= $LOG_FILE
22+
--let SEARCH_PATTERN= ERROR
23+
--source include/search_pattern.inc
24+
25+
--let SEARCH_PATTERN= WARNING
26+
--source include/search_pattern.inc
27+
28+
# Cleanup
29+
--remove_files_wildcard $BUGDIR *
30+
--rmdir $BUGDIR
31+
32+
###########################################################################
33+
# 2. Run --help --verbose on an existing but empty datadir.
34+
###########################################################################
35+
36+
--let $BUGDIR= $MYSQL_TMP_DIR/help_verbose_tc2
37+
--let $LOG_FILE = $BUGDIR/mysqld.log
38+
--let $TEST_DATADIR= $BUGDIR/data
39+
40+
--mkdir $BUGDIR
41+
--mkdir $TEST_DATADIR
42+
43+
--exec $MYSQLD --no-defaults --help --verbose --datadir=$TEST_DATADIR --lc-messages-dir=$MESSAGES_DIR --secure-file-priv="" > $LOG_FILE 2>&1
44+
45+
--echo # There should be no errors or warnings
46+
--let SEARCH_FILE= $LOG_FILE
47+
--let SEARCH_PATTERN= ERROR
48+
--source include/search_pattern.inc
49+
50+
--let SEARCH_PATTERN= WARNING
51+
--source include/search_pattern.inc
52+
53+
--echo # There should be no leftovers in the datadir.
54+
--list_files $TEST_DATADIR
55+
56+
# Cleanup
57+
--remove_files_wildcard $BUGDIR *
58+
--rmdir $TEST_DATADIR
59+
--rmdir $BUGDIR
60+
61+
###########################################################################
62+
# 3. Run --help --verbose on a non-existing datadir.
63+
###########################################################################
64+
65+
--let $BUGDIR= $MYSQL_TMP_DIR/help_verbose_tc3
66+
--let $LOG_FILE = $BUGDIR/mysqld.log
67+
--let $TEST_DATADIR= $BUGDIR/data
68+
69+
--mkdir $BUGDIR
70+
71+
--exec $MYSQLD --no-defaults --help --verbose --datadir=$TEST_DATADIR --lc-messages-dir=$MESSAGES_DIR --secure-file-priv="" > $LOG_FILE 2>&1
72+
73+
--echo # There should be no errors or warnings
74+
--let SEARCH_FILE= $LOG_FILE
75+
--let SEARCH_PATTERN= ERROR
76+
--source include/search_pattern.inc
77+
78+
--let SEARCH_PATTERN= WARNING
79+
--source include/search_pattern.inc
80+
81+
# Cleanup
82+
--remove_files_wildcard $BUGDIR *
83+
--rmdir $BUGDIR

sql/mysqld.cc

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4049,9 +4049,17 @@ a file name for --log-bin-index option", opt_binlog_index_name);
40494049
*/
40504050
tc_log= &tc_log_dummy;
40514051

4052+
/*
4053+
Skip reading the plugin table when starting with --help in order
4054+
to also skip initializing InnoDB. This provides a simpler and more
4055+
uniform handling of various startup use cases, e.g. when the data
4056+
directory does not exist, exists but is empty, exists with InnoDB
4057+
system tablespaces present etc.
4058+
*/
40524059
if (plugin_init(&remaining_argc, remaining_argv,
40534060
(opt_noacl ? PLUGIN_INIT_SKIP_PLUGIN_TABLE : 0) |
4054-
(opt_help ? PLUGIN_INIT_SKIP_INITIALIZATION : 0)))
4061+
(opt_help ? (PLUGIN_INIT_SKIP_INITIALIZATION |
4062+
PLUGIN_INIT_SKIP_PLUGIN_TABLE) : 0)))
40554063
{
40564064
sql_print_error("Failed to initialize plugins.");
40574065
unireg_abort(MYSQLD_ABORT_EXIT);

sql/sql_plugin.cc

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1343,7 +1343,6 @@ static void init_plugin_psi_keys(void)
13431343
int plugin_init(int *argc, char **argv, int flags)
13441344
{
13451345
uint i;
1346-
bool is_myisam;
13471346
st_mysql_plugin **builtins;
13481347
st_mysql_plugin *plugin;
13491348
st_plugin_int tmp, *plugin_ptr, **reap;
@@ -1444,11 +1443,18 @@ int plugin_init(int *argc, char **argv, int flags)
14441443
if (register_builtin(plugin, &tmp, &plugin_ptr))
14451444
goto err_unlock;
14461445

1447-
/* only initialize MyISAM, InnoDB and CSV at this stage */
1448-
is_myisam= !my_strcasecmp(&my_charset_latin1, plugin->name, "MyISAM");
1446+
/*
1447+
Only initialize MyISAM, InnoDB and CSV at this stage.
1448+
Note that when the --help option is supplied, InnoDB is not
1449+
initialized because the plugin table will not be read anyway,
1450+
as indicated by the flag set when the plugin_init() function
1451+
is called.
1452+
*/
1453+
bool is_myisam= !my_strcasecmp(&my_charset_latin1, plugin->name, "MyISAM");
1454+
bool is_innodb= !my_strcasecmp(&my_charset_latin1, plugin->name, "InnoDB");
14491455
if (!is_myisam &&
1450-
my_strcasecmp(&my_charset_latin1, plugin->name, "CSV") &&
1451-
my_strcasecmp(&my_charset_latin1, plugin->name, "InnoDB"))
1456+
(!is_innodb || opt_help) &&
1457+
my_strcasecmp(&my_charset_latin1, plugin->name, "CSV"))
14521458
continue;
14531459

14541460
if (plugin_ptr->state != PLUGIN_IS_UNINITIALIZED ||

0 commit comments

Comments
 (0)