Commit 7e2f9d09 authored by Sergei Golubchik's avatar Sergei Golubchik

max_session_mem_used server variable

parent ab3388c3
......@@ -457,6 +457,10 @@ The following options may be given as the first argument:
--max-seeks-for-key=#
Limit assumed max number of seeks when looking up rows
based on a key
--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
--max-sort-length=# The number of bytes to use when sorting BLOB or TEXT
values (only the first max_sort_length bytes of each
value are used; the rest are ignored)
......@@ -1266,6 +1270,7 @@ max-long-data-size 4194304
max-prepared-stmt-count 16382
max-relay-log-size 1073741824
max-seeks-for-key 18446744073709551615
max-session-mem-used 9223372036854775807
max-sort-length 1024
max-sp-recursion-depth 0
max-statement-time 0
......
......@@ -1997,6 +1997,20 @@ NUMERIC_BLOCK_SIZE 1
ENUM_VALUE_LIST NULL
READ_ONLY NO
COMMAND_LINE_ARGUMENT REQUIRED
VARIABLE_NAME MAX_SESSION_MEM_USED
SESSION_VALUE 9223372036854775807
GLOBAL_VALUE 9223372036854775807
GLOBAL_VALUE_ORIGIN COMPILE-TIME
DEFAULT_VALUE 9223372036854775807
VARIABLE_SCOPE SESSION
VARIABLE_TYPE BIGINT UNSIGNED
VARIABLE_COMMENT Amount of memory a single user session is allowed to allocate. This limits the value of the session variable MEM_USED
NUMERIC_MIN_VALUE 8192
NUMERIC_MAX_VALUE 18446744073709551615
NUMERIC_BLOCK_SIZE 1
ENUM_VALUE_LIST NULL
READ_ONLY NO
COMMAND_LINE_ARGUMENT REQUIRED
VARIABLE_NAME MAX_SORT_LENGTH
SESSION_VALUE 1024
GLOBAL_VALUE 1024
......
......@@ -2193,6 +2193,20 @@ NUMERIC_BLOCK_SIZE 1
ENUM_VALUE_LIST NULL
READ_ONLY NO
COMMAND_LINE_ARGUMENT REQUIRED
VARIABLE_NAME MAX_SESSION_MEM_USED
SESSION_VALUE 9223372036854775807
GLOBAL_VALUE 9223372036854775807
GLOBAL_VALUE_ORIGIN COMPILE-TIME
DEFAULT_VALUE 9223372036854775807
VARIABLE_SCOPE SESSION
VARIABLE_TYPE BIGINT UNSIGNED
VARIABLE_COMMENT Amount of memory a single user session is allowed to allocate. This limits the value of the session variable MEM_USED
NUMERIC_MIN_VALUE 8192
NUMERIC_MAX_VALUE 18446744073709551615
NUMERIC_BLOCK_SIZE 1
ENUM_VALUE_LIST NULL
READ_ONLY NO
COMMAND_LINE_ARGUMENT REQUIRED
VARIABLE_NAME MAX_SORT_LENGTH
SESSION_VALUE 1024
GLOBAL_VALUE 1024
......
......@@ -4001,6 +4001,15 @@ static void my_malloc_size_cb_func(long long size, my_bool is_thread_specific)
(longlong) thd->status_var.local_memory_used,
size));
thd->status_var.local_memory_used+= size;
if (thd->status_var.local_memory_used > (int64)thd->variables.max_mem_used &&
!thd->killed)
{
char buf[1024];
thd->killed= KILL_QUERY;
my_snprintf(buf, sizeof(buf), "--max-thread-mem-used=%llu",
thd->variables.max_mem_used);
my_error(ER_OPTION_PREVENTS_STATEMENT, MYF(0), buf);
}
DBUG_ASSERT((longlong) thd->status_var.local_memory_used >= 0);
}
else if (likely(thd))
......
......@@ -906,8 +906,8 @@ THD::THD(bool is_wsrep_applier)
#endif
{
ulong tmp;
bzero(&variables, sizeof(variables));
mdl_context.init(this);
/*
We set THR_THD to temporally point to this THD to register all the
variables that allocates memory for this THD
......@@ -916,8 +916,11 @@ THD::THD(bool is_wsrep_applier)
set_current_thd(this);
status_var.local_memory_used= sizeof(THD);
status_var.global_memory_used= 0;
variables.max_mem_used= global_system_variables.max_mem_used;
main_da.init();
mdl_context.init(this);
/*
Pass nominal parameters to init_alloc_root only to ensure that
the destructor works OK in case of an error. The main_mem_root
......@@ -964,7 +967,6 @@ THD::THD(bool is_wsrep_applier)
connection_name.str= 0;
connection_name.length= 0;
bzero(&variables, sizeof(variables));
file_id = 0;
query_id= 0;
query_name_consts= 0;
......
......@@ -540,6 +540,7 @@ typedef struct system_variables
ulonglong sortbuff_size;
ulonglong group_concat_max_len;
ulonglong default_regex_flags;
ulonglong max_mem_used;
/**
Place holders to store Multi-source variables in sys_var.cc during
......
......@@ -5401,3 +5401,10 @@ static Sys_var_ulong Sys_log_tc_size(
DEFAULT(my_getpagesize() * 6),
BLOCK_SIZE(my_getpagesize()));
#endif
static Sys_var_ulonglong Sys_max_thread_mem(
"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),
CMD_LINE(REQUIRED_ARG), VALID_RANGE(8192, ULONGLONG_MAX),
DEFAULT(LONGLONG_MAX), BLOCK_SIZE(1));
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