diff options
author | Sergey Vojtovich <svoj@mariadb.org> | 2019-09-20 22:52:00 +0400 |
---|---|---|
committer | Sergey Vojtovich <svoj@mariadb.org> | 2019-09-24 15:49:35 +0400 |
commit | ad77e3ac0930a68e61378790a232f1056f0a8e7c (patch) | |
tree | 7594a673d37662b643fa7585a103d6877ed4f6f7 /sql | |
parent | edef6a007428599fd249815f1dc59a02428090f4 (diff) | |
download | mariadb-git-ad77e3ac0930a68e61378790a232f1056f0a8e7c.tar.gz |
Cleanup session tracker
- call current_schema::mark_as_changed() directly
- call state_change::mark_as_changed() directly
- replaced SESSION_TRACKER_CHANGED with dummy tracker
- replaced Session_tracker::mark_as_changed() with
State_tracker::mark_as_changed()
- hide and devirtualize original State_tracker::mark_as_changed(),
rename it to set_changed()
- all implementations of mark_as_changed() now check is_enabled() for
consistency
- no argument casts anymore
Diffstat (limited to 'sql')
-rw-r--r-- | sql/session_tracker.cc | 19 | ||||
-rw-r--r-- | sql/session_tracker.h | 33 | ||||
-rw-r--r-- | sql/set_var.cc | 29 | ||||
-rw-r--r-- | sql/sql_class.cc | 5 | ||||
-rw-r--r-- | sql/sql_class.h | 2 | ||||
-rw-r--r-- | sql/sql_db.cc | 6 | ||||
-rw-r--r-- | sql/sql_parse.cc | 2 | ||||
-rw-r--r-- | sql/sql_prepare.cc | 4 | ||||
-rw-r--r-- | sql/sql_table.cc | 4 |
9 files changed, 50 insertions, 54 deletions
diff --git a/sql/session_tracker.cc b/sql/session_tracker.cc index 5ba0c73e042..fe5cd3a5d61 100644 --- a/sql/session_tracker.cc +++ b/sql/session_tracker.cc @@ -24,7 +24,7 @@ #include "sql_plugin.h" #include "set_var.h" -void State_tracker::mark_as_changed(THD *thd, LEX_CSTRING *tracked_item_name) +void State_tracker::set_changed(THD *thd) { m_changed= true; thd->lex->safe_to_cache_query= 0; @@ -506,11 +506,12 @@ bool Session_sysvars_tracker::store(THD *thd, String *buf) @param [IN] pointer on a variable */ -void Session_sysvars_tracker::mark_as_changed(THD *thd, - LEX_CSTRING *var) +void Session_sysvars_tracker::mark_as_changed(THD *thd, const sys_var *var) { sysvar_node_st *node; - sys_var *svar= (sys_var *)var; + + if (!is_enabled()) + return; if (!m_parsed) { @@ -529,10 +530,10 @@ void Session_sysvars_tracker::mark_as_changed(THD *thd, Check if the specified system variable is being tracked, if so mark it as changed and also set the class's m_changed flag. */ - if (orig_list.is_enabled() && (node= orig_list.insert_or_search(svar))) + if (orig_list.is_enabled() && (node= orig_list.insert_or_search(var))) { node->m_changed= true; - State_tracker::mark_as_changed(thd, var); + set_changed(thd); } } @@ -679,7 +680,7 @@ bool Transaction_state_tracker::update(THD *thd, set_var *) } if (thd->variables.session_track_transaction_info == TX_TRACK_CHISTICS) tx_changed |= TX_CHG_CHISTICS; - mark_as_changed(thd, NULL); + set_changed(thd); } else m_enabled= false; @@ -1112,7 +1113,7 @@ void Transaction_state_tracker::set_read_flags(THD *thd, { tx_read_flags = flags; tx_changed |= TX_CHG_CHISTICS; - mark_as_changed(thd, NULL); + set_changed(thd); } } @@ -1131,7 +1132,7 @@ void Transaction_state_tracker::set_isol_level(THD *thd, { tx_isol_level = level; tx_changed |= TX_CHG_CHISTICS; - mark_as_changed(thd, NULL); + set_changed(thd); } } diff --git a/sql/session_tracker.h b/sql/session_tracker.h index 226b026d590..269b1bd2359 100644 --- a/sql/session_tracker.h +++ b/sql/session_tracker.h @@ -66,6 +66,8 @@ protected: */ bool m_enabled; + void set_changed(THD *thd); + private: /** Has the session state type changed ? */ bool m_changed; @@ -102,7 +104,7 @@ public: virtual bool store(THD *thd, String *buf)= 0; /** Mark the entity as changed. */ - virtual void mark_as_changed(THD *thd, LEX_CSTRING *name); + void mark_as_changed(THD *thd) { if (is_enabled()) set_changed(thd); } }; @@ -207,7 +209,7 @@ public: bool enable(THD *thd); bool update(THD *thd, set_var *var); bool store(THD *thd, String *buf); - void mark_as_changed(THD *thd, LEX_CSTRING *tracked_item_name); + void mark_as_changed(THD *thd, const sys_var *var); void deinit() { orig_list.deinit(); } /* callback */ static uchar *sysvars_get_key(const char *entry, size_t *length, @@ -376,15 +378,13 @@ private: tx_changed &= uint(~TX_CHG_STATE); tx_changed |= (tx_curr_state != tx_reported_state) ? TX_CHG_STATE : 0; if (tx_changed != TX_CHG_NONE) - mark_as_changed(thd, NULL); + set_changed(thd); } }; #define TRANSACT_TRACKER(X) \ do { if (thd->variables.session_track_transaction_info > TX_TRACK_NONE) \ thd->session_tracker.transaction_info.X; } while(0) -#define SESSION_TRACKER_CHANGED(A,B,C) \ - thd->session_tracker.mark_as_changed(A,B,C) /** @@ -430,14 +430,6 @@ public: m_trackers[i]->enable(thd); } - inline void mark_as_changed(THD *thd, enum enum_session_tracker tracker, - LEX_CSTRING *data) - { - if (m_trackers[tracker]->is_enabled()) - m_trackers[tracker]->mark_as_changed(thd, data); - } - - void store(THD *thd, String *main_buf); }; @@ -446,7 +438,20 @@ int session_tracker_init(); #else #define TRANSACT_TRACKER(X) do{}while(0) -#define SESSION_TRACKER_CHANGED(A,B,C) do{}while(0) + +class Session_tracker +{ + class Dummy_tracker + { + public: + void mark_as_changed(THD *thd) {} + void mark_as_changed(THD *thd, const sys_var *var) {} + }; +public: + Dummy_tracker current_schema; + Dummy_tracker state_change; + Dummy_tracker sysvars; +}; #endif //EMBEDDED_LIBRARY diff --git a/sql/set_var.cc b/sql/set_var.cc index f81e2753ac1..84431d1f7a8 100644 --- a/sql/set_var.cc +++ b/sql/set_var.cc @@ -220,13 +220,12 @@ bool sys_var::update(THD *thd, set_var *var) */ if ((var->type == OPT_SESSION) && (!ret)) { - SESSION_TRACKER_CHANGED(thd, SESSION_SYSVARS_TRACKER, - (LEX_CSTRING*)var->var); + thd->session_tracker.sysvars.mark_as_changed(thd, var->var); /* Here MySQL sends variable name to avoid reporting change of the tracker itself, but we decided that it is not needed */ - SESSION_TRACKER_CHANGED(thd, SESSION_STATE_CHANGE_TRACKER, NULL); + thd->session_tracker.state_change.mark_as_changed(thd); } return ret; @@ -907,7 +906,7 @@ int set_var_user::update(THD *thd) return -1; } - SESSION_TRACKER_CHANGED(thd, SESSION_STATE_CHANGE_TRACKER, NULL); + thd->session_tracker.state_change.mark_as_changed(thd); return 0; } @@ -957,8 +956,7 @@ int set_var_role::update(THD *thd) #ifndef NO_EMBEDDED_ACCESS_CHECKS int res= acl_setrole(thd, role.str, access); if (!res) - thd->session_tracker.mark_as_changed(thd, SESSION_STATE_CHANGE_TRACKER, - NULL); + thd->session_tracker.state_change.mark_as_changed(thd); return res; #else return 0; @@ -1015,18 +1013,13 @@ int set_var_collation_client::update(THD *thd) character_set_results); /* Mark client collation variables as changed */ -#ifndef EMBEDDED_LIBRARY - if (thd->session_tracker.sysvars.is_enabled()) - { - thd->session_tracker.sysvars. - mark_as_changed(thd, (LEX_CSTRING*)Sys_character_set_client_ptr); - thd->session_tracker.sysvars. - mark_as_changed(thd, (LEX_CSTRING*)Sys_character_set_results_ptr); - thd->session_tracker.sysvars. - mark_as_changed(thd, (LEX_CSTRING*)Sys_character_set_connection_ptr); - } - thd->session_tracker.mark_as_changed(thd, SESSION_STATE_CHANGE_TRACKER, NULL); -#endif //EMBEDDED_LIBRARY + thd->session_tracker.sysvars.mark_as_changed(thd, + Sys_character_set_client_ptr); + thd->session_tracker.sysvars.mark_as_changed(thd, + Sys_character_set_results_ptr); + thd->session_tracker.sysvars.mark_as_changed(thd, + Sys_character_set_connection_ptr); + thd->session_tracker.state_change.mark_as_changed(thd); thd->protocol_text.init(thd); thd->protocol_binary.init(thd); diff --git a/sql/sql_class.cc b/sql/sql_class.cc index 4eab241232b..91fc482978d 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -7216,11 +7216,10 @@ void THD::set_last_commit_gtid(rpl_gtid >id) #endif m_last_commit_gtid= gtid; #ifndef EMBEDDED_LIBRARY - if (changed_gtid && session_tracker.sysvars.is_enabled()) + if (changed_gtid) { DBUG_ASSERT(current_thd == this); - session_tracker.sysvars. - mark_as_changed(this, (LEX_CSTRING*)Sys_last_gtid_ptr); + session_tracker.sysvars.mark_as_changed(this, Sys_last_gtid_ptr); } #endif } diff --git a/sql/sql_class.h b/sql/sql_class.h index 72cb8148895..a3d4b4e87d4 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -4685,9 +4685,7 @@ private: AUTHID invoker; public: -#ifndef EMBEDDED_LIBRARY Session_tracker session_tracker; -#endif //EMBEDDED_LIBRARY /* Flag, mutex and condition for a thread to wait for a signal from another thread. diff --git a/sql/sql_db.cc b/sql/sql_db.cc index 756955c6f94..62fbd4b8880 100644 --- a/sql/sql_db.cc +++ b/sql/sql_db.cc @@ -1089,7 +1089,7 @@ exit: if (unlikely(thd->db.str && cmp_db_names(&thd->db, db) && !error)) { mysql_change_db_impl(thd, NULL, 0, thd->variables.collation_server); - SESSION_TRACKER_CHANGED(thd, CURRENT_SCHEMA_TRACKER, NULL); + thd->session_tracker.current_schema.mark_as_changed(thd); } my_dirend(dirp); DBUG_RETURN(error); @@ -1650,8 +1650,8 @@ uint mysql_change_db(THD *thd, const LEX_CSTRING *new_db_name, mysql_change_db_impl(thd, &new_db_file_name, db_access, db_default_cl); done: - SESSION_TRACKER_CHANGED(thd, CURRENT_SCHEMA_TRACKER, NULL); - SESSION_TRACKER_CHANGED(thd, SESSION_STATE_CHANGE_TRACKER, NULL); + thd->session_tracker.current_schema.mark_as_changed(thd); + thd->session_tracker.state_change.mark_as_changed(thd); DBUG_RETURN(0); } diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index 6d053068007..45b539c97d9 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -4814,7 +4814,7 @@ mysql_execute_command(THD *thd) */ if(!res && (lex->create_info.options & HA_LEX_CREATE_TMP_TABLE)) { - SESSION_TRACKER_CHANGED(thd, SESSION_STATE_CHANGE_TRACKER, NULL); + thd->session_tracker.state_change.mark_as_changed(thd); } break; } diff --git a/sql/sql_prepare.cc b/sql/sql_prepare.cc index 5a4e13603a1..9a3013e5d47 100644 --- a/sql/sql_prepare.cc +++ b/sql/sql_prepare.cc @@ -2874,7 +2874,7 @@ void mysql_sql_stmt_prepare(THD *thd) } else { - SESSION_TRACKER_CHANGED(thd, SESSION_STATE_CHANGE_TRACKER, NULL); + thd->session_tracker.state_change.mark_as_changed(thd); my_ok(thd, 0L, 0L, "Statement prepared"); } change_list_savepoint.rollback(thd); @@ -3554,7 +3554,7 @@ void mysql_sql_stmt_close(THD *thd) else { stmt->deallocate(); - SESSION_TRACKER_CHANGED(thd, SESSION_STATE_CHANGE_TRACKER, NULL); + thd->session_tracker.state_change.mark_as_changed(thd); my_ok(thd); } } diff --git a/sql/sql_table.cc b/sql/sql_table.cc index d715e5523cf..13478be4674 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -10180,7 +10180,7 @@ do_continue:; if (table->s->tmp_table != NO_TMP_TABLE) { /* in case of alter temp table send the tracker in OK packet */ - SESSION_TRACKER_CHANGED(thd, SESSION_STATE_CHANGE_TRACKER, NULL); + thd->session_tracker.state_change.mark_as_changed(thd); } /* @@ -11481,7 +11481,7 @@ bool Sql_cmd_create_table_like::execute(THD *thd) ON then send session state notification in OK packet */ if (create_info.options & HA_LEX_CREATE_TMP_TABLE) { - SESSION_TRACKER_CHANGED(thd, SESSION_STATE_CHANGE_TRACKER, NULL); + thd->session_tracker.state_change.mark_as_changed(thd); } my_ok(thd); } |