Skip to content

MDEV-31527: Add --validate-config option to check configuration without starting the server - #4716

Open
bodyhedia44 wants to merge 1 commit into
MariaDB:mainfrom
bodyhedia44:MDEV-31527-validate-config
Open

MDEV-31527: Add --validate-config option to check configuration without starting the server#4716
bodyhedia44 wants to merge 1 commit into
MariaDB:mainfrom
bodyhedia44:MDEV-31527-validate-config

Conversation

@bodyhedia44

@bodyhedia44 bodyhedia44 commented Mar 1, 2026

Copy link
Copy Markdown
Contributor

MDEV-31527: Add --validate-config option

Summary

Add a new --validate-config command-line option that validates the server
configuration (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):

  1. Valid config → exit 0
  2. Unknown CLI option → exit non-zero
  3. No pid file created (server doesn't start)
  4. No help text output
  5. Bad option in config file → exit non-zero with error message
  6. Valid config file → exit 0 with success message

Exit codes

Scenario Exit code
Valid configuration 0
Unknown option 2
Unknown variable 7

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-config option, adapted for
MariaDB's parsing architecture.

@bodyhedia44
bodyhedia44 force-pushed the MDEV-31527-validate-config branch 2 times, most recently from 82f19f2 to 99d166e Compare March 2, 2026 00:17
@gkodinov gkodinov added the External Contribution All PRs from entities outside of MariaDB Foundation, Corporation, Codership agreements. label Mar 2, 2026

@gkodinov gkodinov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thank you for your contribution. This is a preliminary review.

Comment thread sql/mysqld.cc
Comment thread mysql-test/main/validate_config.test Outdated
Comment thread mysql-test/main/validate_config.test Outdated
Comment thread mysql-test/main/validate_config.test
Comment thread mysql-test/main/validate_config.test Outdated
Comment thread mysql-test/main/validate_config.test Outdated
Comment thread mysql-test/main/validate_config.test
@bodyhedia44
bodyhedia44 force-pushed the MDEV-31527-validate-config branch from 99d166e to 7510e9e Compare March 4, 2026 20:07
@bodyhedia44
bodyhedia44 requested a review from gkodinov March 4, 2026 20:08
@bodyhedia44

Copy link
Copy Markdown
Contributor Author

Done

@gkodinov gkodinov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

Comment thread sql/mysqld.cc
@gkodinov
gkodinov requested a review from raghunandanbhat March 5, 2026 10:13
@bodyhedia44
bodyhedia44 force-pushed the MDEV-31527-validate-config branch 3 times, most recently from 8e832a0 to e2a0e86 Compare March 5, 2026 11:31
Comment thread mysql-test/main/validate_config.test
Comment thread mysql-test/main/validate_config.test
Comment thread mysql-test/main/validate_config.test

@raghunandanbhat raghunandanbhat left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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!

@bodyhedia44
bodyhedia44 force-pushed the MDEV-31527-validate-config branch from e2a0e86 to a7c374d Compare March 10, 2026 11:36
@bodyhedia44

Copy link
Copy Markdown
Contributor Author

Done

@bodyhedia44
bodyhedia44 force-pushed the MDEV-31527-validate-config branch from a7c374d to 4466433 Compare March 10, 2026 12:00

@raghunandanbhat raghunandanbhat left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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?

Comment thread mysql-test/main/validate_config.test Outdated
@bodyhedia44
bodyhedia44 force-pushed the MDEV-31527-validate-config branch from 4466433 to 2cedcbc Compare March 11, 2026 13:23

@raghunandanbhat raghunandanbhat left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

Comment thread mysql-test/main/validate_config.test Outdated
@bodyhedia44
bodyhedia44 force-pushed the MDEV-31527-validate-config branch from 2cedcbc to 8d367a6 Compare March 13, 2026 12:48
@bodyhedia44

Copy link
Copy Markdown
Contributor Author

Done

@raghunandanbhat raghunandanbhat left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

code looks good; please make the change in the test and it is ready for testing.

Comment thread mysql-test/main/validate_config.test Outdated
@bodyhedia44
bodyhedia44 force-pushed the MDEV-31527-validate-config branch from 8d367a6 to c259355 Compare March 16, 2026 20:38
@bodyhedia44

Copy link
Copy Markdown
Contributor Author

Done

@raghunandanbhat raghunandanbhat left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

looks good. thanks @bodyhedia44

Comment thread sql/mysqld.cc Outdated
#ifndef EMBEDDED_LIBRARY
if (opt_abort && !opt_verbose)
if (opt_abort && !opt_verbose &&
(!opt_validate_config || opt_help || opt_version))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

in your patch opt_abort = opt_validate_config || opt_help || opt_version.

there's no need to test all four variables here

Comment thread sql/mysqld.cc Outdated
if (opt_abort)
{
if (opt_validate_config && !opt_help && !opt_version)
sql_print_information("Configuration is valid.");

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't think this should have && !opt_help && !opt_version. A user asked to validate config, execution got that far, they deserve to see a message

@gkodinov gkodinov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Notes from the tester (copy from the Jira). Either discuss directly on Jira or rectify and commit an updaye:

1: This should not be happening:
Abdelrahman Hedia
--validate-config --log-bin creates binlog index file in datadir ( -bin.index)

2: Adjustments of values for options - they give warnings+ server will start with that adjusted value.
So - it is "Configuration is valid." - but maybe not what user intended? Maybe worth to mention it in the note or state?, e.g.:

2026-06-15 16:08:32 0 [Warning] option 'table_open_cache': unsigned value 0 adjusted to 10
2026-06-15 16:08:32 0 [Warning] option 'innodb-buffer-pool-size': unsigned value 1 adjusted to 2097152
2026-06-15 16:08:32 0 [Note] Plugin 'FEEDBACK' is disabled.
2026-06-15 16:08:32 0 [Note] Configuration is valid.

@bodyhedia44
bodyhedia44 force-pushed the MDEV-31527-validate-config branch from c259355 to 9af3d42 Compare June 26, 2026 00:52
@bodyhedia44

Copy link
Copy Markdown
Contributor Author

Done

@bodyhedia44
bodyhedia44 requested review from gkodinov and vuvova June 26, 2026 00:53

@gkodinov gkodinov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM. Please wait for @raghunandanbhat 's review

@gkodinov
gkodinov requested review from raghunandanbhat and removed request for vuvova June 26, 2026 08:17
--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

@ParadoxV5 ParadoxV5 Jun 26, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Late but non-important comment:
What do the software/script conventions define --dry/--dry-run as?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

git has a --dry-run, don't know others. its like conducting a rehearsal.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

it's MySQL compatibility, if I'm not mistaken. We should use the same name that MySQL does

@raghunandanbhat raghunandanbhat left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@bodyhedia44, your recent changes failed to compile on few buildbots, please fix them.

since this is a mysql compatibility feature, I'd be ok with it not validating configs related to storage engines or plugins which are not initialized (similar to what mysql does) -

The scope of the --validate-config option is limited to configuration checking that the server can perform without undergoing its normal startup process. As such, the configuration check does not initialize storage engines and other plugins, components, and so forth, and does not validate options associated with those uninitialized subsystems.

@vuvova any thoughts? skip validating configs for uninitialized serve components?

Comment thread sql/mysqld.cc Outdated
{
if (validate_config_has_warnings)
sql_print_information("Configuration is valid, but some option values "
"were adjusted; see warnings above.");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this message can be misleading at times when only warning is printed and no options were adjusted.
validate_config_has_warnings is set for every WARNING_LEVEL message, not just value adjustments. So an out-of-scope warning like --validate-config --plugin-load-add=aaaa emitting unknown variable ... - prints "some option values were adjusted" even though nothing was adjusted.

Either set the flag only when a value is actually adjusted or re-word the message to something honest for all warnings. ex: "Configuration is valid; warnings were reported, see above."

@bodyhedia44
bodyhedia44 force-pushed the MDEV-31527-validate-config branch from 9af3d42 to c855268 Compare July 9, 2026 17:49
@bodyhedia44

Copy link
Copy Markdown
Contributor Author

Hi @raghunandanbhat

All three failing CI checks are unrelated to this PR — none touch the --validate-config code path, and main.validate_config passes on every builder that ran it.

amd64-msan-clang-20 and amd64-ubuntu-2204-debug-ps — both fail on innodb.skip_locked_nowait, which times out with ER_LOCK_WAIT_TIMEOUT (1205). It's a timing-sensitive InnoDB row-lock test (unrelated to config parsing).

amd64-debian-12-deb-autobake — fails at dpkg-checkbuilddeps: Unmet build dependencies: libboost-system-dev, aborting in <1s before any compilation. That's a build dependency missing on the worker, not a code issue.

@bodyhedia44

Copy link
Copy Markdown
Contributor Author

the old faild builds i fixed it

@bodyhedia44

Copy link
Copy Markdown
Contributor Author

@raghunandanbhat Gentle ping on this! I've addressed the previous comments and it's ready for another look whenever you have a moment.

…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.
  When any value is adjusted, the success note says "Configuration is valid, but
  some option values were adjusted; see warnings above."

Exit codes:
  0  - Configuration is valid
  2  - Unknown option encountered
  7  - Unknown variable encountered
  Other non-zero codes are possible for other parse errors (e.g. invalid enum
  value, numeric parse error). The option description now correctly states
  "non-zero for failure" rather than "1 for failure".

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.

--help and --version take precedence: when either is present alongside
--validate-config, the server prints help/version and exits cleanly without
performing config validation. Tests 7, 10, 11, 12 cover these cases.

Bug fixes included in this patch:
- --validate-config --log-bin no longer creates a spurious <host>-bin.index
  file in the datadir. The binlog index open is now guarded by !opt_abort
  (was: !opt_help), skipping it for all early-exit paths including --help
  --verbose.
- Simplified early-exit condition in init_common_variables() from a
  four-variable expression to (opt_help || opt_version) && !opt_verbose,
  which is equivalent and clearer (vuvova review).
- Simplified success-message condition in init_server_components() by
  removing redundant !opt_help && !opt_version guards; those paths already
  exit before reaching this point (vuvova review).

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.).
@raghunandanbhat
raghunandanbhat force-pushed the MDEV-31527-validate-config branch from c855268 to 663dc80 Compare August 10, 2026 12:27

@raghunandanbhat raghunandanbhat left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

looks good, thanks @bodyhedia44.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

External Contribution All PRs from entities outside of MariaDB Foundation, Corporation, Codership agreements.

Development

Successfully merging this pull request may close these issues.

6 participants