Skip to content

MDEV-35635: START SLAVE UNTIL allows CHANGE MASTER TO options #3909

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

MohanadKh03
Copy link
Contributor

@MohanadKh03 MohanadKh03 commented Mar 21, 2025

  • *The Jira issue number for this PR is: MDEV-35635

Description

This commit separates master's options from slave options in sql_yacc.yy by replacing master_file_def with slave_until_file_def which only contain the options needed in the query:

START SLAVE UNTIL

These are the only options valid in this query
MASTER_LOG_FILE_SYM, MASTER_LOG_POS_SYM, RELAY_LOG_FILE_SYM and RELAY_LOG_POS_SYM and MASTER_GTID_POS

This is only a change in the symbols the START SLAVE command did not use any functionalty related to what was included in master_file_def

Release Notes

How can this PR be tested?

This can be tested using start_slave_until.test file which should test valid options queries and invalid ones
Invalid being anything that is not part of this
MASTER_LOG_FILE_SYM, MASTER_LOG_POS_SYM, RELAY_LOG_FILE_SYM and RELAY_LOG_POS_SYM and MASTER_GTID_POS

Basing the PR against the correct MariaDB version

  • This is a new feature or a refactoring, and the PR is based against the main branch.
  • This is a bug fix, and the PR is based against the earliest maintained branch in which the bug can be reproduced.

PR quality check

  • I checked the CODING_STANDARDS.md file and my PR conforms to this where appropriate.
  • For any trivial modifications to the PR, I am ok with the reviewer making the changes themselves.

@svoj svoj added the External Contribution All PRs from entities outside of MariaDB Foundation, Corporation, Codership agreements. label Mar 21, 2025
Copy link
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.

Hi @MohanadKh03 !

Thanks for submitting the patch with a test case already! I've left a few suggestions to the test, and then a couple more suggestions for the git commit message itself:

  1. Please keep each line to 72 characters in length
  2. Git commit messages don't support markdown, so you can remove/simplify the formatting a bit (though note the PR description does support markdown)
  3. Can you re-phrase/extend the problem description to start off with a description that is more user-facing? That is, a typical user won't know what "master_file_def options" are, but you can describe the problem without using that phrase. Then later in the commit message, you can mention it (as it is good to still mention this for developers).

# Clean up after tests.
DROP TABLE t1;
source include/rpl_end.inc;
# ==== End of test ====
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you echo the "End of test" line? And also end the file in a new line.


connection slave;
-- error ER_PARSE_ERROR
start slave until master_log_file='$master_log_file', master_log_pos=$master_log_pos_1, MASTER_USE_GTID=NO, MASTER_DEMOTE_TO_SLAVE=1;
Copy link
Contributor

Choose a reason for hiding this comment

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

To use value substitution (using for variables set via the let mysqltest construct), you need to start the line with the mysqltest command eval. So this should be

Suggested change
start slave until master_log_file='$master_log_file', master_log_pos=$master_log_pos_1, MASTER_USE_GTID=NO, MASTER_DEMOTE_TO_SLAVE=1;
eval start slave until master_log_file='$master_log_file', master_log_pos=$master_log_pos_1, MASTER_USE_GTID=NO, MASTER_DEMOTE_TO_SLAVE=1;

Though to the complete test case, I don't think you actually need to use substitution at all, as you are just testing parsing options. So ultimately I'd say you could do something like

Suggested change
start slave until master_log_file='$master_log_file', master_log_pos=$master_log_pos_1, MASTER_USE_GTID=NO, MASTER_DEMOTE_TO_SLAVE=1;
--error ER_PARSE_ERROR
start slave until master_log_file='master-bin.000001', master_log_pos=4, MASTER_USE_GTID=NO, MASTER_DEMOTE_TO_SLAVE=1;
--error ER_BAD_SLAVE
start slave until master_log_file='master-bin.000001', master_log_pos=4;

and a few other options to test completeness.

# MDEV-35635
# Testing issues around invalid parameters and START SLAVE UNTIL behavior.

# Include necessary configurations
Copy link
Contributor

Choose a reason for hiding this comment

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

You shouldn't need any pre-amble source for this test, as it is just testing parsing. I think really all that this test needs are the actual start slave lines, no set-up data is needed. Then, for a "passing" test, you can just set the expectation ER_BAD_SLAVE (as no slave is actually configured, but it proves the parsing has gone through)

@MohanadKh03 MohanadKh03 marked this pull request as ready for review March 25, 2025 00:47
@MohanadKh03 MohanadKh03 requested a review from bnestere March 26, 2025 00:48
Copy link
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.

Hi @MohanadKh03 ,

Looks great, thanks! I very much appreciate the spelling out of the test description and git commit message :)

I'm going to pass review along to our replication QA engineer, @mariadb-SusilBehera , to give an extra set of eyes to your MTR test.

#
# Valid query options (using only slave options)
#

Copy link
Contributor

Choose a reason for hiding this comment

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

Here could you --echo to restate

ER_BAD_SLAVE: Dummy error which should be treated as a passing test as this is a parser test not a logical one

So when looking through the .result file, it is stated that the error is good?

sql/sql_yacc.yy Outdated
| RELAY_LOG_POS_SYM '=' ulong_num
{
Lex->mi.relay_log_pos = $3;
Lex->mi.relay_log_pos= MY_MAX(BIN_LOG_HEADER_SIZE, Lex->mi.relay_log_pos);
Copy link
Contributor

Choose a reason for hiding this comment

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

You should be able to just use $3, like in MASTER_LOG_POS_SYM's definition. Also, can you reiterate the comment about what this MY_MAX operator is for, as is done with master_file_def

Suggested change
Lex->mi.relay_log_pos= MY_MAX(BIN_LOG_HEADER_SIZE, Lex->mi.relay_log_pos);
/* Adjust if < BIN_LOG_HEADER_SIZE (same comment as master_file_dif rule for MASTER_LOG_POS_SYM) */
Lex->mi.relay_log_pos= MY_MAX(BIN_LOG_HEADER_SIZE, $3);

--error ER_BAD_SLAVE
START slave UNTIL MASTER_GTID_POS = '0-1-1';

# Clean up after tests.
Copy link
Contributor

Choose a reason for hiding this comment

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

There's no clean up to be done, so you can probably just remove this line altogether

START slave UNTIL MASTER_GTID_POS = '0-1-1';

# Clean up after tests.
--echo ==== End of test ====
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
--echo ==== End of test ====
--echo ==== End of test main.start_slave_until ====

@bnestere bnestere self-assigned this Apr 1, 2025
Copy link

@mariadb-SusilBehera mariadb-SusilBehera left a comment

Choose a reason for hiding this comment

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

I've added just one more review comment.

;

slave_until_file_def:

Choose a reason for hiding this comment

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

MASTER_GTID_POS is missing here. Shouldn't we include an entry for this here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not really needed inside this one this is just for handling master/slave combinations for MASTER/SLAVE_LOG_FILE and MASTER/SLAVE_LOG_POS

but MASTER_GTID_POS_SYM is already in the slave_until rule

server/sql/sql_yacc.yy

Lines 8397 to 8400 in 2fe28c6

| UNTIL_SYM MASTER_GTID_POS_SYM '=' TEXT_STRING_sys
{
Lex->mi.gtid_pos_str = $4;
Lex->mi.is_until_before_gtids= false;

@MohanadKh03 MohanadKh03 force-pushed the mdev-35635 branch 2 times, most recently from 5b57a37 to 4e73f9e Compare April 2, 2025 21:50
@bnestere
Copy link
Contributor

To report on the status of this ticket, the work has been reviewed and accepted, and is waiting to be QA tested as part of the 12.1 sprint, which is planned to start on June 3.

@bnestere bnestere added the Replication Patches involved in replication label May 28, 2025
Restrict START SLAVE UNTIL to slave options disallowing master options

START SLAVE UNTIL was allowing both slave and master options, which
could cause confusion and misconfigurations. This commit fixes that by
restricting it to these valid slave options:
     - MASTER_LOG_FILE, MASTER_LOG_POS
     - RELAY_LOG_FILE, RELAY_LOG_POS
     - MASTER_GTID_POS

The parser change replaces `master_file_def` with `slave_until_file_def`
in `sql_yacc.yy`, making sure master options like MASTER_USE_GTID and
MASTER_DEMOTE_TO_SLAVE aren’t allowed anymore.
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. Replication Patches involved in replication
Development

Successfully merging this pull request may close these issues.

4 participants