diff --git a/mysql-test/suite/rpl/r/rpl_start_alter_restart_master.result b/mysql-test/suite/rpl/r/rpl_start_alter_restart_master.result index 2b53fde52a75b..d87067c187e8e 100644 --- a/mysql-test/suite/rpl/r/rpl_start_alter_restart_master.result +++ b/mysql-test/suite/rpl/r/rpl_start_alter_restart_master.result @@ -12,7 +12,8 @@ set global slave_parallel_mode=optimistic; set global gtid_strict_mode=1; start slave; connection master; -call mtr.add_suppression("ALTER query started at .+ could not be completed"); +SET @@session.server_id= 11; +call mtr.add_suppression("ALTER query started at 0-11-\\d+ could not be completed"); SET @old_debug_master= @@global.debug; set binlog_alter_two_phase=true; create table t3( a int primary key, b int) engine=innodb; @@ -37,7 +38,7 @@ t3 CREATE TABLE `t3` ( include/show_binlog_events.inc Log_name Pos Event_type Server_id End_log_pos Info master-bin.000001 # Gtid # # BEGIN GTID #-#-# -master-bin.000001 # Query # # use `mtr`; INSERT INTO test_suppressions (pattern) VALUES ( NAME_CONST('pattern',_latin1'ALTER query started at .+ could not be completed' COLLATE 'latin1_swedish_ci')) +master-bin.000001 # Query # # use `mtr`; INSERT INTO test_suppressions (pattern) VALUES ( NAME_CONST('pattern',_latin1'ALTER query started at 0-11-\\d+ could not be completed' COLLATE 'latin1_swedish_ci')) master-bin.000001 # Query # # COMMIT master-bin.000001 # Gtid # # GTID #-#-# master-bin.000001 # Query # # use `test`; create table t3( a int primary key, b int) engine=innodb @@ -56,7 +57,7 @@ connection slave; include/show_binlog_events.inc Log_name Pos Event_type Server_id End_log_pos Info slave-bin.000001 # Gtid # # BEGIN GTID #-#-# -slave-bin.000001 # Query # # use `mtr`; INSERT INTO test_suppressions (pattern) VALUES ( NAME_CONST('pattern',_latin1'ALTER query started at .+ could not be completed' COLLATE 'latin1_swedish_ci')) +slave-bin.000001 # Query # # use `mtr`; INSERT INTO test_suppressions (pattern) VALUES ( NAME_CONST('pattern',_latin1'ALTER query started at 0-11-\\d+ could not be completed' COLLATE 'latin1_swedish_ci')) slave-bin.000001 # Query # # COMMIT slave-bin.000001 # Gtid # # GTID #-#-# slave-bin.000001 # Query # # use `test`; create table t3( a int primary key, b int) engine=innodb diff --git a/mysql-test/suite/rpl/t/rpl_start_alter_restart_master.test b/mysql-test/suite/rpl/t/rpl_start_alter_restart_master.test index aac3af6fc142f..550c94dfdcf28 100644 --- a/mysql-test/suite/rpl/t/rpl_start_alter_restart_master.test +++ b/mysql-test/suite/rpl/t/rpl_start_alter_restart_master.test @@ -26,7 +26,12 @@ set global gtid_strict_mode=1; start slave; --connection master -call mtr.add_suppression("ALTER query started at .+ could not be completed"); +# MDEV-35474 Start Alter GTID Error Message Can Use Wrong Server_Id +# +# When replicating, the GTID the slave warns should be of this sessional +# server_id rather than 1 from reconnecting to the restarted master. +SET @@session.server_id= 11; +call mtr.add_suppression("ALTER query started at 0-11-\\d+ could not be completed"); SET @old_debug_master= @@global.debug; --let $binlog_alter_two_phase= `select @@binlog_alter_two_phase` diff --git a/sql/log.cc b/sql/log.cc index 9493e53756600..c2a7d4d8a01cc 100644 --- a/sql/log.cc +++ b/sql/log.cc @@ -626,8 +626,9 @@ bool write_bin_log_start_alter(THD *thd, bool& partial_alter, start_alter_info *info= thd->rgi_slave->sa_info; bool is_shutdown= false; - info->sa_seq_no= start_alter_id; - info->domain_id= thd->variables.gtid_domain_id; + info->gtid.domain_id= thd->variables.gtid_domain_id; + info->gtid.server_id= thd->variables.server_id; + info->gtid.seq_no= start_alter_id; mysql_mutex_lock(&mi->start_alter_list_lock); // possible stop-slave's marking of the whole alter state list is checked is_shutdown= mi->is_shutdown; diff --git a/sql/log_event_server.cc b/sql/log_event_server.cc index 2fbc2b7e47f2f..b3b2a15cf93e7 100644 --- a/sql/log_event_server.cc +++ b/sql/log_event_server.cc @@ -1682,8 +1682,9 @@ static start_alter_info *get_new_start_alter_info(THD *thd) sql_print_error("Failed to allocate memory for ddl log free list"); return 0; } - info->sa_seq_no= 0; - info->domain_id= 0; + info->gtid.domain_id= 0; + info->gtid.server_id= 0; + info->gtid.seq_no= 0; info->direct_commit_alter= false; info->state= start_alter_state::INVALID; mysql_cond_init(0, &info->start_alter_cond, NULL); @@ -1769,8 +1770,8 @@ int Query_log_event::handle_split_alter_query_log_event(rpl_group_info *rgi, List_iterator info_iterator(mi->start_alter_list); while ((info= info_iterator++)) { - if(info->sa_seq_no == rgi->gtid_ev_sa_seq_no && - info->domain_id == rgi->current_gtid.domain_id) + if(info->gtid.seq_no == rgi->gtid_ev_sa_seq_no && + info->gtid.domain_id == rgi->current_gtid.domain_id) { info_iterator.remove(); break; @@ -2705,10 +2706,9 @@ static void check_and_remove_stale_alter(Relay_log_info *rli) { DBUG_ASSERT(info->state == start_alter_state::REGISTERED); - sql_print_warning("ALTER query started at %u-%lu-%llu could not " + sql_print_warning("ALTER query started at %u-%u-%llu could not " "be completed because of unexpected master server " - "or its binlog change", info->domain_id, - mi->master_id, info->sa_seq_no); + "or its binlog change", PARAM_GTID(info->gtid)); info_iterator.remove(); mysql_mutex_lock(&mi->start_alter_lock); info->state= start_alter_state::ROLLBACK_ALTER; diff --git a/sql/rpl_rli.h b/sql/rpl_rli.h index cf991584573da..e5dd25a12ed1b 100644 --- a/sql/rpl_rli.h +++ b/sql/rpl_rli.h @@ -654,8 +654,7 @@ struct start_alter_info /* ALTER id is defined as a pair of GTID's seq_no and domain_id. */ - decltype(rpl_gtid::seq_no) sa_seq_no; // key for searching (SA's id) - uint32 domain_id; + rpl_gtid gtid; // rpl_gtid::seq_no is the key for searching (SA's id) bool direct_commit_alter; // when true CA thread executes the whole query /* 0 prepared and not error from commit and rollback diff --git a/sql/sql_table.cc b/sql/sql_table.cc index 6e0c63d850801..36cf45b99980a 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -7628,7 +7628,7 @@ write_bin_log_start_alter_rollback(THD *thd, uint64 &start_alter_id, start_alter_info *info= thd->rgi_slave->sa_info; Master_info *mi= thd->rgi_slave->rli->mi; - if (info->sa_seq_no == 0) + if (info->gtid.seq_no == 0) { /* Error occurred before SA got to processing incl its binlogging.