Skip to content

Commit

Permalink
Update per-user-session-vars on COM_CHANGE_USER
Browse files Browse the repository at this point in the history
Summary: per-user-session variables were not applying after calling COM_CHANGE_USER. Call the update function after each user change, and also on com_rpc user switches

Reviewed By: jkedgar

Differential Revision: D9982186

fbshipit-source-id: 398c4b1
  • Loading branch information
abal147 authored and facebook-github-bot committed Sep 21, 2018
1 parent af3dc25 commit 6d0e912
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 2 deletions.
12 changes: 12 additions & 0 deletions mysql-test/r/com_rpc.result
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,18 @@ SELECT @my_var; SET @my_var='other_value'; SELECT @my_var|
new_value
@my_var
other_value

# Case 16: Per-user-session-variables

SET @original_val = @@global.per_user_session_var_default_val;
SET @@global.per_user_session_var_default_val = "scriptro:lock_wait_timeout=23";
SELECT @@global.lock_wait_timeout, @@session.lock_wait_timeout;
@@global.lock_wait_timeout @@session.lock_wait_timeout
604800.000000 23.000000
SET @@global.per_user_session_var_default_val = @original_val;
SELECT @@global.per_user_session_var_default_val;
@@global.per_user_session_var_default_val
NULL
drop database db_default;
drop database db_rpc;
drop user scriptro;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,12 @@ SET GLOBAL per_user_session_var_default_val = "usr1:binlog_format=MIXED";
SELECT @@GLOBAL.binlog_format, @@SESSION.binlog_format;
@@GLOBAL.binlog_format @@SESSION.binlog_format
STATEMENT MIXED
SELECT @@GLOBAL.binlog_format, @@SESSION.binlog_format;
@@GLOBAL.binlog_format @@SESSION.binlog_format
STATEMENT STATEMENT
SELECT @@GLOBAL.binlog_format, @@SESSION.binlog_format;
@@GLOBAL.binlog_format @@SESSION.binlog_format
STATEMENT MIXED
SET GLOBAL per_user_session_var_default_val = "usr1:binlog_format=ROW";
SELECT @@GLOBAL.binlog_format, @@SESSION.binlog_format;
@@GLOBAL.binlog_format @@SESSION.binlog_format
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,13 @@ SET GLOBAL per_user_session_var_default_val = "usr1:binlog_format=MIXED";
connect (con_usr1,localhost,usr1,,);
SELECT @@GLOBAL.binlog_format, @@SESSION.binlog_format;

# Ensure that per-user session variables remain on change user
change_user admin1;
SELECT @@GLOBAL.binlog_format, @@SESSION.binlog_format;

change_user usr1;
SELECT @@GLOBAL.binlog_format, @@SESSION.binlog_format;

connection default;
SET GLOBAL per_user_session_var_default_val = "usr1:binlog_format=ROW";
connect (con_usr1_ssl,localhost,usr1,,,,,SSL);
Expand Down
28 changes: 28 additions & 0 deletions mysql-test/t/com_rpc.test
Original file line number Diff line number Diff line change
Expand Up @@ -800,6 +800,34 @@ connection default;
eval KILL $rpc_id;
--enable_query_log

--echo
--echo # Case 16: Per-user-session-variables
--echo

connection default;
SET @original_val = @@global.per_user_session_var_default_val;

SET @@global.per_user_session_var_default_val = "scriptro:lock_wait_timeout=23";
connect (conn,localhost,root,,db_default);
--query_attrs_add rpc_role scriptro
--query_attrs_add rpc_db db_rpc

SELECT @@global.lock_wait_timeout, @@session.lock_wait_timeout;

# This is not expected but need to do cleanup while bug persists
let $rpc_id=get_rpc_id();
connection default;
--disable_query_log
eval KILL $rpc_id;
--enable_query_log
connection conn;

disconnect conn;

connection default;
SET @@global.per_user_session_var_default_val = @original_val;
SELECT @@global.per_user_session_var_default_val;

# delete all dbs and users
connection default;

Expand Down
2 changes: 0 additions & 2 deletions sql/mysqld.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6604,8 +6604,6 @@ bool Per_user_session_variables::init_do(User_session_vars_sp& per_user_vars,
*/
bool Per_user_session_variables::set_thd(THD *thd)
{
thd->get_stmt_da()->reset_diagnostics_area();

bool ret = true;
std::string err_msg;

Expand Down
1 change: 1 addition & 0 deletions sql/sql_parse.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1799,6 +1799,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd, char* packet,
}
#endif /* NO_EMBEDDED_ACCESS_CHECKS */
mysql_mutex_lock(&thd->LOCK_thd_data);
per_user_session_variables.set_thd(thd);
my_free(save_db);
mysql_mutex_unlock(&thd->LOCK_thd_data);
my_free(save_security_ctx.user);
Expand Down
1 change: 1 addition & 0 deletions sql/sql_parse_com_rpc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ std::pair<bool, std::shared_ptr<Srv_session>> handle_com_rpc(THD *conn_thd)
my_error(ER_RPC_FAILED_TO_SWITCH_DB, MYF(0), rpc_db.c_str());
goto error;
}
per_user_session_variables.set_thd(srv_session->get_thd());
}

if (srv_session->attach())
Expand Down

0 comments on commit 6d0e912

Please sign in to comment.