diff --git a/mysql-test/suite/multi_source/reset_slave.result b/mysql-test/suite/multi_source/reset_slave.result index 5d1227e15d4cf..8274c4693aa8c 100644 --- a/mysql-test/suite/multi_source/reset_slave.result +++ b/mysql-test/suite/multi_source/reset_slave.result @@ -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'; @@ -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 mysqld-relay-bin-master1.000002 master-bin.000001 No No 0 0 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 +Relay_Log_File mysqld-relay-bin-master1.000002 +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 +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 No No 0 0 0 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_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 +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' diff --git a/mysql-test/suite/multi_source/reset_slave.test b/mysql-test/suite/multi_source/reset_slave.test index 073fd6cc1cb34..ab2904430464b 100644 --- a/mysql-test/suite/multi_source/reset_slave.test +++ b/mysql-test/suite/multi_source/reset_slave.test @@ -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 $relay_log_pos $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_space -show slave 'master1' status; +--query_vertical show slave 'master1' status --list_files $datadir mysqld* reset slave 'master1' all; diff --git a/mysql-test/suite/multi_source/simple.result b/mysql-test/suite/multi_source/simple.result index 26fed19e4f7e9..55dfbb805b030 100644 --- a/mysql-test/suite/multi_source/simple.result +++ b/mysql-test/suite/multi_source/simple.result @@ -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 diff --git a/mysql-test/suite/rpl/r/rpl_change_master.result b/mysql-test/suite/rpl/r/rpl_change_master.result index 48cec72d91738..773a0a2386419 100644 --- a/mysql-test/suite/rpl/r/rpl_change_master.result +++ b/mysql-test/suite/rpl/r/rpl_change_master.result @@ -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 diff --git a/mysql-test/suite/rpl/t/rpl_change_master.test b/mysql-test/suite/rpl/t/rpl_change_master.test index 7337cfb952c7e..6fd10933daa6b 100644 --- a/mysql-test/suite/rpl/t/rpl_change_master.test +++ b/mysql-test/suite/rpl/t/rpl_change_master.test @@ -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 diff --git a/sql/rpl_mi.cc b/sql/rpl_mi.cc index 35895b5292eff..abdc3d967bafc 100644 --- a/sql/rpl_mi.cc +++ b/sql/rpl_mi.cc @@ -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; diff --git a/sql/rpl_mi.h b/sql/rpl_mi.h index 2e8f6b78ab844..a3e9c553fe83c 100644 --- a/sql/rpl_mi.h +++ b/sql/rpl_mi.h @@ -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 */ diff --git a/sql/sql_repl.cc b/sql/sql_repl.cc index a46aabfa4858b..c4c3e7d338b39 100644 --- a/sql/sql_repl.cc +++ b/sql/sql_repl.cc @@ -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