Skip to content

Commit 1c7c5f4

Browse files
Varun Deep SainiEricHayter
authored andcommitted
MDEV-15327 Reset Master_Server_Id on CHANGE MASTER and RESET SLAVE
Master_Server_Id was not cleared after CHANGE MASTER or RESET SLAVE, showing a stale value until the slave reconnected. Reset master_id and prev_master_id to 0 in both code paths. The reset value (0) will be present in SHOW SLAVE STATUS until it is re-evaluated to the id of a new connected master server. Signed-off-by: Varun Deep Saini <varun.23bcs10048@ms.sst.scaler.com>
1 parent bd06d0d commit 1c7c5f4

12 files changed

Lines changed: 277 additions & 66 deletions

File tree

mysql-test/suite/multi_source/reset_slave.result

Lines changed: 112 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,123 @@ insert into t1 values (1),(2);
1313
connection slave;
1414
stop slave 'master1';
1515
show slave 'master1' status;
16-
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
17-
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
16+
Slave_IO_State
17+
Master_Host 127.0.0.1
18+
Master_User root
19+
Master_Port MYPORT_1
20+
Connect_Retry 60
21+
Master_Log_File master-bin.000001
22+
Read_Master_Log_Pos <read_master_log_pos>
23+
Relay_Log_File mysqld-relay-bin-master1.000002
24+
Relay_Log_Pos <relay_log_pos>
25+
Relay_Master_Log_File master-bin.000001
26+
Slave_IO_Running No
27+
Slave_SQL_Running No
28+
Replicate_Do_DB
29+
Replicate_Ignore_DB
30+
Replicate_Do_Table
31+
Replicate_Ignore_Table
32+
Replicate_Wild_Do_Table
33+
Replicate_Wild_Ignore_Table
34+
Last_Errno 0
35+
Last_Error
36+
Skip_Counter 0
37+
Exec_Master_Log_Pos <read_master_log_pos>
38+
Relay_Log_Space <relay_log_space>
39+
Until_Condition None
40+
Until_Log_File
41+
Until_Log_Pos 0
42+
Master_SSL_Allowed Yes
43+
Master_SSL_CA_File
44+
Master_SSL_CA_Path
45+
Master_SSL_Cert
46+
Master_SSL_Cipher
47+
Master_SSL_Key
48+
Seconds_Behind_Master NULL
49+
Master_SSL_Verify_Server_Cert No
50+
Last_IO_Errno 0
51+
Last_IO_Error
52+
Last_SQL_Errno 0
53+
Last_SQL_Error
54+
Replicate_Ignore_Server_Ids
55+
Master_Server_Id 1
56+
Master_SSL_Crl
57+
Master_SSL_Crlpath
58+
Using_Gtid Slave_Pos
59+
Gtid_IO_Pos 0-1-3
60+
Replicate_Do_Domain_Ids
61+
Replicate_Ignore_Domain_Ids
62+
Parallel_Mode optimistic
63+
SQL_Delay 0
64+
SQL_Remaining_Delay NULL
65+
Slave_SQL_Running_State
66+
Slave_DDL_Groups 2
67+
Slave_Non_Transactional_Groups 1
68+
Slave_Transactional_Groups 0
69+
Replicate_Rewrite_DB
70+
Connects_Tried 1
71+
Master_Retry_Count 100000
1872
mysqld-relay-bin-master1.000001
1973
mysqld-relay-bin-master1.000002
2074
mysqld-relay-bin-master1.index
2175
reset slave 'master1';
2276
show slave 'master1' status;
23-
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
24-
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
77+
Slave_IO_State
78+
Master_Host 127.0.0.1
79+
Master_User root
80+
Master_Port MYPORT_1
81+
Connect_Retry 60
82+
Master_Log_File
83+
Read_Master_Log_Pos 4
84+
Relay_Log_File
85+
Relay_Log_Pos <relay_log_pos>
86+
Relay_Master_Log_File
87+
Slave_IO_Running No
88+
Slave_SQL_Running No
89+
Replicate_Do_DB
90+
Replicate_Ignore_DB
91+
Replicate_Do_Table
92+
Replicate_Ignore_Table
93+
Replicate_Wild_Do_Table
94+
Replicate_Wild_Ignore_Table
95+
Last_Errno 0
96+
Last_Error
97+
Skip_Counter 0
98+
Exec_Master_Log_Pos 0
99+
Relay_Log_Space <relay_log_space>
100+
Until_Condition None
101+
Until_Log_File
102+
Until_Log_Pos 0
103+
Master_SSL_Allowed Yes
104+
Master_SSL_CA_File
105+
Master_SSL_CA_Path
106+
Master_SSL_Cert
107+
Master_SSL_Cipher
108+
Master_SSL_Key
109+
Seconds_Behind_Master NULL
110+
Master_SSL_Verify_Server_Cert No
111+
Last_IO_Errno 0
112+
Last_IO_Error
113+
Last_SQL_Errno 0
114+
Last_SQL_Error
115+
Replicate_Ignore_Server_Ids
116+
Master_Server_Id 0
117+
Master_SSL_Crl
118+
Master_SSL_Crlpath
119+
Using_Gtid Slave_Pos
120+
Gtid_IO_Pos
121+
Replicate_Do_Domain_Ids
122+
Replicate_Ignore_Domain_Ids
123+
Parallel_Mode optimistic
124+
SQL_Delay 0
125+
SQL_Remaining_Delay NULL
126+
Slave_SQL_Running_State
127+
Slave_DDL_Groups 2
128+
Slave_Non_Transactional_Groups 1
129+
Slave_Transactional_Groups 0
130+
Replicate_Rewrite_DB
131+
Connects_Tried 0
132+
Master_Retry_Count 100000
25133
reset slave 'master1' all;
26134
show slave 'master1' status;
27135
ERROR HY000: There is no master connection 'master1'

mysql-test/suite/multi_source/reset_slave.test

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,16 @@ let read_master_log_pos=`select $binlog_start_pos + 608`;
4343
let relay_log_pos=`select 2*$binlog_start_pos + 652`;
4444
let relay_log_space=`select 3*$binlog_start_pos + 714`;
4545

46+
# Master_Server_Id should be 1 (master's server_id from previous connection)
4647
--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>
47-
show slave 'master1' status;
48+
--query_vertical show slave 'master1' status
4849
--list_files $datadir mysqld*
4950

5051
reset slave 'master1';
5152

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

5658
reset slave 'master1' all;

mysql-test/suite/multi_source/simple.result

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ Last_IO_Error
318318
Last_SQL_Errno 0
319319
Last_SQL_Error
320320
Replicate_Ignore_Server_Ids
321-
Master_Server_Id 1
321+
Master_Server_Id 0
322322
Master_SSL_Crl
323323
Master_SSL_Crlpath
324324
Using_Gtid Slave_Pos

mysql-test/suite/rpl/r/rpl_change_master.result

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,28 @@ connection master;
2626
CHANGE MASTER TO MASTER_USER='root', MASTER_SSL=0, MASTER_SSL_CA='', MASTER_SSL_CERT='',
2727
MASTER_SSL_KEY='', MASTER_SSL_CRL='', MASTER_SSL_CRLPATH='';
2828
CHANGE MASTER TO MASTER_USER='root', MASTER_PASSWORD='', MASTER_SSL=0;
29+
#
30+
# MDEV-15327 Reset Master_Server_Id on CHANGE MASTER and RESET SLAVE
31+
#
32+
connection slave;
33+
include/assert.inc [Master_Server_Id should be non-zero after replication setup]
34+
include/stop_slave.inc
35+
change master to master_user='root';
36+
include/assert.inc [Master_Server_Id should be 0 after CHANGE MASTER]
37+
include/start_slave.inc
38+
connection master;
39+
create table t1 (a int);
40+
connection slave;
41+
include/assert.inc [Master_Server_Id should be non-zero after reconnection]
42+
include/stop_slave.inc
43+
reset slave;
44+
include/assert.inc [Master_Server_Id should be 0 after RESET SLAVE]
45+
include/start_slave.inc
46+
connection master;
47+
insert into t1 values (1);
48+
connection slave;
49+
include/assert.inc [Master_Server_Id should be non-zero after reconnection following RESET SLAVE]
50+
connection master;
51+
drop table t1;
52+
connection slave;
2953
include/rpl_end.inc

mysql-test/suite/rpl/t/rpl_change_master.test

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,5 +108,58 @@ CHANGE MASTER TO MASTER_USER='root', MASTER_SSL=0, MASTER_SSL_CA='', MASTER_SSL_
108108
MASTER_SSL_KEY='', MASTER_SSL_CRL='', MASTER_SSL_CRLPATH='';
109109
CHANGE MASTER TO MASTER_USER='root', MASTER_PASSWORD='', MASTER_SSL=0;
110110

111+
--echo #
112+
--echo # MDEV-15327 Reset Master_Server_Id on CHANGE MASTER and RESET SLAVE
113+
--echo #
114+
115+
connection slave;
116+
117+
--let $assert_text= Master_Server_Id should be non-zero after replication setup
118+
--let $assert_cond= [SHOW SLAVE STATUS, Master_Server_Id, 1] > 0
119+
--source include/assert.inc
120+
121+
#
122+
# Test CHANGE MASTER resets Master_Server_Id
123+
#
124+
125+
source include/stop_slave.inc;
126+
change master to master_user='root';
127+
128+
--let $assert_text= Master_Server_Id should be 0 after CHANGE MASTER
129+
--let $assert_cond= [SHOW SLAVE STATUS, Master_Server_Id, 1] = 0
130+
--source include/assert.inc
131+
132+
source include/start_slave.inc;
133+
connection master;
134+
create table t1 (a int);
135+
sync_slave_with_master;
136+
137+
--let $assert_text= Master_Server_Id should be non-zero after reconnection
138+
--let $assert_cond= [SHOW SLAVE STATUS, Master_Server_Id, 1] > 0
139+
--source include/assert.inc
140+
141+
#
142+
# Test RESET SLAVE resets Master_Server_Id
143+
#
144+
145+
source include/stop_slave.inc;
146+
reset slave;
147+
148+
--let $assert_text= Master_Server_Id should be 0 after RESET SLAVE
149+
--let $assert_cond= [SHOW SLAVE STATUS, Master_Server_Id, 1] = 0
150+
--source include/assert.inc
151+
152+
source include/start_slave.inc;
153+
connection master;
154+
insert into t1 values (1);
155+
sync_slave_with_master;
156+
157+
--let $assert_text= Master_Server_Id should be non-zero after reconnection following RESET SLAVE
158+
--let $assert_cond= [SHOW SLAVE STATUS, Master_Server_Id, 1] > 0
159+
--source include/assert.inc
160+
161+
connection master;
162+
drop table t1;
163+
sync_slave_with_master;
111164

112165
--source include/rpl_end.inc

sql/log_event.cc

Lines changed: 33 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818

1919
#include "mariadb.h"
20+
#include "mysql/psi/psi_base.h"
2021
#include "sql_priv.h"
2122
#include "handler.h"
2223
#ifndef MYSQL_CLIENT
@@ -3722,13 +3723,13 @@ Table_map_log_event::~Table_map_log_event()
37223723
@param[in] field SIGNEDNESS field in table_map_event.
37233724
@param[in] length length of the field
37243725
*/
3725-
static void parse_signedness(std::vector<bool> &vec,
3726+
static void parse_signedness(Dynamic_array<bool> &vec,
37263727
unsigned char *field, unsigned int length)
37273728
{
37283729
for (unsigned int i= 0; i < length; i++)
37293730
{
37303731
for (unsigned char c= 0x80; c != 0; c>>= 1)
3731-
vec.push_back(field[i] & c);
3732+
vec.append(field[i] & c);
37323733
}
37333734
}
37343735

@@ -3751,8 +3752,8 @@ static void parse_default_charset(Table_map_log_event::Optional_metadata_fields:
37513752
unsigned int col_index= net_field_length(&p);
37523753
unsigned int col_charset= net_field_length(&p);
37533754

3754-
default_charset.charset_pairs.push_back(std::make_pair(col_index,
3755-
col_charset));
3755+
default_charset.charset_pairs.append(std::make_pair(col_index,
3756+
col_charset));
37563757
}
37573758
}
37583759

@@ -3763,13 +3764,13 @@ static void parse_default_charset(Table_map_log_event::Optional_metadata_fields:
37633764
@param[in] field COLUMN_CHARSET field in table_map_event.
37643765
@param[in] length length of the field
37653766
*/
3766-
static void parse_column_charset(std::vector<unsigned int> &vec,
3767+
static void parse_column_charset(Dynamic_array<uint> &vec,
37673768
unsigned char *field, unsigned int length)
37683769
{
37693770
unsigned char* p= field;
37703771

37713772
while (p < field + length)
3772-
vec.push_back(net_field_length(&p));
3773+
vec.append(net_field_length(&p));
37733774
}
37743775

37753776
/**
@@ -3806,21 +3807,25 @@ static bool parse_column_name(MEM_ROOT *root, LEX_CSTRING *name,
38063807
@param[in] field COLUMN_NAME field in table_map_event.
38073808
@param[in] length length of the field
38083809
*/
3809-
static void parse_set_str_value(std::vector<Table_map_log_event::
3810-
Optional_metadata_fields::str_vector> &vec,
3811-
unsigned char *field, unsigned int length)
3810+
static void parse_set_str_value(
3811+
Dynamic_array<Table_map_log_event::Optional_metadata_fields::str_vector>
3812+
&vec,
3813+
unsigned char *field, unsigned int length)
38123814
{
38133815
unsigned char* p= field;
38143816

38153817
while (p < field + length)
38163818
{
38173819
unsigned int count= net_field_length(&p);
38183820

3819-
vec.push_back(std::vector<std::string>());
3821+
if (vec.reserve(vec.elements() + 1))
3822+
return;
3823+
vec.elements(vec.elements() + 1);
3824+
vec.back()->init(PSI_INSTRUMENT_MEM);
38203825
for (unsigned int i= 0; i < count; i++)
38213826
{
38223827
unsigned len1= net_field_length(&p);
3823-
vec.back().push_back(std::string(reinterpret_cast<char *>(p), len1));
3828+
vec.back()->append(LEX_CSTRING{reinterpret_cast<char *>(p), len1});
38243829
p+= len1;
38253830
}
38263831
}
@@ -3833,13 +3838,13 @@ static void parse_set_str_value(std::vector<Table_map_log_event::
38333838
@param[in] field GEOMETRY_TYPE field in table_map_event.
38343839
@param[in] length length of the field
38353840
*/
3836-
static void parse_geometry_type(std::vector<unsigned int> &vec,
3841+
static void parse_geometry_type(Dynamic_array<uint> &vec,
38373842
unsigned char *field, unsigned int length)
38383843
{
38393844
unsigned char* p= field;
38403845

38413846
while (p < field + length)
3842-
vec.push_back(net_field_length(&p));
3847+
vec.append(net_field_length(&p));
38433848
}
38443849

38453850
/**
@@ -3852,14 +3857,15 @@ static void parse_geometry_type(std::vector<unsigned int> &vec,
38523857
@param[in] field SIMPLE_PRIMARY_KEY field in table_map_event.
38533858
@param[in] length length of the field
38543859
*/
3855-
static void parse_simple_pk(std::vector<Table_map_log_event::
3856-
Optional_metadata_fields::uint_pair> &vec,
3857-
unsigned char *field, unsigned int length)
3860+
static void parse_simple_pk(
3861+
Dynamic_array<Table_map_log_event::Optional_metadata_fields::uint_pair>
3862+
&vec,
3863+
unsigned char *field, unsigned int length)
38583864
{
38593865
unsigned char* p= field;
38603866

38613867
while (p < field + length)
3862-
vec.push_back(std::make_pair(net_field_length(&p), 0));
3868+
vec.append(std::make_pair(net_field_length(&p), 0));
38633869
}
38643870

38653871
/**
@@ -3872,17 +3878,18 @@ static void parse_simple_pk(std::vector<Table_map_log_event::
38723878
@param[in] length length of the field
38733879
*/
38743880

3875-
static void parse_pk_with_prefix(std::vector<Table_map_log_event::
3876-
Optional_metadata_fields::uint_pair> &vec,
3877-
unsigned char *field, unsigned int length)
3881+
static void parse_pk_with_prefix(
3882+
Dynamic_array<Table_map_log_event::Optional_metadata_fields::uint_pair>
3883+
&vec,
3884+
unsigned char *field, unsigned int length)
38783885
{
38793886
unsigned char* p= field;
38803887

38813888
while (p < field + length)
38823889
{
38833890
unsigned int col_index= net_field_length(&p);
38843891
unsigned int col_prefix= net_field_length(&p);
3885-
vec.push_back(std::make_pair(col_index, col_prefix));
3892+
vec.append(std::make_pair(col_index, col_prefix));
38863893
}
38873894
}
38883895

@@ -3891,6 +3898,11 @@ Optional_metadata_fields(MEM_ROOT *root, uint master_columns,
38913898
uchar* optional_metadata,
38923899
size_t optional_metadata_len,
38933900
bool only_column_names)
3901+
: m_signedness(PSI_INSTRUMENT_MEM), m_column_charset(PSI_INSTRUMENT_MEM),
3902+
m_enum_and_set_column_charset(PSI_INSTRUMENT_MEM),
3903+
m_enum_str_value(PSI_INSTRUMENT_MEM),
3904+
m_set_str_value(PSI_INSTRUMENT_MEM), m_geometry_type(PSI_INSTRUMENT_MEM),
3905+
m_primary_key(PSI_INSTRUMENT_MEM)
38943906
{
38953907
unsigned int len;
38963908
uchar *metadata_end;

0 commit comments

Comments
 (0)