mirror of
https://github.com/MariaDB/server.git
synced 2025-08-08 11:22:35 +03:00
MDEV 4427: query timeouts
Added MAX_STATEMENT_TIME user variable to automaticly kill queries after a given time limit has expired. - Added timer functions based on pthread_cond_timedwait - Added kill_handlerton() to signal storage engines about kill/timeout - Added support for GRANT ... MAX_STATEMENT_TIME=# - Copy max_statement_time to current user, if stored in mysql.user - Added status variable max_statement_time_exceeded - Added KILL_TIMEOUT - Removed digest hash from performance schema tests as they change all the time. - Updated test results that changed because of the new user variables or new fields in mysql.user This functionallity is inspired by work done by Davi Arnaut at twitter. Test case is copied from Davi's work. Documentation can be found at https://kb.askmonty.org/en/how-to-limittimeout-queries/ mysql-test/r/mysqld--help.result: Updated for new help message mysql-test/suite/perfschema/r/all_instances.result: Added new mutex mysql-test/suite/sys_vars/r/max_statement_time_basic.result: Added testing of max_statement_time mysql-test/suite/sys_vars/t/max_statement_time_basic.test: Added testing of max_statement_time mysql-test/t/max_statement_time.test: Added testing of max_statement_time mysys/CMakeLists.txt: Added thr_timer mysys/my_init.c: mysys/mysys_priv.h: Added new mutex and condition variables Added new mutex and condition variables mysys/thr_timer.c: Added timer functions based on pthread_cond_timedwait() This can be compiled with HAVE_TIMER_CREATE to benchmark agains timer_create()/timer_settime() sql/lex.h: Added MAX_STATEMENT_TIME sql/log_event.cc: Safety fix (timeout should be threated as an interrupted query) sql/mysqld.cc: Added support for timers Added status variable max_statement_time_exceeded sql/share/errmsg-utf8.txt: Added ER_QUERY_TIMEOUT sql/signal_handler.cc: Added support for KILL_TIMEOUT sql/sql_acl.cc: Added support for GRANT ... MAX_STATEMENT_TIME=# Copy max_statement_time to current user sql/sql_class.cc: Added timer functionality to THD. Added thd_kill_timeout() sql/sql_class.h: Added timer functionality to THD. Added KILL_TIMEOUT Added max_statement_time variable in similar manner as long_query_time was done. sql/sql_connect.cc: Added handling of max_statement_time_exceeded sql/sql_parse.cc: Added starting and stopping timers for queries. sql/sql_show.cc: Added max_statement_time_exceeded for user/connects status in MariaDB 10.0 sql/sql_yacc.yy: Added support for GRANT ... MAX_STATEMENT_TIME=# syntax, to be enabled in 10.0 sql/structs.h: Added max_statement_time user resource sql/sys_vars.cc: Added max_statement_time variables mysql-test/suite/roles/create_and_drop_role_invalid_user_table.test Removed test as we require all fields in mysql.user table. scripts/mysql_system_tables.sql scripts/mysql_system_tables_data.sql scripts/mysql_system_tables_fix.sql Updated mysql.user with new max_statement_time field
This commit is contained in:
@@ -861,6 +861,23 @@ bool Drop_table_error_handler::handle_condition(THD *thd,
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Send timeout to thread.
|
||||
|
||||
Note that this is always safe as the thread will always remove it's
|
||||
timeouts at end of query (and thus before THD is destroyed)
|
||||
*/
|
||||
|
||||
extern "C" void thd_kill_timeout(THD* thd)
|
||||
{
|
||||
thd->status_var.max_statement_time_exceeded++;
|
||||
mysql_mutex_lock(&thd->LOCK_thd_data);
|
||||
/* Kill queries that can't cause data corruptions */
|
||||
thd->awake(KILL_TIMEOUT);
|
||||
mysql_mutex_unlock(&thd->LOCK_thd_data);
|
||||
}
|
||||
|
||||
|
||||
THD::THD(bool is_wsrep_applier)
|
||||
:Statement(&main_lex, &main_mem_root, STMT_CONVENTIONAL_EXECUTION,
|
||||
/* statement id */ 0),
|
||||
@@ -1058,6 +1075,8 @@ THD::THD(bool is_wsrep_applier)
|
||||
protocol_text.init(this);
|
||||
protocol_binary.init(this);
|
||||
|
||||
thr_timer_init(&query_timer, (void (*)(void*)) thd_kill_timeout, this);
|
||||
|
||||
tablespace_op=FALSE;
|
||||
|
||||
/*
|
||||
@@ -1373,6 +1392,7 @@ extern "C" THD *_current_thd_noinline(void)
|
||||
return my_pthread_getspecific_ptr(THD*,THR_THD);
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
Init common variables that has to be reset on start and on change_user
|
||||
*/
|
||||
@@ -1779,6 +1799,7 @@ void add_diff_to_status(STATUS_VAR *to_var, STATUS_VAR *from_var,
|
||||
This is normally called from another thread's THD object.
|
||||
|
||||
@note Do always call this while holding LOCK_thd_data.
|
||||
NOT_KILLED is used to awake a thread for a slave
|
||||
*/
|
||||
|
||||
void THD::awake(killed_state state_to_set)
|
||||
@@ -1790,6 +1811,13 @@ void THD::awake(killed_state state_to_set)
|
||||
|
||||
print_aborted_warning(3, "KILLED");
|
||||
|
||||
/*
|
||||
Don't degrade killed state, for example from a KILL_CONNECTION to
|
||||
STATEMENT TIMEOUT
|
||||
*/
|
||||
if (killed >= KILL_CONNECTION)
|
||||
state_to_set= killed;
|
||||
|
||||
/* Set the 'killed' flag of 'this', which is the target THD object. */
|
||||
killed= state_to_set;
|
||||
|
||||
@@ -1821,6 +1849,7 @@ void THD::awake(killed_state state_to_set)
|
||||
mysql_mutex_lock(&mysys_var->mutex);
|
||||
if (!system_thread) // Don't abort locks
|
||||
mysys_var->abort=1;
|
||||
|
||||
/*
|
||||
This broadcast could be up in the air if the victim thread
|
||||
exits the cond in the time between read and broadcast, but that is
|
||||
@@ -1989,6 +2018,9 @@ int killed_errno(killed_state killed)
|
||||
case KILL_QUERY:
|
||||
case KILL_QUERY_HARD:
|
||||
DBUG_RETURN(ER_QUERY_INTERRUPTED);
|
||||
case KILL_TIMEOUT:
|
||||
case KILL_TIMEOUT_HARD:
|
||||
DBUG_RETURN(ER_STATEMENT_TIMEOUT);
|
||||
case KILL_SERVER:
|
||||
case KILL_SERVER_HARD:
|
||||
DBUG_RETURN(ER_SERVER_SHUTDOWN);
|
||||
|
Reference in New Issue
Block a user