mirror of
https://github.com/MariaDB/server.git
synced 2025-01-24 07:44:22 +01:00
cc8aed3eb7
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
147 lines
3.4 KiB
Text
147 lines
3.4 KiB
Text
|
|
# Test the MAX_STATEMENT_TIME option.
|
|
|
|
SET @@MAX_STATEMENT_TIME=2;
|
|
select @@max_statement_time;
|
|
@@max_statement_time
|
|
2.000000
|
|
SELECT SLEEP(1);
|
|
SLEEP(1)
|
|
0
|
|
SELECT SLEEP(3);
|
|
SLEEP(3)
|
|
1
|
|
SET @@MAX_STATEMENT_TIME=0;
|
|
SELECT SLEEP(1);
|
|
SLEEP(1)
|
|
0
|
|
SHOW STATUS LIKE "max_statement_time_exceeded";
|
|
Variable_name Value
|
|
Max_statement_time_exceeded 1
|
|
CREATE TABLE t1 (a INT, b VARCHAR(300)) engine=myisam;
|
|
INSERT INTO t1 VALUES (1, 'string');
|
|
SELECT 0;
|
|
0
|
|
0
|
|
|
|
# Test the MAX_STATEMENT_TIME option with SF (should have no effect).
|
|
|
|
CREATE PROCEDURE p1()
|
|
BEGIN
|
|
declare tmp int;
|
|
SET @@MAX_STATEMENT_TIME=0.0001;
|
|
SELECT COUNT(*) INTO tmp FROM t1 WHERE b LIKE '%z%';
|
|
SET @@MAX_STATEMENT_TIME=0;
|
|
END|
|
|
CREATE PROCEDURE p2()
|
|
BEGIN
|
|
SET @@MAX_STATEMENT_TIME=5;
|
|
END|
|
|
SELECT @@MAX_STATEMENT_TIME;
|
|
@@MAX_STATEMENT_TIME
|
|
0.000000
|
|
CALL p1();
|
|
CALL p2();
|
|
SELECT @@MAX_STATEMENT_TIME;
|
|
@@MAX_STATEMENT_TIME
|
|
5.000000
|
|
SET @@MAX_STATEMENT_TIME=0;
|
|
DROP PROCEDURE p1;
|
|
DROP PROCEDURE p2;
|
|
DROP TABLE t1;
|
|
|
|
# MAX_STATEMENT_TIME account resource
|
|
|
|
GRANT USAGE ON *.* TO user1@localhost WITH MAX_STATEMENT_TIME 1.005;
|
|
# con1
|
|
SELECT @@max_statement_time;
|
|
@@max_statement_time
|
|
1.005000
|
|
# restart and reconnect
|
|
set @global.userstat=1;
|
|
SELECT @@global.max_statement_time,@@session.max_statement_time;
|
|
@@global.max_statement_time @@session.max_statement_time
|
|
0.000000 1.005000
|
|
select sleep(100);
|
|
sleep(100)
|
|
1
|
|
SHOW STATUS LIKE "max_statement_time_exceeded";
|
|
Variable_name Value
|
|
Max_statement_time_exceeded 1
|
|
show grants for user1@localhost;
|
|
Grants for user1@localhost
|
|
GRANT USAGE ON *.* TO 'user1'@'localhost' WITH MAX_STATEMENT_TIME 1.005000
|
|
set @global.userstat=0;
|
|
DROP USER user1@localhost;
|
|
|
|
# MAX_STATEMENT_TIME status variables.
|
|
|
|
flush status;
|
|
SET @@max_statement_time=0;
|
|
SELECT CONVERT(VARIABLE_VALUE, UNSIGNED) INTO @time_exceeded
|
|
FROM INFORMATION_SCHEMA.GLOBAL_STATUS
|
|
WHERE VARIABLE_NAME = 'max_statement_time_exceeded';
|
|
SET @@max_statement_time=0.5;
|
|
SELECT SLEEP(2);
|
|
SLEEP(2)
|
|
1
|
|
SHOW STATUS LIKE '%timeout%';
|
|
Variable_name Value
|
|
Ssl_default_timeout 0
|
|
Ssl_session_cache_timeouts 0
|
|
SET @@max_statement_time=0;
|
|
# Ensure that the counters for:
|
|
# - statements that exceeded their maximum execution time
|
|
# are incremented.
|
|
SELECT 1 AS STATUS FROM INFORMATION_SCHEMA.GLOBAL_STATUS
|
|
WHERE VARIABLE_NAME = 'max_statement_time_exceeded'
|
|
AND CONVERT(VARIABLE_VALUE, UNSIGNED) > @time_exceeded;
|
|
STATUS
|
|
1
|
|
|
|
# Check that the appropriate error status is set.
|
|
|
|
CREATE TABLE t1 (a INT) ENGINE=InnoDB;
|
|
INSERT INTO t1 VALUES (1);
|
|
START TRANSACTION;
|
|
SELECT * FROM t1 FOR UPDATE;
|
|
a
|
|
1
|
|
SET @@SESSION.max_statement_time = 0.5;
|
|
UPDATE t1 SET a = 2;
|
|
ERROR 70100: Query execution was interrupted (max_statement_time exceeded)
|
|
SHOW WARNINGS;
|
|
Level Code Message
|
|
Error 1967 Query execution was interrupted (max_statement_time exceeded)
|
|
ROLLBACK;
|
|
DROP TABLE t1;
|
|
|
|
# Test interaction with lock waits.
|
|
|
|
CREATE TABLE t1 (a INT) ENGINE=InnoDB;
|
|
INSERT INTO t1 VALUES (1);
|
|
SET @@SESSION.max_statement_time= 0.5;
|
|
LOCK TABLES t1 WRITE;
|
|
SELECT @@SESSION.max_statement_time;
|
|
@@SESSION.max_statement_time
|
|
0.500000
|
|
LOCK TABLES t1 READ;
|
|
ERROR 70100: Query execution was interrupted (max_statement_time exceeded)
|
|
UNLOCK TABLES;
|
|
BEGIN;
|
|
SELECT * FROM t1;
|
|
a
|
|
1
|
|
ALTER TABLE t1 ADD COLUMN b INT;
|
|
ERROR 70100: Query execution was interrupted (max_statement_time exceeded)
|
|
ROLLBACK;
|
|
SELECT GET_LOCK('lock', 1);
|
|
GET_LOCK('lock', 1)
|
|
1
|
|
SELECT GET_LOCK('lock', 1);
|
|
GET_LOCK('lock', 1)
|
|
NULL
|
|
SELECT RELEASE_LOCK('lock');
|
|
RELEASE_LOCK('lock')
|
|
1
|
|
DROP TABLE t1;
|