Commit 489ad3fb authored by Brandon Nesterenko's avatar Brandon Nesterenko Committed by Andrei

MDEV-33924: Gtid_log_event thread_id should be 32-bit

In accordance with MDEV-15089, and to be consistent with
Query_log_event::thread_id, the Gtid_log_event::thread_id
should also be 32-bit when writing/reading to the binary
log.
parent 878cfdb0
...@@ -8,20 +8,20 @@ Table Op Msg_type Msg_text ...@@ -8,20 +8,20 @@ Table Op Msg_type Msg_text
test.t1 optimize status OK test.t1 optimize status OK
connection slave; connection slave;
connection master; connection master;
# MYSQL_BINLOG local > primary_outfile # MYSQL_BINLOG primary_local_binlog > primary_outfile
include/assert_grep.inc [Ensure only 3 GTID events exist (Primary)] include/assert_grep.inc [Ensure only 3 GTID events exist (Primary)]
include/assert_grep.inc [Ensure each GTID event has the thread id (Primary)] include/assert_grep.inc [Ensure each GTID event has the thread id (Primary)]
# #
# GTID event's thread_id should use psuedo_thread_id # GTID event's thread_id should use pseudo_thread_id
connection master; connection master;
set @@pseudo_thread_id=99999; set @@pseudo_thread_id=99999;
insert into t1 values(2); insert into t1 values(2);
# MYSQL_BINLOG local > primary_outfile # MYSQL_BINLOG primary_local_binlog > primary_outfile
include/assert_grep.inc [GTID event's thread_id should use pseudo_thread_id] include/assert_grep.inc [GTID event's thread_id should use pseudo_thread_id]
# #
# Test the serial replica # Test the serial replica
connection slave; connection slave;
# MYSQL_BINLOG local > replica_outfile # MYSQL_BINLOG replica_local_binlog > replica_outfile
include/assert_grep.inc [Ensure the same number of GTID events on the replica as the primary] include/assert_grep.inc [Ensure the same number of GTID events on the replica as the primary]
include/assert_grep.inc [Ensure GTID events logged with primary's thread id maintain that value] include/assert_grep.inc [Ensure GTID events logged with primary's thread id maintain that value]
include/assert_grep.inc [Ensure GTID event logged with pseudo_thread_id on primary maintains that value] include/assert_grep.inc [Ensure GTID event logged with pseudo_thread_id on primary maintains that value]
...@@ -36,24 +36,36 @@ insert into t1 values(3); ...@@ -36,24 +36,36 @@ insert into t1 values(3);
insert into t1 values(4); insert into t1 values(4);
connection slave; connection slave;
connection slave; connection slave;
# MYSQL_BINLOG local > replica_outfile # MYSQL_BINLOG replica_local_binlog > replica_outfile
include/assert_grep.inc [Ensure the same number of GTID events on the replica as the primary] include/assert_grep.inc [Ensure the same number of GTID events on the replica as the primary]
include/assert_grep.inc [Ensure GTID the new events are logged on the replica with the thread_id of the master primary thread id] include/assert_grep.inc [Ensure GTID the new events are logged on the replica with the thread_id of the master primary thread id]
include/stop_slave.inc include/stop_slave.inc
SET @@GLOBAL.slave_parallel_threads=0; SET @@GLOBAL.slave_parallel_threads=0;
include/start_slave.inc include/start_slave.inc
# #
# MDEV-33924: If psuedo_thread_id is set to 0, this should still be # MDEV-33924: If pseudo_thread_id is set to 0, thread_id should still be
# written and propagated to slaves # written and propagated to slaves
connection master; connection master;
set @@pseudo_thread_id=0; set @@pseudo_thread_id=0;
insert into t1 values(33924); insert into t1 values(33924);
# MYSQL_BINLOG local > primary_outfile # MYSQL_BINLOG primary_local_binlog > primary_outfile
include/assert_grep.inc [GTID event's thread_id should write pseudo_thread_id value of 0] include/assert_grep.inc [GTID event's thread_id should write pseudo_thread_id value of 0]
connection slave; connection slave;
connection slave; connection slave;
# MYSQL_BINLOG local > replica_outfile # MYSQL_BINLOG replica_local_binlog > replica_outfile
include/assert_grep.inc [A 0 value for GTID event's thread_id should be propagated on replicas] include/assert_grep.inc [A 0 value for GTID event's thread_id should be propagated on replicas]
# If pseudo_thread_id is set to a value greater than 4 bytes, thread_id
# should be truncated to a 32-bit value in the binary log (see
# MDEV-15089 for details)
connection master;
set @@pseudo_thread_id=99999999999999999999;
insert into t1 values(15089);
# MYSQL_BINLOG primary_local_binlog > primary_outfile
include/assert_grep.inc [GTID event's thread_id should truncate values higher than 32 bit]
connection slave;
connection slave;
# MYSQL_BINLOG replica_local_binlog > replica_outfile
include/assert_grep.inc [The truncated thread_id should be preserved on the replica]
# #
# Cleanup # Cleanup
connection master; connection master;
......
...@@ -21,10 +21,10 @@ optimize table t1; ...@@ -21,10 +21,10 @@ optimize table t1;
--connection master --connection master
--let datadir= `select @@datadir` --let datadir= `select @@datadir`
--let filename= query_get_value(SHOW MASTER STATUS, File, 1) --let filename= query_get_value(SHOW MASTER STATUS, File, 1)
--let local=$datadir/$filename --let primary_local_binlog=$datadir/$filename
--let primary_outfile=$MYSQLTEST_VARDIR/tmp/primary_binlog.sql --let primary_outfile=$MYSQLTEST_VARDIR/tmp/primary_binlog.sql
--echo # MYSQL_BINLOG local > primary_outfile --echo # MYSQL_BINLOG primary_local_binlog > primary_outfile
--exec $MYSQL_BINLOG $local > $primary_outfile --exec $MYSQL_BINLOG $primary_local_binlog > $primary_outfile
--let $assert_count= 3 --let $assert_count= 3
--let $assert_text= Ensure only $assert_count GTID events exist (Primary) --let $assert_text= Ensure only $assert_count GTID events exist (Primary)
...@@ -37,13 +37,13 @@ optimize table t1; ...@@ -37,13 +37,13 @@ optimize table t1;
--source include/assert_grep.inc --source include/assert_grep.inc
--echo # --echo #
--echo # GTID event's thread_id should use psuedo_thread_id --echo # GTID event's thread_id should use pseudo_thread_id
--connection master --connection master
--let $old_pseudo_id= `SELECT @@SESSION.pseudo_thread_id` --let $old_pseudo_id= `SELECT @@SESSION.pseudo_thread_id`
set @@pseudo_thread_id=99999; set @@pseudo_thread_id=99999;
insert into t1 values(2); insert into t1 values(2);
--echo # MYSQL_BINLOG local > primary_outfile --echo # MYSQL_BINLOG primary_local_binlog > primary_outfile
--exec $MYSQL_BINLOG $local > $primary_outfile --exec $MYSQL_BINLOG $primary_local_binlog > $primary_outfile
--let $assert_count= 1 --let $assert_count= 1
--let $assert_text= GTID event's thread_id should use pseudo_thread_id --let $assert_text= GTID event's thread_id should use pseudo_thread_id
...@@ -61,10 +61,10 @@ insert into t1 values(2); ...@@ -61,10 +61,10 @@ insert into t1 values(2);
--let replica_thread_id=`select connection_id()` --let replica_thread_id=`select connection_id()`
--let datadir= `select @@datadir` --let datadir= `select @@datadir`
--let filename= query_get_value(SHOW MASTER STATUS, File, 1) --let filename= query_get_value(SHOW MASTER STATUS, File, 1)
--let local=$datadir/$filename --let replica_local_binlog=$datadir/$filename
--let replica_outfile=$MYSQLTEST_VARDIR/tmp/serial_replica_binlog.sql --let replica_outfile=$MYSQLTEST_VARDIR/tmp/serial_replica_binlog.sql
--echo # MYSQL_BINLOG local > replica_outfile --echo # MYSQL_BINLOG replica_local_binlog > replica_outfile
--exec $MYSQL_BINLOG $local > $replica_outfile --exec $MYSQL_BINLOG $replica_local_binlog > $replica_outfile
--let $assert_count= 4 --let $assert_count= 4
--let $assert_text= Ensure the same number of GTID events on the replica as the primary --let $assert_text= Ensure the same number of GTID events on the replica as the primary
...@@ -97,13 +97,12 @@ insert into t1 values(4); ...@@ -97,13 +97,12 @@ insert into t1 values(4);
--sync_slave_with_master --sync_slave_with_master
--connection slave --connection slave
--echo # MYSQL_BINLOG local > replica_outfile --echo # MYSQL_BINLOG replica_local_binlog > replica_outfile
--exec $MYSQL_BINLOG $local > $replica_outfile --exec $MYSQL_BINLOG $replica_local_binlog > $replica_outfile
--let $assert_count= 6 --let $assert_count= 6
--let $assert_text= Ensure the same number of GTID events on the replica as the primary --let $assert_text= Ensure the same number of GTID events on the replica as the primary
--let $assert_select=GTID [0-9]-[0-9]-[0-9] --let $assert_select=GTID [0-9]-[0-9]-[0-9]
#--let $assert_file= $replica_outfile
--source include/assert_grep.inc --source include/assert_grep.inc
--let $assert_count= 5 --let $assert_count= 5
...@@ -117,17 +116,14 @@ insert into t1 values(4); ...@@ -117,17 +116,14 @@ insert into t1 values(4);
--echo # --echo #
--echo # MDEV-33924: If psuedo_thread_id is set to 0, this should still be --echo # MDEV-33924: If pseudo_thread_id is set to 0, thread_id should still be
--echo # written and propagated to slaves --echo # written and propagated to slaves
--connection master --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` --let $old_pseudo_id= `SELECT @@SESSION.pseudo_thread_id`
set @@pseudo_thread_id=0; set @@pseudo_thread_id=0;
insert into t1 values(33924); insert into t1 values(33924);
--echo # MYSQL_BINLOG local > primary_outfile --echo # MYSQL_BINLOG primary_local_binlog > primary_outfile
--exec $MYSQL_BINLOG $local > $primary_outfile --exec $MYSQL_BINLOG $primary_local_binlog > $primary_outfile
--let $assert_count= 1 --let $assert_count= 1
--let $assert_text= GTID event's thread_id should write pseudo_thread_id value of 0 --let $assert_text= GTID event's thread_id should write pseudo_thread_id value of 0
...@@ -137,17 +133,42 @@ insert into t1 values(33924); ...@@ -137,17 +133,42 @@ insert into t1 values(33924);
--sync_slave_with_master --sync_slave_with_master
--connection slave --connection slave
--let datadir= `select @@datadir` --echo # MYSQL_BINLOG replica_local_binlog > replica_outfile
--let filename= query_get_value(SHOW MASTER STATUS, File, 1) --exec $MYSQL_BINLOG $replica_local_binlog > $replica_outfile
--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_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_select=GTID [0-9]-[0-9]-[0-9].*thread_id=0\$
--let $assert_file= $replica_outfile --let $assert_file= $replica_outfile
--source include/assert_grep.inc --source include/assert_grep.inc
--echo # If pseudo_thread_id is set to a value greater than 4 bytes, thread_id
--echo # should be truncated to a 32-bit value in the binary log (see
--echo # MDEV-15089 for details)
--connection master
# Silence the truncation warning
--disable_warnings
set @@pseudo_thread_id=99999999999999999999;
--enable_warnings
insert into t1 values(15089);
--echo # MYSQL_BINLOG primary_local_binlog > primary_outfile
--exec $MYSQL_BINLOG $primary_local_binlog > $primary_outfile
--let $assert_count= 1
--let $assert_text= GTID event's thread_id should truncate values higher than 32 bit
--let $assert_select=GTID [0-9]-[0-9]-[0-9].*thread_id=4294967295\$
--let $assert_file= $primary_outfile
--source include/assert_grep.inc
--sync_slave_with_master
--connection slave
--echo # MYSQL_BINLOG replica_local_binlog > replica_outfile
--exec $MYSQL_BINLOG $replica_local_binlog > $replica_outfile
--let $assert_text= The truncated thread_id should be preserved on the replica
--let $assert_select=GTID [0-9]-[0-9]-[0-9].*thread_id=4294967295\$
--let $assert_file= $replica_outfile
--source include/assert_grep.inc
--disable_query_log --disable_query_log
--connection master --connection master
--eval set @@pseudo_thread_id=$old_pseudo_id --eval set @@pseudo_thread_id=$old_pseudo_id
......
...@@ -2458,10 +2458,10 @@ Gtid_log_event::Gtid_log_event(const uchar *buf, uint event_len, ...@@ -2458,10 +2458,10 @@ Gtid_log_event::Gtid_log_event(const uchar *buf, uint event_len,
} }
if (flags_extra & FL_EXTRA_THREAD_ID && if (flags_extra & FL_EXTRA_THREAD_ID &&
static_cast<uint>(buf - buf_0) <= event_len + 8) static_cast<uint>(buf - buf_0) <= event_len + 4)
{ {
thread_id= uint8korr(buf); thread_id= uint4korr(buf);
buf+= 8; buf+= 4;
} }
} }
/* /*
......
...@@ -2937,7 +2937,7 @@ Gtid_log_event::write(Log_event_writer *writer) ...@@ -2937,7 +2937,7 @@ Gtid_log_event::write(Log_event_writer *writer)
uchar buf[GTID_HEADER_LEN + 2 + sizeof(XID) uchar buf[GTID_HEADER_LEN + 2 + sizeof(XID)
+ 1 /* flags_extra: */ + 1 /* flags_extra: */
+ 4 /* Extra Engines */ + 4 /* Extra Engines */
+ 8 /* FL_EXTRA_THREAD_ID */]; + 4 /* FL_EXTRA_THREAD_ID */];
size_t write_len= 13; size_t write_len= 13;
int8store(buf, seq_no); int8store(buf, seq_no);
...@@ -2980,8 +2980,8 @@ Gtid_log_event::write(Log_event_writer *writer) ...@@ -2980,8 +2980,8 @@ Gtid_log_event::write(Log_event_writer *writer)
if (flags_extra & FL_EXTRA_THREAD_ID) if (flags_extra & FL_EXTRA_THREAD_ID)
{ {
int8store(buf + write_len, thread_id); int4store(buf + write_len, thread_id);
write_len+= 8; write_len+= 4;
} }
if (write_len < GTID_HEADER_LEN) if (write_len < GTID_HEADER_LEN)
......
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