MDEV-39223 Reversed executable comments incorrectly written in binlog#4885
Open
tonychen2001 wants to merge 1 commit intoMariaDB:mainfrom
Open
MDEV-39223 Reversed executable comments incorrectly written in binlog#4885tonychen2001 wants to merge 1 commit intoMariaDB:mainfrom
tonychen2001 wants to merge 1 commit intoMariaDB:mainfrom
Conversation
gkodinov
reviewed
Apr 1, 2026
Member
gkodinov
left a comment
There was a problem hiding this comment.
Thank you for fixing this so fast! This is a preliminary review.
LGTM.
Please stand by for the final review.
gkodinov
approved these changes
Apr 1, 2026
0457aaa to
ead8834
Compare
bnestere
requested changes
Apr 15, 2026
Contributor
bnestere
left a comment
There was a problem hiding this comment.
Thank you for the patch, @tonychen2001 !
i've left a couple comments.
ead8834 to
3ad7288
Compare
bnestere
approved these changes
Apr 16, 2026
Contributor
bnestere
left a comment
There was a problem hiding this comment.
Looks good, @tonychen2001! Thanks for updating the test with a quick turnaround.
Please also remember to update the git commit message with your reviewer (me)
Reviewed-by: Brandon Nesterenko <brandon.nesterenko@mariadb.com>
When a reversed executable comment (/*!!version */ or /*M!!version */) is not executed on the master (server version >= specified version), the binlog writer only neutralized the second '!' to a space, leaving `/*! command */`, an executable comment the slave would then try to execute. Fix (non-executed path): also replace the first '!' with a space so the SQL becomes /* (a plain comment). The restore path for unclosed comments also restores both '!' characters. Additionally, when a reversed executable comment IS executed on the source (server version < specified version), the /*!!version syntax was preserved verbatim in the binlog. A replica with a higher version could re-evaluate the reversed condition, fail it, and skip the command — causing source/replica divergence. Unlike forward executable comments (/*!version */), where replication to same-or-higher versions guarantees the replica also executes, reversed comments have the opposite semantics and are not safe to preserve as-is. Fix (executed path): overwrite the version digits with spaces in the raw query buffer so the binlog contains /*!! (a non-versioned reversed executable comment) which the replica always executes regardless of its version. Added rpl_reversed_comments.test mirroring rpl_conditional_comments.test with reversed equivalents for all forward comment replication test cases: mix of applied/not-applied, prepared statements, unclosed comments, nested comments, delimiter edge case, and MariaDB-specific /*M!! syntax. All new code of the whole pull request, including one or several files that are either new files or modified ones, are contributed under the BSD-new license. I am contributing on behalf of my employer Amazon Web Services, Inc. Reviewed-by: Brandon Nesterenko <brandon.nesterenko@mariadb.com>
3ad7288 to
cdac834
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This addresses an issue introduced in #4724.
When a reversed executable comment (/*!!version */ or /*M!!version */)
is not executed on the master (server version >= specified version),
the binlog writer only neutralized the second '!' to a space, leaving
/*! command */, an executable comment the slave would then try toexecute.
Fix (non-executed path): also replace the first '!' with a space so the
SQL becomes /* (a plain comment). The restore path for unclosed comments
also restores both '!' characters.
Additionally, when a reversed executable comment IS executed on the
source (server version < specified version), the /!!version syntax was
preserved verbatim in the binlog. A replica with a higher version could
re-evaluate the reversed condition, fail it, and skip the command —
causing source/replica divergence. Unlike forward executable comments
(/!version */), where replication to same-or-higher versions guarantees
the replica also executes, reversed comments have the opposite semantics
and are not safe to preserve as-is.
Fix (executed path): overwrite the version digits with spaces in the raw
query buffer so the binlog contains /*!! (a non-versioned reversed
executable comment) which the replica always executes regardless of its
version.
Ultimately, if a reverse comment was executed on the source it must be executed on the replica regardless of
versioning. Similarly, if a reverse comment was not executed on the source it must not be executed on the replica regardless of versioning.
How can this PR be tested?
Added rpl_reversed_comments.test mirroring rpl_conditional_comments.test
with equivalent test cases:
Basing the PR against the correct MariaDB version
Copyright
All new code of the whole pull request, including one or several files that are either new files or modified ones, are contributed under the BSD-new license. I am contributing on behalf of my employer Amazon Web Services, Inc.