mirror of
https://github.com/MariaDB/server.git
synced 2025-08-01 03:47:19 +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:
@ -36,6 +36,7 @@ def information_schema CLIENT_STATISTICS CPU_TIME 6 0 NO double NULL NULL 21 NUL
|
||||
def information_schema CLIENT_STATISTICS DENIED_CONNECTIONS 20 0 NO bigint NULL NULL 19 0 NULL NULL NULL bigint(21) select
|
||||
def information_schema CLIENT_STATISTICS EMPTY_QUERIES 23 0 NO bigint NULL NULL 19 0 NULL NULL NULL bigint(21) select
|
||||
def information_schema CLIENT_STATISTICS LOST_CONNECTIONS 21 0 NO bigint NULL NULL 19 0 NULL NULL NULL bigint(21) select
|
||||
def information_schema CLIENT_STATISTICS MAX_STATEMENT_TIME_EXCEEDED 24 0 NO bigint NULL NULL 19 0 NULL NULL NULL bigint(21) select
|
||||
def information_schema CLIENT_STATISTICS OTHER_COMMANDS 17 0 NO bigint NULL NULL 19 0 NULL NULL NULL bigint(21) select
|
||||
def information_schema CLIENT_STATISTICS ROLLBACK_TRANSACTIONS 19 0 NO bigint NULL NULL 19 0 NULL NULL NULL bigint(21) select
|
||||
def information_schema CLIENT_STATISTICS ROWS_DELETED 12 0 NO bigint NULL NULL 19 0 NULL NULL NULL bigint(21) select
|
||||
@ -408,6 +409,7 @@ def information_schema USER_STATISTICS CPU_TIME 6 0 NO double NULL NULL 21 NULL
|
||||
def information_schema USER_STATISTICS DENIED_CONNECTIONS 20 0 NO bigint NULL NULL 19 0 NULL NULL NULL bigint(21) select
|
||||
def information_schema USER_STATISTICS EMPTY_QUERIES 23 0 NO bigint NULL NULL 19 0 NULL NULL NULL bigint(21) select
|
||||
def information_schema USER_STATISTICS LOST_CONNECTIONS 21 0 NO bigint NULL NULL 19 0 NULL NULL NULL bigint(21) select
|
||||
def information_schema USER_STATISTICS MAX_STATEMENT_TIME_EXCEEDED 24 0 NO bigint NULL NULL 19 0 NULL NULL NULL bigint(21) select
|
||||
def information_schema USER_STATISTICS OTHER_COMMANDS 17 0 NO bigint NULL NULL 19 0 NULL NULL NULL bigint(21) select
|
||||
def information_schema USER_STATISTICS ROLLBACK_TRANSACTIONS 19 0 NO bigint NULL NULL 19 0 NULL NULL NULL bigint(21) select
|
||||
def information_schema USER_STATISTICS ROWS_DELETED 12 0 NO bigint NULL NULL 19 0 NULL NULL NULL bigint(21) select
|
||||
@ -533,6 +535,7 @@ NULL information_schema CLIENT_STATISTICS DENIED_CONNECTIONS bigint NULL NULL NU
|
||||
NULL information_schema CLIENT_STATISTICS LOST_CONNECTIONS bigint NULL NULL NULL NULL bigint(21)
|
||||
NULL information_schema CLIENT_STATISTICS ACCESS_DENIED bigint NULL NULL NULL NULL bigint(21)
|
||||
NULL information_schema CLIENT_STATISTICS EMPTY_QUERIES bigint NULL NULL NULL NULL bigint(21)
|
||||
NULL information_schema CLIENT_STATISTICS MAX_STATEMENT_TIME_EXCEEDED bigint NULL NULL NULL NULL bigint(21)
|
||||
3.0000 information_schema COLLATIONS COLLATION_NAME varchar 32 96 utf8 utf8_general_ci varchar(32)
|
||||
3.0000 information_schema COLLATIONS CHARACTER_SET_NAME varchar 32 96 utf8 utf8_general_ci varchar(32)
|
||||
NULL information_schema COLLATIONS ID bigint NULL NULL NULL NULL bigint(11)
|
||||
@ -906,6 +909,7 @@ NULL information_schema USER_STATISTICS DENIED_CONNECTIONS bigint NULL NULL NULL
|
||||
NULL information_schema USER_STATISTICS LOST_CONNECTIONS bigint NULL NULL NULL NULL bigint(21)
|
||||
NULL information_schema USER_STATISTICS ACCESS_DENIED bigint NULL NULL NULL NULL bigint(21)
|
||||
NULL information_schema USER_STATISTICS EMPTY_QUERIES bigint NULL NULL NULL NULL bigint(21)
|
||||
NULL information_schema USER_STATISTICS MAX_STATEMENT_TIME_EXCEEDED bigint NULL NULL NULL NULL bigint(21)
|
||||
3.0000 information_schema VIEWS TABLE_CATALOG varchar 512 1536 utf8 utf8_general_ci varchar(512)
|
||||
3.0000 information_schema VIEWS TABLE_SCHEMA varchar 64 192 utf8 utf8_general_ci varchar(64)
|
||||
3.0000 information_schema VIEWS TABLE_NAME varchar 64 192 utf8 utf8_general_ci varchar(64)
|
||||
|
@ -227,6 +227,7 @@ def mysql user is_role 44 N NO enum 1 3 NULL NULL NULL utf8 utf8_general_ci enum
|
||||
def mysql user Lock_tables_priv 21 N NO enum 1 3 NULL NULL NULL utf8 utf8_general_ci enum('N','Y') select,insert,update,references
|
||||
def mysql user max_connections 39 0 NO int NULL NULL 10 0 NULL NULL NULL int(11) unsigned select,insert,update,references
|
||||
def mysql user max_questions 37 0 NO int NULL NULL 10 0 NULL NULL NULL int(11) unsigned select,insert,update,references
|
||||
def mysql user max_statement_time 46 0.000000 NO decimal NULL NULL 12 6 NULL NULL NULL decimal(12,6) select,insert,update,references
|
||||
def mysql user max_updates 38 0 NO int NULL NULL 10 0 NULL NULL NULL int(11) unsigned select,insert,update,references
|
||||
def mysql user max_user_connections 40 0 NO int NULL NULL 10 0 NULL NULL NULL int(11) select,insert,update,references
|
||||
def mysql user Password 3 NO char 41 41 NULL NULL NULL latin1 latin1_bin char(41) select,insert,update,references
|
||||
@ -568,3 +569,4 @@ NULL mysql user max_user_connections int NULL NULL NULL NULL int(11)
|
||||
3.0000 mysql user password_expired enum 1 3 utf8 utf8_general_ci enum('N','Y')
|
||||
3.0000 mysql user is_role enum 1 3 utf8 utf8_general_ci enum('N','Y')
|
||||
3.0000 mysql user default_role char 80 240 utf8 utf8_bin char(80)
|
||||
NULL mysql user max_statement_time decimal NULL NULL NULL NULL decimal(12,6)
|
||||
|
@ -132,6 +132,7 @@ authentication_string
|
||||
password_expired N
|
||||
is_role N
|
||||
default_role
|
||||
max_statement_time 0.000000
|
||||
Host localhost
|
||||
User testuser2
|
||||
Password
|
||||
@ -177,6 +178,7 @@ authentication_string
|
||||
password_expired N
|
||||
is_role N
|
||||
default_role
|
||||
max_statement_time 0.000000
|
||||
Host localhost
|
||||
User testuser3
|
||||
Password
|
||||
@ -222,6 +224,7 @@ authentication_string
|
||||
password_expired N
|
||||
is_role N
|
||||
default_role
|
||||
max_statement_time 0.000000
|
||||
#
|
||||
# Add GRANT OPTION db_datadict.* to testuser1;
|
||||
GRANT UPDATE ON db_datadict.* TO 'testuser1'@'localhost' WITH GRANT OPTION;
|
||||
@ -291,6 +294,7 @@ authentication_string
|
||||
password_expired N
|
||||
is_role N
|
||||
default_role
|
||||
max_statement_time 0.000000
|
||||
Host localhost
|
||||
User testuser2
|
||||
Password
|
||||
@ -336,6 +340,7 @@ authentication_string
|
||||
password_expired N
|
||||
is_role N
|
||||
default_role
|
||||
max_statement_time 0.000000
|
||||
Host localhost
|
||||
User testuser3
|
||||
Password
|
||||
@ -381,6 +386,7 @@ authentication_string
|
||||
password_expired N
|
||||
is_role N
|
||||
default_role
|
||||
max_statement_time 0.000000
|
||||
# Establish connection testuser1 (user=testuser1)
|
||||
SELECT * FROM information_schema.user_privileges
|
||||
WHERE grantee LIKE '''testuser%'''
|
||||
@ -436,6 +442,7 @@ authentication_string
|
||||
password_expired N
|
||||
is_role N
|
||||
default_role
|
||||
max_statement_time 0.000000
|
||||
Host localhost
|
||||
User testuser2
|
||||
Password
|
||||
@ -481,6 +488,7 @@ authentication_string
|
||||
password_expired N
|
||||
is_role N
|
||||
default_role
|
||||
max_statement_time 0.000000
|
||||
Host localhost
|
||||
User testuser3
|
||||
Password
|
||||
@ -526,6 +534,7 @@ authentication_string
|
||||
password_expired N
|
||||
is_role N
|
||||
default_role
|
||||
max_statement_time 0.000000
|
||||
SHOW GRANTS;
|
||||
Grants for testuser1@localhost
|
||||
GRANT USAGE ON *.* TO 'testuser1'@'localhost'
|
||||
@ -603,6 +612,7 @@ authentication_string
|
||||
password_expired N
|
||||
is_role N
|
||||
default_role
|
||||
max_statement_time 0.000000
|
||||
Host localhost
|
||||
User testuser2
|
||||
Password
|
||||
@ -648,6 +658,7 @@ authentication_string
|
||||
password_expired N
|
||||
is_role N
|
||||
default_role
|
||||
max_statement_time 0.000000
|
||||
Host localhost
|
||||
User testuser3
|
||||
Password
|
||||
@ -693,6 +704,7 @@ authentication_string
|
||||
password_expired N
|
||||
is_role N
|
||||
default_role
|
||||
max_statement_time 0.000000
|
||||
GRANT SELECT ON *.* TO 'testuser1'@'localhost' WITH GRANT OPTION;
|
||||
#
|
||||
# Here <SELECT YES> is shown correctly for testuser1;
|
||||
@ -762,6 +774,7 @@ authentication_string
|
||||
password_expired N
|
||||
is_role N
|
||||
default_role
|
||||
max_statement_time 0.000000
|
||||
Host localhost
|
||||
User testuser2
|
||||
Password
|
||||
@ -807,6 +820,7 @@ authentication_string
|
||||
password_expired N
|
||||
is_role N
|
||||
default_role
|
||||
max_statement_time 0.000000
|
||||
Host localhost
|
||||
User testuser3
|
||||
Password
|
||||
@ -852,6 +866,7 @@ authentication_string
|
||||
password_expired N
|
||||
is_role N
|
||||
default_role
|
||||
max_statement_time 0.000000
|
||||
# Switch to connection testuser1
|
||||
SELECT * FROM information_schema.user_privileges
|
||||
WHERE grantee LIKE '''testuser%'''
|
||||
@ -907,6 +922,7 @@ authentication_string
|
||||
password_expired N
|
||||
is_role N
|
||||
default_role
|
||||
max_statement_time 0.000000
|
||||
Host localhost
|
||||
User testuser2
|
||||
Password
|
||||
@ -952,6 +968,7 @@ authentication_string
|
||||
password_expired N
|
||||
is_role N
|
||||
default_role
|
||||
max_statement_time 0.000000
|
||||
Host localhost
|
||||
User testuser3
|
||||
Password
|
||||
@ -997,6 +1014,7 @@ authentication_string
|
||||
password_expired N
|
||||
is_role N
|
||||
default_role
|
||||
max_statement_time 0.000000
|
||||
SHOW GRANTS;
|
||||
Grants for testuser1@localhost
|
||||
GRANT SELECT ON *.* TO 'testuser1'@'localhost' WITH GRANT OPTION
|
||||
@ -1104,6 +1122,7 @@ authentication_string
|
||||
password_expired N
|
||||
is_role N
|
||||
default_role
|
||||
max_statement_time 0.000000
|
||||
Host localhost
|
||||
User testuser2
|
||||
Password
|
||||
@ -1149,6 +1168,7 @@ authentication_string
|
||||
password_expired N
|
||||
is_role N
|
||||
default_role
|
||||
max_statement_time 0.000000
|
||||
Host localhost
|
||||
User testuser3
|
||||
Password
|
||||
@ -1194,6 +1214,7 @@ authentication_string
|
||||
password_expired N
|
||||
is_role N
|
||||
default_role
|
||||
max_statement_time 0.000000
|
||||
# Switch to connection testuser1
|
||||
SELECT * FROM information_schema.user_privileges
|
||||
WHERE grantee LIKE '''testuser%'''
|
||||
@ -1296,6 +1317,7 @@ authentication_string
|
||||
password_expired N
|
||||
is_role N
|
||||
default_role
|
||||
max_statement_time 0.000000
|
||||
Host localhost
|
||||
User testuser2
|
||||
Password
|
||||
@ -1341,6 +1363,7 @@ authentication_string
|
||||
password_expired N
|
||||
is_role N
|
||||
default_role
|
||||
max_statement_time 0.000000
|
||||
Host localhost
|
||||
User testuser3
|
||||
Password
|
||||
@ -1386,6 +1409,7 @@ authentication_string
|
||||
password_expired N
|
||||
is_role N
|
||||
default_role
|
||||
max_statement_time 0.000000
|
||||
# Switch to connection testuser1
|
||||
SELECT * FROM information_schema.user_privileges
|
||||
WHERE grantee LIKE '''testuser%'''
|
||||
@ -1441,6 +1465,7 @@ authentication_string
|
||||
password_expired N
|
||||
is_role N
|
||||
default_role
|
||||
max_statement_time 0.000000
|
||||
Host localhost
|
||||
User testuser2
|
||||
Password
|
||||
@ -1486,6 +1511,7 @@ authentication_string
|
||||
password_expired N
|
||||
is_role N
|
||||
default_role
|
||||
max_statement_time 0.000000
|
||||
Host localhost
|
||||
User testuser3
|
||||
Password
|
||||
@ -1531,6 +1557,7 @@ authentication_string
|
||||
password_expired N
|
||||
is_role N
|
||||
default_role
|
||||
max_statement_time 0.000000
|
||||
SHOW GRANTS;
|
||||
Grants for testuser1@localhost
|
||||
GRANT USAGE ON *.* TO 'testuser1'@'localhost'
|
||||
@ -1593,6 +1620,7 @@ authentication_string
|
||||
password_expired N
|
||||
is_role N
|
||||
default_role
|
||||
max_statement_time 0.000000
|
||||
Host localhost
|
||||
User testuser2
|
||||
Password
|
||||
@ -1638,6 +1666,7 @@ authentication_string
|
||||
password_expired N
|
||||
is_role N
|
||||
default_role
|
||||
max_statement_time 0.000000
|
||||
Host localhost
|
||||
User testuser3
|
||||
Password
|
||||
@ -1683,6 +1712,7 @@ authentication_string
|
||||
password_expired N
|
||||
is_role N
|
||||
default_role
|
||||
max_statement_time 0.000000
|
||||
SHOW GRANTS;
|
||||
Grants for testuser1@localhost
|
||||
GRANT USAGE ON *.* TO 'testuser1'@'localhost'
|
||||
@ -1760,6 +1790,7 @@ authentication_string
|
||||
password_expired N
|
||||
is_role N
|
||||
default_role
|
||||
max_statement_time 0.000000
|
||||
Host localhost
|
||||
User testuser2
|
||||
Password
|
||||
@ -1805,6 +1836,7 @@ authentication_string
|
||||
password_expired N
|
||||
is_role N
|
||||
default_role
|
||||
max_statement_time 0.000000
|
||||
Host localhost
|
||||
User testuser3
|
||||
Password
|
||||
@ -1850,6 +1882,7 @@ authentication_string
|
||||
password_expired N
|
||||
is_role N
|
||||
default_role
|
||||
max_statement_time 0.000000
|
||||
# Switch to connection testuser1
|
||||
SELECT * FROM information_schema.user_privileges
|
||||
WHERE grantee LIKE '''testuser%'''
|
||||
|
Reference in New Issue
Block a user