| 1 |
# |
| 2 |
# Verify that GTID log events are written into the binary log along with the |
| 3 |
# id of the thread which originally executed the transaction. On the primary, |
| 4 |
# this is the id of the user connection (or the pseudo_thread_id). The replica |
| 5 |
# should maintain this value when binlogging. |
| 6 |
# |
| 7 |
# References: |
| 8 |
# MDEV-7850: MariaDB doesn't show thread_id for ROW-based events in binlog |
| 9 |
# |
| 10 |
--source include/have_binlog_format_row.inc |
| 11 |
--source include/master-slave.inc |
| 12 |
|
| 13 |
--connection master |
| 14 |
--let primary_thread_id=`select connection_id()` |
| 15 |
create table t1(a int); |
| 16 |
insert into t1 values(1); |
| 17 |
optimize table t1; |
| 18 |
|
| 19 |
--sync_slave_with_master |
| 20 |
|
| 21 |
--connection master |
| 22 |
--let datadir= `select @@datadir` |
| 23 |
--let filename= query_get_value(SHOW MASTER STATUS, File, 1) |
| 24 |
--let primary_local_binlog=$datadir/$filename |
| 25 |
--let primary_outfile=$MYSQLTEST_VARDIR/tmp/primary_binlog.sql |
| 26 |
--echo # MYSQL_BINLOG primary_local_binlog > primary_outfile |
| 27 |
--exec $MYSQL_BINLOG $primary_local_binlog > $primary_outfile |
| 28 |
|
| 29 |
--let $assert_count= 3 |
| 30 |
--let $assert_text= Ensure only $assert_count GTID events exist (Primary) |
| 31 |
--let $assert_select=GTID [0-9]-[0-9]-[0-9] |
| 32 |
--let $assert_file= $primary_outfile |
| 33 |
--source include/assert_grep.inc |
| 34 |
|
| 35 |
--let $assert_text= Ensure each GTID event has the thread id (Primary) |
| 36 |
--let $assert_select=GTID [0-9]-[0-9]-[0-9].*thread_id=$primary_thread_id\$ |
| 37 |
--source include/assert_grep.inc |
| 38 |
|
| 39 |
--echo # |
| 40 |
--echo # GTID event's thread_id should use pseudo_thread_id |
| 41 |
--connection master |
| 42 |
--let $old_pseudo_id= `SELECT @@SESSION.pseudo_thread_id` |
| 43 |
set @@pseudo_thread_id=99999; |
| 44 |
insert into t1 values(2); |
| 45 |
--echo # MYSQL_BINLOG primary_local_binlog > primary_outfile |
| 46 |
--exec $MYSQL_BINLOG $primary_local_binlog > $primary_outfile |
| 47 |
|
| 48 |
--let $assert_count= 1 |
| 49 |
--let $assert_text= GTID event's thread_id should use pseudo_thread_id |
| 50 |
--let $assert_select=GTID [0-9]-[0-9]-[0-9].*thread_id=99999\$ |
| 51 |
--source include/assert_grep.inc |
| 52 |
|
| 53 |
--disable_query_log |
| 54 |
--eval set @@pseudo_thread_id=$old_pseudo_id |
| 55 |
--enable_query_log |
| 56 |
|
| 57 |
|
| 58 |
--echo # |
| 59 |
--echo # Test the serial replica |
| 60 |
--connection slave |
| 61 |
--let replica_thread_id=`select connection_id()` |
| 62 |
--let datadir= `select @@datadir` |
| 63 |
--let filename= query_get_value(SHOW MASTER STATUS, File, 1) |
| 64 |
--let replica_local_binlog=$datadir/$filename |
| 65 |
--let replica_outfile=$MYSQLTEST_VARDIR/tmp/serial_replica_binlog.sql |
| 66 |
--echo # MYSQL_BINLOG replica_local_binlog > replica_outfile |
| 67 |
--exec $MYSQL_BINLOG $replica_local_binlog > $replica_outfile |
| 68 |
|
| 69 |
--let $assert_count= 4 |
| 70 |
--let $assert_text= Ensure the same number of GTID events on the replica as the primary |
| 71 |
--let $assert_select=GTID [0-9]-[0-9]-[0-9] |
| 72 |
--let $assert_file= $replica_outfile |
| 73 |
--source include/assert_grep.inc |
| 74 |
|
| 75 |
--let $assert_count= 3 |
| 76 |
--let $assert_text= Ensure GTID events logged with primary's thread id maintain that value |
| 77 |
--let $assert_select=GTID [0-9]-[0-9]-[0-9].*thread_id=$primary_thread_id\$ |
| 78 |
--source include/assert_grep.inc |
| 79 |
|
| 80 |
--let $assert_count= 1 |
| 81 |
--let $assert_text= Ensure GTID event logged with pseudo_thread_id on primary maintains that value |
| 82 |
--let $assert_select=GTID [0-9]-[0-9]-[0-9].*thread_id=99999\$ |
| 83 |
--source include/assert_grep.inc |
| 84 |
|
| 85 |
|
| 86 |
--echo # |
| 87 |
--echo # Test the parallel replica |
| 88 |
--connection slave |
| 89 |
--source include/stop_slave.inc |
| 90 |
--let $old_parallel_threads= `SELECT @@GLOBAL.slave_parallel_threads` |
| 91 |
SET @@GLOBAL.slave_parallel_threads=1; |
| 92 |
--source include/start_slave.inc |
| 93 |
|
| 94 |
--connection master |
| 95 |
insert into t1 values(3); |
| 96 |
insert into t1 values(4); |
| 97 |
--sync_slave_with_master |
| 98 |
|
| 99 |
--connection slave |
| 100 |
--echo # MYSQL_BINLOG replica_local_binlog > replica_outfile |
| 101 |
--exec $MYSQL_BINLOG $replica_local_binlog > $replica_outfile |
| 102 |
|
| 103 |
--let $assert_count= 6 |
| 104 |
--let $assert_text= Ensure the same number of GTID events on the replica as the primary |
| 105 |
--let $assert_select=GTID [0-9]-[0-9]-[0-9] |
| 106 |
--source include/assert_grep.inc |
| 107 |
|
| 108 |
--let $assert_count= 5 |
| 109 |
--let $assert_text= Ensure GTID the new events are logged on the replica with the thread_id of the master primary thread id |
| 110 |
--let $assert_select=GTID [0-9]-[0-9]-[0-9].*thread_id=$primary_thread_id\$ |
| 111 |
--source include/assert_grep.inc |
| 112 |
|
| 113 |
--source include/stop_slave.inc |
| 114 |
--eval SET @@GLOBAL.slave_parallel_threads=$old_parallel_threads |
| 115 |
--source include/start_slave.inc |
| 116 |
|
| 117 |
|
| 118 |
--echo # |
| 119 |
--echo # MDEV-33924: If pseudo_thread_id is set to 0, thread_id should still be |
| 120 |
--echo # written and propagated to slaves |
| 121 |
--connection master |
| 122 |
--let $old_pseudo_id= `SELECT @@SESSION.pseudo_thread_id` |
| 123 |
set @@pseudo_thread_id=0; |
| 124 |
insert into t1 values(33924); |
| 125 |
--echo # MYSQL_BINLOG primary_local_binlog > primary_outfile |
| 126 |
--exec $MYSQL_BINLOG $primary_local_binlog > $primary_outfile |
| 127 |
|
| 128 |
--let $assert_count= 1 |
| 129 |
--let $assert_text= GTID event's thread_id should write pseudo_thread_id value of 0 |
| 130 |
--let $assert_select=GTID [0-9]-[0-9]-[0-9].*thread_id=0\$ |
| 131 |
--let $assert_file= $primary_outfile |
| 132 |
--source include/assert_grep.inc |
| 133 |
|
| 134 |
--sync_slave_with_master |
| 135 |
--connection slave |
| 136 |
--echo # MYSQL_BINLOG replica_local_binlog > replica_outfile |
| 137 |
--exec $MYSQL_BINLOG $replica_local_binlog > $replica_outfile |
| 138 |
|
| 139 |
--let $assert_text= A 0 value for GTID event's thread_id should be propagated on replicas |
| 140 |
--let $assert_select=GTID [0-9]-[0-9]-[0-9].*thread_id=0\$ |
| 141 |
--let $assert_file= $replica_outfile |
| 142 |
--source include/assert_grep.inc |
| 143 |
|
| 144 |
--echo # If pseudo_thread_id is set to a value greater than 4 bytes, thread_id |
| 145 |
--echo # should be truncated to a 32-bit value in the binary log (see |
| 146 |
--echo # MDEV-15089 for details) |
| 147 |
--connection master |
| 148 |
# Silence the truncation warning |
| 149 |
--disable_warnings |
| 150 |
set @@pseudo_thread_id=99999999999999999999; |
| 151 |
--enable_warnings |
| 152 |
insert into t1 values(15089); |
| 153 |
--echo # MYSQL_BINLOG primary_local_binlog > primary_outfile |
| 154 |
--exec $MYSQL_BINLOG $primary_local_binlog > $primary_outfile |
| 155 |
|
| 156 |
--let $assert_count= 1 |
| 157 |
--let $assert_text= GTID event's thread_id should truncate values higher than 32 bit |
| 158 |
--let $assert_select=GTID [0-9]-[0-9]-[0-9].*thread_id=4294967295\$ |
| 159 |
--let $assert_file= $primary_outfile |
| 160 |
--source include/assert_grep.inc |
| 161 |
|
| 162 |
--sync_slave_with_master |
| 163 |
--connection slave |
| 164 |
--echo # MYSQL_BINLOG replica_local_binlog > replica_outfile |
| 165 |
--exec $MYSQL_BINLOG $replica_local_binlog > $replica_outfile |
| 166 |
|
| 167 |
--let $assert_text= The truncated thread_id should be preserved on the replica |
| 168 |
--let $assert_select=GTID [0-9]-[0-9]-[0-9].*thread_id=4294967295\$ |
| 169 |
--let $assert_file= $replica_outfile |
| 170 |
--source include/assert_grep.inc |
| 171 |
|
| 172 |
--disable_query_log |
| 173 |
--connection master |
| 174 |
--eval set @@pseudo_thread_id=$old_pseudo_id |
| 175 |
--enable_query_log |
| 176 |
|
| 177 |
|
| 178 |
--echo # |
| 179 |
--echo # Cleanup |
| 180 |
--connection master |
| 181 |
drop table t1; |
| 182 |
remove_file $primary_outfile; |
| 183 |
remove_file $replica_outfile; |
| 184 |
|
| 185 |
--source include/rpl_end.inc |