revision-id: 943e0b77d567141963b17d1c83b4e5692c46ebc4 (mariadb-10.2.15-69-g943e0b77d56) parent(s): a7068c05c3d6c4b268f63ae6add9a7d8168fdb8b author: Oleksandr Byelkin committer: Oleksandr Byelkin timestamp: 2018-06-19 18:25:10 +0200 message: MDEV-15477: SESSION_SYSVARS_TRACKER does not track last_gtid register changes of last_gtid --- mysql-test/r/session_tracker_last_gtid.result | 33 +++++++++++++++++++++++++++ mysql-test/t/session_tracker_last_gtid.test | 18 +++++++++++++++ sql/log.cc | 5 +++- sql/set_var.h | 2 +- sql/sql_class.cc | 13 ++++++++++- sql/sql_class.h | 8 ++++++- sql/sys_vars.cc | 7 ++++-- 7 files changed, 80 insertions(+), 6 deletions(-) diff --git a/mysql-test/r/session_tracker_last_gtid.result b/mysql-test/r/session_tracker_last_gtid.result new file mode 100644 index 00000000000..6ed850d4ff5 --- /dev/null +++ b/mysql-test/r/session_tracker_last_gtid.result @@ -0,0 +1,33 @@ +# +# MDEV-15477: SESSION_SYSVARS_TRACKER does not track last_gtid +# +SET @@session.session_track_system_variables='last_gtid'; +create table t1 (a int) engine=innodb; +-- Tracker : SESSION_TRACK_SYSTEM_VARIABLES +-- last_gtid +-- 0-1-1 + +select @@last_gtid; +@@last_gtid +0-1-1 +-- Tracker : SESSION_TRACK_SYSTEM_VARIABLES +-- last_gtid +-- 0-1-1 + +insert into t1 values (1); +-- Tracker : SESSION_TRACK_SYSTEM_VARIABLES +-- last_gtid +-- 0-1-2 + +select @@last_gtid; +@@last_gtid +0-1-2 +-- Tracker : SESSION_TRACK_SYSTEM_VARIABLES +-- last_gtid +-- 0-1-2 + +drop table t1; +-- Tracker : SESSION_TRACK_SYSTEM_VARIABLES +-- last_gtid +-- 0-1-3 + diff --git a/mysql-test/t/session_tracker_last_gtid.test b/mysql-test/t/session_tracker_last_gtid.test new file mode 100644 index 00000000000..ccd2c25b31f --- /dev/null +++ b/mysql-test/t/session_tracker_last_gtid.test @@ -0,0 +1,18 @@ + +--source include/have_innodb.inc +--source include/have_binlog_format_statement.inc + +--enable_session_track_info + +--echo # +--echo # MDEV-15477: SESSION_SYSVARS_TRACKER does not track last_gtid +--echo # + +SET @@session.session_track_system_variables='last_gtid'; +create table t1 (a int) engine=innodb; +select @@last_gtid; +insert into t1 values (1); +select @@last_gtid; +drop table t1; + +--disable_session_track_info diff --git a/sql/log.cc b/sql/log.cc index 973aecb16e8..d83f2e1930c 100644 --- a/sql/log.cc +++ b/sql/log.cc @@ -46,6 +46,8 @@ #include <stdarg.h> #include <m_ctype.h> // For test_if_number +#include <set_var.h> // for Sys_last_gtid_ptr + #ifdef _WIN32 #include "message.h" #endif @@ -5945,7 +5947,8 @@ MYSQL_BIN_LOG::write_gtid_event(THD *thd, bool standalone, } if (err) DBUG_RETURN(true); - thd->last_commit_gtid= gtid; + + thd->set_last_commit_gtid(gtid); Gtid_log_event gtid_event(thd, seq_no, domain_id, standalone, LOG_EVENT_SUPPRESS_USE_F, is_transactional, diff --git a/sql/set_var.h b/sql/set_var.h index 7a48e319466..24e25af2245 100644 --- a/sql/set_var.h +++ b/sql/set_var.h @@ -424,7 +424,7 @@ sql_mode_t expand_sql_mode(sql_mode_t sql_mode); bool sql_mode_string_representation(THD *thd, sql_mode_t sql_mode, LEX_STRING *ls); int default_regex_flags_pcre(const THD *thd); -extern sys_var *Sys_autocommit_ptr; +extern sys_var *Sys_autocommit_ptr, *Sys_last_gtid_ptr; CHARSET_INFO *get_old_charset_by_name(const char *old_name); diff --git a/sql/sql_class.cc b/sql/sql_class.cc index 7e15eff4dd4..d2959b0dac5 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -1287,7 +1287,7 @@ void THD::init(void) bzero((char *) &org_status_var, sizeof(org_status_var)); status_in_global= 0; start_bytes_received= 0; - last_commit_gtid.seq_no= 0; + m_last_commit_gtid.seq_no= 0; last_stmt= NULL; /* Reset status of last insert id */ arg_of_last_insert_id_function= FALSE; @@ -7069,6 +7069,17 @@ THD::signal_wakeup_ready() mysql_cond_signal(&COND_wakeup_ready); } +void THD::set_last_commit_gtid(rpl_gtid >id) +{ + bool changed_gtid= (m_last_commit_gtid.seq_no != gtid.seq_no); + m_last_commit_gtid= gtid; + if (changed_gtid && + session_tracker.get_tracker(SESSION_SYSVARS_TRACKER)->is_enabled()) + { + session_tracker.get_tracker(SESSION_SYSVARS_TRACKER)-> + mark_as_changed(this, (LEX_CSTRING*)Sys_last_gtid_ptr); + } +} void wait_for_commit::reinit() diff --git a/sql/sql_class.h b/sql/sql_class.h index a12015ecfe4..024ec3b4017 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -4254,7 +4254,13 @@ class THD :public Statement, The GTID assigned to the last commit. If no GTID was assigned to any commit so far, this is indicated by last_commit_gtid.seq_no == 0. */ - rpl_gtid last_commit_gtid; +private: + rpl_gtid m_last_commit_gtid; + +public: + rpl_gtid get_last_commit_gtid() { return m_last_commit_gtid; } + void set_last_commit_gtid(rpl_gtid >id); + LF_PINS *tdc_hash_pins; LF_PINS *xid_hash_pins; diff --git a/sql/sys_vars.cc b/sql/sys_vars.cc index c3d786af945..1fd75cb5040 100644 --- a/sql/sys_vars.cc +++ b/sql/sys_vars.cc @@ -1828,6 +1828,8 @@ static Sys_var_last_gtid Sys_last_gtid( "or the empty string if none.", READ_ONLY sys_var::ONLY_SESSION, NO_CMD_LINE); +export sys_var *Sys_last_gtid_ptr= &Sys_last_gtid; // for check changing + uchar * Sys_var_last_gtid::session_value_ptr(THD *thd, const LEX_STRING *base) @@ -1838,8 +1840,9 @@ Sys_var_last_gtid::session_value_ptr(THD *thd, const LEX_STRING *base) bool first= true; str.length(0); - if ((thd->last_commit_gtid.seq_no > 0 && - rpl_slave_state_tostring_helper(&str, &thd->last_commit_gtid, &first)) || + rpl_gtid gtid= thd->get_last_commit_gtid(); + if ((gtid.seq_no > 0 && + rpl_slave_state_tostring_helper(&str, >id, &first)) || !(p= thd->strmake(str.ptr(), str.length()))) { my_error(ER_OUT_OF_RESOURCES, MYF(0));