Skip to content
New issue

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

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

Already on GitHub? # to your account

MDEV-19248 Implement MASTER_BIND for CHANGE MASTER #3883

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions mysql-test/include/check-testcase.inc
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ if ($tmp)
--echo Replicate_Rewrite_DB #
--echo Connects_Tried #
--echo Master_Retry_Count #
--echo Master_Bind
}
if (!$tmp) {
# Note: after WL#5177, fields 13-18 shall not be filtered-out.
Expand Down
55 changes: 55 additions & 0 deletions mysql-test/main/master_bind_basic.result
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Is `''` when not specified
CHANGE MASTER 'named' TO master_host='example.com';
CHANGE MASTER TO master_host='127.0.0.1', master_ssl_verify_server_cert=0;
SELECT Connection_name, Master_Bind FROM information_schema.SLAVE_STATUS;
Connection_name Master_Bind

named
# Replace when specified
CHANGE MASTER 'named' TO master_bind='localhost';
CHANGE MASTER TO master_bind='127.0.0.1';
SELECT Connection_name, Master_Bind FROM information_schema.SLAVE_STATUS;
Connection_name Master_Bind
127.0.0.1
named localhost

Choose a reason for hiding this comment

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

IMO master_bind is for network interface name. But here in the test we've IP address and hostname instead. Shouldn't we test with network interface name?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good call. Why did MySQL document as and test with IP addresses 😕?

Choose a reason for hiding this comment

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

I couldn't find any MySQL test which does MASTER_BIND testing. But the doc https://dev.mysql.com/doc/refman/8.0/en/change-master-to.html says MASTER_BIND = 'interface_name'.

Copy link
Contributor Author

@ParadoxV5 ParadoxV5 Mar 11, 2025

Choose a reason for hiding this comment

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

Choose a reason for hiding this comment

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

Thank you for the pointers. MASTER_BIND is network interface IP address only. The doc should have MASTER_BIND = 'interface_ip_address' instead. But do we need MASTER_HOST if MASTER_BIND is set?

Copy link
Contributor Author

@ParadoxV5 ParadoxV5 Mar 12, 2025

Choose a reason for hiding this comment

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

  • MASTER_BIND = address of this replica to connect with (optional)
  • MASTER_HOST = address of the primary to connect to (mandatory)

# SHOW SLAVE STATUS also show the configuations
Connection_name = ''
Connection_name = 'named'
Master_Bind = '127.0.0.1'
Master_Bind = 'localhost'
Master_Bind = '127.0.0.1'
Master_Bind = 'localhost'
# Restore specified config on restart
# restart: --skip-slave-start
SELECT Connection_name, Master_Bind FROM information_schema.SLAVE_STATUS;
Connection_name Master_Bind
127.0.0.1
named localhost
# Keep specified config on RESET REPLICA
RESET REPLICA 'named';
RESET REPLICA;
SELECT Connection_name, Master_Bind FROM information_schema.SLAVE_STATUS;
Connection_name Master_Bind
127.0.0.1
named localhost
# Don't replace when not specified
CHANGE MASTER TO master_user='root';
CHANGE MASTER 'named' TO master_user='root';
SELECT Connection_name, Master_Bind FROM information_schema.SLAVE_STATUS;
Connection_name Master_Bind
127.0.0.1
named localhost
# Numeric
CHANGE MASTER TO master_bind=10;
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '10' at line 1
CHANGE MASTER 'named' TO master_bind=11;
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '11' at line 1
# `''` also counts as specified
CHANGE MASTER TO master_bind='';
CHANGE MASTER 'named' TO master_bind='';
SELECT Connection_name, Master_Bind FROM information_schema.SLAVE_STATUS;
Connection_name Master_Bind

Choose a reason for hiding this comment

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

We can add a test with a non-existing network interface value. SHOW SLAVE STATUS should error out.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Be it interface or address, currently the field doesn’t check its string value and rely on the replicating client to check its options at START REPLICA.

And I think that’s fine: technically one might upgrade their hardware upgrade inbetween CHANGE MASTER nand START REPLICA.

Choose a reason for hiding this comment

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

Ok. Shall cover it at QA stage.

named
# Cleanup
RESET REPLICA 'named' ALL;
53 changes: 53 additions & 0 deletions mysql-test/main/master_bind_basic.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# MDEV-19248: Test the `Master_Bind` field of
# CHANGE MASTER [name] TO and SHOW SLAVE [name] STATUS & co. (no feature testing)
# Two connections tests that the field is per-connection.

--echo # Is `''` when not specified
CHANGE MASTER 'named' TO master_host='example.com';
CHANGE MASTER TO master_host='127.0.0.1', master_ssl_verify_server_cert=0;
SELECT Connection_name, Master_Bind FROM information_schema.SLAVE_STATUS;

--echo # Replace when specified
CHANGE MASTER 'named' TO master_bind='localhost';
# Default master does not replace named master
CHANGE MASTER TO master_bind='127.0.0.1';
SELECT Connection_name, Master_Bind FROM information_schema.SLAVE_STATUS;

--echo # SHOW SLAVE STATUS also show the configuations
--let $all_slaves_status= 1
--let $status_items= Connection_name, Master_Bind
--source include/show_slave_status.inc
--let $all_slaves_status= 0
--let $status_items= Master_Bind
--source include/show_slave_status.inc
--let $slave_name= 'named'
--source include/show_slave_status.inc

--echo # Restore specified config on restart
--let $restart_parameters= --skip-slave-start
--source include/restart_mysqld.inc # not_embedded
SELECT Connection_name, Master_Bind FROM information_schema.SLAVE_STATUS;

--echo # Keep specified config on RESET REPLICA
RESET REPLICA 'named';
RESET REPLICA;
SELECT Connection_name, Master_Bind FROM information_schema.SLAVE_STATUS;

--echo # Don't replace when not specified
CHANGE MASTER TO master_user='root';
CHANGE MASTER 'named' TO master_user='root';
SELECT Connection_name, Master_Bind FROM information_schema.SLAVE_STATUS;

--echo # Numeric
--error ER_PARSE_ERROR
CHANGE MASTER TO master_bind=10;
--error ER_PARSE_ERROR
CHANGE MASTER 'named' TO master_bind=11;

--echo # `''` also counts as specified
CHANGE MASTER TO master_bind='';
CHANGE MASTER 'named' TO master_bind='';
SELECT Connection_name, Master_Bind FROM information_schema.SLAVE_STATUS;

--echo # Cleanup
RESET REPLICA 'named' ALL;
20 changes: 11 additions & 9 deletions mysql-test/suite/funcs_1/r/is_columns_is.result
Original file line number Diff line number Diff line change
Expand Up @@ -392,23 +392,24 @@ def information_schema SESSION_VARIABLES VARIABLE_VALUE 2 NULL NO varchar 4096 1
def information_schema SLAVE_STATUS Connection_name 1 NULL NO varchar 64 192 NULL NULL NULL utf8mb3 utf8mb3_general_ci varchar(64) select NEVER NULL NO NO
def information_schema SLAVE_STATUS Connects_Tried 57 NULL NO bigint NULL NULL 20 0 NULL NULL NULL bigint(20) unsigned select NEVER NULL NO NO
def information_schema SLAVE_STATUS Connect_Retry 7 NULL NO int NULL NULL 10 0 NULL NULL NULL int(10) unsigned select NEVER NULL NO NO
def information_schema SLAVE_STATUS Executed_log_entries 61 NULL NO int NULL NULL 10 0 NULL NULL NULL int(10) unsigned select NEVER NULL NO NO
def information_schema SLAVE_STATUS Executed_log_entries 62 NULL NO int NULL NULL 10 0 NULL NULL NULL int(10) unsigned select NEVER NULL NO NO
def information_schema SLAVE_STATUS Exec_Master_Log_Pos 24 NULL NO bigint NULL NULL 20 0 NULL NULL NULL bigint(20) unsigned select NEVER NULL NO NO
def information_schema SLAVE_STATUS Gtid_IO_Pos 46 NULL NO varchar 21844 65532 NULL NULL NULL utf8mb3 utf8mb3_general_ci varchar(21844) select NEVER NULL NO NO
def information_schema SLAVE_STATUS Gtid_Slave_Pos 64 NULL NO varchar 21844 65532 NULL NULL NULL utf8mb3 utf8mb3_general_ci varchar(21844) select NEVER NULL NO NO
def information_schema SLAVE_STATUS Gtid_Slave_Pos 65 NULL NO varchar 21844 65532 NULL NULL NULL utf8mb3 utf8mb3_general_ci varchar(21844) select NEVER NULL NO NO
def information_schema SLAVE_STATUS Last_Errno 21 NULL NO smallint NULL NULL 5 0 NULL NULL NULL smallint(4) unsigned select NEVER NULL NO NO
def information_schema SLAVE_STATUS Last_Error 22 NULL YES varchar 1024 3072 NULL NULL NULL utf8mb3 utf8mb3_general_ci varchar(1024) select NEVER NULL NO NO
def information_schema SLAVE_STATUS Last_IO_Errno 37 NULL NO smallint NULL NULL 5 0 NULL NULL NULL smallint(4) unsigned select NEVER NULL NO NO
def information_schema SLAVE_STATUS Last_IO_Error 38 NULL YES varchar 1024 3072 NULL NULL NULL utf8mb3 utf8mb3_general_ci varchar(1024) select NEVER NULL NO NO
def information_schema SLAVE_STATUS Last_SQL_Errno 39 NULL NO smallint NULL NULL 5 0 NULL NULL NULL smallint(4) unsigned select NEVER NULL NO NO
def information_schema SLAVE_STATUS Last_SQL_Error 40 NULL YES varchar 1024 3072 NULL NULL NULL utf8mb3 utf8mb3_general_ci varchar(1024) select NEVER NULL NO NO
def information_schema SLAVE_STATUS Master_Bind 59 NULL YES varchar 255 765 NULL NULL NULL utf8mb3 utf8mb3_general_ci varchar(255) select NEVER NULL NO NO
def information_schema SLAVE_STATUS Master_Host 4 NULL YES varchar 255 765 NULL NULL NULL utf8mb3 utf8mb3_general_ci varchar(255) select NEVER NULL NO NO
def information_schema SLAVE_STATUS Master_last_event_time 65 NULL YES datetime NULL NULL NULL NULL 0 NULL NULL datetime select NEVER NULL NO NO
def information_schema SLAVE_STATUS Master_last_event_time 66 NULL YES datetime NULL NULL NULL NULL 0 NULL NULL datetime select NEVER NULL NO NO
def information_schema SLAVE_STATUS Master_Log_File 8 NULL NO varchar 512 1536 NULL NULL NULL utf8mb3 utf8mb3_general_ci varchar(512) select NEVER NULL NO NO
def information_schema SLAVE_STATUS Master_Port 6 NULL NO smallint NULL NULL 5 0 NULL NULL NULL smallint(5) unsigned select NEVER NULL NO NO
def information_schema SLAVE_STATUS Master_Retry_Count 58 NULL NO bigint NULL NULL 20 0 NULL NULL NULL bigint(20) unsigned select NEVER NULL NO NO
def information_schema SLAVE_STATUS Master_Server_Id 42 NULL NO int NULL NULL 10 0 NULL NULL NULL int(10) unsigned select NEVER NULL NO NO
def information_schema SLAVE_STATUS Master_Slave_time_diff 67 NULL YES int NULL NULL 10 0 NULL NULL NULL int(10) unsigned select NEVER NULL NO NO
def information_schema SLAVE_STATUS Master_Slave_time_diff 68 NULL YES int NULL NULL 10 0 NULL NULL NULL int(10) unsigned select NEVER NULL NO NO
def information_schema SLAVE_STATUS Master_SSL_Allowed 29 NULL YES varchar 7 21 NULL NULL NULL utf8mb3 utf8mb3_general_ci varchar(7) select NEVER NULL NO NO
def information_schema SLAVE_STATUS Master_SSL_CA_File 30 NULL YES varchar 512 1536 NULL NULL NULL utf8mb3 utf8mb3_general_ci varchar(512) select NEVER NULL NO NO
def information_schema SLAVE_STATUS Master_SSL_CA_Path 31 NULL YES varchar 512 1536 NULL NULL NULL utf8mb3 utf8mb3_general_ci varchar(512) select NEVER NULL NO NO
Expand All @@ -419,7 +420,7 @@ def information_schema SLAVE_STATUS Master_SSL_Crlpath 44 NULL YES varchar 512 1
def information_schema SLAVE_STATUS Master_SSL_Key 34 NULL YES varchar 512 1536 NULL NULL NULL utf8mb3 utf8mb3_general_ci varchar(512) select NEVER NULL NO NO
def information_schema SLAVE_STATUS Master_SSL_Verify_Server_Cert 36 NULL NO varchar 3 9 NULL NULL NULL utf8mb3 utf8mb3_general_ci varchar(3) select NEVER NULL NO NO
def information_schema SLAVE_STATUS Master_User 5 NULL YES varchar 384 1152 NULL NULL NULL utf8mb3 utf8mb3_general_ci varchar(384) select NEVER NULL NO NO
def information_schema SLAVE_STATUS Max_relay_log_size 60 NULL NO int NULL NULL 10 0 NULL NULL NULL int(10) unsigned select NEVER NULL NO NO
def information_schema SLAVE_STATUS Max_relay_log_size 61 NULL NO int NULL NULL 10 0 NULL NULL NULL int(10) unsigned select NEVER NULL NO NO
def information_schema SLAVE_STATUS Parallel_Mode 49 NULL NO varchar 12 36 NULL NULL NULL utf8mb3 utf8mb3_general_ci varchar(12) select NEVER NULL NO NO
def information_schema SLAVE_STATUS Read_Master_Log_Pos 9 NULL NO bigint NULL NULL 20 0 NULL NULL NULL bigint(20) unsigned select NEVER NULL NO NO
def information_schema SLAVE_STATUS Relay_Log_File 10 NULL NO varchar 512 1536 NULL NULL NULL utf8mb3 utf8mb3_general_ci varchar(512) select NEVER NULL NO NO
Expand All @@ -436,16 +437,16 @@ def information_schema SLAVE_STATUS Replicate_Ignore_Table 18 NULL NO varchar 21
def information_schema SLAVE_STATUS Replicate_Rewrite_DB 56 NULL NO varchar 21844 65532 NULL NULL NULL utf8mb3 utf8mb3_general_ci varchar(21844) select NEVER NULL NO NO
def information_schema SLAVE_STATUS Replicate_Wild_Do_Table 19 NULL NO varchar 21844 65532 NULL NULL NULL utf8mb3 utf8mb3_general_ci varchar(21844) select NEVER NULL NO NO
def information_schema SLAVE_STATUS Replicate_Wild_Ignore_Table 20 NULL NO varchar 21844 65532 NULL NULL NULL utf8mb3 utf8mb3_general_ci varchar(21844) select NEVER NULL NO NO
def information_schema SLAVE_STATUS Retried_transactions 59 NULL NO int NULL NULL 10 0 NULL NULL NULL int(10) unsigned select NEVER NULL NO NO
def information_schema SLAVE_STATUS Retried_transactions 60 NULL NO int NULL NULL 10 0 NULL NULL NULL int(10) unsigned select NEVER NULL NO NO
def information_schema SLAVE_STATUS Seconds_Behind_Master 35 NULL YES bigint NULL NULL 20 0 NULL NULL NULL bigint(20) unsigned select NEVER NULL NO NO
def information_schema SLAVE_STATUS Skip_Counter 23 NULL NO int NULL NULL 10 0 NULL NULL NULL int(10) unsigned select NEVER NULL NO NO
def information_schema SLAVE_STATUS Slave_DDL_Groups 53 NULL NO bigint NULL NULL 20 0 NULL NULL NULL bigint(20) unsigned select NEVER NULL NO NO
def information_schema SLAVE_STATUS Slave_heartbeat_period 63 NULL NO float NULL NULL 9 3 NULL NULL NULL float(9,3) select NEVER NULL NO NO
def information_schema SLAVE_STATUS Slave_heartbeat_period 64 NULL NO float NULL NULL 9 3 NULL NULL NULL float(9,3) select NEVER NULL NO NO
def information_schema SLAVE_STATUS Slave_IO_Running 13 NULL NO varchar 10 30 NULL NULL NULL utf8mb3 utf8mb3_general_ci varchar(10) select NEVER NULL NO NO
def information_schema SLAVE_STATUS Slave_IO_State 3 NULL YES varchar 64 192 NULL NULL NULL utf8mb3 utf8mb3_general_ci varchar(64) select NEVER NULL NO NO
def information_schema SLAVE_STATUS Slave_last_event_time 66 NULL YES datetime NULL NULL NULL NULL 0 NULL NULL datetime select NEVER NULL NO NO
def information_schema SLAVE_STATUS Slave_last_event_time 67 NULL YES datetime NULL NULL NULL NULL 0 NULL NULL datetime select NEVER NULL NO NO
def information_schema SLAVE_STATUS Slave_Non_Transactional_Groups 54 NULL NO bigint NULL NULL 20 0 NULL NULL NULL bigint(20) unsigned select NEVER NULL NO NO
def information_schema SLAVE_STATUS Slave_received_heartbeats 62 NULL NO int NULL NULL 10 0 NULL NULL NULL int(10) unsigned select NEVER NULL NO NO
def information_schema SLAVE_STATUS Slave_received_heartbeats 63 NULL NO int NULL NULL 10 0 NULL NULL NULL int(10) unsigned select NEVER NULL NO NO
def information_schema SLAVE_STATUS Slave_SQL_Running 14 NULL NO varchar 3 9 NULL NULL NULL utf8mb3 utf8mb3_general_ci varchar(3) select NEVER NULL NO NO
def information_schema SLAVE_STATUS Slave_SQL_Running_State 52 NULL YES varchar 21844 65532 NULL NULL NULL utf8mb3 utf8mb3_general_ci varchar(21844) select NEVER NULL NO NO
def information_schema SLAVE_STATUS Slave_SQL_State 2 NULL YES varchar 64 192 NULL NULL NULL utf8mb3 utf8mb3_general_ci varchar(64) select NEVER NULL NO NO
Expand Down Expand Up @@ -1124,6 +1125,7 @@ NULL information_schema SLAVE_STATUS Slave_Transactional_Groups bigint NULL NULL
3.0000 information_schema SLAVE_STATUS Replicate_Rewrite_DB varchar 21844 65532 utf8mb3 utf8mb3_general_ci varchar(21844)
NULL information_schema SLAVE_STATUS Connects_Tried bigint NULL NULL NULL NULL bigint(20) unsigned
NULL information_schema SLAVE_STATUS Master_Retry_Count bigint NULL NULL NULL NULL bigint(20) unsigned
3.0000 information_schema SLAVE_STATUS Master_Bind varchar 255 765 utf8mb3 utf8mb3_general_ci varchar(255)
NULL information_schema SLAVE_STATUS Retried_transactions int NULL NULL NULL NULL int(10) unsigned
NULL information_schema SLAVE_STATUS Max_relay_log_size int NULL NULL NULL NULL int(10) unsigned
NULL information_schema SLAVE_STATUS Executed_log_entries int NULL NULL NULL NULL int(10) unsigned
Expand Down
Loading