From fd0156fc130759b762af6ce9aa46ec0a536021da Mon Sep 17 00:00:00 2001 From: Geng Tian Date: Tue, 2 Dec 2025 00:18:18 +0000 Subject: [PATCH] MDEV-37842 Fix CHANGE_MASTER_TO warning message When `master_use_gtid` is set to no in the master database and the user runs `CHANGE MASTER TO master_use_gtid= NO;`, the server will print following warning: ``` Note 4190 CHANGE MASTER TO is implicitly changing the value of 'Using_Gtid' from 'No' to 'No' ``` This is because the code only checks if the new value is "NO", regardless if the original value is also no. Change the if statement to only print the message when the original value is not "No". --- ...l_change_master_use_gtid_no_warning.result | 34 +++++++++ ...rpl_change_master_use_gtid_no_warning.test | 69 +++++++++++++++++++ sql/sql_repl.cc | 2 +- 3 files changed, 104 insertions(+), 1 deletion(-) create mode 100644 mysql-test/suite/rpl/r/rpl_change_master_use_gtid_no_warning.result create mode 100644 mysql-test/suite/rpl/t/rpl_change_master_use_gtid_no_warning.test diff --git a/mysql-test/suite/rpl/r/rpl_change_master_use_gtid_no_warning.result b/mysql-test/suite/rpl/r/rpl_change_master_use_gtid_no_warning.result new file mode 100644 index 0000000000000..4f12ba8c71c54 --- /dev/null +++ b/mysql-test/suite/rpl/r/rpl_change_master_use_gtid_no_warning.result @@ -0,0 +1,34 @@ +include/master-slave.inc +[connection master] +connection slave; +include/stop_slave.inc +# +# Test Case 1: No warning when Using_Gtid is already 'No' and +# explicitly setting master_use_gtid=NO +# +CHANGE MASTER TO master_use_gtid=NO; +# Using_Gtid should be 'No': No +CHANGE MASTER TO master_use_gtid=NO; +# No warning should appear above +# +# Test Case 2: No warning when Using_Gtid is already 'No' and +# setting relay_log_pos (which implicitly sets Using_Gtid to No) +# +CHANGE MASTER TO relay_log_pos=0; +# No warning should appear above +# +# Test Case 3: Warning IS shown when actually changing from +# Slave_Pos to No (via relay_log_pos) +# +CHANGE MASTER TO master_use_gtid=Slave_Pos; +# Using_Gtid should be 'Slave_Pos': Slave_Pos +CHANGE MASTER TO relay_log_pos=0; +Warnings: +Note 4190 CHANGE MASTER TO is implicitly changing the value of 'Using_Gtid' from 'Slave_Pos' to 'No' +# Warning 4190 should appear above about changing from 'Slave_Pos' to 'No' +# +# Cleanup +# +CHANGE MASTER TO master_use_gtid=NO; +include/start_slave.inc +include/rpl_end.inc diff --git a/mysql-test/suite/rpl/t/rpl_change_master_use_gtid_no_warning.test b/mysql-test/suite/rpl/t/rpl_change_master_use_gtid_no_warning.test new file mode 100644 index 0000000000000..ecce85f064079 --- /dev/null +++ b/mysql-test/suite/rpl/t/rpl_change_master_use_gtid_no_warning.test @@ -0,0 +1,69 @@ +# +# MDEV-37842: Fix CHANGE_MASTER_TO warning message +# +# Purpose: +# Verify that CHANGE MASTER TO master_use_gtid=NO does not produce +# a spurious warning when Using_Gtid is already 'No'. +# +# The bug was that running: +# CHANGE MASTER TO master_use_gtid=NO; +# when Using_Gtid was already 'No' would produce: +# Note 4190 CHANGE MASTER TO is implicitly changing the value of +# 'Using_Gtid' from 'No' to 'No' +# +# This test verifies: +# 1. No warning when changing from No to No (explicit master_use_gtid=NO) +# 2. No warning when Using_Gtid is already No and relay_log_pos is set (which implicitly sets Using_Gtid to No) +# 3. Warning IS shown when actually changing from Slave_Pos to No +# + +--source include/master-slave.inc + +--connection slave +--source include/stop_slave.inc + +--echo # +--echo # Test Case 1: No warning when Using_Gtid is already 'No' and +--echo # explicitly setting master_use_gtid=NO +--echo # + +# First ensure Using_Gtid is No +CHANGE MASTER TO master_use_gtid=NO; +--let $using_gtid= query_get_value(SHOW SLAVE STATUS, Using_Gtid, 1) +--echo # Using_Gtid should be 'No': $using_gtid + +# Now set it to NO again - should NOT produce warning 4190 +CHANGE MASTER TO master_use_gtid=NO; +--echo # No warning should appear above + +--echo # +--echo # Test Case 2: No warning when Using_Gtid is already 'No' and +--echo # setting relay_log_pos (which implicitly sets Using_Gtid to No) +--echo # + +# Using_Gtid is still No from previous test +CHANGE MASTER TO relay_log_pos=0; +--echo # No warning should appear above + +--echo # +--echo # Test Case 3: Warning IS shown when actually changing from +--echo # Slave_Pos to No (via relay_log_pos) +--echo # + +# Set Using_Gtid to Slave_Pos first +CHANGE MASTER TO master_use_gtid=Slave_Pos; +--let $using_gtid= query_get_value(SHOW SLAVE STATUS, Using_Gtid, 1) +--echo # Using_Gtid should be 'Slave_Pos': $using_gtid + +# Now set relay_log_pos which implicitly changes Using_Gtid to No +# This SHOULD produce warning 4190 +CHANGE MASTER TO relay_log_pos=0; +--echo # Warning 4190 should appear above about changing from 'Slave_Pos' to 'No' + +--echo # +--echo # Cleanup +--echo # +CHANGE MASTER TO master_use_gtid=NO; +--source include/start_slave.inc + +--source include/rpl_end.inc diff --git a/sql/sql_repl.cc b/sql/sql_repl.cc index 21b7aa84f1780..7dba05a597bf1 100644 --- a/sql/sql_repl.cc +++ b/sql/sql_repl.cc @@ -3869,7 +3869,7 @@ bool change_master(THD* thd, Master_info* mi, bool *master_info_added) lex_mi->log_file_name || lex_mi->pos || lex_mi->relay_log_name || lex_mi->relay_log_pos) { - if (lex_mi->use_gtid_opt != LEX_MASTER_INFO::LEX_GTID_NO) + if (lex_mi->use_gtid_opt != LEX_MASTER_INFO::LEX_GTID_NO && mi->using_gtid_astext(mi->using_gtid) != mi->using_gtid_astext(Master_info::USE_GTID_NO)) { push_warning_printf( thd, Sql_condition::WARN_LEVEL_NOTE, WARN_OPTION_CHANGING,