Commit f520c0fd authored by Brandon Nesterenko's avatar Brandon Nesterenko Committed by Andrei

Gtid_log_event thread_id missing in binlog when pseudo_thread_id is set to 0 or negative

If pseudo_thread_id is set to 0 (or implicitly set to 0 because
it was attempted to be set to a negative value), then the
thread_id attribute of the Gtid_log_event will not be written
at all, whereas the Query_log_event still will write
thread_id=0.  The underlying problem was that the
FL_EXTRA_THREAD_ID would only be added if thread_id was greater
than 0.

This patch fixes this by changing the condition to mark the
FL_EXTRA_THREAD_ID when generating a GTID log event, such that
it will always be written on the primary, and if on the slave,
the rpl_group_info's gtid_ev_flags_extra is checked to see if
the flag was present when reading it in.

Reviewed By:
============
Andrei Elkin <andrei.elkin@mariadb.com>
parent a4e5862e
......@@ -43,6 +43,18 @@ include/stop_slave.inc
SET @@GLOBAL.slave_parallel_threads=0;
include/start_slave.inc
#
# MDEV-33924: If psuedo_thread_id is set to 0, this should still be
# written and propagated to slaves
connection master;
set @@pseudo_thread_id=0;
insert into t1 values(33924);
# MYSQL_BINLOG local > primary_outfile
include/assert_grep.inc [GTID event's thread_id should write pseudo_thread_id value of 0]
connection slave;
connection slave;
# MYSQL_BINLOG local > replica_outfile
include/assert_grep.inc [A 0 value for GTID event's thread_id should be propagated on replicas]
#
# Cleanup
connection master;
drop table t1;
......
......@@ -116,6 +116,43 @@ insert into t1 values(4);
--source include/start_slave.inc
--echo #
--echo # MDEV-33924: If psuedo_thread_id is set to 0, this should still be
--echo # written and propagated to slaves
--connection master
--let datadir= `select @@datadir`
--let filename= query_get_value(SHOW MASTER STATUS, File, 1)
--let local=$datadir/$filename
--let $old_pseudo_id= `SELECT @@SESSION.pseudo_thread_id`
set @@pseudo_thread_id=0;
insert into t1 values(33924);
--echo # MYSQL_BINLOG local > primary_outfile
--exec $MYSQL_BINLOG $local > $primary_outfile
--let $assert_count= 1
--let $assert_text= GTID event's thread_id should write pseudo_thread_id value of 0
--let $assert_select=GTID [0-9]-[0-9]-[0-9].*thread_id=0\$
--let $assert_file= $primary_outfile
--source include/assert_grep.inc
--sync_slave_with_master
--connection slave
--let datadir= `select @@datadir`
--let filename= query_get_value(SHOW MASTER STATUS, File, 1)
--let local=$datadir/$filename
--echo # MYSQL_BINLOG local > replica_outfile
--exec $MYSQL_BINLOG $local > $replica_outfile
--let $assert_text= A 0 value for GTID event's thread_id should be propagated on replicas
--let $assert_select=GTID [0-9]-[0-9]-[0-9].*thread_id=0\$
--let $assert_file= $replica_outfile
--source include/assert_grep.inc
--disable_query_log
--connection master
--eval set @@pseudo_thread_id=$old_pseudo_id
--enable_query_log
--echo #
--echo # Cleanup
......
......@@ -2462,8 +2462,6 @@ Gtid_log_event::Gtid_log_event(const uchar *buf, uint event_len,
{
thread_id= uint8korr(buf);
buf+= 8;
DBUG_ASSERT(thread_id > 0);
}
}
/*
......
......@@ -2841,7 +2841,8 @@ Gtid_log_event::Gtid_log_event(THD *thd_arg, uint64 seq_no_arg,
/* Preserve any DDL or WAITED flag in the slave's binlog. */
if (thd_arg->rgi_slave)
flags2|= (thd_arg->rgi_slave->gtid_ev_flags2 & (FL_DDL|FL_WAITED));
if (thread_id > 0)
if (!thd->rgi_slave ||
thd_arg->rgi_slave->gtid_ev_flags_extra & FL_EXTRA_THREAD_ID)
flags_extra|= FL_EXTRA_THREAD_ID;
XID_STATE &xid_state= thd->transaction->xid_state;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment