Skip to content

MDEV-39223 Reversed executable comments incorrectly written in binlog#4885

Open
tonychen2001 wants to merge 1 commit intoMariaDB:mainfrom
tonychen2001:MDEV-39223
Open

MDEV-39223 Reversed executable comments incorrectly written in binlog#4885
tonychen2001 wants to merge 1 commit intoMariaDB:mainfrom
tonychen2001:MDEV-39223

Conversation

@tonychen2001
Copy link
Copy Markdown
Contributor

@tonychen2001 tonychen2001 commented Mar 31, 2026

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 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.

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:

  • mix of applied/not-applied
  • prepared statements
  • unclosed comments,
  • nested comments
  • delimiter edge case
  • MariaDB-specific /*M!! syntax

Basing the PR against the correct MariaDB version

  • This is a bug fix, and the PR is based against the branch main as the 13.0 branch does not exist at the moment.

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.

@gkodinov gkodinov added the External Contribution All PRs from entities outside of MariaDB Foundation, Corporation, Codership agreements. label Apr 1, 2026
Copy link
Copy Markdown
Member

@gkodinov gkodinov left a comment

Choose a reason for hiding this comment

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

Thank you for fixing this so fast! This is a preliminary review.

LGTM.

Please stand by for the final review.

@gkodinov gkodinov requested a review from bnestere April 1, 2026 08:39
@tonychen2001 tonychen2001 force-pushed the MDEV-39223 branch 2 times, most recently from 0457aaa to ead8834 Compare April 11, 2026 00:07
Copy link
Copy Markdown
Contributor

@bnestere bnestere left a comment

Choose a reason for hiding this comment

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

Thank you for the patch, @tonychen2001 !

i've left a couple comments.

Comment thread mysql-test/suite/rpl/t/rpl_reversed_comments.test Outdated
Comment thread sql/sql_lex.cc
Copy link
Copy Markdown
Contributor

@bnestere bnestere left a comment

Choose a reason for hiding this comment

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

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>

Comment thread sql/sql_lex.cc
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>
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.

4 participants