Skip to content

Commit

Permalink
MDEV-27978 fix wrong name in error when max_session_mem_used exceeded
Browse files Browse the repository at this point in the history
Fixed typo in my_malloc_size_cb_func. There is no max-thread-mem-used
sys variable in MariaDB, only max-session-mem-used. The relevant entry
in sys_vars.cc is also fixed.

Added a fallback case in case we could allocate the 256 bytes for the
error message containing the exact setting.
  • Loading branch information
haidong authored and grooverdan committed Mar 8, 2022
1 parent a92f07f commit 114476f
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 3 deletions.
10 changes: 10 additions & 0 deletions mysql-test/r/error_simulation.result
Original file line number Diff line number Diff line change
Expand Up @@ -128,3 +128,13 @@ SELECT f1(1);
Got one of the listed errors
DROP FUNCTION f1;
SET debug_dbug= @saved_dbug;
#
# MDEV-27978 wrong option name in error when exceeding max_session_mem_used
#
SET SESSION max_session_mem_used = 8192;
SELECT * FROM information_schema.processlist;
ERROR HY000: The MariaDB server is running with the --max-session-mem-used=8192 option so it cannot execute this statement
SET SESSION max_session_mem_used = DEFAULT;
#
# End of 10.2 tests
#
2 changes: 1 addition & 1 deletion mysql-test/r/truncate_notembedded.result
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ a
UNLOCK TABLES;
connection con1;
TRUNCATE TABLE t1;
ERROR HY000: The MariaDB server is running with the --max-thread-mem-used=45500 option so it cannot execute this statement
ERROR HY000: The MariaDB server is running with the --max-session-mem-used=45500 option so it cannot execute this statement
disconnect con1;
connection default;
DROP TABLE t1;
Expand Down
13 changes: 13 additions & 0 deletions mysql-test/t/error_simulation.test
Original file line number Diff line number Diff line change
Expand Up @@ -158,3 +158,16 @@ SET SESSION debug_dbug="+d,simulate_create_virtual_tmp_table_out_of_memory";
SELECT f1(1);
DROP FUNCTION f1;
SET debug_dbug= @saved_dbug;

--echo #
--echo # MDEV-27978 wrong option name in error when exceeding max_session_mem_used
--echo #
SET SESSION max_session_mem_used = 8192;
--error ER_OPTION_PREVENTS_STATEMENT
SELECT * FROM information_schema.processlist;
SET SESSION max_session_mem_used = DEFAULT;


--echo #
--echo # End of 10.2 tests
--echo #
7 changes: 6 additions & 1 deletion sql/mysqld.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4090,13 +4090,18 @@ static void my_malloc_size_cb_func(long long size, my_bool is_thread_specific)
/* Ensure we don't get called here again */
char buf[50], *buf2;
thd->set_killed(KILL_QUERY);
my_snprintf(buf, sizeof(buf), "--max-thread-mem-used=%llu",
my_snprintf(buf, sizeof(buf), "--max-session-mem-used=%llu",
thd->variables.max_mem_used);
if ((buf2= (char*) thd->alloc(256)))
{
my_snprintf(buf2, 256, ER_THD(thd, ER_OPTION_PREVENTS_STATEMENT), buf);
thd->set_killed(KILL_QUERY, ER_OPTION_PREVENTS_STATEMENT, buf2);
}
else
{
thd->set_killed(KILL_QUERY, ER_OPTION_PREVENTS_STATEMENT,
"--max-session-mem-used");
}
}
DBUG_ASSERT((longlong) thd->status_var.local_memory_used >= 0 ||
!debug_assert_on_not_freed_memory);
Expand Down
2 changes: 1 addition & 1 deletion sql/sys_vars.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5719,7 +5719,7 @@ static Sys_var_ulong Sys_log_tc_size(
BLOCK_SIZE(my_getpagesize()));
#endif

static Sys_var_ulonglong Sys_max_thread_mem(
static Sys_var_ulonglong Sys_max_session_mem_used(
"max_session_mem_used", "Amount of memory a single user session "
"is allowed to allocate. This limits the value of the "
"session variable MEM_USED", SESSION_VAR(max_mem_used),
Expand Down

0 comments on commit 114476f

Please sign in to comment.