Commit ad77e3ac authored by Sergey Vojtovich's avatar Sergey Vojtovich

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
parent edef6a00
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
#include "sql_plugin.h" #include "sql_plugin.h"
#include "set_var.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; m_changed= true;
thd->lex->safe_to_cache_query= 0; thd->lex->safe_to_cache_query= 0;
...@@ -506,11 +506,12 @@ bool Session_sysvars_tracker::store(THD *thd, String *buf) ...@@ -506,11 +506,12 @@ bool Session_sysvars_tracker::store(THD *thd, String *buf)
@param [IN] pointer on a variable @param [IN] pointer on a variable
*/ */
void Session_sysvars_tracker::mark_as_changed(THD *thd, void Session_sysvars_tracker::mark_as_changed(THD *thd, const sys_var *var)
LEX_CSTRING *var)
{ {
sysvar_node_st *node; sysvar_node_st *node;
sys_var *svar= (sys_var *)var;
if (!is_enabled())
return;
if (!m_parsed) if (!m_parsed)
{ {
...@@ -529,10 +530,10 @@ void Session_sysvars_tracker::mark_as_changed(THD *thd, ...@@ -529,10 +530,10 @@ void Session_sysvars_tracker::mark_as_changed(THD *thd,
Check if the specified system variable is being tracked, if so Check if the specified system variable is being tracked, if so
mark it as changed and also set the class's m_changed flag. 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; 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 *) ...@@ -679,7 +680,7 @@ bool Transaction_state_tracker::update(THD *thd, set_var *)
} }
if (thd->variables.session_track_transaction_info == TX_TRACK_CHISTICS) if (thd->variables.session_track_transaction_info == TX_TRACK_CHISTICS)
tx_changed |= TX_CHG_CHISTICS; tx_changed |= TX_CHG_CHISTICS;
mark_as_changed(thd, NULL); set_changed(thd);
} }
else else
m_enabled= false; m_enabled= false;
...@@ -1112,7 +1113,7 @@ void Transaction_state_tracker::set_read_flags(THD *thd, ...@@ -1112,7 +1113,7 @@ void Transaction_state_tracker::set_read_flags(THD *thd,
{ {
tx_read_flags = flags; tx_read_flags = flags;
tx_changed |= TX_CHG_CHISTICS; 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, ...@@ -1131,7 +1132,7 @@ void Transaction_state_tracker::set_isol_level(THD *thd,
{ {
tx_isol_level = level; tx_isol_level = level;
tx_changed |= TX_CHG_CHISTICS; tx_changed |= TX_CHG_CHISTICS;
mark_as_changed(thd, NULL); set_changed(thd);
} }
} }
......
...@@ -66,6 +66,8 @@ class State_tracker ...@@ -66,6 +66,8 @@ class State_tracker
*/ */
bool m_enabled; bool m_enabled;
void set_changed(THD *thd);
private: private:
/** Has the session state type changed ? */ /** Has the session state type changed ? */
bool m_changed; bool m_changed;
...@@ -102,7 +104,7 @@ class State_tracker ...@@ -102,7 +104,7 @@ class State_tracker
virtual bool store(THD *thd, String *buf)= 0; virtual bool store(THD *thd, String *buf)= 0;
/** Mark the entity as changed. */ /** 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 @@ class Session_sysvars_tracker: public State_tracker ...@@ -207,7 +209,7 @@ class Session_sysvars_tracker: public State_tracker
bool enable(THD *thd); bool enable(THD *thd);
bool update(THD *thd, set_var *var); bool update(THD *thd, set_var *var);
bool store(THD *thd, String *buf); 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(); } void deinit() { orig_list.deinit(); }
/* callback */ /* callback */
static uchar *sysvars_get_key(const char *entry, size_t *length, static uchar *sysvars_get_key(const char *entry, size_t *length,
...@@ -376,15 +378,13 @@ class Transaction_state_tracker : public State_tracker ...@@ -376,15 +378,13 @@ class Transaction_state_tracker : public State_tracker
tx_changed &= uint(~TX_CHG_STATE); tx_changed &= uint(~TX_CHG_STATE);
tx_changed |= (tx_curr_state != tx_reported_state) ? TX_CHG_STATE : 0; tx_changed |= (tx_curr_state != tx_reported_state) ? TX_CHG_STATE : 0;
if (tx_changed != TX_CHG_NONE) if (tx_changed != TX_CHG_NONE)
mark_as_changed(thd, NULL); set_changed(thd);
} }
}; };
#define TRANSACT_TRACKER(X) \ #define TRANSACT_TRACKER(X) \
do { if (thd->variables.session_track_transaction_info > TX_TRACK_NONE) \ do { if (thd->variables.session_track_transaction_info > TX_TRACK_NONE) \
thd->session_tracker.transaction_info.X; } while(0) 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 @@ class Session_tracker ...@@ -430,14 +430,6 @@ class Session_tracker
m_trackers[i]->enable(thd); 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); void store(THD *thd, String *main_buf);
}; };
...@@ -446,7 +438,20 @@ int session_tracker_init(); ...@@ -446,7 +438,20 @@ int session_tracker_init();
#else #else
#define TRANSACT_TRACKER(X) do{}while(0) #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 #endif //EMBEDDED_LIBRARY
......
...@@ -220,13 +220,12 @@ bool sys_var::update(THD *thd, set_var *var) ...@@ -220,13 +220,12 @@ bool sys_var::update(THD *thd, set_var *var)
*/ */
if ((var->type == OPT_SESSION) && (!ret)) if ((var->type == OPT_SESSION) && (!ret))
{ {
SESSION_TRACKER_CHANGED(thd, SESSION_SYSVARS_TRACKER, thd->session_tracker.sysvars.mark_as_changed(thd, var->var);
(LEX_CSTRING*)var->var);
/* /*
Here MySQL sends variable name to avoid reporting change of Here MySQL sends variable name to avoid reporting change of
the tracker itself, but we decided that it is not needed 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; return ret;
...@@ -907,7 +906,7 @@ int set_var_user::update(THD *thd) ...@@ -907,7 +906,7 @@ int set_var_user::update(THD *thd)
return -1; return -1;
} }
SESSION_TRACKER_CHANGED(thd, SESSION_STATE_CHANGE_TRACKER, NULL); thd->session_tracker.state_change.mark_as_changed(thd);
return 0; return 0;
} }
...@@ -957,8 +956,7 @@ int set_var_role::update(THD *thd) ...@@ -957,8 +956,7 @@ int set_var_role::update(THD *thd)
#ifndef NO_EMBEDDED_ACCESS_CHECKS #ifndef NO_EMBEDDED_ACCESS_CHECKS
int res= acl_setrole(thd, role.str, access); int res= acl_setrole(thd, role.str, access);
if (!res) if (!res)
thd->session_tracker.mark_as_changed(thd, SESSION_STATE_CHANGE_TRACKER, thd->session_tracker.state_change.mark_as_changed(thd);
NULL);
return res; return res;
#else #else
return 0; return 0;
...@@ -1015,18 +1013,13 @@ int set_var_collation_client::update(THD *thd) ...@@ -1015,18 +1013,13 @@ int set_var_collation_client::update(THD *thd)
character_set_results); character_set_results);
/* Mark client collation variables as changed */ /* Mark client collation variables as changed */
#ifndef EMBEDDED_LIBRARY thd->session_tracker.sysvars.mark_as_changed(thd,
if (thd->session_tracker.sysvars.is_enabled()) Sys_character_set_client_ptr);
{ thd->session_tracker.sysvars.mark_as_changed(thd,
thd->session_tracker.sysvars. Sys_character_set_results_ptr);
mark_as_changed(thd, (LEX_CSTRING*)Sys_character_set_client_ptr); thd->session_tracker.sysvars.mark_as_changed(thd,
thd->session_tracker.sysvars. Sys_character_set_connection_ptr);
mark_as_changed(thd, (LEX_CSTRING*)Sys_character_set_results_ptr); thd->session_tracker.state_change.mark_as_changed(thd);
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->protocol_text.init(thd); thd->protocol_text.init(thd);
thd->protocol_binary.init(thd); thd->protocol_binary.init(thd);
......
...@@ -7216,11 +7216,10 @@ void THD::set_last_commit_gtid(rpl_gtid &gtid) ...@@ -7216,11 +7216,10 @@ void THD::set_last_commit_gtid(rpl_gtid &gtid)
#endif #endif
m_last_commit_gtid= gtid; m_last_commit_gtid= gtid;
#ifndef EMBEDDED_LIBRARY #ifndef EMBEDDED_LIBRARY
if (changed_gtid && session_tracker.sysvars.is_enabled()) if (changed_gtid)
{ {
DBUG_ASSERT(current_thd == this); DBUG_ASSERT(current_thd == this);
session_tracker.sysvars. session_tracker.sysvars.mark_as_changed(this, Sys_last_gtid_ptr);
mark_as_changed(this, (LEX_CSTRING*)Sys_last_gtid_ptr);
} }
#endif #endif
} }
......
...@@ -4685,9 +4685,7 @@ class THD: public THD_count, /* this must be first */ ...@@ -4685,9 +4685,7 @@ class THD: public THD_count, /* this must be first */
AUTHID invoker; AUTHID invoker;
public: public:
#ifndef EMBEDDED_LIBRARY
Session_tracker session_tracker; Session_tracker session_tracker;
#endif //EMBEDDED_LIBRARY
/* /*
Flag, mutex and condition for a thread to wait for a signal from another Flag, mutex and condition for a thread to wait for a signal from another
thread. thread.
......
...@@ -1089,7 +1089,7 @@ mysql_rm_db_internal(THD *thd, const LEX_CSTRING *db, bool if_exists, bool silen ...@@ -1089,7 +1089,7 @@ mysql_rm_db_internal(THD *thd, const LEX_CSTRING *db, bool if_exists, bool silen
if (unlikely(thd->db.str && cmp_db_names(&thd->db, db) && !error)) if (unlikely(thd->db.str && cmp_db_names(&thd->db, db) && !error))
{ {
mysql_change_db_impl(thd, NULL, 0, thd->variables.collation_server); 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); my_dirend(dirp);
DBUG_RETURN(error); DBUG_RETURN(error);
...@@ -1650,8 +1650,8 @@ uint mysql_change_db(THD *thd, const LEX_CSTRING *new_db_name, ...@@ -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); mysql_change_db_impl(thd, &new_db_file_name, db_access, db_default_cl);
done: done:
SESSION_TRACKER_CHANGED(thd, CURRENT_SCHEMA_TRACKER, NULL); thd->session_tracker.current_schema.mark_as_changed(thd);
SESSION_TRACKER_CHANGED(thd, SESSION_STATE_CHANGE_TRACKER, NULL); thd->session_tracker.state_change.mark_as_changed(thd);
DBUG_RETURN(0); DBUG_RETURN(0);
} }
......
...@@ -4814,7 +4814,7 @@ mysql_execute_command(THD *thd) ...@@ -4814,7 +4814,7 @@ mysql_execute_command(THD *thd)
*/ */
if(!res && (lex->create_info.options & HA_LEX_CREATE_TMP_TABLE)) 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; break;
} }
......
...@@ -2874,7 +2874,7 @@ void mysql_sql_stmt_prepare(THD *thd) ...@@ -2874,7 +2874,7 @@ void mysql_sql_stmt_prepare(THD *thd)
} }
else 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"); my_ok(thd, 0L, 0L, "Statement prepared");
} }
change_list_savepoint.rollback(thd); change_list_savepoint.rollback(thd);
...@@ -3554,7 +3554,7 @@ void mysql_sql_stmt_close(THD *thd) ...@@ -3554,7 +3554,7 @@ void mysql_sql_stmt_close(THD *thd)
else else
{ {
stmt->deallocate(); stmt->deallocate();
SESSION_TRACKER_CHANGED(thd, SESSION_STATE_CHANGE_TRACKER, NULL); thd->session_tracker.state_change.mark_as_changed(thd);
my_ok(thd); my_ok(thd);
} }
} }
......
...@@ -10180,7 +10180,7 @@ do_continue:; ...@@ -10180,7 +10180,7 @@ do_continue:;
if (table->s->tmp_table != NO_TMP_TABLE) if (table->s->tmp_table != NO_TMP_TABLE)
{ {
/* in case of alter temp table send the tracker in OK packet */ /* 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) ...@@ -11481,7 +11481,7 @@ bool Sql_cmd_create_table_like::execute(THD *thd)
ON then send session state notification in OK packet */ ON then send session state notification in OK packet */
if (create_info.options & HA_LEX_CREATE_TMP_TABLE) 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); my_ok(thd);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment