summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSachin Kumar <sachin.setiya@mariadb.com>2021-04-16 10:22:17 +0100
committerSachin Kumar <sachin.setiya@mariadb.com>2021-04-23 12:40:00 +0100
commitf89e3d48a2fc1cd4ac5be79d99afb1d2f3d6e144 (patch)
tree4826f5f4a4c47d40e2c4270c4facd9e39d29d299
parent2b4000e3005900a84aa84ebe24b87c070f7e2e44 (diff)
downloadmariadb-git-bb-10.3-MDEV-21117-7820.tar.gz
MDEV-7850 MariaDB doesn't show thread_id for ROW-based events in binlogbb-10.3-MDEV-21117-7820
Add thread id to Gtid_log_event. FL_EXTRA_THREAD_ID flag is added to detect if there is thread_id in GTID_EVENT or not
-rw-r--r--mysql-test/suite/rpl/r/rpl_gtid_thread_id.result16
-rw-r--r--mysql-test/suite/rpl/t/rpl_gtid_thread_id.test43
-rw-r--r--sql/log_event.cc19
-rw-r--r--sql/log_event.h3
4 files changed, 81 insertions, 0 deletions
diff --git a/mysql-test/suite/rpl/r/rpl_gtid_thread_id.result b/mysql-test/suite/rpl/r/rpl_gtid_thread_id.result
new file mode 100644
index 00000000000..98e55388807
--- /dev/null
+++ b/mysql-test/suite/rpl/r/rpl_gtid_thread_id.result
@@ -0,0 +1,16 @@
+include/master-slave.inc
+[connection master]
+connection master;
+create table t1(a int);
+insert into t1 values(1);
+insert into t1 values(1);
+set @@pseudo_thread_id=99999;
+drop table t1;
+connection slave;
+#Only 2 matches
+FOUND 2 /GTID [0-9]-[0-9]-[0-9] trans thread_id=master_thread_id \n/ in binlog.sql
+#Only 1 matches
+FOUND 1 /GTID [0-9]-[0-9]-[0-9] ddl thread_id=master_thread_id \n/ in binlog.sql
+#Only 1 matches
+FOUND 1 /GTID [0-9]-[0-9]-[0-9] ddl thread_id=99999\n/ in binlog.sql
+include/rpl_end.inc
diff --git a/mysql-test/suite/rpl/t/rpl_gtid_thread_id.test b/mysql-test/suite/rpl/t/rpl_gtid_thread_id.test
new file mode 100644
index 00000000000..ff9f653e271
--- /dev/null
+++ b/mysql-test/suite/rpl/t/rpl_gtid_thread_id.test
@@ -0,0 +1,43 @@
+#
+# This will test If Gtid_log_event have thread_id info
+#
+--source include/have_binlog_format_row.inc
+--source include/master-slave.inc
+
+--connection master
+--let thread_id=`select connection_id()`
+create table t1(a int);
+insert into t1 values(1);
+insert into t1 values(1);
+set @@pseudo_thread_id=99999;
+drop table t1;
+
+--sync_slave_with_master
+let datadir= `select @@datadir`;
+let filename= slave-bin.000001;
+let local=$datadir/slave-bin.000001;
+let outfile=$MYSQLTEST_VARDIR/tmp/binlog.sql;
+exec $MYSQL_BINLOG $local > $outfile;
+
+--let SEARCH_FILE= $outfile
+## Should be same as master thread_id $thread_id
+--let SEARCH_PATTERN=GTID [0-9]-[0-9]-[0-9] trans thread_id=$thread_id\n
+--echo #Only 2 matches
+##replace the thread_id beacsue it an be different on different runs
+--replace_regex /thread_id=[0-9]+/thread_id=master_thread_id /
+--source include/search_pattern_in_file.inc
+
+#Please note that \n after $thread_id is important otherwise it can match
+#prefix of @@pseudo_thread_id set at master
+--let SEARCH_PATTERN=GTID [0-9]-[0-9]-[0-9] ddl thread_id=$thread_id\n
+--echo #Only 1 matches
+--replace_regex /thread_id=[0-9]+/thread_id=master_thread_id /
+--source include/search_pattern_in_file.inc
+
+## Should be same as master pseudo_thread_id 99999
+--let SEARCH_PATTERN=GTID [0-9]-[0-9]-[0-9] ddl thread_id=99999\n
+--echo #Only 1 matches
+--source include/search_pattern_in_file.inc
+remove_file $outfile;
+
+--source include/rpl_end.inc
diff --git a/sql/log_event.cc b/sql/log_event.cc
index d0f8ea60fdc..f98f1a3bf66 100644
--- a/sql/log_event.cc
+++ b/sql/log_event.cc
@@ -7950,6 +7950,15 @@ Gtid_log_event::Gtid_log_event(const char *buf, uint event_len,
DBUG_ASSERT(extra_engines > 0);
}
+ if (flags_extra & FL_EXTRA_THREAD_ID)
+ {
+ DBUG_ASSERT(static_cast<uint>(buf - buf_0) <= event_len - 4);
+
+ thread_id= uint4korr(buf);
+ buf+= 4;
+
+ DBUG_ASSERT(thread_id > 0);
+ }
}
/*
the strict '<' part of the assert corresponds to extra zero-padded
@@ -8011,6 +8020,8 @@ Gtid_log_event::Gtid_log_event(THD *thd_arg, uint64 seq_no_arg,
if (extra_engines > 0)
flags_extra|= FL_EXTRA_MULTI_ENGINE;
}
+ flags_extra|= FL_EXTRA_THREAD_ID;
+ thread_id= thd->variables.pseudo_thread_id;
}
@@ -8074,6 +8085,11 @@ Gtid_log_event::write()
buf[write_len]= extra_engines;
write_len++;
}
+ if (flags_extra & FL_EXTRA_THREAD_ID)
+ {
+ int4store(buf+write_len, thread_id);
+ write_len+= 4;
+ }
if (write_len < GTID_HEADER_LEN)
{
@@ -8272,6 +8288,9 @@ Gtid_log_event::print(FILE *file, PRINT_EVENT_INFO *print_event_info)
if (flags2 & FL_WAITED)
if (my_b_write_string(&cache, " waited"))
goto err;
+ if (flags_extra & FL_EXTRA_THREAD_ID)
+ if (my_b_printf(&cache, " thread_id=%u", thread_id))
+ goto err;
if (my_b_printf(&cache, "\n"))
goto err;
diff --git a/sql/log_event.h b/sql/log_event.h
index 1036e9a44d4..205d4ab4d1a 100644
--- a/sql/log_event.h
+++ b/sql/log_event.h
@@ -3373,6 +3373,7 @@ public:
in the transaction. Zero, when the base engine only is present.
*/
uint8 extra_engines;
+ my_thread_id thread_id;
/* Flags2. */
@@ -3409,6 +3410,8 @@ public:
to the event when the transaction involves only one engine.
*/
static const uchar FL_EXTRA_MULTI_ENGINE= 1;
+ /*Storing thread id into gtid*/
+ static const uchar FL_EXTRA_THREAD_ID= 2;
#ifdef MYSQL_SERVER
Gtid_log_event(THD *thd_arg, uint64 seq_no, uint32 domain_id, bool standalone,