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.
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.
8e832a0 to
e2a0e86
Compare
raghunandanbhat
left a comment
There was a problem hiding this comment.
What happens if someone tries to check the version while validating the config? (Version print should probably take precedence and exit 0). Add a test for this case.
Please make the suggested changes & thanks for contribution!
e2a0e86 to
a7c374d
Compare
|
Done |
a7c374d to
4466433
Compare
raghunandanbhat
left a comment
There was a problem hiding this comment.
When --help is present, mariadbd does not validate invalid configs, just prints the help text and exits (same with --version).
$ ./mariadbd --help --invalid-config
./mariadbd Ver 13.0.0-MariaDB-debug for Linux on x86_64 (Source distribution)
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Starts the MariaDB database server.
Usage: ./mariadbd [OPTIONS]
For more help options (several pages), use mariadbd --verbose --help.
@bodyhedia44, your tests suggest that --help should take precedence over --validate-config. What if all three - --invalid-option, --help and --validate-confg are present? Should this validate the invalid config or just print help text and exit?
the current behavior is, it validates and prints the error indicating unknown option
$ ./mariadbd --help --invalid-config --validate-config
2026-03-10 23:02:11 0 [ERROR] ./mariadbd: unknown option '--invalid-config'
./mariadbd Ver 13.0.0-MariaDB-debug for Linux on x86_64 (Source distribution)
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Starts the MariaDB database server.
Usage: ./mariadbd [OPTIONS]
For more help options (several pages), use mariadbd --verbose --help.
Same is true for --version, --validate-config and --invalid-option as well.
maybe @vuvova or @sanja-byelkin can comment on this?
4466433 to
2cedcbc
Compare
raghunandanbhat
left a comment
There was a problem hiding this comment.
To be clear on the existing behavior (before this patch):
mariadbd --help --invalid-option- prints help and exits cleanly. it does not evaluate the invalid config.mariadbd --version --invalid-option- prints version and exits cleanly. it does not evaluate the invalid config.mariadbd --help --verbose --invalid-option- takes the long path to load plugins for the verbose help menu, evaluates the config, and crashes with an "unknown option" error. it is the only exception.
currently, the PR breaks this behavior. if a user runs mariadbd --help --validate-config --invalid-option, the server incorrectly takes the long initialization path, evaluates the config, and crashes with an "unknown option" error, rather than short-circuiting to print the help text. please fix this.
add two more tests to ensure we don't regress. they verify that --help and --version correctly ignore invalid configurations and exit cleanly, even when --validate-config is present.
--exec $MYSQLD_BOOTSTRAP_CMD --help --validate-config --invalid-config--exec $MYSQLD_BOOTSTRAP_CMD --version --validate-config --invalid-config
2cedcbc to
8d367a6
Compare
|
Done |
raghunandanbhat
left a comment
There was a problem hiding this comment.
code looks good; please make the change in the test and it is ready for testing.
…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.).
8d367a6 to
c259355
Compare
|
Done |
raghunandanbhat
left a comment
There was a problem hiding this comment.
looks good. thanks @bodyhedia44
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.