-
-
Notifications
You must be signed in to change notification settings - Fork 2k
MDEV-31527: Add --validate-config option to check configuration without starting the server #4716
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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 |
| 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; | ||
|
|
||
| --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 | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd find a better, more stable text to search. 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 | ||
|
|
||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
| --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 | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
|
||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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; | ||
|
|
@@ -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 */ | ||
|
|
@@ -4131,7 +4134,7 @@ static int init_common_variables() | |
| sf_leaking_memory= 0; // no memory leaks from now on | ||
|
|
||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would move the |
||
| #ifndef EMBEDDED_LIBRARY | ||
| if (opt_abort && !opt_verbose) | ||
| if (opt_abort && !opt_verbose && !opt_validate_config) | ||
| unireg_abort(0); | ||
| #endif /*!EMBEDDED_LIBRARY*/ | ||
|
|
||
|
|
@@ -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}, | ||
|
|
@@ -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; | ||
|
|
||
There was a problem hiding this comment.
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?