mirror of
https://github.com/MariaDB/server.git
synced 2025-05-05 16:59:35 +03:00
This patch introduces timeouts for metadata locks. The timeout is specified in seconds using the new dynamic system variable "lock_wait_timeout" which has both GLOBAL and SESSION scopes. Allowed values range from 1 to 31536000 seconds (= 1 year). The default value is 1 year. The new server parameter "lock-wait-timeout" can be used to set the default value parameter upon server startup. "lock_wait_timeout" applies to all statements that use metadata locks. These include DML and DDL operations on tables, views, stored procedures and stored functions. They also include LOCK TABLES, FLUSH TABLES WITH READ LOCK and HANDLER statements. The patch also changes thr_lock.c code (table data locks used by MyISAM and other simplistic engines) to use the same system variable. InnoDB row locks are unaffected. One exception to the handling of the "lock_wait_timeout" variable is delayed inserts. All delayed inserts are executed with a timeout of 1 year regardless of the setting for the global variable. As the connection issuing the delayed insert gets no notification of delayed insert timeouts, we want to avoid unnecessary timeouts. It's important to note that the timeout value is used for each lock acquired and that one statement can take more than one lock. A statement can therefore block for longer than the lock_wait_timeout value before reporting a timeout error. When lock timeout occurs, ER_LOCK_WAIT_TIMEOUT is reported. Test case added to lock_multi.test. include/my_pthread.h: Added macros for comparing two timespec structs. include/thr_lock.h: Introduced timeouts for thr_lock.c locks. mysql-test/r/mysqld--help-notwin.result: Updated result file with the new server variable. mysql-test/r/mysqld--help-win.result: Updated result file with the new server variable. mysql-test/suite/sys_vars/r/lock_wait_timeout_basic.result: Added basic test for the new server variable. mysql-test/suite/sys_vars/t/lock_wait_timeout_basic.test: Added basic test for the new server variable. mysys/thr_lock.c: Introduced timeouts for thr_lock.c locks. sql/mdl.cc: Introduced timeouts for metadata locks. sql/mdl.h: Introduced timeouts for metadata locks. sql/sql_base.cc: Introduced timeouts in tdc_wait_for_old_versions(). sql/sql_class.h: Added new server variable lock_wait_timeout. sql/sys_vars.cc: Added new server variable lock_wait_timeout.
214 lines
9.1 KiB
Plaintext
214 lines
9.1 KiB
Plaintext
############## mysql-test\t\lock_wait_timeout_basic.test #######################
|
|
# #
|
|
# Variable Name: lock_wait_timeout #
|
|
# Scope: GLOBAL & SESSION #
|
|
# Access Type: Dynamic #
|
|
# Data Type: Numeric #
|
|
# Default Value: 1 #
|
|
# Range: 1 - 31536000 #
|
|
# #
|
|
# #
|
|
# Creation Date: 2010-02-08 #
|
|
# Author: Jon Olav Hauglid #
|
|
# #
|
|
# Description: Test Cases of Dynamic System Variable "lock_wait_timeout" #
|
|
# that checks behavior of this variable in the following ways #
|
|
# * Default Value #
|
|
# * Valid & Invalid values #
|
|
# * Scope & Access method #
|
|
# * Data Integrity #
|
|
# #
|
|
# Reference: http://dev.mysql.com/doc/refman/5.5/en/ #
|
|
# server-system-variables.html#option_mysqld_lock-wait-timeout #
|
|
# #
|
|
################################################################################
|
|
|
|
--source include/load_sysvars.inc
|
|
|
|
#####################################################################
|
|
# START OF lock_wait_timeout TESTS #
|
|
#####################################################################
|
|
|
|
#############################################################
|
|
# Save initial value #
|
|
#############################################################
|
|
|
|
SET @start_global_value = @@global.lock_wait_timeout;
|
|
SELECT @start_global_value;
|
|
SET @start_session_value = @@session.lock_wait_timeout;
|
|
SELECT @start_session_value;
|
|
|
|
|
|
--echo '#--------------------FN_DYNVARS_002_01-------------------------#'
|
|
#####################################################################
|
|
# Display the DEFAULT value of lock_wait_timeout #
|
|
#####################################################################
|
|
|
|
SET @@global.lock_wait_timeout = 100;
|
|
SET @@global.lock_wait_timeout = DEFAULT;
|
|
SELECT @@global.lock_wait_timeout;
|
|
|
|
SET @@session.lock_wait_timeout = 200;
|
|
SET @@session.lock_wait_timeout = DEFAULT;
|
|
SELECT @@session.lock_wait_timeout;
|
|
|
|
|
|
--echo '#--------------------FN_DYNVARS_002_02-------------------------#'
|
|
#####################################################################
|
|
# Check the DEFAULT value of lock_wait_timeout #
|
|
#####################################################################
|
|
|
|
SET @@global.lock_wait_timeout = @start_global_value;
|
|
SELECT @@global.lock_wait_timeout = 31536000;
|
|
SET @@session.lock_wait_timeout = @start_session_value;
|
|
SELECT @@session.lock_wait_timeout = 31536000;
|
|
|
|
|
|
--echo '#--------------------FN_DYNVARS_002_03-------------------------#'
|
|
###############################################################################
|
|
# Change the value of lock_wait_timeout to a valid value for GLOBAL Scope #
|
|
###############################################################################
|
|
|
|
SET @@global.lock_wait_timeout = 1;
|
|
SELECT @@global.lock_wait_timeout;
|
|
SET @@global.lock_wait_timeout = 60020;
|
|
SELECT @@global.lock_wait_timeout;
|
|
SET @@global.lock_wait_timeout = 65535;
|
|
SELECT @@global.lock_wait_timeout;
|
|
|
|
|
|
--echo '#--------------------FN_DYNVARS_002_04-------------------------#'
|
|
###############################################################################
|
|
# Change the value of lock_wait_timeout to a valid value for SESSION Scope #
|
|
###############################################################################
|
|
|
|
SET @@session.lock_wait_timeout = 1;
|
|
SELECT @@session.lock_wait_timeout;
|
|
SET @@session.lock_wait_timeout = 50050;
|
|
SELECT @@session.lock_wait_timeout;
|
|
SET @@session.lock_wait_timeout = 65535;
|
|
SELECT @@session.lock_wait_timeout;
|
|
|
|
|
|
--echo '#------------------FN_DYNVARS_002_05-----------------------#'
|
|
#################################################################
|
|
# Change the value of lock_wait_timeout to an invalid value #
|
|
#################################################################
|
|
# for global scope
|
|
SET @@global.lock_wait_timeout = 0;
|
|
SELECT @@global.lock_wait_timeout;
|
|
SET @@global.lock_wait_timeout = -1024;
|
|
SELECT @@global.lock_wait_timeout;
|
|
SET @@global.lock_wait_timeout = 31536001;
|
|
SELECT @@global.lock_wait_timeout;
|
|
--Error ER_WRONG_TYPE_FOR_VAR
|
|
SET @@global.lock_wait_timeout = ON;
|
|
SELECT @@global.lock_wait_timeout;
|
|
--Error ER_WRONG_TYPE_FOR_VAR
|
|
SET @@global.lock_wait_timeout = OFF;
|
|
SELECT @@global.lock_wait_timeout;
|
|
--Error ER_WRONG_TYPE_FOR_VAR
|
|
SET @@global.lock_wait_timeout = test;
|
|
SELECT @@global.lock_wait_timeout;
|
|
# for session scope
|
|
SET @@session.lock_wait_timeout = 0;
|
|
SELECT @@session.lock_wait_timeout;
|
|
SET @@session.lock_wait_timeout = -2;
|
|
SELECT @@session.lock_wait_timeout;
|
|
SET @@session.lock_wait_timeout = 31537000;
|
|
SELECT @@session.lock_wait_timeout;
|
|
|
|
--Error ER_WRONG_TYPE_FOR_VAR
|
|
SET @@session.lock_wait_timeout = ON;
|
|
SELECT @@session.lock_wait_timeout;
|
|
--Error ER_WRONG_TYPE_FOR_VAR
|
|
SET @@session.lock_wait_timeout = OFF;
|
|
SELECT @@session.lock_wait_timeout;
|
|
--Error ER_WRONG_TYPE_FOR_VAR
|
|
SET @@session.lock_wait_timeout = test;
|
|
SELECT @@session.lock_wait_timeout;
|
|
|
|
|
|
|
|
--echo '#------------------FN_DYNVARS_002_06-----------------------#'
|
|
####################################################################
|
|
# Check if the value in GLOBAL Table matches value in variable #
|
|
####################################################################
|
|
|
|
SELECT @@global.lock_wait_timeout = VARIABLE_VALUE
|
|
FROM INFORMATION_SCHEMA.GLOBAL_VARIABLES
|
|
WHERE VARIABLE_NAME='lock_wait_timeout';
|
|
|
|
|
|
--echo '#------------------FN_DYNVARS_002_07-----------------------#'
|
|
####################################################################
|
|
# Check if the value in SESSION Table matches value in variable #
|
|
####################################################################
|
|
|
|
SELECT @@session.lock_wait_timeout = VARIABLE_VALUE
|
|
FROM INFORMATION_SCHEMA.SESSION_VARIABLES
|
|
WHERE VARIABLE_NAME='lock_wait_timeout';
|
|
|
|
|
|
--echo '#------------------FN_DYNVARS_002_08-----------------------#'
|
|
####################################################################
|
|
# Check if TRUE and FALSE values can be used on variable #
|
|
####################################################################
|
|
|
|
SET @@global.lock_wait_timeout = TRUE;
|
|
SELECT @@global.lock_wait_timeout;
|
|
SET @@global.lock_wait_timeout = FALSE;
|
|
SELECT @@global.lock_wait_timeout;
|
|
|
|
|
|
--echo '#---------------------FN_DYNVARS_001_09----------------------#'
|
|
###############################################################################
|
|
# Check if global and session variables are independant of each other #
|
|
###############################################################################
|
|
|
|
SET @@global.lock_wait_timeout = 10;
|
|
SET @@session.lock_wait_timeout = 11;
|
|
SELECT @@lock_wait_timeout = @@global.lock_wait_timeout;
|
|
|
|
|
|
--echo '#---------------------FN_DYNVARS_001_10----------------------#'
|
|
##############################################################################
|
|
# Check if accessing variable with SESSION,LOCAL and without SCOPE points #
|
|
# to same session variable #
|
|
##############################################################################
|
|
|
|
SET @@lock_wait_timeout = 100;
|
|
SELECT @@lock_wait_timeout = @@local.lock_wait_timeout;
|
|
SELECT @@local.lock_wait_timeout = @@session.lock_wait_timeout;
|
|
|
|
|
|
--echo '#---------------------FN_DYNVARS_001_11----------------------#'
|
|
###############################################################################
|
|
# Check if lock_wait_timeout can be accessed with and without @@ sign #
|
|
###############################################################################
|
|
|
|
SET lock_wait_timeout = 1;
|
|
SELECT @@lock_wait_timeout;
|
|
--Error ER_UNKNOWN_TABLE
|
|
SELECT local.lock_wait_timeout;
|
|
--Error ER_UNKNOWN_TABLE
|
|
SELECT session.lock_wait_timeout;
|
|
--Error ER_BAD_FIELD_ERROR
|
|
SELECT lock_wait_timeout = @@session.lock_wait_timeout;
|
|
|
|
|
|
####################################
|
|
# Restore initial value #
|
|
####################################
|
|
|
|
SET @@global.lock_wait_timeout = @start_global_value;
|
|
SELECT @@global.lock_wait_timeout;
|
|
SET @@session.lock_wait_timeout = @start_session_value;
|
|
SELECT @@session.lock_wait_timeout;
|
|
|
|
|
|
###################################################
|
|
# END OF lock_wait_timeout TESTS #
|
|
###################################################
|
|
|