Skip to content
/ server Public
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions mysql-test/main/mysqld--help.result
Original file line number Diff line number Diff line change
Expand Up @@ -1739,6 +1739,9 @@ The following specify which files/extra groups are read (specified before remain
--userstat Enables statistics gathering for USER_STATISTICS,
CLIENT_STATISTICS, INDEX_STATISTICS and TABLE_STATISTICS
tables in the INFORMATION_SCHEMA
--validate-config Validate the server configuration specified by the user
and exit with an exit code of 0 for success or 1 for
failure, without starting the server
-v, --verbose Used with --help option for detailed help
-V, --version[=name]
Output version information and exit
Expand Down Expand Up @@ -2180,6 +2183,7 @@ transaction-read-only FALSE
updatable-views-with-limit YES
use-stat-tables PREFERABLY_FOR_QUERIES
userstat FALSE
validate-config FALSE
verbose TRUE
wait-timeout 28800

Expand Down
21 changes: 21 additions & 0 deletions mysql-test/main/validate_config.result
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#
# Test 1: --validate-config with valid configuration should succeed (exit 0)
#
#
# Test 2: --validate-config with unknown option should fail (exit != 0)
#
#
# Test 3: --validate-config should not start the server (no pid file)
#
#
# Test 4: --validate-config should not produce help output
#
NOT FOUND /To see what values a running/ in test5.log
#
# Test 5: --validate-config with bad option in config file should fail
#
FOUND 1 /unknown variable 'zzz_bogus_option=123'/ in test6.log
#
# Test 6: --validate-config with valid config file should succeed
#
FOUND 1 /Configuration is valid/ in test7.log
72 changes: 72 additions & 0 deletions mysql-test/main/validate_config.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#
# Test --validate-config option (MDEV-31527)
#
# The --validate-config flag validates the configuration and exits
# with exit code 0 on success, or 1 on failure, without starting
# the server.
#

--source include/not_embedded.inc

# mysqld refuses to run as root normally.
--source include/not_as_root.inc

mkdir $MYSQLTEST_VARDIR/tmp/validate_config;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you need a specific tmp subdir with your files? Why not just use the base tmp but prefix the files with the mdev number as suggested below?


--echo #
--echo # Test 1: --validate-config with valid configuration should succeed (exit 0)
--echo #
--exec $MYSQLD_BOOTSTRAP_CMD --skip-networking --datadir=$MYSQLTEST_VARDIR/tmp/validate_config --skip-grant-tables --validate-config >$MYSQLTEST_VARDIR/tmp/validate_config/test1.log 2>&1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you need --skip-grant-tables and --skip-networking? It's not supposed to matter.


--echo #
--echo # Test 2: --validate-config with unknown option should fail (exit != 0)
--echo #
--error 2
--exec $MYSQLD_BOOTSTRAP_CMD --skip-networking --datadir=$MYSQLTEST_VARDIR/tmp/validate_config --skip-grant-tables --validate-config --nonexistentoption >$MYSQLTEST_VARDIR/tmp/validate_config/test2.log 2>&1

--echo #
--echo # Test 3: --validate-config should not start the server (no pid file)
--echo #
--exec $MYSQLD_BOOTSTRAP_CMD --skip-networking --datadir=$MYSQLTEST_VARDIR/tmp/validate_config --skip-grant-tables --validate-config --pid-file=$MYSQLTEST_VARDIR/tmp/validate_config/validate.pid >$MYSQLTEST_VARDIR/tmp/validate_config/test4.log 2>&1
--error 1
--file_exists $MYSQLTEST_VARDIR/tmp/validate_config/validate.pid

--echo #
--echo # Test 4: --validate-config should not produce help output
--echo #
--exec $MYSQLD_BOOTSTRAP_CMD --skip-networking --datadir=$MYSQLTEST_VARDIR/tmp/validate_config --skip-grant-tables --validate-config >$MYSQLTEST_VARDIR/tmp/validate_config/test5.log 2>&1
# The log should NOT contain the --help option listing
--let SEARCH_FILE=$MYSQLTEST_VARDIR/tmp/validate_config/test5.log
--let SEARCH_PATTERN=To see what values a running
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd find a better, more stable text to search.
Note that on my computer, this is never produced. I get:

blackbook:~$dev/server-main/bld/sql/mariadbd --help
dev/server-main/bld/sql/mariadbd  Ver 13.0.0-MariaDB-debug for osx10.21 on arm64 (Source distribution)
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Starts the MariaDB database server.

Usage: dev/server-main/bld/sql/mariadbd [OPTIONS]

For more help options (several pages), use mariadbd --verbose --help.
blackbook:~$

I'd suggest using either "^Usage:.*mariadbd" or "Starts the MariaDB database server.".

--source include/search_pattern_in_file.inc

--echo #
--echo # Test 5: --validate-config with bad option in config file should fail
--echo #
# Note: $MYSQLD_BOOTSTRAP_CMD contains --no-defaults which prevents
# --defaults-file from being processed. Use $MYSQLD directly instead.
--write_file $MYSQLTEST_VARDIR/tmp/validate_config/bad.cnf
[mariadb]
zzz_bogus_option=123
EOF
--error 7
--exec $MYSQLD --defaults-file=$MYSQLTEST_VARDIR/tmp/validate_config/bad.cnf --skip-networking --skip-grant-tables --validate-config --lc-messages-dir=$MYSQL_SHAREDIR --datadir=$MYSQLTEST_VARDIR/tmp/validate_config --plugin-dir=$MYSQLTEST_VARDIR/plugins --character-sets-dir=$MYSQL_CHARSETSDIR --console --core-file >$MYSQLTEST_VARDIR/tmp/validate_config/test6.log 2>&1
--let SEARCH_FILE=$MYSQLTEST_VARDIR/tmp/validate_config/test6.log
--let SEARCH_PATTERN=unknown variable 'zzz_bogus_option=123'
--source include/search_pattern_in_file.inc

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not remove the file right here? Makes for a better test locality.
Optional: I've got into the habit of prefixing all the temp files produced by tests with the "mdev-" so that, if something is left on disk by error, the name is more distinct.

--echo #
--echo # Test 6: --validate-config with valid config file should succeed
--echo #
--write_file $MYSQLTEST_VARDIR/tmp/validate_config/good.cnf
[mariadb]
max_connections=50
EOF
--exec $MYSQLD --defaults-file=$MYSQLTEST_VARDIR/tmp/validate_config/good.cnf --skip-networking --skip-grant-tables --validate-config --lc-messages-dir=$MYSQL_SHAREDIR --datadir=$MYSQLTEST_VARDIR/tmp/validate_config --plugin-dir=$MYSQLTEST_VARDIR/plugins --character-sets-dir=$MYSQL_CHARSETSDIR --console --core-file >$MYSQLTEST_VARDIR/tmp/validate_config/test7.log 2>&1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lots of options you do not need here too.

--let SEARCH_FILE=$MYSQLTEST_VARDIR/tmp/validate_config/test7.log
--let SEARCH_PATTERN=Configuration is valid
--source include/search_pattern_in_file.inc

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add a test (and describe in the MDEV what is the expected behavior) for the new option with --verbose, with --help and --bootstrap.

# Cleanup
remove_files_wildcard $MYSQLTEST_VARDIR/tmp/validate_config;
rmdir $MYSQLTEST_VARDIR/tmp/validate_config;
12 changes: 10 additions & 2 deletions sql/mysqld.cc
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,7 @@ handlerton *opt_binlog_engine_hton;
bool opt_bin_log_compress;
uint opt_bin_log_compress_min_len;
my_bool opt_log, debug_assert_if_crashed_table= 0, opt_help= 0;
my_bool opt_validate_config= 0;
my_bool debug_assert_on_not_freed_memory= 0;
my_bool disable_log_notes, opt_support_flashback= 0;
static my_bool opt_abort;
Expand Down Expand Up @@ -1901,6 +1902,8 @@ extern "C" void unireg_abort(int exit_code)

if (opt_help)
usage();
else if (opt_validate_config && !exit_code)
sql_print_information("Configuration is valid.");
else if (exit_code)
sql_print_error("Aborting");
/* Don't write more notes to the log to not hide error message */
Expand Down Expand Up @@ -4131,7 +4134,7 @@ static int init_common_variables()
sf_leaking_memory= 0; // no memory leaks from now on

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would move the else if() from above be a regular if() { sql_print_information() } here.

#ifndef EMBEDDED_LIBRARY
if (opt_abort && !opt_verbose)
if (opt_abort && !opt_verbose && !opt_validate_config)
unireg_abort(0);
#endif /*!EMBEDDED_LIBRARY*/

Expand Down Expand Up @@ -6780,6 +6783,11 @@ struct my_option my_long_options[]=
{"help", '?', "Display this help and exit",
&opt_help, &opt_help, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
0, 0},
{"validate-config", 0, "Validate the server configuration specified by the user "
"and exit with an exit code of 0 for success or 1 for failure, "
"without starting the server",
&opt_validate_config, &opt_validate_config, 0, GET_BOOL, NO_ARG, 0, 0, 0,
0, 0, 0},
{"ansi", 'a', "Use ANSI SQL syntax instead of MariaDB syntax. This mode "
"will also set transaction isolation level 'serializable'", 0, 0, 0,
GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
Expand Down Expand Up @@ -9057,7 +9065,7 @@ static int get_options(int *argc_ptr, char ***argv_ptr)
mysqld_get_one_option)))
return ho_error;

if (!opt_help)
if (!opt_help && !opt_validate_config)
delete_dynamic(&all_options);
else
opt_abort= 1;
Expand Down