Skip to content
/ server Public
Open
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
120 changes: 114 additions & 6 deletions mysql-test/suite/multi_source/reset_slave.result
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
connect slave,127.0.0.1,root,,,$SERVER_MYPORT_3;
change master 'master1' to
master_port=MYPORT_1,
change master 'master1' to
master_port=MYPORT_1,
master_host='127.0.0.1', master_ssl_verify_server_cert=0,
master_user='root';
start slave 'master1';
Expand All @@ -13,15 +13,123 @@ insert into t1 values (1),(2);
connection slave;
stop slave 'master1';
show slave 'master1' status;
Slave_IO_State Master_Host Master_User Master_Port Connect_Retry Master_Log_File Read_Master_Log_Pos Relay_Log_File Relay_Log_Pos Relay_Master_Log_File Slave_IO_Running Slave_SQL_Running Replicate_Do_DB Replicate_Ignore_DB Replicate_Do_Table Replicate_Ignore_Table Replicate_Wild_Do_Table Replicate_Wild_Ignore_Table Last_Errno Last_Error Skip_Counter Exec_Master_Log_Pos Relay_Log_Space Until_Condition Until_Log_File Until_Log_Pos Master_SSL_Allowed Master_SSL_CA_File Master_SSL_CA_Path Master_SSL_Cert Master_SSL_Cipher Master_SSL_Key Seconds_Behind_Master Master_SSL_Verify_Server_Cert Last_IO_Errno Last_IO_Error Last_SQL_Errno Last_SQL_Error Replicate_Ignore_Server_Ids Master_Server_Id Master_SSL_Crl Master_SSL_Crlpath Using_Gtid Gtid_IO_Pos Replicate_Do_Domain_Ids Replicate_Ignore_Domain_Ids Parallel_Mode SQL_Delay SQL_Remaining_Delay Slave_SQL_Running_State Slave_DDL_Groups Slave_Non_Transactional_Groups Slave_Transactional_Groups Replicate_Rewrite_DB Connects_Tried Master_Retry_Count
127.0.0.1 root MYPORT_1 60 master-bin.000001 <read_master_log_pos> mysqld-relay-bin-master1.000002 <relay_log_pos> master-bin.000001 No No 0 0 <read_master_log_pos> <relay_log_space> None 0 Yes NULL No 0 0 1 Slave_Pos 0-1-3 optimistic 0 NULL 2 1 0 1 100000
Slave_IO_State
Master_Host 127.0.0.1
Master_User root
Master_Port MYPORT_1
Connect_Retry 60
Master_Log_File master-bin.000001
Read_Master_Log_Pos <read_master_log_pos>
Relay_Log_File mysqld-relay-bin-master1.000002
Relay_Log_Pos <relay_log_pos>
Relay_Master_Log_File master-bin.000001
Slave_IO_Running No
Slave_SQL_Running No
Replicate_Do_DB
Replicate_Ignore_DB
Replicate_Do_Table
Replicate_Ignore_Table
Replicate_Wild_Do_Table
Replicate_Wild_Ignore_Table
Last_Errno 0
Last_Error
Skip_Counter 0
Exec_Master_Log_Pos <read_master_log_pos>
Relay_Log_Space <relay_log_space>
Until_Condition None
Until_Log_File
Until_Log_Pos 0
Master_SSL_Allowed Yes
Master_SSL_CA_File
Master_SSL_CA_Path
Master_SSL_Cert
Master_SSL_Cipher
Master_SSL_Key
Seconds_Behind_Master NULL
Master_SSL_Verify_Server_Cert No
Last_IO_Errno 0
Last_IO_Error
Last_SQL_Errno 0
Last_SQL_Error
Replicate_Ignore_Server_Ids
Master_Server_Id 1
Master_SSL_Crl
Master_SSL_Crlpath
Using_Gtid Slave_Pos
Gtid_IO_Pos 0-1-3
Replicate_Do_Domain_Ids
Replicate_Ignore_Domain_Ids
Parallel_Mode optimistic
SQL_Delay 0
SQL_Remaining_Delay NULL
Slave_SQL_Running_State
Slave_DDL_Groups 2
Slave_Non_Transactional_Groups 1
Slave_Transactional_Groups 0
Replicate_Rewrite_DB
Connects_Tried 1
Master_Retry_Count 100000
mysqld-relay-bin-master1.000001
mysqld-relay-bin-master1.000002
mysqld-relay-bin-master1.index
reset slave 'master1';
show slave 'master1' status;
Slave_IO_State Master_Host Master_User Master_Port Connect_Retry Master_Log_File Read_Master_Log_Pos Relay_Log_File Relay_Log_Pos Relay_Master_Log_File Slave_IO_Running Slave_SQL_Running Replicate_Do_DB Replicate_Ignore_DB Replicate_Do_Table Replicate_Ignore_Table Replicate_Wild_Do_Table Replicate_Wild_Ignore_Table Last_Errno Last_Error Skip_Counter Exec_Master_Log_Pos Relay_Log_Space Until_Condition Until_Log_File Until_Log_Pos Master_SSL_Allowed Master_SSL_CA_File Master_SSL_CA_Path Master_SSL_Cert Master_SSL_Cipher Master_SSL_Key Seconds_Behind_Master Master_SSL_Verify_Server_Cert Last_IO_Errno Last_IO_Error Last_SQL_Errno Last_SQL_Error Replicate_Ignore_Server_Ids Master_Server_Id Master_SSL_Crl Master_SSL_Crlpath Using_Gtid Gtid_IO_Pos Replicate_Do_Domain_Ids Replicate_Ignore_Domain_Ids Parallel_Mode SQL_Delay SQL_Remaining_Delay Slave_SQL_Running_State Slave_DDL_Groups Slave_Non_Transactional_Groups Slave_Transactional_Groups Replicate_Rewrite_DB Connects_Tried Master_Retry_Count
127.0.0.1 root MYPORT_1 60 4 <relay_log_pos> No No 0 0 0 <relay_log_space> None 0 Yes NULL No 0 0 1 Slave_Pos optimistic 0 NULL 2 1 0 0 100000
Slave_IO_State
Master_Host 127.0.0.1
Master_User root
Master_Port MYPORT_1
Connect_Retry 60
Master_Log_File
Read_Master_Log_Pos 4
Relay_Log_File
Relay_Log_Pos <relay_log_pos>
Relay_Master_Log_File
Slave_IO_Running No
Slave_SQL_Running No
Replicate_Do_DB
Replicate_Ignore_DB
Replicate_Do_Table
Replicate_Ignore_Table
Replicate_Wild_Do_Table
Replicate_Wild_Ignore_Table
Last_Errno 0
Last_Error
Skip_Counter 0
Exec_Master_Log_Pos 0
Relay_Log_Space <relay_log_space>
Until_Condition None
Until_Log_File
Until_Log_Pos 0
Master_SSL_Allowed Yes
Master_SSL_CA_File
Master_SSL_CA_Path
Master_SSL_Cert
Master_SSL_Cipher
Master_SSL_Key
Seconds_Behind_Master NULL
Master_SSL_Verify_Server_Cert No
Last_IO_Errno 0
Last_IO_Error
Last_SQL_Errno 0
Last_SQL_Error
Replicate_Ignore_Server_Ids
Master_Server_Id 0
Master_SSL_Crl
Master_SSL_Crlpath
Using_Gtid Slave_Pos
Gtid_IO_Pos
Replicate_Do_Domain_Ids
Replicate_Ignore_Domain_Ids
Parallel_Mode optimistic
SQL_Delay 0
SQL_Remaining_Delay NULL
Slave_SQL_Running_State
Slave_DDL_Groups 2
Slave_Non_Transactional_Groups 1
Slave_Transactional_Groups 0
Replicate_Rewrite_DB
Connects_Tried 0
Master_Retry_Count 100000
reset slave 'master1' all;
show slave 'master1' status;
ERROR HY000: There is no master connection 'master1'
Expand Down
6 changes: 4 additions & 2 deletions mysql-test/suite/multi_source/reset_slave.test
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,16 @@ let read_master_log_pos=`select $binlog_start_pos + 608`;
let relay_log_pos=`select 2*$binlog_start_pos + 652`;
let relay_log_space=`select 3*$binlog_start_pos + 714`;

# Master_Server_Id should be 1 (master's server_id from previous connection)
--replace_result $SERVER_MYPORT_1 MYPORT_1 $read_master_log_pos <read_master_log_pos> $relay_log_pos <relay_log_pos> $relay_log_space <relay_log_space>
show slave 'master1' status;
--query_vertical show slave 'master1' status
--list_files $datadir mysqld*

reset slave 'master1';

# Master_Server_Id should be 0 (MDEV-15327: RESET SLAVE resets it)
--replace_result $SERVER_MYPORT_1 MYPORT_1 $relay_log_pos <relay_log_pos> $relay_log_space <relay_log_space>
show slave 'master1' status;
--query_vertical show slave 'master1' status
--list_files $datadir mysqld*

reset slave 'master1' all;
Expand Down
2 changes: 1 addition & 1 deletion mysql-test/suite/multi_source/simple.result
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ Last_IO_Error
Last_SQL_Errno 0
Last_SQL_Error
Replicate_Ignore_Server_Ids
Master_Server_Id 1
Master_Server_Id 0
Master_SSL_Crl
Master_SSL_Crlpath
Using_Gtid Slave_Pos
Expand Down
24 changes: 24 additions & 0 deletions mysql-test/suite/rpl/r/rpl_change_master.result
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,28 @@ connection master;
CHANGE MASTER TO MASTER_USER='root', MASTER_SSL=0, MASTER_SSL_CA='', MASTER_SSL_CERT='',
MASTER_SSL_KEY='', MASTER_SSL_CRL='', MASTER_SSL_CRLPATH='';
CHANGE MASTER TO MASTER_USER='root', MASTER_PASSWORD='', MASTER_SSL=0;
#
# MDEV-15327 Reset Master_Server_Id on CHANGE MASTER and RESET SLAVE
#
connection slave;
include/assert.inc [Master_Server_Id should be non-zero after replication setup]
include/stop_slave.inc
change master to master_user='root';
include/assert.inc [Master_Server_Id should be 0 after CHANGE MASTER]
include/start_slave.inc
connection master;
create table t1 (a int);
connection slave;
include/assert.inc [Master_Server_Id should be non-zero after reconnection]
include/stop_slave.inc
reset slave;
include/assert.inc [Master_Server_Id should be 0 after RESET SLAVE]
include/start_slave.inc
connection master;
insert into t1 values (1);
connection slave;
include/assert.inc [Master_Server_Id should be non-zero after reconnection following RESET SLAVE]
connection master;
drop table t1;
connection slave;
include/rpl_end.inc
53 changes: 53 additions & 0 deletions mysql-test/suite/rpl/t/rpl_change_master.test
Original file line number Diff line number Diff line change
Expand Up @@ -108,5 +108,58 @@ CHANGE MASTER TO MASTER_USER='root', MASTER_SSL=0, MASTER_SSL_CA='', MASTER_SSL_
MASTER_SSL_KEY='', MASTER_SSL_CRL='', MASTER_SSL_CRLPATH='';
CHANGE MASTER TO MASTER_USER='root', MASTER_PASSWORD='', MASTER_SSL=0;

--echo #
--echo # MDEV-15327 Reset Master_Server_Id on CHANGE MASTER and RESET SLAVE
--echo #

connection slave;

--let $assert_text= Master_Server_Id should be non-zero after replication setup
--let $assert_cond= [SHOW SLAVE STATUS, Master_Server_Id, 1] > 0
--source include/assert.inc

#
# Test CHANGE MASTER resets Master_Server_Id
#

source include/stop_slave.inc;
change master to master_user='root';

--let $assert_text= Master_Server_Id should be 0 after CHANGE MASTER
--let $assert_cond= [SHOW SLAVE STATUS, Master_Server_Id, 1] = 0
--source include/assert.inc

source include/start_slave.inc;
connection master;
create table t1 (a int);
sync_slave_with_master;

--let $assert_text= Master_Server_Id should be non-zero after reconnection
--let $assert_cond= [SHOW SLAVE STATUS, Master_Server_Id, 1] > 0
--source include/assert.inc

#
# Test RESET SLAVE resets Master_Server_Id
#

source include/stop_slave.inc;
reset slave;

--let $assert_text= Master_Server_Id should be 0 after RESET SLAVE
--let $assert_cond= [SHOW SLAVE STATUS, Master_Server_Id, 1] = 0
--source include/assert.inc

source include/start_slave.inc;
connection master;
insert into t1 values (1);
sync_slave_with_master;

--let $assert_text= Master_Server_Id should be non-zero after reconnection following RESET SLAVE
--let $assert_cond= [SHOW SLAVE STATUS, Master_Server_Id, 1] > 0
--source include/assert.inc

connection master;
drop table t1;
sync_slave_with_master;

--source include/rpl_end.inc
7 changes: 7 additions & 0 deletions sql/rpl_mi.cc
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,16 @@ bool Master_info::shall_ignore_server_id(ulong s_id)
change_master_id_cmp) != NULL;
}

void Master_info::reset_master_server_id()
{
master_id= 0;
prev_master_id= 0;
}

void Master_info::clear_in_memory_info(bool all)
{
init_master_log_pos(this);
reset_master_server_id();
if (all)
{
port= MYSQL_PORT;
Expand Down
1 change: 1 addition & 0 deletions sql/rpl_mi.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ class Master_info: public Master_info_file, public Slave_reporting_capability
~Master_info();
bool shall_ignore_server_id(ulong s_id);
void clear_in_memory_info(bool all);
void reset_master_server_id();
bool error()
{
/* If malloc() in initialization failed */
Expand Down
1 change: 1 addition & 0 deletions sql/sql_repl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4569,6 +4569,7 @@ bool change_master(THD* thd, Master_info* mi, bool *master_info_added)
if (lex_mi->heartbeat_period)
lex_mi->heartbeat_period(mi);
mi->received_heartbeats= 0; // counter lives until master is CHANGEd
mi->reset_master_server_id();

/*
Reset the last time server_id list if the current CHANGE MASTER
Expand Down