MDEV-31527: Add --validate-config option to check configuration without starting the server#4716
MDEV-31527: Add --validate-config option to check configuration without starting the server#4716bodyhedia44 wants to merge 1 commit intoMariaDB:mainfrom
Conversation
82f19f2 to
99d166e
Compare
gkodinov
left a comment
There was a problem hiding this comment.
Thank you for your contribution. This is a preliminary review.
mysql-test/main/validate_config.test
Outdated
| --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 |
There was a problem hiding this comment.
Why do you need --skip-grant-tables and --skip-networking? It's not supposed to matter.
mysql-test/main/validate_config.test
Outdated
| --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 |
There was a problem hiding this comment.
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.".
mysql-test/main/validate_config.test
Outdated
| # mysqld refuses to run as root normally. | ||
| --source include/not_as_root.inc | ||
|
|
||
| mkdir $MYSQLTEST_VARDIR/tmp/validate_config; |
There was a problem hiding this comment.
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?
mysql-test/main/validate_config.test
Outdated
| [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 |
There was a problem hiding this comment.
lots of options you do not need here too.
99d166e to
7510e9e
Compare
|
Done |
gkodinov
left a comment
There was a problem hiding this comment.
Thanks for working on this with me. LGTM. One question for the final reviewer.
Please update the jira and the commit message and stand by for the final review.
| {"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 " |
There was a problem hiding this comment.
One final nitpick: Looking at https://mariadb.com/docs/server/server-management/install-and-upgrade-mariadb/configuring-mariadb/configuring-mariadb-with-option-files it seems like all of the configuration file related options contain the word "defaults" in some shape or form: --defaults-file, --no-defaults etc. Even the related tool is called https://mariadb.com/docs/server/clients-and-utilities/administrative-tools/my_print_defaults.
What the new option added does in essence is basically what my_print_defaults does, but without the printing. I'd name the option --validate-defaults to be consistent with the naming used so far. But, since this is a MySQL compatible option, I'd not insist on it. And leave the decision to the final approver.
I'd also be prudent to spell out exactly what kind of "validation" is happening. To me this is a check that:
- all the config files specified or defaulted are reachable.
- the syntax of these config files is consistent.
- there are no unknown options specified
- the values for the options fall within the compiled validity limits
I'd put all of the above in the jira and into the commit message itself.
3300ee2 to
8e832a0
Compare
…ut starting the server Add a new --validate-config command-line option that validates the server configuration (from config files and command line) and exits with 0 on success or non-zero on failure, without actually starting the server. This is useful for DBAs to verify configuration changes before restarting: mariadbd --defaults-file=/etc/my.cnf --validate-config The validation checks the following: - Config files explicitly specified via --defaults-file or --defaults-extra-file must exist and be readable - There are no unknown options specified (in config files or on the command line) - Option values are type-checked (e.g. numeric options reject non-numeric input). Out-of-range values are adjusted to valid limits with a warning, not rejected. The implementation reuses the existing --help code path (opt_abort), which already loads plugins to validate their variables and runs a final parsing pass with skip_unknown=0 to detect unknown options. The only difference is that --validate-config suppresses help output. Note: this is intentionally named --validate-config (not --validate-defaults) for MySQL compatibility, although --validate-defaults would be more consistent with MariaDB's existing defaults-related options (--defaults-file, --no-defaults, my_print_defaults, etc.).
8e832a0 to
e2a0e86
Compare
MDEV-31527: Add --validate-config option
Summary
Add a new
--validate-configcommand-line option that validates the serverconfiguration (from config files and command line) and exits with exit code
0 on success or non-zero on failure, without actually starting the server.
Use case
mariadbd --defaults-file=/etc/my.cnf --validate-config
DBAs can verify configuration changes before restarting production servers.
Test cases (
mysql-test/main/validate_config.test):Exit codes
How to use
Validate a config file before restarting
mariadbd --defaults-file=/etc/my.cnf --validate-config
Validate with additional command-line overrides
mariadbd --defaults-file=/etc/my.cnf --validate-config --max-connections=500
Matching MySQL 8.0 behavior
This is equivalent to MySQL 8.0's
--validate-configoption, adapted forMariaDB's parsing architecture.