summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mysql-test/suite/rpl/r/rpl_gtid_thread_id.result22
-rw-r--r--mysql-test/suite/rpl/t/rpl_gtid_thread_id.test50
-rw-r--r--sql/log_event.cc47
-rw-r--r--sql/log_event.h7
4 files changed, 122 insertions, 4 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..de55f9e4adf
--- /dev/null
+++ b/mysql-test/suite/rpl/r/rpl_gtid_thread_id.result
@@ -0,0 +1,22 @@
+include/master-slave.inc
+[connection master]
+connection slave;
+include/stop_slave.inc
+RESET MASTER;
+RESET SLAVE;
+include/start_slave.inc
+connection master;
+RESET 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..571b7a29708
--- /dev/null
+++ b/mysql-test/suite/rpl/t/rpl_gtid_thread_id.test
@@ -0,0 +1,50 @@
+#
+# This will test If Gtid_log_event have thread_id info
+#
+--source include/have_binlog_format_row.inc
+--source include/master-slave.inc
+
+--connection slave
+--source include/stop_slave.inc
+RESET MASTER;
+RESET SLAVE;
+--source include/start_slave.inc
+
+--connection master
+RESET 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 fed2b14652f..25e77281104 100644
--- a/sql/log_event.cc
+++ b/sql/log_event.cc
@@ -7905,10 +7905,12 @@ bool Binlog_checkpoint_log_event::write()
Gtid_log_event::Gtid_log_event(const char *buf, uint event_len,
const Format_description_log_event *description_event)
- : Log_event(buf, description_event), seq_no(0), commit_id(0)
+ : Log_event(buf, description_event), seq_no(0), commit_id(0),
+ flags_extra(0)
{
uint8 header_size= description_event->common_header_len;
uint8 post_header_len= description_event->post_header_len[GTID_EVENT-1];
+ const char *buf_0= buf;
if (event_len < (uint) header_size + (uint) post_header_len ||
post_header_len < GTID_HEADER_LEN)
return;
@@ -7928,6 +7930,25 @@ Gtid_log_event::Gtid_log_event(const char *buf, uint event_len,
}
++buf;
commit_id= uint8korr(buf);
+ buf= buf_0 + (uint)header_size + GTID_HEADER_LEN + 2;
+ }
+ else
+ buf= buf_0 + (uint)header_size + GTID_HEADER_LEN;
+
+ /* the extra flags check and actions */
+ if (static_cast<uint>(buf - buf_0) < event_len)
+ {
+ flags_extra= *buf++;
+
+ 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);
+ }
}
}
@@ -7940,7 +7961,9 @@ Gtid_log_event::Gtid_log_event(THD *thd_arg, uint64 seq_no_arg,
uint64 commit_id_arg)
: Log_event(thd_arg, flags_arg, is_transactional),
seq_no(seq_no_arg), commit_id(commit_id_arg), domain_id(domain_id_arg),
- flags2((standalone ? FL_STANDALONE : 0) | (commit_id_arg ? FL_GROUP_COMMIT_ID : 0))
+ flags2((standalone ? FL_STANDALONE : 0) |
+ (commit_id_arg ? FL_GROUP_COMMIT_ID : 0)),
+ flags_extra(0)
{
cache_type= Log_event::EVENT_NO_CACHE;
bool is_tmp_table= thd_arg->lex->stmt_accessed_temp_table();
@@ -7961,6 +7984,9 @@ 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));
+ flags_extra|= FL_EXTRA_THREAD_ID;
+ thread_id= thd->variables.pseudo_thread_id;
+
}
@@ -8003,7 +8029,7 @@ Gtid_log_event::peek(const char *event_start, size_t event_len,
bool
Gtid_log_event::write()
{
- uchar buf[GTID_HEADER_LEN+2];
+ uchar buf[GTID_HEADER_LEN+2+ /* flags_extra: */ 1+4];
size_t write_len;
int8store(buf, seq_no);
@@ -8019,6 +8045,17 @@ Gtid_log_event::write()
bzero(buf+13, GTID_HEADER_LEN-13);
write_len= GTID_HEADER_LEN;
}
+ if (flags_extra > 0)
+ {
+ buf[write_len]= flags_extra;
+ write_len++;
+ }
+
+ if (flags_extra & FL_EXTRA_THREAD_ID)
+ {
+ int4store(buf+write_len, thread_id);
+ write_len+= 4;
+ }
return write_header(write_len) ||
write_data(buf, write_len) ||
write_footer();
@@ -8211,6 +8248,10 @@ 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 57282fe58ce..a0e3c99e688 100644
--- a/sql/log_event.h
+++ b/sql/log_event.h
@@ -3365,9 +3365,14 @@ public:
uint64 commit_id;
uint32 domain_id;
uchar flags2;
-
+ uint flags_extra; // more flags area placed after the regular flags2's one
+ my_thread_id thread_id;
/* Flags2. */
+ /*Storing thread id into gtid*/
+ static const uchar FL_EXTRA_THREAD_ID= 1;
+
+
/* FL_STANDALONE is set when there is no terminating COMMIT event. */
static const uchar FL_STANDALONE= 1;
/*