Commit e0b6db2d authored by Yuchen Pei's avatar Yuchen Pei

MDEV-31609 Send initial values of system variables in first OK packet

Values of all session tracking system variables will be sent in the
first ok packet upon connection after successful authentication.

Also updated mtr to print session track info on connection (h/t Sergei
Golubchik) so that we can write mtr tests for this change.
parent e32736ec
......@@ -688,6 +688,7 @@ void enable_optimizer_trace(struct st_connection *con);
void display_optimizer_trace(struct st_connection *con,
DYNAMIC_STRING *ds);
static void append_session_track_info(DYNAMIC_STRING *ds, MYSQL *mysql);
class LogFile {
FILE* m_file;
......@@ -5975,6 +5976,8 @@ int connect_n_handle_errors(struct st_command *command,
// Ignore errors intentionally
}
if (display_session_track_info)
append_session_track_info(ds, con);
var_set_errno(0);
handle_no_error(command);
......
......@@ -151,4 +151,25 @@ SELECT @@session.session_track_system_variables;
SET SESSION session_track_system_variables="sql_slave_skip_counter", sql_slave_skip_counter= 0;
# Restoring the original values.
SET @@global.session_track_system_variables = @global_saved_tmp;
# End of tests.
#
# MDEV-31609 Send initial values of system variables in first OK packet
#
set @old_session_track_system_variables=@@global.session_track_system_variables;
set global session_track_system_variables="autocommit,character_set_client,character_set_connection,redirect_url,time_zone";
connect foo,localhost,root;
-- Tracker : SESSION_TRACK_SYSTEM_VARIABLES
-- autocommit
-- ON
-- time_zone
-- SYSTEM
-- character_set_client
-- latin1
-- character_set_connection
-- latin1
-- redirect_url
--
connection default;
disconnect foo;
set global session_track_system_variables=@old_session_track_system_variables;
# End of tests 11.5
......@@ -125,4 +125,22 @@ SET SESSION session_track_system_variables="sql_slave_skip_counter", sql_slave_s
--echo # Restoring the original values.
SET @@global.session_track_system_variables = @global_saved_tmp;
--echo # End of tests.
--echo #
--echo # MDEV-31609 Send initial values of system variables in first OK packet
--echo #
set @old_session_track_system_variables=@@global.session_track_system_variables;
# We set the session_track_system_variables to exclude
# character_set_results as it can appear out of order in the CI
# builder x86-debian-sid.
set global session_track_system_variables="autocommit,character_set_client,character_set_connection,redirect_url,time_zone";
enable_session_track_info;
connect foo,localhost,root;
disable_session_track_info;
connection default;
disconnect foo;
set global session_track_system_variables=@old_session_track_system_variables;
--echo # End of tests 11.5
......@@ -516,6 +516,22 @@ bool Session_sysvars_tracker::store(THD *thd, String *buf)
return false;
}
/* Parse all session track system variables if not parsed yet. */
void Session_sysvars_tracker::maybe_parse_all(THD *thd)
{
if (!m_parsed)
{
DBUG_ASSERT(thd->variables.session_track_system_variables);
LEX_STRING tmp= { thd->variables.session_track_system_variables,
strlen(thd->variables.session_track_system_variables) };
if (orig_list.parse_var_list(thd, tmp, true, thd->charset()))
{
orig_list.reinit();
return;
}
m_parsed= true;
}
}
/**
Mark the system variable as changed.
......@@ -530,18 +546,7 @@ void Session_sysvars_tracker::mark_as_changed(THD *thd, const sys_var *var)
if (!is_enabled())
return;
if (!m_parsed)
{
DBUG_ASSERT(thd->variables.session_track_system_variables);
LEX_STRING tmp= { thd->variables.session_track_system_variables,
strlen(thd->variables.session_track_system_variables) };
if (orig_list.parse_var_list(thd, tmp, true, thd->charset()))
{
orig_list.reinit();
return;
}
m_parsed= true;
}
maybe_parse_all(thd);
/*
Check if the specified system variable is being tracked, if so
......@@ -554,6 +559,23 @@ void Session_sysvars_tracker::mark_as_changed(THD *thd, const sys_var *var)
}
}
/**
Mark all session tracking system variables as changed.
*/
void Session_sysvars_tracker::mark_all_as_changed(THD *thd)
{
if (!is_enabled())
return;
maybe_parse_all(thd);
for (ulong i= 0; i < orig_list.size(); i++)
{
orig_list.at(i)->m_changed= true;
set_changed(thd);
}
}
/**
Supply key to a hash.
......
......@@ -155,16 +155,18 @@ class Session_sysvars_tracker: public State_tracker
}
sysvar_node_st *search(const sys_var *svar);
public:
vars_list(): track_all(false) { init(); }
~vars_list() { if (my_hash_inited(&m_registered_sysvars)) free_hash(); }
void deinit() { free_hash(); }
ulong size() { return m_registered_sysvars.records; }
sysvar_node_st *at(ulong i)
{
DBUG_ASSERT(i < m_registered_sysvars.records);
return reinterpret_cast<sysvar_node_st*>(
my_hash_element(&m_registered_sysvars, i));
}
public:
vars_list(): track_all(false) { init(); }
~vars_list() { if (my_hash_inited(&m_registered_sysvars)) free_hash(); }
void deinit() { free_hash(); }
sysvar_node_st *insert_or_search(const sys_var *svar)
{
......@@ -199,6 +201,7 @@ class Session_sysvars_tracker: public State_tracker
*/
vars_list orig_list;
bool m_parsed;
void maybe_parse_all(THD *thd);
public:
void init(THD *thd);
......@@ -207,6 +210,7 @@ class Session_sysvars_tracker: public State_tracker
bool update(THD *thd, set_var *var);
bool store(THD *thd, String *buf);
void mark_as_changed(THD *thd, const sys_var *var);
void mark_all_as_changed(THD *thd);
void deinit() { orig_list.deinit(); }
/* callback */
static uchar *sysvars_get_key(const char *entry, size_t *length,
......
......@@ -1167,6 +1167,7 @@ static bool login_connection(THD *thd)
my_net_set_write_timeout(net, connect_timeout);
error= check_connection(thd);
thd->session_tracker.sysvars.mark_all_as_changed(thd);
thd->protocol->end_statement();
if (unlikely(error))
......
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