Merge lp:~vlad-lesin/percona-server/sql_timeout into lp:percona-server/5.5
- sql_timeout
- Merge into 5.5
Status: | Rejected |
---|---|
Rejected by: | Alexey Kopytov |
Proposed branch: | lp:~vlad-lesin/percona-server/sql_timeout |
Merge into: | lp:percona-server/5.5 |
Diff against target: |
1169 lines (+910/-4) 16 files modified
Percona-Server/mysql-test/r/mysqld--help-notwin.result (+2/-0) Percona-Server/mysql-test/r/percona_server_variables_debug.result (+1/-0) Percona-Server/mysql-test/r/percona_server_variables_release.result (+1/-0) Percona-Server/mysql-test/r/percona_sql_timeout.result (+120/-0) Percona-Server/mysql-test/suite/sys_vars/r/sql_timeout_basic.result (+164/-0) Percona-Server/mysql-test/suite/sys_vars/t/sql_timeout_basic.test (+210/-0) Percona-Server/mysql-test/t/percona_sql_timeout.test (+44/-0) Percona-Server/sql/CMakeLists.txt (+1/-1) Percona-Server/sql/mysqld.cc (+59/-2) Percona-Server/sql/mysqld.h (+5/-1) Percona-Server/sql/sql_class.cc (+5/-0) Percona-Server/sql/sql_class.h (+6/-0) Percona-Server/sql/sql_parse.cc (+3/-0) Percona-Server/sql/sql_timeout.cc (+228/-0) Percona-Server/sql/sql_timeout.h (+55/-0) Percona-Server/sql/sys_vars.cc (+6/-0) |
To merge this branch: | bzr merge lp:~vlad-lesin/percona-server/sql_timeout |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Laurynas Biveinis (community) | Needs Fixing | ||
Vlad Lesin (community) | Needs Resubmitting | ||
Alexey Kopytov (community) | Needs Fixing | ||
Vadim Tkachenko | Needs Fixing | ||
Review via email: mp+89693@code.launchpad.net |
Commit message
Description of the change
This is draft implementation of https:/
The QUERY_TIMEOUT keyword is used to point maximum query execution time. The example of using:
SELECT SLEEP(20) /*! QUERY_TIMEOUT = 10 */;
This keyword may be used in every statement except "begin".
The keyword has a higher priority then SQL_TIMEOUT session variable. For example:
SET SESSION SQL_TIMEOUT = 100;
SELECT SLEEP(20) /*! QUERY_TIMEOUT = 10 */;
The second query will be killed in 10 seconds.
I haven't yet found the way of using the same name for keyword and session variable.
The smoke tests may be done such way:
NUM_PROCESSES=50; for i in `seq 1 $NUM_PROCESSES`; do TIMEOUT=$(( $RANDOM % 20 )); (mysql -uroot test -e "select sleep(20) query_timeout=
Vlad Lesin (vlad-lesin) wrote : | # |
> The name of option should be the same in all case.
>
> If it is:
> SET SESSION SQL_TIMEOUT = 100;
>
> Then it should be:
> SELECT SLEEP(20) /*! SQL_TIMEOUT = 10 */;
Ok. Done.
But when you use this variant of "set" statement you have to wrap the variable name with `` (SET SESSION `SQL_TIMEOUT` = 10) because this name coincides with the keyword. It's the common rule when a variable name coincides with a keyword.
Is it acceptable?
Vadim Tkachenko (vadim-tk) wrote : | # |
Is it keyword because we use it in comment ?
On Tue, Jan 24, 2012 at 10:33 AM, Vladislav Lesin <email address hidden> wrote:
> Review: Needs Information
>
>> The name of option should be the same in all case.
>>
>> If it is:
>> SET SESSION SQL_TIMEOUT = 100;
>>
>> Then it should be:
>> SELECT SLEEP(20) /*! SQL_TIMEOUT = 10 */;
>
> Ok. Done.
>
> But when you use this variant of "set" statement you have to wrap the variable name with `` (SET SESSION `SQL_TIMEOUT` = 10) because this name coincides with the keyword. It's the common rule when a variable name coincides with a keyword.
>
> Is it acceptable?
> --
> https:/
> Your team Percona developers is subscribed to branch lp:percona-server.
--
Vadim Tkachenko, CTO, Percona Inc.
Phone +1-925-400-7377, Skype: vadimtk153
Schedule meeting: http://
Join us at Percona Live: MySQL Conference And Expo 2012
http://
Alexey Kopytov (akopytov) wrote : | # |
On 24.01.12 22:37, Vadim Tkachenko wrote:
> Is it keyword because we use it in comment ?
>
Yes, /*! */ are executable comments. As in, it must be valid SQL code
inside, not just an arbitrary string.
Vadim Tkachenko (vadim-tk) wrote : | # |
Ok, then it is fine.
On Tue, Jan 24, 2012 at 10:43 AM, Alexey Kopytov
<email address hidden> wrote:
> On 24.01.12 22:37, Vadim Tkachenko wrote:
>> Is it keyword because we use it in comment ?
>>
>
> Yes, /*! */ are executable comments. As in, it must be valid SQL code
> inside, not just an arbitrary string.
>
> --
> https:/
> Your team Percona developers is subscribed to branch lp:percona-server.
--
Vadim Tkachenko, CTO, Percona Inc.
Phone +1-925-400-7377, Skype: vadimtk153
Schedule meeting: http://
Join us at Percona Live: MySQL Conference And Expo 2012
http://
Vlad Lesin (vlad-lesin) wrote : | # |
Vadim proposed me to use kewpie for testing. I tried to work with it. But a lot of tests fail on the current branch of Percona-Server. May be there are some special ways to run this tool to have successful tests passing. I din't find them in google and documentation. I asked Alexey Kopytov about this and he answered that the integration with Percona-Server had not yet completed and he didn't recommend me to use this tool to avoid troubles with implementation and code review.
The question is should I use the kewpie or old good mysqltest may be used? If kewpie is the preferable solution whom I can contanct to clear some questions up?
Patrick Crews (patrick-crews) wrote : | # |
I would recommend using mysqltest / MTR if you can express tests in the provided language.
If you have difficulty in testing your changes via what MTR provides, then one can use kewpie.
Out of curiosity - how were you trying to run the software? Could you share command lines / failure output? It is still a work in progress, but should be suitable for your needs here (provided MTR is unsuitable)
Vlad Lesin (vlad-lesin) wrote : | # |
> Out of curiosity - how were you trying to run the software? Could you share
> command lines / failure output? It is still a work in progress, but should be
> suitable for your needs here (provided MTR is unsuitable)
Sorry, I used wrong command line agruments for building percona-server. That's why a lot of tests didn't work. It's ok now. I successfully used kewpie for testing this feature. Thank's.
Alexey Kopytov (akopytov) wrote : | # |
Hi Vladislav,
On 23.01.12 18:43, Vladislav Lesin wrote:
> Vladislav Lesin has proposed merging lp:~vlad-lesin/percona-server/sql_timeout into lp:percona-server.
>
> Requested reviews:
> Alexey Kopytov (akopytov)
>
> For more details, see:
> https:/
>
> This is draft implementation of https:/
>
The current implementation is better than your original design proposal,
but is still worse than what I have suggested (which is now described in
the blueprint).
There's still a lot of unnecessary work. Suppose you have 100 threads
started about the same time with a 600 seconds timeout. What the timeout
monitor thread will be doing with the current implementation is wake up
every 0.25 sec, walk through all 100 threads while holding the
LOCK_timeout mutex (so, for example, no new connections can be created
during this time). Around 4 * 600 * 100 loop iterations before it has to
do any real work. And then when it has to kill a thread, it will
possibly wait in LOCK_thd_data (while still holding LOCK_timeout, and
thus possibly blocking new connections).
Why not implement it as I written in the worklog, i.e. as a queue?
Other comments and questions in no particular order:
- why is sql_timeout a session-only variable? I don't see any reasons
for that.
- please implement the per-query syntax as a SELECT option.
- I don't see any comments except those in the copy-pasted code
- calling add_to_
idea for a number of reasons. The most important one is that timeouts
will not work for prepared statements, and work not as one would expect
for stored routines. Besides, don't you call it twice in case of
per-query syntax?
- please don't use SLEEP() in cases. It always means trouble, because on
slow/overloaded test machines such tests behave unpredictably. For
example, on a slow/overloaded machine, SELECT SLEEP(3) may actually take
4 or more seconds, so the test case from your patch would fail.
I think we can simplify tests to make them reliable. For example, use
SLEEP(1000) and just verified it's interrupted (i.e. returns 1) when a
timeout is set.
- please remove the copy-pasted code related to Dec and IA64 from
sql_timeout_
- many lines with trailing whitespace, try for example:
grep '^+.* \+$' sql_timeout.patch
- please always put opening braces on separate lines, there's a few
cases where this rule is violated
Alexey Kopytov (akopytov) : | # |
Vlad Lesin (vlad-lesin) wrote : | # |
Everything is done except making SQL_TIMEOUT not only session but global variable too. Because blueprint describes it as a session variable. It's not an issue to do this but in this case we should change the blueprint too.
Each item in the queue has a pointer to the thread object to have
ability to invoke "kill query" function for that thread. Every time we use sql_timeout we push that pointer and expiration time to the queue. And after the query is executed we remove the item from the queue. The "remove" operation searches the queue item with certain thread pointer using hash table.
Vadim Tkachenko (vadim-tk) wrote : | # |
Vlad,
We need to have GLOBAL variable also, that's my bad, I did not think
about it initially.
I updated blueprint.
On Tue, Feb 7, 2012 at 4:10 AM, Vladislav Lesin <email address hidden> wrote:
> Review: Resubmit
>
> Everything is done except making SQL_TIMEOUT not only session but global variable too. Because blueprint describes it as a session variable. It's not an issue to do this but in this case we should change the blueprint too.
>
> Each item in the queue has a pointer to the thread object to have
> ability to invoke "kill query" function for that thread. Every time we use sql_timeout we push that pointer and expiration time to the queue. And after the query is executed we remove the item from the queue. The "remove" operation searches the queue item with certain thread pointer using hash table.
> --
> https:/
> You are reviewing the proposed merge of lp:~vlad-lesin/percona-server/sql_timeout into lp:percona-server.
--
Vadim Tkachenko, CTO, Percona Inc.
Phone +1-925-400-7377, Skype: vadimtk153
Schedule meeting: http://
Join us at Percona Live: MySQL Conference And Expo 2012
http://
Vlad Lesin (vlad-lesin) wrote : | # |
> Vlad,
>
> We need to have GLOBAL variable also, that's my bad, I did not think
> about it initially.
> I updated blueprint.
Ok, done.
Alexey Kopytov (akopytov) wrote : | # |
Vladislav,
I have reviewed the new version of patch and have a number of comments and questions:
- why a thread is only added to the monitor if it's a SELECT query:
> + sql_timeout_
> res= execute_
> + sql_timeout_
What happens with non-SELECT statements when we have a global or a session timeout value?
- please merge from trunk, there's a conflict in 'series'
- sql_timeout_hand is defined but never used
- init_thread_
the monitor state. Why not do it in the sql_timeout_
- clean_up_mutexes() seems to be a wrong place to destroy the monitor
state. Why not do it in sql_timeout_
- please add my_thread_init() to sql_timeout_
- http://
- please adjust main.mysqld-
- there's a compiler warning on 32-bit systems in sys_vars.cc
- in sys_vars.cc the variable is declared as Sys_var_ulong, but the
max value is ULONGLONG_MAX (which is the reason for the warning)
- I don't like that we allocate/free the Sql_timeout_info structure in
add(
and then making add()/remove() use that variable instead?
- I think it's a huge overkill to modify queues API in the server just to
be able to use hash when removing. Just walking the queue to find
the element to remove should be sufficient. It's a relatively rare
event, right?
- I wonder what's the reasoning behind making
was_
volatile
- please rename was_added_
shorter. 'has_sql_timeout' sounds descriptive enough to me.
- there's a number of cases when assignments have a space before '='
- please wrap the statements in QUEUE_ITEM_
"do {...} while(0)". please also explain why it is needed :)
- there's a number of cases when variable assignments do NOT have a
space after '='
- please don't use comma-separated assignments
- add a space after a typecast
- please use 'static inline' rather than just 'inline' in sql_timeout.cc
- you don't have to use my_sleep() in ::exit(), if you do all
destructio
montor thread to shutdown, and it will handle everything else
- I still see a few cases when opening braces are not on a separate
line
- some lines are wider than 80 characters
- please put declarations at the start of a block. it makes reading
the code and finding variable types much easier, especially when
declarations are separated from the code with a blank line
- do you really need to separate tests sql_timeout_
sql_
Alexey Kopytov (akopytov) wrote : | # |
Vladislav,
Please also remove support for per-query syntax. As we discussed previously, we will implement them in a different way later.
Vlad Lesin (vlad-lesin) wrote : | # |
Done.
Vlad Lesin (vlad-lesin) wrote : | # |
Jenkins build:
http://
All remarks of Alexey Kopytov were taken into account.
Vlad Lesin (vlad-lesin) wrote : | # |
http://
Laurynas Biveinis (laurynas-biveinis) wrote : | # |
The blueprint has to be expanded with more details,
i.e. parts of "Description of the Change" in the MP have to be
moved there. Likewise, there is some discussion in bug 671227,
which should be accounted for in the blueprint, (i.e. we decided to
do this and not that etc).
If there is no query option variable support, then this part should
be moved to another blueprint, probably set as dependant on this
one.
Line 363: for reference can put the blueprint link.
Line 368: unless I'm missing something, there is no need to include
load_
values, SQL_TIMEOUT is not such.
Lines 399--410: I don't understand what does the
"FN_
Lines 449--450, 460--461 seem redundant.
Lines 462--463: why it's only a warning to set a negative time out
value which then gets "truncated" to zero? IMHO it makes more sense
to make it error instead, if that's possible of course.
I don't like the SET @@global.
@@global.
on loaded Jenkins hosts. Since it's not sane (even if legal) to
assign TRUE timeout, I'd leave the test only for FALSE.
I am not sure if the test is stable on busy servers. Some of the
connection threads might get starved and return results at
unexpected times, breaking the test. I'd test the basic feature
with a single connection test, and if there's need to have
concurrent testing, I'd do it separately with the query log
disabled (basically just to test that the server does not crash).
Also, the timed-out statements produce any warnings? If yes, maybe
it's possible to record only thesm with the query log disabled.
Then the result file part for them would be a sequence of warnings,
independent of their actual order.
No need for extra empty line at 774.
The sql_timeout_expire can be set in THD::THD initializer list.
What about prepared statements? Is timeout honored for them? What
about setting it inside of a PS? Perhaps makes sense to add test
cases for it?
Whitespace issue in lines 878--880. Also can just use return (a -
b);
Line 901 s/properly/proper
For defensive programming I'd protect the queue_init_ex with
LOCK_queue too.
Please use C++ static_cast instead of C-style cast in
Sql_
any C casts where C++ casts would make more sense.
In the monitor function, I'd get rid of now variable and always
invoke my_micro_time(). The reason is that THD data lock, kill,
unlock might take a long time for busy queries or buggy code paths
that do not check kill state very often.
For the reason we need to release LOCK_queue around that code and
move queue_remove to be the 1st statement in the loop so that
queue_top and queue_remove happen atomically.
Space after (%s) in line 993.
In the add method, the LOCK_queue can be held for shorter time:
thd-
outside it. Or, I'd set t...
Alexey Kopytov (akopytov) wrote : | # |
Closing, as sql_timeout will only be implemented in 5.6.
Unmerged revisions
- 237. By Vlad Lesin
-
Get SQL_TIMEOUT=X variable to make queries automatically be killed
when they are taking too long time.
Example:
SET SQL_TIMEOUT=10;
SELECT SLEEP(20);The query will be killed in 10 seconds.
Preview Diff
1 | === modified file 'Percona-Server/mysql-test/r/mysqld--help-notwin.result' | |||
2 | --- Percona-Server/mysql-test/r/mysqld--help-notwin.result 2012-04-19 16:51:34 +0000 | |||
3 | +++ Percona-Server/mysql-test/r/mysqld--help-notwin.result 2012-04-26 09:57:20 +0000 | |||
4 | @@ -724,6 +724,7 @@ | |||
5 | 724 | replication. | 724 | replication. |
6 | 725 | --sql-mode=name Syntax: sql-mode=mode[,mode[,mode...]]. See the manual | 725 | --sql-mode=name Syntax: sql-mode=mode[,mode[,mode...]]. See the manual |
7 | 726 | for the complete list of valid sql modes | 726 | for the complete list of valid sql modes |
8 | 727 | --sql-timeout=# Timeout in seconds to wait before killing query. | ||
9 | 727 | --stored-program-cache=# | 728 | --stored-program-cache=# |
10 | 728 | The soft upper limit for number of cached stored routines | 729 | The soft upper limit for number of cached stored routines |
11 | 729 | for one connection. | 730 | for one connection. |
12 | @@ -1013,6 +1014,7 @@ | |||
13 | 1013 | sort-buffer-size 2097152 | 1014 | sort-buffer-size 2097152 |
14 | 1014 | sporadic-binlog-dump-fail FALSE | 1015 | sporadic-binlog-dump-fail FALSE |
15 | 1015 | sql-mode | 1016 | sql-mode |
16 | 1017 | sql-timeout 0 | ||
17 | 1016 | stored-program-cache 256 | 1018 | stored-program-cache 256 |
18 | 1017 | symbolic-links FALSE | 1019 | symbolic-links FALSE |
19 | 1018 | sync-binlog 0 | 1020 | sync-binlog 0 |
20 | 1019 | 1021 | ||
21 | === modified file 'Percona-Server/mysql-test/r/percona_server_variables_debug.result' | |||
22 | --- Percona-Server/mysql-test/r/percona_server_variables_debug.result 2012-04-18 23:26:11 +0000 | |||
23 | +++ Percona-Server/mysql-test/r/percona_server_variables_debug.result 2012-04-26 09:57:20 +0000 | |||
24 | @@ -344,6 +344,7 @@ | |||
25 | 344 | SQL_SAFE_UPDATES | 344 | SQL_SAFE_UPDATES |
26 | 345 | SQL_SELECT_LIMIT | 345 | SQL_SELECT_LIMIT |
27 | 346 | SQL_SLAVE_SKIP_COUNTER | 346 | SQL_SLAVE_SKIP_COUNTER |
28 | 347 | SQL_TIMEOUT | ||
29 | 347 | SQL_WARNINGS | 348 | SQL_WARNINGS |
30 | 348 | SSL_CA | 349 | SSL_CA |
31 | 349 | SSL_CAPATH | 350 | SSL_CAPATH |
32 | 350 | 351 | ||
33 | === modified file 'Percona-Server/mysql-test/r/percona_server_variables_release.result' | |||
34 | --- Percona-Server/mysql-test/r/percona_server_variables_release.result 2012-04-18 23:26:11 +0000 | |||
35 | +++ Percona-Server/mysql-test/r/percona_server_variables_release.result 2012-04-26 09:57:20 +0000 | |||
36 | @@ -338,6 +338,7 @@ | |||
37 | 338 | SQL_SAFE_UPDATES | 338 | SQL_SAFE_UPDATES |
38 | 339 | SQL_SELECT_LIMIT | 339 | SQL_SELECT_LIMIT |
39 | 340 | SQL_SLAVE_SKIP_COUNTER | 340 | SQL_SLAVE_SKIP_COUNTER |
40 | 341 | SQL_TIMEOUT | ||
41 | 341 | SQL_WARNINGS | 342 | SQL_WARNINGS |
42 | 342 | SSL_CA | 343 | SSL_CA |
43 | 343 | SSL_CAPATH | 344 | SSL_CAPATH |
44 | 344 | 345 | ||
45 | === added file 'Percona-Server/mysql-test/r/percona_sql_timeout.result' | |||
46 | --- Percona-Server/mysql-test/r/percona_sql_timeout.result 1970-01-01 00:00:00 +0000 | |||
47 | +++ Percona-Server/mysql-test/r/percona_sql_timeout.result 2012-04-26 09:57:20 +0000 | |||
48 | @@ -0,0 +1,120 @@ | |||
49 | 1 | SLEEP(1) | ||
50 | 2 | 0 | ||
51 | 3 | SLEEP(1000) | ||
52 | 4 | 1 | ||
53 | 5 | SLEEP(2) | ||
54 | 6 | 0 | ||
55 | 7 | SLEEP(1) | ||
56 | 8 | 0 | ||
57 | 9 | SLEEP(1000) | ||
58 | 10 | 1 | ||
59 | 11 | SLEEP(2) | ||
60 | 12 | 0 | ||
61 | 13 | SLEEP(1) | ||
62 | 14 | 0 | ||
63 | 15 | SLEEP(1000) | ||
64 | 16 | 1 | ||
65 | 17 | SLEEP(2) | ||
66 | 18 | 0 | ||
67 | 19 | SLEEP(1) | ||
68 | 20 | 0 | ||
69 | 21 | SLEEP(1000) | ||
70 | 22 | 1 | ||
71 | 23 | SLEEP(2) | ||
72 | 24 | 0 | ||
73 | 25 | SLEEP(1) | ||
74 | 26 | 0 | ||
75 | 27 | SLEEP(1000) | ||
76 | 28 | 1 | ||
77 | 29 | SLEEP(2) | ||
78 | 30 | 0 | ||
79 | 31 | SLEEP(1) | ||
80 | 32 | 0 | ||
81 | 33 | SLEEP(1000) | ||
82 | 34 | 1 | ||
83 | 35 | SLEEP(2) | ||
84 | 36 | 0 | ||
85 | 37 | SLEEP(1) | ||
86 | 38 | 0 | ||
87 | 39 | SLEEP(1000) | ||
88 | 40 | 1 | ||
89 | 41 | SLEEP(2) | ||
90 | 42 | 0 | ||
91 | 43 | SLEEP(1) | ||
92 | 44 | 0 | ||
93 | 45 | SLEEP(1000) | ||
94 | 46 | 1 | ||
95 | 47 | SLEEP(2) | ||
96 | 48 | 0 | ||
97 | 49 | SLEEP(1) | ||
98 | 50 | 0 | ||
99 | 51 | SLEEP(1000) | ||
100 | 52 | 1 | ||
101 | 53 | SLEEP(2) | ||
102 | 54 | 0 | ||
103 | 55 | SLEEP(1) | ||
104 | 56 | 0 | ||
105 | 57 | SLEEP(1000) | ||
106 | 58 | 1 | ||
107 | 59 | SLEEP(2) | ||
108 | 60 | 0 | ||
109 | 61 | SLEEP(1) | ||
110 | 62 | 0 | ||
111 | 63 | SLEEP(1000) | ||
112 | 64 | 1 | ||
113 | 65 | SLEEP(2) | ||
114 | 66 | 0 | ||
115 | 67 | SLEEP(1) | ||
116 | 68 | 0 | ||
117 | 69 | SLEEP(1000) | ||
118 | 70 | 1 | ||
119 | 71 | SLEEP(2) | ||
120 | 72 | 0 | ||
121 | 73 | SLEEP(1) | ||
122 | 74 | 0 | ||
123 | 75 | SLEEP(1000) | ||
124 | 76 | 1 | ||
125 | 77 | SLEEP(2) | ||
126 | 78 | 0 | ||
127 | 79 | SLEEP(1) | ||
128 | 80 | 0 | ||
129 | 81 | SLEEP(1000) | ||
130 | 82 | 1 | ||
131 | 83 | SLEEP(2) | ||
132 | 84 | 0 | ||
133 | 85 | SLEEP(1) | ||
134 | 86 | 0 | ||
135 | 87 | SLEEP(1000) | ||
136 | 88 | 1 | ||
137 | 89 | SLEEP(2) | ||
138 | 90 | 0 | ||
139 | 91 | SLEEP(1) | ||
140 | 92 | 0 | ||
141 | 93 | SLEEP(1000) | ||
142 | 94 | 1 | ||
143 | 95 | SLEEP(2) | ||
144 | 96 | 0 | ||
145 | 97 | SLEEP(1) | ||
146 | 98 | 0 | ||
147 | 99 | SLEEP(1000) | ||
148 | 100 | 1 | ||
149 | 101 | SLEEP(2) | ||
150 | 102 | 0 | ||
151 | 103 | SLEEP(1) | ||
152 | 104 | 0 | ||
153 | 105 | SLEEP(1000) | ||
154 | 106 | 1 | ||
155 | 107 | SLEEP(2) | ||
156 | 108 | 0 | ||
157 | 109 | SLEEP(1) | ||
158 | 110 | 0 | ||
159 | 111 | SLEEP(1000) | ||
160 | 112 | 1 | ||
161 | 113 | SLEEP(2) | ||
162 | 114 | 0 | ||
163 | 115 | SLEEP(1) | ||
164 | 116 | 0 | ||
165 | 117 | SLEEP(1000) | ||
166 | 118 | 1 | ||
167 | 119 | SLEEP(2) | ||
168 | 120 | 0 | ||
169 | 0 | 121 | ||
170 | === added file 'Percona-Server/mysql-test/suite/sys_vars/r/sql_timeout_basic.result' | |||
171 | --- Percona-Server/mysql-test/suite/sys_vars/r/sql_timeout_basic.result 1970-01-01 00:00:00 +0000 | |||
172 | +++ Percona-Server/mysql-test/suite/sys_vars/r/sql_timeout_basic.result 2012-04-26 09:57:20 +0000 | |||
173 | @@ -0,0 +1,164 @@ | |||
174 | 1 | SET @start_global_value = @@global.sql_timeout; | ||
175 | 2 | SELECT @start_global_value; | ||
176 | 3 | @start_global_value | ||
177 | 4 | 0 | ||
178 | 5 | SET @start_session_value = @@session.sql_timeout; | ||
179 | 6 | SELECT @start_session_value; | ||
180 | 7 | @start_session_value | ||
181 | 8 | 0 | ||
182 | 9 | '#--------------------FN_DYNVARS_083_01-------------------------#' | ||
183 | 10 | SET @@global.sql_timeout = 100; | ||
184 | 11 | SET @@global.sql_timeout = DEFAULT; | ||
185 | 12 | SELECT @@global.sql_timeout; | ||
186 | 13 | @@global.sql_timeout | ||
187 | 14 | 0 | ||
188 | 15 | SET @@session.sql_timeout = 200; | ||
189 | 16 | SET @@session.sql_timeout = DEFAULT; | ||
190 | 17 | SELECT @@session.sql_timeout; | ||
191 | 18 | @@session.sql_timeout | ||
192 | 19 | 0 | ||
193 | 20 | '#--------------------FN_DYNVARS_083_02-------------------------#' | ||
194 | 21 | SET @@global.sql_timeout = DEFAULT; | ||
195 | 22 | SELECT @@global.sql_timeout = 0; | ||
196 | 23 | @@global.sql_timeout = 0 | ||
197 | 24 | 1 | ||
198 | 25 | SET @@session.sql_timeout = DEFAULT; | ||
199 | 26 | SELECT @@session.sql_timeout = 0; | ||
200 | 27 | @@session.sql_timeout = 0 | ||
201 | 28 | 1 | ||
202 | 29 | '#--------------------FN_DYNVARS_083_03-------------------------#' | ||
203 | 30 | SET @@global.sql_timeout = 100; | ||
204 | 31 | SELECT @@global.sql_timeout; | ||
205 | 32 | @@global.sql_timeout | ||
206 | 33 | 100 | ||
207 | 34 | SET @@global.sql_timeout = 200; | ||
208 | 35 | SELECT @@global.sql_timeout; | ||
209 | 36 | @@global.sql_timeout | ||
210 | 37 | 200 | ||
211 | 38 | SET @@global.sql_timeout = 65536; | ||
212 | 39 | SELECT @@global.sql_timeout; | ||
213 | 40 | @@global.sql_timeout | ||
214 | 41 | 65536 | ||
215 | 42 | SET @@global.sql_timeout = 4294967295; | ||
216 | 43 | SELECT @@global.sql_timeout; | ||
217 | 44 | @@global.sql_timeout | ||
218 | 45 | 4294967295 | ||
219 | 46 | SET @@global.sql_timeout = 4294967294; | ||
220 | 47 | SELECT @@global.sql_timeout; | ||
221 | 48 | @@global.sql_timeout | ||
222 | 49 | 4294967294 | ||
223 | 50 | '#--------------------FN_DYNVARS_083_04-------------------------#' | ||
224 | 51 | SET @@session.sql_timeout = 100; | ||
225 | 52 | SELECT @@session.sql_timeout; | ||
226 | 53 | @@session.sql_timeout | ||
227 | 54 | 100 | ||
228 | 55 | SET @@session.sql_timeout = 200; | ||
229 | 56 | SELECT @@session.sql_timeout; | ||
230 | 57 | @@session.sql_timeout | ||
231 | 58 | 200 | ||
232 | 59 | SET @@session.sql_timeout = 4294967295; | ||
233 | 60 | SELECT @@session.sql_timeout; | ||
234 | 61 | @@session.sql_timeout | ||
235 | 62 | 4294967295 | ||
236 | 63 | SET @@session.sql_timeout = 4294967294; | ||
237 | 64 | SELECT @@session.sql_timeout; | ||
238 | 65 | @@session.sql_timeout | ||
239 | 66 | 4294967294 | ||
240 | 67 | SET @@session.sql_timeout = 65535; | ||
241 | 68 | SELECT @@session.sql_timeout; | ||
242 | 69 | @@session.sql_timeout | ||
243 | 70 | 65535 | ||
244 | 71 | '#------------------FN_DYNVARS_083_05-----------------------#' | ||
245 | 72 | SET @@global.sql_timeout = 0; | ||
246 | 73 | SELECT @@global.sql_timeout; | ||
247 | 74 | @@global.sql_timeout | ||
248 | 75 | 0 | ||
249 | 76 | SET @@global.sql_timeout = -1024; | ||
250 | 77 | Warnings: | ||
251 | 78 | Warning 1292 Truncated incorrect sql_timeout value: '-1024' | ||
252 | 79 | SELECT @@global.sql_timeout; | ||
253 | 80 | @@global.sql_timeout | ||
254 | 81 | 0 | ||
255 | 82 | SET @@global.sql_timeout = 65530.34; | ||
256 | 83 | ERROR 42000: Incorrect argument type to variable 'sql_timeout' | ||
257 | 84 | SELECT @@global.sql_timeout; | ||
258 | 85 | @@global.sql_timeout | ||
259 | 86 | 0 | ||
260 | 87 | SET @@global.sql_timeout = test; | ||
261 | 88 | ERROR 42000: Incorrect argument type to variable 'sql_timeout' | ||
262 | 89 | SELECT @@global.sql_timeout; | ||
263 | 90 | @@global.sql_timeout | ||
264 | 91 | 0 | ||
265 | 92 | SET @@session.sql_timeout = 0; | ||
266 | 93 | SELECT @@session.sql_timeout; | ||
267 | 94 | @@session.sql_timeout | ||
268 | 95 | 0 | ||
269 | 96 | SET @@session.sql_timeout = -2; | ||
270 | 97 | Warnings: | ||
271 | 98 | Warning 1292 Truncated incorrect sql_timeout value: '-2' | ||
272 | 99 | SELECT @@session.sql_timeout; | ||
273 | 100 | @@session.sql_timeout | ||
274 | 101 | 0 | ||
275 | 102 | SET @@session.sql_timeout = 65530.34; | ||
276 | 103 | ERROR 42000: Incorrect argument type to variable 'sql_timeout' | ||
277 | 104 | SELECT @@session.sql_timeout; | ||
278 | 105 | @@session.sql_timeout | ||
279 | 106 | 0 | ||
280 | 107 | SET @@session.sql_timeout = test; | ||
281 | 108 | ERROR 42000: Incorrect argument type to variable 'sql_timeout' | ||
282 | 109 | SELECT @@session.sql_timeout; | ||
283 | 110 | @@session.sql_timeout | ||
284 | 111 | 0 | ||
285 | 112 | '#------------------FN_DYNVARS_083_06-----------------------#' | ||
286 | 113 | SELECT @@global.sql_timeout = VARIABLE_VALUE | ||
287 | 114 | FROM INFORMATION_SCHEMA.GLOBAL_VARIABLES | ||
288 | 115 | WHERE VARIABLE_NAME='sql_timeout'; | ||
289 | 116 | @@global.sql_timeout = VARIABLE_VALUE | ||
290 | 117 | 1 | ||
291 | 118 | '#------------------FN_DYNVARS_083_07-----------------------#' | ||
292 | 119 | SELECT @@session.sql_timeout = VARIABLE_VALUE | ||
293 | 120 | FROM INFORMATION_SCHEMA.SESSION_VARIABLES | ||
294 | 121 | WHERE VARIABLE_NAME='sql_timeout'; | ||
295 | 122 | @@session.sql_timeout = VARIABLE_VALUE | ||
296 | 123 | 1 | ||
297 | 124 | '#------------------FN_DYNVARS_083_08-----------------------#' | ||
298 | 125 | SET @@global.sql_timeout = TRUE; | ||
299 | 126 | SELECT @@global.sql_timeout; | ||
300 | 127 | @@global.sql_timeout | ||
301 | 128 | 1 | ||
302 | 129 | SET @@global.sql_timeout = FALSE; | ||
303 | 130 | SELECT @@global.sql_timeout; | ||
304 | 131 | @@global.sql_timeout | ||
305 | 132 | 0 | ||
306 | 133 | '#---------------------FN_DYNVARS_083_09----------------------#' | ||
307 | 134 | SET @@global.sql_timeout = 100; | ||
308 | 135 | SELECT @@sql_timeout = @@global.sql_timeout; | ||
309 | 136 | @@sql_timeout = @@global.sql_timeout | ||
310 | 137 | 0 | ||
311 | 138 | '#---------------------FN_DYNVARS_083_10----------------------#' | ||
312 | 139 | SET @@sql_timeout = 1000; | ||
313 | 140 | SELECT @@sql_timeout = @@local.sql_timeout; | ||
314 | 141 | @@sql_timeout = @@local.sql_timeout | ||
315 | 142 | 1 | ||
316 | 143 | SELECT @@local.sql_timeout = @@session.sql_timeout; | ||
317 | 144 | @@local.sql_timeout = @@session.sql_timeout | ||
318 | 145 | 1 | ||
319 | 146 | '#---------------------FN_DYNVARS_083_11----------------------#' | ||
320 | 147 | SET sql_timeout = 100; | ||
321 | 148 | SELECT @@sql_timeout; | ||
322 | 149 | @@sql_timeout | ||
323 | 150 | 100 | ||
324 | 151 | SELECT local.sql_timeout; | ||
325 | 152 | ERROR 42S02: Unknown table 'local' in field list | ||
326 | 153 | SELECT session.sql_timeout; | ||
327 | 154 | ERROR 42S02: Unknown table 'session' in field list | ||
328 | 155 | SELECT sql_timeout = @@session.sql_timeout; | ||
329 | 156 | ERROR 42S22: Unknown column 'sql_timeout' in 'field list' | ||
330 | 157 | SET @@global.sql_timeout = @start_global_value; | ||
331 | 158 | SELECT @@global.sql_timeout; | ||
332 | 159 | @@global.sql_timeout | ||
333 | 160 | 0 | ||
334 | 161 | SET @@session.sql_timeout = @start_session_value; | ||
335 | 162 | SELECT @@session.sql_timeout; | ||
336 | 163 | @@session.sql_timeout | ||
337 | 164 | 0 | ||
338 | 0 | 165 | ||
339 | === added file 'Percona-Server/mysql-test/suite/sys_vars/t/sql_timeout_basic.test' | |||
340 | --- Percona-Server/mysql-test/suite/sys_vars/t/sql_timeout_basic.test 1970-01-01 00:00:00 +0000 | |||
341 | +++ Percona-Server/mysql-test/suite/sys_vars/t/sql_timeout_basic.test 2012-04-26 09:57:20 +0000 | |||
342 | @@ -0,0 +1,210 @@ | |||
343 | 1 | ############mysql-test\suite\sysvars\t\sql_timeout_basic.test################## | ||
344 | 2 | # # | ||
345 | 3 | # Variable Name: sql_timeout # | ||
346 | 4 | # Scope: GLOBAL | SESSION # | ||
347 | 5 | # Access Type: Dynamic # | ||
348 | 6 | # Data Type: numeric # | ||
349 | 7 | # Default Value: 0 # | ||
350 | 8 | # Range: 1-4294967295 # | ||
351 | 9 | # # | ||
352 | 10 | # # | ||
353 | 11 | # Creation Date: 2012-02-08 # | ||
354 | 12 | # Author: Vlad Lesin # | ||
355 | 13 | # # | ||
356 | 14 | # Description: Test Cases of Dynamic System Variable sql_timeout # | ||
357 | 15 | # that checks the behavior of this variable in the following ways# | ||
358 | 16 | # * Default Value # | ||
359 | 17 | # * Valid & Invalid values # | ||
360 | 18 | # * Scope & Access method # | ||
361 | 19 | # * Data Integrity # | ||
362 | 20 | # # | ||
363 | 21 | # Reference: none # | ||
364 | 22 | # # | ||
365 | 23 | # # | ||
366 | 24 | ############################################################################### | ||
367 | 25 | |||
368 | 26 | --source include/load_sysvars.inc | ||
369 | 27 | |||
370 | 28 | ############################################################ | ||
371 | 29 | # START OF sql_timeout TESTS # | ||
372 | 30 | ############################################################ | ||
373 | 31 | |||
374 | 32 | |||
375 | 33 | ############################################################# | ||
376 | 34 | # Save initial value # | ||
377 | 35 | ############################################################# | ||
378 | 36 | |||
379 | 37 | SET @start_global_value = @@global.sql_timeout; | ||
380 | 38 | SELECT @start_global_value; | ||
381 | 39 | SET @start_session_value = @@session.sql_timeout; | ||
382 | 40 | SELECT @start_session_value; | ||
383 | 41 | |||
384 | 42 | |||
385 | 43 | --echo '#--------------------FN_DYNVARS_083_01-------------------------#' | ||
386 | 44 | ################################################################# | ||
387 | 45 | # Display the DEFAULT value of sql_timeout # | ||
388 | 46 | ################################################################# | ||
389 | 47 | |||
390 | 48 | SET @@global.sql_timeout = 100; | ||
391 | 49 | SET @@global.sql_timeout = DEFAULT; | ||
392 | 50 | SELECT @@global.sql_timeout; | ||
393 | 51 | |||
394 | 52 | SET @@session.sql_timeout = 200; | ||
395 | 53 | SET @@session.sql_timeout = DEFAULT; | ||
396 | 54 | SELECT @@session.sql_timeout; | ||
397 | 55 | |||
398 | 56 | |||
399 | 57 | --echo '#--------------------FN_DYNVARS_083_02-------------------------#' | ||
400 | 58 | ################################################################# | ||
401 | 59 | # Check the DEFAULT value of sql_timeout # | ||
402 | 60 | ################################################################# | ||
403 | 61 | |||
404 | 62 | SET @@global.sql_timeout = DEFAULT; | ||
405 | 63 | SELECT @@global.sql_timeout = 0; | ||
406 | 64 | |||
407 | 65 | SET @@session.sql_timeout = DEFAULT; | ||
408 | 66 | SELECT @@session.sql_timeout = 0; | ||
409 | 67 | |||
410 | 68 | |||
411 | 69 | --echo '#--------------------FN_DYNVARS_083_03-------------------------#' | ||
412 | 70 | ########################################################################### | ||
413 | 71 | # Change the value of sql_timeout to a valid value for GLOBAL Scope # | ||
414 | 72 | ########################################################################### | ||
415 | 73 | |||
416 | 74 | SET @@global.sql_timeout = 100; | ||
417 | 75 | SELECT @@global.sql_timeout; | ||
418 | 76 | SET @@global.sql_timeout = 200; | ||
419 | 77 | SELECT @@global.sql_timeout; | ||
420 | 78 | SET @@global.sql_timeout = 65536; | ||
421 | 79 | SELECT @@global.sql_timeout; | ||
422 | 80 | SET @@global.sql_timeout = 4294967295; | ||
423 | 81 | SELECT @@global.sql_timeout; | ||
424 | 82 | SET @@global.sql_timeout = 4294967294; | ||
425 | 83 | SELECT @@global.sql_timeout; | ||
426 | 84 | |||
427 | 85 | |||
428 | 86 | --echo '#--------------------FN_DYNVARS_083_04-------------------------#' | ||
429 | 87 | ############################################################################ | ||
430 | 88 | # Change the value of sql_timeout to a valid value for SESSION Scope # | ||
431 | 89 | ############################################################################ | ||
432 | 90 | SET @@session.sql_timeout = 100; | ||
433 | 91 | SELECT @@session.sql_timeout; | ||
434 | 92 | SET @@session.sql_timeout = 200; | ||
435 | 93 | SELECT @@session.sql_timeout; | ||
436 | 94 | SET @@session.sql_timeout = 4294967295; | ||
437 | 95 | SELECT @@session.sql_timeout; | ||
438 | 96 | SET @@session.sql_timeout = 4294967294; | ||
439 | 97 | SELECT @@session.sql_timeout; | ||
440 | 98 | SET @@session.sql_timeout = 65535; | ||
441 | 99 | SELECT @@session.sql_timeout; | ||
442 | 100 | |||
443 | 101 | |||
444 | 102 | --echo '#------------------FN_DYNVARS_083_05-----------------------#' | ||
445 | 103 | ############################################################# | ||
446 | 104 | # Change the value of sql_timeout to an invalid value # | ||
447 | 105 | ############################################################# | ||
448 | 106 | |||
449 | 107 | SET @@global.sql_timeout = 0; | ||
450 | 108 | SELECT @@global.sql_timeout; | ||
451 | 109 | SET @@global.sql_timeout = -1024; | ||
452 | 110 | SELECT @@global.sql_timeout; | ||
453 | 111 | --Error ER_WRONG_TYPE_FOR_VAR | ||
454 | 112 | SET @@global.sql_timeout = 65530.34; | ||
455 | 113 | SELECT @@global.sql_timeout; | ||
456 | 114 | --Error ER_WRONG_TYPE_FOR_VAR | ||
457 | 115 | SET @@global.sql_timeout = test; | ||
458 | 116 | SELECT @@global.sql_timeout; | ||
459 | 117 | |||
460 | 118 | SET @@session.sql_timeout = 0; | ||
461 | 119 | SELECT @@session.sql_timeout; | ||
462 | 120 | SET @@session.sql_timeout = -2; | ||
463 | 121 | SELECT @@session.sql_timeout; | ||
464 | 122 | --Error ER_WRONG_TYPE_FOR_VAR | ||
465 | 123 | SET @@session.sql_timeout = 65530.34; | ||
466 | 124 | SELECT @@session.sql_timeout; | ||
467 | 125 | |||
468 | 126 | --Error ER_WRONG_TYPE_FOR_VAR | ||
469 | 127 | SET @@session.sql_timeout = test; | ||
470 | 128 | SELECT @@session.sql_timeout; | ||
471 | 129 | |||
472 | 130 | |||
473 | 131 | --echo '#------------------FN_DYNVARS_083_06-----------------------#' | ||
474 | 132 | #################################################################### | ||
475 | 133 | # Check if the value in GLOBAL Table matches value in variable # | ||
476 | 134 | #################################################################### | ||
477 | 135 | |||
478 | 136 | |||
479 | 137 | SELECT @@global.sql_timeout = VARIABLE_VALUE | ||
480 | 138 | FROM INFORMATION_SCHEMA.GLOBAL_VARIABLES | ||
481 | 139 | WHERE VARIABLE_NAME='sql_timeout'; | ||
482 | 140 | |||
483 | 141 | --echo '#------------------FN_DYNVARS_083_07-----------------------#' | ||
484 | 142 | #################################################################### | ||
485 | 143 | # Check if the value in SESSION Table matches value in variable # | ||
486 | 144 | #################################################################### | ||
487 | 145 | |||
488 | 146 | SELECT @@session.sql_timeout = VARIABLE_VALUE | ||
489 | 147 | FROM INFORMATION_SCHEMA.SESSION_VARIABLES | ||
490 | 148 | WHERE VARIABLE_NAME='sql_timeout'; | ||
491 | 149 | |||
492 | 150 | |||
493 | 151 | --echo '#------------------FN_DYNVARS_083_08-----------------------#' | ||
494 | 152 | #################################################################### | ||
495 | 153 | # Check if TRUE and FALSE values can be used on variable # | ||
496 | 154 | #################################################################### | ||
497 | 155 | |||
498 | 156 | SET @@global.sql_timeout = TRUE; | ||
499 | 157 | SELECT @@global.sql_timeout; | ||
500 | 158 | SET @@global.sql_timeout = FALSE; | ||
501 | 159 | SELECT @@global.sql_timeout; | ||
502 | 160 | |||
503 | 161 | |||
504 | 162 | --echo '#---------------------FN_DYNVARS_083_09----------------------#' | ||
505 | 163 | ############################################################################# | ||
506 | 164 | # Check if accessing variable with and without GLOBAL point # | ||
507 | 165 | # to same variable # | ||
508 | 166 | ############################################################################# | ||
509 | 167 | |||
510 | 168 | SET @@global.sql_timeout = 100; | ||
511 | 169 | SELECT @@sql_timeout = @@global.sql_timeout; | ||
512 | 170 | |||
513 | 171 | |||
514 | 172 | --echo '#---------------------FN_DYNVARS_083_10----------------------#' | ||
515 | 173 | ############################################################################# | ||
516 | 174 | # Check if accessing variable with SESSION,LOCAL and without SCOPE points # | ||
517 | 175 | # to same session variable # | ||
518 | 176 | ############################################################################# | ||
519 | 177 | |||
520 | 178 | SET @@sql_timeout = 1000; | ||
521 | 179 | SELECT @@sql_timeout = @@local.sql_timeout; | ||
522 | 180 | SELECT @@local.sql_timeout = @@session.sql_timeout; | ||
523 | 181 | |||
524 | 182 | |||
525 | 183 | --echo '#---------------------FN_DYNVARS_083_11----------------------#' | ||
526 | 184 | ############################################################################ | ||
527 | 185 | # Check if sql_timeout can be accessed with and without @@ sign # | ||
528 | 186 | ############################################################################ | ||
529 | 187 | |||
530 | 188 | SET sql_timeout = 100; | ||
531 | 189 | SELECT @@sql_timeout; | ||
532 | 190 | --Error ER_UNKNOWN_TABLE | ||
533 | 191 | SELECT local.sql_timeout; | ||
534 | 192 | --Error ER_UNKNOWN_TABLE | ||
535 | 193 | SELECT session.sql_timeout; | ||
536 | 194 | --Error ER_BAD_FIELD_ERROR | ||
537 | 195 | SELECT sql_timeout = @@session.sql_timeout; | ||
538 | 196 | |||
539 | 197 | |||
540 | 198 | #################################### | ||
541 | 199 | # Restore initial value # | ||
542 | 200 | #################################### | ||
543 | 201 | |||
544 | 202 | SET @@global.sql_timeout = @start_global_value; | ||
545 | 203 | SELECT @@global.sql_timeout; | ||
546 | 204 | SET @@session.sql_timeout = @start_session_value; | ||
547 | 205 | SELECT @@session.sql_timeout; | ||
548 | 206 | |||
549 | 207 | |||
550 | 208 | ############################################################# | ||
551 | 209 | # END OF sql_timeout TESTS # | ||
552 | 210 | ############################################################# | ||
553 | 0 | 211 | ||
554 | === added file 'Percona-Server/mysql-test/t/percona_sql_timeout.test' | |||
555 | --- Percona-Server/mysql-test/t/percona_sql_timeout.test 1970-01-01 00:00:00 +0000 | |||
556 | +++ Percona-Server/mysql-test/t/percona_sql_timeout.test 2012-04-26 09:57:20 +0000 | |||
557 | @@ -0,0 +1,44 @@ | |||
558 | 1 | # | ||
559 | 2 | # SQL_TIMEOUT test | ||
560 | 3 | # | ||
561 | 4 | # SQL_TIMEOUT is a session variable or | ||
562 | 5 | # query keyword which sets the time | ||
563 | 6 | # limit for query execution. | ||
564 | 7 | |||
565 | 8 | # Save the initial number of concurrent sessions | ||
566 | 9 | --source include/count_sessions.inc | ||
567 | 10 | |||
568 | 11 | |||
569 | 12 | --disable_query_log | ||
570 | 13 | |||
571 | 14 | --let $sessions_count=20 | ||
572 | 15 | |||
573 | 16 | --let $i=$sessions_count | ||
574 | 17 | while ($i) { | ||
575 | 18 | --dec $i | ||
576 | 19 | |||
577 | 20 | --let $connection_name=connection_$i | ||
578 | 21 | --connect ($connection_name,localhost,root,,) | ||
579 | 22 | --delimiter +++ | ||
580 | 23 | let $statement= | ||
581 | 24 | SELECT SLEEP(1); | ||
582 | 25 | SET @@SESSION.SQL_TIMEOUT = 1; | ||
583 | 26 | SELECT SLEEP(1000); | ||
584 | 27 | SET @@SESSION.SQL_TIMEOUT = 0; | ||
585 | 28 | SELECT SLEEP(2); | ||
586 | 29 | +++ | ||
587 | 30 | --delimiter ; | ||
588 | 31 | --send_eval $statement | ||
589 | 32 | } | ||
590 | 33 | |||
591 | 34 | --let $i=$sessions_count | ||
592 | 35 | while ($i) { | ||
593 | 36 | --dec $i | ||
594 | 37 | --let $connection_name=connection_$i | ||
595 | 38 | --connection $connection_name | ||
596 | 39 | --reap | ||
597 | 40 | --disconnect $connection_name | ||
598 | 41 | } | ||
599 | 42 | |||
600 | 43 | --connection default | ||
601 | 44 | --source include/wait_until_count_sessions.inc | ||
602 | 0 | 45 | ||
603 | === modified file 'Percona-Server/sql/CMakeLists.txt' | |||
604 | --- Percona-Server/sql/CMakeLists.txt 2012-04-19 16:51:34 +0000 | |||
605 | +++ Percona-Server/sql/CMakeLists.txt 2012-04-26 09:57:20 +0000 | |||
606 | @@ -76,7 +76,7 @@ | |||
607 | 76 | sql_profile.cc event_parse_data.cc sql_alter.cc | 76 | sql_profile.cc event_parse_data.cc sql_alter.cc |
608 | 77 | sql_signal.cc rpl_handler.cc mdl.cc sql_admin.cc | 77 | sql_signal.cc rpl_handler.cc mdl.cc sql_admin.cc |
609 | 78 | transaction.cc sys_vars.cc sql_truncate.cc datadict.cc | 78 | transaction.cc sys_vars.cc sql_truncate.cc datadict.cc |
611 | 79 | sql_reload.cc | 79 | sql_reload.cc sql_timeout.cc |
612 | 80 | ${GEN_SOURCES} | 80 | ${GEN_SOURCES} |
613 | 81 | ${MYSYS_LIBWRAP_SOURCE}) | 81 | ${MYSYS_LIBWRAP_SOURCE}) |
614 | 82 | 82 | ||
615 | 83 | 83 | ||
616 | === modified file 'Percona-Server/sql/mysqld.cc' | |||
617 | --- Percona-Server/sql/mysqld.cc 2012-04-19 16:51:34 +0000 | |||
618 | +++ Percona-Server/sql/mysqld.cc 2012-04-26 09:57:20 +0000 | |||
619 | @@ -71,6 +71,8 @@ | |||
620 | 71 | 71 | ||
621 | 72 | #include "query_response_time.h" | 72 | #include "query_response_time.h" |
622 | 73 | 73 | ||
623 | 74 | #include "sql_timeout.h" | ||
624 | 75 | |||
625 | 74 | #ifdef WITH_PERFSCHEMA_STORAGE_ENGINE | 76 | #ifdef WITH_PERFSCHEMA_STORAGE_ENGINE |
626 | 75 | #include "../storage/perfschema/pfs_server.h" | 77 | #include "../storage/perfschema/pfs_server.h" |
627 | 76 | #endif /* WITH_PERFSCHEMA_STORAGE_ENGINE */ | 78 | #endif /* WITH_PERFSCHEMA_STORAGE_ENGINE */ |
628 | @@ -671,6 +673,7 @@ | |||
629 | 671 | mysql_rwlock_t LOCK_system_variables_hash; | 673 | mysql_rwlock_t LOCK_system_variables_hash; |
630 | 672 | mysql_cond_t COND_thread_count; | 674 | mysql_cond_t COND_thread_count; |
631 | 673 | pthread_t signal_thread; | 675 | pthread_t signal_thread; |
632 | 676 | pthread_t sql_timeout_thread; | ||
633 | 674 | pthread_attr_t connection_attrib; | 677 | pthread_attr_t connection_attrib; |
634 | 675 | mysql_mutex_t LOCK_server_started; | 678 | mysql_mutex_t LOCK_server_started; |
635 | 676 | mysql_cond_t COND_server_started; | 679 | mysql_cond_t COND_server_started; |
636 | @@ -1439,6 +1442,7 @@ | |||
637 | 1439 | */ | 1442 | */ |
638 | 1440 | wait_for_signal_thread_to_end(); | 1443 | wait_for_signal_thread_to_end(); |
639 | 1441 | mysql_audit_finalize(); | 1444 | mysql_audit_finalize(); |
640 | 1445 | sql_timeout_monitor.exit(); | ||
641 | 1442 | clean_up_mutexes(); | 1446 | clean_up_mutexes(); |
642 | 1443 | clean_up_error_log_mutex(); | 1447 | clean_up_error_log_mutex(); |
643 | 1444 | #ifdef WITH_PERFSCHEMA_STORAGE_ENGINE | 1448 | #ifdef WITH_PERFSCHEMA_STORAGE_ENGINE |
644 | @@ -4289,6 +4293,48 @@ | |||
645 | 4289 | } | 4293 | } |
646 | 4290 | #endif//DBUG_OFF | 4294 | #endif//DBUG_OFF |
647 | 4291 | 4295 | ||
648 | 4296 | |||
649 | 4297 | pthread_handler_t sql_timeout_thread_func(void *arg __attribute__((unused))) | ||
650 | 4298 | { | ||
651 | 4299 | my_thread_init(); | ||
652 | 4300 | sql_timeout_monitor.init(); | ||
653 | 4301 | /* SQL_TIMEOUT loop */ | ||
654 | 4302 | sql_timeout_monitor.monitor(); | ||
655 | 4303 | sql_timeout_monitor.deinit(); | ||
656 | 4304 | my_thread_end(); | ||
657 | 4305 | return(0); | ||
658 | 4306 | } | ||
659 | 4307 | |||
660 | 4308 | /** | ||
661 | 4309 | Start SQL_TIMEOUT monitor loop in a separate thread. | ||
662 | 4310 | */ | ||
663 | 4311 | static void start_sql_timeout_thread(void) | ||
664 | 4312 | { | ||
665 | 4313 | int error; | ||
666 | 4314 | pthread_attr_t thr_attr; | ||
667 | 4315 | DBUG_ENTER("start_sql_timeout_thread"); | ||
668 | 4316 | (void) pthread_attr_init(&thr_attr); | ||
669 | 4317 | (void) pthread_attr_setdetachstate(&thr_attr, PTHREAD_CREATE_DETACHED); | ||
670 | 4318 | pthread_attr_setstacksize(&thr_attr, my_thread_stack_size); | ||
671 | 4319 | mysql_mutex_lock(&LOCK_thread_count); | ||
672 | 4320 | if ((error= mysql_thread_create(key_thread_sql_timeout, | ||
673 | 4321 | &sql_timeout_thread, | ||
674 | 4322 | &thr_attr, | ||
675 | 4323 | sql_timeout_thread_func, | ||
676 | 4324 | 0))) | ||
677 | 4325 | { | ||
678 | 4326 | sql_print_error("Can't create sql_timeout-thread (error %d, errno: %d)", | ||
679 | 4327 | error,errno); | ||
680 | 4328 | exit(1); | ||
681 | 4329 | } | ||
682 | 4330 | /* Waiting for monitor thread start */ | ||
683 | 4331 | mysql_cond_wait(&COND_thread_count, &LOCK_thread_count); | ||
684 | 4332 | mysql_mutex_unlock(&LOCK_thread_count); | ||
685 | 4333 | |||
686 | 4334 | (void) pthread_attr_destroy(&thr_attr); | ||
687 | 4335 | DBUG_VOID_RETURN; | ||
688 | 4336 | } | ||
689 | 4337 | |||
690 | 4292 | #ifdef __WIN__ | 4338 | #ifdef __WIN__ |
691 | 4293 | int win_main(int argc, char **argv) | 4339 | int win_main(int argc, char **argv) |
692 | 4294 | #else | 4340 | #else |
693 | @@ -4579,6 +4625,7 @@ | |||
694 | 4579 | */ | 4625 | */ |
695 | 4580 | error_handler_hook= my_message_sql; | 4626 | error_handler_hook= my_message_sql; |
696 | 4581 | start_signal_handler(); // Creates pidfile | 4627 | start_signal_handler(); // Creates pidfile |
697 | 4628 | start_sql_timeout_thread(); | ||
698 | 4582 | 4629 | ||
699 | 4583 | if (mysql_rm_tmp_tables() || acl_init(opt_noacl) || | 4630 | if (mysql_rm_tmp_tables() || acl_init(opt_noacl) || |
700 | 4584 | my_tz_init((THD *)0, default_tz_name, opt_bootstrap)) | 4631 | my_tz_init((THD *)0, default_tz_name, opt_bootstrap)) |
701 | @@ -7879,6 +7926,7 @@ | |||
702 | 7879 | key_LOCK_prepared_stmt_count, | 7926 | key_LOCK_prepared_stmt_count, |
703 | 7880 | key_LOCK_rpl_status, key_LOCK_server_started, key_LOCK_status, | 7927 | key_LOCK_rpl_status, key_LOCK_server_started, key_LOCK_status, |
704 | 7881 | key_LOCK_system_variables_hash, key_LOCK_table_share, key_LOCK_thd_data, | 7928 | key_LOCK_system_variables_hash, key_LOCK_table_share, key_LOCK_thd_data, |
705 | 7929 | key_LOCK_sql_timeout_monitor, | ||
706 | 7882 | key_LOCK_user_conn, key_LOCK_uuid_generator, key_LOG_LOCK_log, | 7930 | key_LOCK_user_conn, key_LOCK_uuid_generator, key_LOG_LOCK_log, |
707 | 7883 | key_master_info_data_lock, key_master_info_run_lock, | 7931 | key_master_info_data_lock, key_master_info_run_lock, |
708 | 7884 | key_master_info_sleep_lock, | 7932 | key_master_info_sleep_lock, |
709 | @@ -7931,6 +7979,9 @@ | |||
710 | 7931 | { &key_LOCK_prepared_stmt_count, "LOCK_prepared_stmt_count", PSI_FLAG_GLOBAL}, | 7979 | { &key_LOCK_prepared_stmt_count, "LOCK_prepared_stmt_count", PSI_FLAG_GLOBAL}, |
711 | 7932 | { &key_LOCK_rpl_status, "LOCK_rpl_status", PSI_FLAG_GLOBAL}, | 7980 | { &key_LOCK_rpl_status, "LOCK_rpl_status", PSI_FLAG_GLOBAL}, |
712 | 7933 | { &key_LOCK_server_started, "LOCK_server_started", PSI_FLAG_GLOBAL}, | 7981 | { &key_LOCK_server_started, "LOCK_server_started", PSI_FLAG_GLOBAL}, |
713 | 7982 | { &key_LOCK_sql_timeout_monitor, | ||
714 | 7983 | "Sql_timeout_monitor::LOCK_timeouts", | ||
715 | 7984 | PSI_FLAG_GLOBAL}, | ||
716 | 7934 | { &key_LOCK_status, "LOCK_status", PSI_FLAG_GLOBAL}, | 7985 | { &key_LOCK_status, "LOCK_status", PSI_FLAG_GLOBAL}, |
717 | 7935 | { &key_LOCK_system_variables_hash, "LOCK_system_variables_hash", PSI_FLAG_GLOBAL}, | 7986 | { &key_LOCK_system_variables_hash, "LOCK_system_variables_hash", PSI_FLAG_GLOBAL}, |
718 | 7936 | { &key_LOCK_table_share, "LOCK_table_share", PSI_FLAG_GLOBAL}, | 7987 | { &key_LOCK_table_share, "LOCK_table_share", PSI_FLAG_GLOBAL}, |
719 | @@ -7991,6 +8042,7 @@ | |||
720 | 7991 | key_COND_thread_count, key_COND_thread_cache, key_COND_flush_thread_cache; | 8042 | key_COND_thread_count, key_COND_thread_cache, key_COND_flush_thread_cache; |
721 | 7992 | PSI_cond_key key_RELAYLOG_update_cond; | 8043 | PSI_cond_key key_RELAYLOG_update_cond; |
722 | 7993 | PSI_cond_key key_COND_wakeup_ready, key_COND_queue_busy; | 8044 | PSI_cond_key key_COND_wakeup_ready, key_COND_queue_busy; |
723 | 8045 | PSI_cond_key key_COND_sql_timeout_monitor; | ||
724 | 7994 | 8046 | ||
725 | 7995 | static PSI_cond_info all_server_conds[]= | 8047 | static PSI_cond_info all_server_conds[]= |
726 | 7996 | { | 8048 | { |
727 | @@ -8010,6 +8062,9 @@ | |||
728 | 8010 | { &key_COND_queue_busy, "COND_queue_busy", PSI_FLAG_GLOBAL}, | 8062 | { &key_COND_queue_busy, "COND_queue_busy", PSI_FLAG_GLOBAL}, |
729 | 8011 | { &key_COND_rpl_status, "COND_rpl_status", PSI_FLAG_GLOBAL}, | 8063 | { &key_COND_rpl_status, "COND_rpl_status", PSI_FLAG_GLOBAL}, |
730 | 8012 | { &key_COND_server_started, "COND_server_started", PSI_FLAG_GLOBAL}, | 8064 | { &key_COND_server_started, "COND_server_started", PSI_FLAG_GLOBAL}, |
731 | 8065 | { &key_COND_sql_timeout_monitor, | ||
732 | 8066 | "Sql_timeout_monitor::COND_timeouts", | ||
733 | 8067 | PSI_FLAG_GLOBAL}, | ||
734 | 8013 | { &key_COND_wakeup_ready, "THD::COND_wakeup_ready", 0}, | 8068 | { &key_COND_wakeup_ready, "THD::COND_wakeup_ready", 0}, |
735 | 8014 | { &key_delayed_insert_cond, "Delayed_insert::cond", 0}, | 8069 | { &key_delayed_insert_cond, "Delayed_insert::cond", 0}, |
736 | 8015 | { &key_delayed_insert_cond_client, "Delayed_insert::cond_client", 0}, | 8070 | { &key_delayed_insert_cond_client, "Delayed_insert::cond_client", 0}, |
737 | @@ -8032,7 +8087,8 @@ | |||
738 | 8032 | 8087 | ||
739 | 8033 | PSI_thread_key key_thread_bootstrap, key_thread_delayed_insert, | 8088 | PSI_thread_key key_thread_bootstrap, key_thread_delayed_insert, |
740 | 8034 | key_thread_handle_manager, key_thread_main, | 8089 | key_thread_handle_manager, key_thread_main, |
742 | 8035 | key_thread_one_connection, key_thread_signal_hand; | 8090 | key_thread_one_connection, key_thread_signal_hand, |
743 | 8091 | key_thread_sql_timeout; | ||
744 | 8036 | 8092 | ||
745 | 8037 | static PSI_thread_info all_server_threads[]= | 8093 | static PSI_thread_info all_server_threads[]= |
746 | 8038 | { | 8094 | { |
747 | @@ -8057,7 +8113,8 @@ | |||
748 | 8057 | { &key_thread_handle_manager, "manager", PSI_FLAG_GLOBAL}, | 8113 | { &key_thread_handle_manager, "manager", PSI_FLAG_GLOBAL}, |
749 | 8058 | { &key_thread_main, "main", PSI_FLAG_GLOBAL}, | 8114 | { &key_thread_main, "main", PSI_FLAG_GLOBAL}, |
750 | 8059 | { &key_thread_one_connection, "one_connection", 0}, | 8115 | { &key_thread_one_connection, "one_connection", 0}, |
752 | 8060 | { &key_thread_signal_hand, "signal_handler", PSI_FLAG_GLOBAL} | 8116 | { &key_thread_signal_hand, "signal_handler", PSI_FLAG_GLOBAL}, |
753 | 8117 | { &key_thread_sql_timeout, "sql_timeout", PSI_FLAG_GLOBAL}, | ||
754 | 8061 | }; | 8118 | }; |
755 | 8062 | 8119 | ||
756 | 8063 | #ifdef HAVE_MMAP | 8120 | #ifdef HAVE_MMAP |
757 | 8064 | 8121 | ||
758 | === modified file 'Percona-Server/sql/mysqld.h' | |||
759 | --- Percona-Server/sql/mysqld.h 2012-04-19 16:51:34 +0000 | |||
760 | +++ Percona-Server/sql/mysqld.h 2012-04-26 09:57:20 +0000 | |||
761 | @@ -269,6 +269,7 @@ | |||
762 | 269 | key_LOCK_prepared_stmt_count, | 269 | key_LOCK_prepared_stmt_count, |
763 | 270 | key_LOCK_rpl_status, key_LOCK_server_started, key_LOCK_status, | 270 | key_LOCK_rpl_status, key_LOCK_server_started, key_LOCK_status, |
764 | 271 | key_LOCK_table_share, key_LOCK_thd_data, | 271 | key_LOCK_table_share, key_LOCK_thd_data, |
765 | 272 | key_LOCK_sql_timeout_monitor, | ||
766 | 272 | key_LOCK_user_conn, key_LOCK_uuid_generator, key_LOG_LOCK_log, | 273 | key_LOCK_user_conn, key_LOCK_uuid_generator, key_LOG_LOCK_log, |
767 | 273 | key_master_info_data_lock, key_master_info_run_lock, | 274 | key_master_info_data_lock, key_master_info_run_lock, |
768 | 274 | key_master_info_sleep_lock, | 275 | key_master_info_sleep_lock, |
769 | @@ -302,10 +303,13 @@ | |||
770 | 302 | key_COND_thread_count, key_COND_thread_cache, key_COND_flush_thread_cache; | 303 | key_COND_thread_count, key_COND_thread_cache, key_COND_flush_thread_cache; |
771 | 303 | extern PSI_cond_key key_RELAYLOG_update_cond; | 304 | extern PSI_cond_key key_RELAYLOG_update_cond; |
772 | 304 | extern PSI_cond_key key_COND_wakeup_ready, key_COND_queue_busy; | 305 | extern PSI_cond_key key_COND_wakeup_ready, key_COND_queue_busy; |
773 | 306 | extern PSI_cond_key key_COND_sql_timeout_monitor; | ||
774 | 307 | |||
775 | 305 | 308 | ||
776 | 306 | extern PSI_thread_key key_thread_bootstrap, key_thread_delayed_insert, | 309 | extern PSI_thread_key key_thread_bootstrap, key_thread_delayed_insert, |
777 | 307 | key_thread_handle_manager, key_thread_kill_server, key_thread_main, | 310 | key_thread_handle_manager, key_thread_kill_server, key_thread_main, |
779 | 308 | key_thread_one_connection, key_thread_signal_hand; | 311 | key_thread_one_connection, key_thread_signal_hand, |
780 | 312 | key_thread_sql_timeout; | ||
781 | 309 | 313 | ||
782 | 310 | #ifdef HAVE_MMAP | 314 | #ifdef HAVE_MMAP |
783 | 311 | extern PSI_file_key key_file_map; | 315 | extern PSI_file_key key_file_map; |
784 | 312 | 316 | ||
785 | === modified file 'Percona-Server/sql/sql_class.cc' | |||
786 | --- Percona-Server/sql/sql_class.cc 2012-04-19 16:51:34 +0000 | |||
787 | +++ Percona-Server/sql/sql_class.cc 2012-04-26 09:57:20 +0000 | |||
788 | @@ -60,6 +60,7 @@ | |||
789 | 60 | #include "debug_sync.h" | 60 | #include "debug_sync.h" |
790 | 61 | #include "sql_parse.h" // is_update_query | 61 | #include "sql_parse.h" // is_update_query |
791 | 62 | #include "sql_callback.h" | 62 | #include "sql_callback.h" |
792 | 63 | #include "sql_timeout.h" | ||
793 | 63 | 64 | ||
794 | 64 | /* | 65 | /* |
795 | 65 | The following is used to initialise Table_ident with a internal | 66 | The following is used to initialise Table_ident with a internal |
796 | @@ -871,6 +872,7 @@ | |||
797 | 871 | lex->current_select= 0; | 872 | lex->current_select= 0; |
798 | 872 | start_time=(time_t) 0; | 873 | start_time=(time_t) 0; |
799 | 873 | start_utime= prior_thr_create_utime= 0L; | 874 | start_utime= prior_thr_create_utime= 0L; |
800 | 875 | sql_timeout_expire= 0; | ||
801 | 874 | utime_after_lock= 0L; | 876 | utime_after_lock= 0L; |
802 | 875 | current_linfo = 0; | 877 | current_linfo = 0; |
803 | 876 | slave_thread = 0; | 878 | slave_thread = 0; |
804 | @@ -1490,6 +1492,9 @@ | |||
805 | 1490 | { | 1492 | { |
806 | 1491 | THD_CHECK_SENTRY(this); | 1493 | THD_CHECK_SENTRY(this); |
807 | 1492 | DBUG_ENTER("~THD()"); | 1494 | DBUG_ENTER("~THD()"); |
808 | 1495 | |||
809 | 1496 | sql_timeout_monitor.remove(this); | ||
810 | 1497 | |||
811 | 1493 | /* Ensure that no one is using THD */ | 1498 | /* Ensure that no one is using THD */ |
812 | 1494 | mysql_mutex_lock(&LOCK_thd_data); | 1499 | mysql_mutex_lock(&LOCK_thd_data); |
813 | 1495 | mysys_var=0; // Safety (shouldn't be needed) | 1500 | mysys_var=0; // Safety (shouldn't be needed) |
814 | 1496 | 1501 | ||
815 | === modified file 'Percona-Server/sql/sql_class.h' | |||
816 | --- Percona-Server/sql/sql_class.h 2012-04-18 23:26:38 +0000 | |||
817 | +++ Percona-Server/sql/sql_class.h 2012-04-26 09:57:20 +0000 | |||
818 | @@ -492,6 +492,7 @@ | |||
819 | 492 | ulong trans_prealloc_size; | 492 | ulong trans_prealloc_size; |
820 | 493 | ulong log_warnings; | 493 | ulong log_warnings; |
821 | 494 | ulong group_concat_max_len; | 494 | ulong group_concat_max_len; |
822 | 495 | ulong sql_timeout; | ||
823 | 495 | 496 | ||
824 | 496 | ulong binlog_format; ///< binlog format for this thd (see enum_binlog_format) | 497 | ulong binlog_format; ///< binlog format for this thd (see enum_binlog_format) |
825 | 497 | my_bool binlog_direct_non_trans_update; | 498 | my_bool binlog_direct_non_trans_update; |
826 | @@ -1653,6 +1654,11 @@ | |||
827 | 1653 | /* remote (peer) port */ | 1654 | /* remote (peer) port */ |
828 | 1654 | uint16 peer_port; | 1655 | uint16 peer_port; |
829 | 1655 | time_t start_time, user_time; | 1656 | time_t start_time, user_time; |
830 | 1657 | /* | ||
831 | 1658 | Expire time in microseconds for sql_timeout monitor thread. The 0 value | ||
832 | 1659 | means the current thread is not monitored by sql_timeout monitor. | ||
833 | 1660 | */ | ||
834 | 1661 | ulonglong sql_timeout_expire; | ||
835 | 1656 | // track down slow pthread_create | 1662 | // track down slow pthread_create |
836 | 1657 | ulonglong prior_thr_create_utime, thr_create_utime; | 1663 | ulonglong prior_thr_create_utime, thr_create_utime; |
837 | 1658 | ulonglong start_utime, utime_after_lock; | 1664 | ulonglong start_utime, utime_after_lock; |
838 | 1659 | 1665 | ||
839 | === modified file 'Percona-Server/sql/sql_parse.cc' | |||
840 | --- Percona-Server/sql/sql_parse.cc 2012-04-19 16:51:34 +0000 | |||
841 | +++ Percona-Server/sql/sql_parse.cc 2012-04-26 09:57:20 +0000 | |||
842 | @@ -95,6 +95,7 @@ | |||
843 | 95 | #include "debug_sync.h" | 95 | #include "debug_sync.h" |
844 | 96 | #include "probes_mysql.h" | 96 | #include "probes_mysql.h" |
845 | 97 | #include "set_var.h" | 97 | #include "set_var.h" |
846 | 98 | #include "sql_timeout.h" | ||
847 | 98 | 99 | ||
848 | 99 | #define FLAGSTR(V,F) ((V)&(F)?#F" ":"") | 100 | #define FLAGSTR(V,F) ((V)&(F)?#F" ":"") |
849 | 100 | 101 | ||
850 | @@ -5801,7 +5802,9 @@ | |||
851 | 5801 | (char *) thd->security_ctx->host_or_ip, | 5802 | (char *) thd->security_ctx->host_or_ip, |
852 | 5802 | 0); | 5803 | 0); |
853 | 5803 | 5804 | ||
854 | 5805 | sql_timeout_monitor.add(thd); | ||
855 | 5804 | error= mysql_execute_command(thd); | 5806 | error= mysql_execute_command(thd); |
856 | 5807 | sql_timeout_monitor.remove(thd); | ||
857 | 5805 | MYSQL_QUERY_EXEC_DONE(error); | 5808 | MYSQL_QUERY_EXEC_DONE(error); |
858 | 5806 | } | 5809 | } |
859 | 5807 | } | 5810 | } |
860 | 5808 | 5811 | ||
861 | === added file 'Percona-Server/sql/sql_timeout.cc' | |||
862 | --- Percona-Server/sql/sql_timeout.cc 1970-01-01 00:00:00 +0000 | |||
863 | +++ Percona-Server/sql/sql_timeout.cc 2012-04-26 09:57:20 +0000 | |||
864 | @@ -0,0 +1,228 @@ | |||
865 | 1 | #include "sql_timeout.h" | ||
866 | 2 | #include "my_sys.h" | ||
867 | 3 | #include "mysqld.h" | ||
868 | 4 | |||
869 | 5 | #define INITIAL_QUEUE_SIZE 1000 | ||
870 | 6 | |||
871 | 7 | /** | ||
872 | 8 | Is used in priority queue to compare THDs by expire time. | ||
873 | 9 | */ | ||
874 | 10 | |||
875 | 11 | static int compare_thd(void *not_used __attribute__((unused)), | ||
876 | 12 | uchar *a_ptr,uchar* b_ptr) | ||
877 | 13 | { | ||
878 | 14 | ulonglong a= ((THD *) a_ptr)->sql_timeout_expire; | ||
879 | 15 | ulonglong b= ((THD *) b_ptr)->sql_timeout_expire; | ||
880 | 16 | return (a < b) ? -1 : (a == b) ? 0 : 1; | ||
881 | 17 | } | ||
882 | 18 | |||
883 | 19 | |||
884 | 20 | /** | ||
885 | 21 | Initialize SQL_TIMEOUT monitor. | ||
886 | 22 | |||
887 | 23 | @note This function must be called before any actions with monitor. | ||
888 | 24 | */ | ||
889 | 25 | |||
890 | 26 | void Sql_timeout_monitor::init() | ||
891 | 27 | { | ||
892 | 28 | need_to_exit= false; | ||
893 | 29 | completed= true; | ||
894 | 30 | mysql_mutex_init(key_LOCK_sql_timeout_monitor, | ||
895 | 31 | &LOCK_queue, | ||
896 | 32 | MY_MUTEX_INIT_FAST); | ||
897 | 33 | mysql_cond_init(key_COND_sql_timeout_monitor, &COND_queue, NULL); | ||
898 | 34 | /* | ||
899 | 35 | THD is not POD type. Thats why offsetof(...) is not used here to get | ||
900 | 36 | priority member offset for the queue. The 0 offset is passed as an | ||
901 | 37 | argument but compare_thd(...) function does properly comparison. | ||
902 | 38 | */ | ||
903 | 39 | init_queue_ex(&queue, INITIAL_QUEUE_SIZE + 1, 0, 0, | ||
904 | 40 | compare_thd, NULL, INITIAL_QUEUE_SIZE + 1); | ||
905 | 41 | } | ||
906 | 42 | |||
907 | 43 | |||
908 | 44 | /** | ||
909 | 45 | Deinitialize SQL_TIMEOUT monitor. | ||
910 | 46 | |||
911 | 47 | Clean up and destroy all monitor data. | ||
912 | 48 | */ | ||
913 | 49 | |||
914 | 50 | void Sql_timeout_monitor::deinit() | ||
915 | 51 | { | ||
916 | 52 | mysql_mutex_lock(&LOCK_queue); | ||
917 | 53 | for (size_t i= 0; i < queue.elements; ++i) | ||
918 | 54 | ((THD *)queue_element(&queue, i))->sql_timeout_expire= 0; | ||
919 | 55 | queue_remove_all(&queue); | ||
920 | 56 | delete_queue(&queue); | ||
921 | 57 | mysql_mutex_unlock(&LOCK_queue); | ||
922 | 58 | mysql_cond_destroy(&COND_queue); | ||
923 | 59 | mysql_mutex_destroy(&LOCK_queue); | ||
924 | 60 | } | ||
925 | 61 | |||
926 | 62 | |||
927 | 63 | /** | ||
928 | 64 | SQL_TIMEOUT monitor loop. | ||
929 | 65 | |||
930 | 66 | If thread wants to be monitored it must add itself to the monitor | ||
931 | 67 | before query execution and remove after. The monitor holds all | ||
932 | 68 | threads in prority queue. The priority is an expiration time of | ||
933 | 69 | query execution. The monitor idles till the top expiration time | ||
934 | 70 | in the queue. Then it kills all theads with expired execution time. | ||
935 | 71 | If there are no threads in the queue the monitor thread completely | ||
936 | 72 | idles. | ||
937 | 73 | |||
938 | 74 | This function must be invoked in a separate thread. To exit from | ||
939 | 75 | this function Sql_timeout_monitor::exit() must be called. | ||
940 | 76 | */ | ||
941 | 77 | |||
942 | 78 | void Sql_timeout_monitor::monitor() | ||
943 | 79 | { | ||
944 | 80 | completed= false; | ||
945 | 81 | |||
946 | 82 | /* Signal monitor is started */ | ||
947 | 83 | mysql_mutex_lock(&LOCK_thread_count); | ||
948 | 84 | mysql_mutex_unlock(&LOCK_thread_count); | ||
949 | 85 | mysql_cond_broadcast(&COND_thread_count); | ||
950 | 86 | |||
951 | 87 | mysql_mutex_lock(&LOCK_queue); | ||
952 | 88 | while (!need_to_exit) | ||
953 | 89 | { | ||
954 | 90 | int error= 0; | ||
955 | 91 | |||
956 | 92 | if (queue.elements) | ||
957 | 93 | { | ||
958 | 94 | THD *thd; | ||
959 | 95 | ulonglong sleep_time; | ||
960 | 96 | struct timespec abstime; | ||
961 | 97 | ulonglong now= my_micro_time(); | ||
962 | 98 | |||
963 | 99 | while ( (thd= (THD *) queue_top(&queue))->sql_timeout_expire <= now) | ||
964 | 100 | { | ||
965 | 101 | mysql_mutex_lock(&thd->LOCK_thd_data); | ||
966 | 102 | thd->awake(THD::KILL_QUERY); | ||
967 | 103 | mysql_mutex_unlock(&thd->LOCK_thd_data); | ||
968 | 104 | queue_remove(&queue, 0); | ||
969 | 105 | /* | ||
970 | 106 | Mark the thread as removed from SQL_TIMEOUT monitor. | ||
971 | 107 | So there is no need to remove it in | ||
972 | 108 | Sql_timeout_monitor::remove(THD *thd) | ||
973 | 109 | after query execution. | ||
974 | 110 | */ | ||
975 | 111 | thd->sql_timeout_expire= 0; | ||
976 | 112 | if (!queue.elements) | ||
977 | 113 | break; | ||
978 | 114 | } | ||
979 | 115 | |||
980 | 116 | if (!queue.elements) | ||
981 | 117 | continue; | ||
982 | 118 | |||
983 | 119 | sleep_time= thd->sql_timeout_expire - now; | ||
984 | 120 | set_timespec_nsec(abstime, sleep_time); | ||
985 | 121 | error= mysql_cond_timedwait(&COND_queue, &LOCK_queue, &abstime); | ||
986 | 122 | } | ||
987 | 123 | else | ||
988 | 124 | error= mysql_cond_wait(&COND_queue, &LOCK_queue); | ||
989 | 125 | |||
990 | 126 | if (error && error != EINTR && error != ETIMEDOUT && error != ETIME) | ||
991 | 127 | { | ||
992 | 128 | if (!shutdown_in_progress && !abort_loop) | ||
993 | 129 | sql_print_error("The error %d (%s)occured on wait condition variable " | ||
994 | 130 | "in sql_timeout monitor. Exit thread.", | ||
995 | 131 | error, strerror((ulong)error)); | ||
996 | 132 | break; | ||
997 | 133 | } | ||
998 | 134 | } | ||
999 | 135 | |||
1000 | 136 | mysql_mutex_unlock(&LOCK_queue); | ||
1001 | 137 | completed= true; | ||
1002 | 138 | } | ||
1003 | 139 | |||
1004 | 140 | |||
1005 | 141 | /** | ||
1006 | 142 | Add connection thread to the SQL_TIMEOUT monitor. | ||
1007 | 143 | |||
1008 | 144 | Add connection thread to the SQL_TIMEOUT monitor. | ||
1009 | 145 | Do nothing if SQL_TIMEOUT is 0 or the thread has already | ||
1010 | 146 | added. | ||
1011 | 147 | |||
1012 | 148 | @param thd pointer to the thread to add | ||
1013 | 149 | */ | ||
1014 | 150 | |||
1015 | 151 | void Sql_timeout_monitor::add(THD *thd) | ||
1016 | 152 | { | ||
1017 | 153 | DBUG_ASSERT(thd); | ||
1018 | 154 | |||
1019 | 155 | ulong timeout= thd->variables.sql_timeout; | ||
1020 | 156 | |||
1021 | 157 | if (thd->sql_timeout_expire || !timeout) | ||
1022 | 158 | return; | ||
1023 | 159 | |||
1024 | 160 | mysql_mutex_lock(&LOCK_queue); | ||
1025 | 161 | thd->sql_timeout_expire= my_micro_time() + (ulonglong)timeout*1000000; | ||
1026 | 162 | |||
1027 | 163 | if (queue_insert_safe(&queue, (uchar *)thd)) | ||
1028 | 164 | { | ||
1029 | 165 | thd->sql_timeout_expire= 0; | ||
1030 | 166 | sql_print_error("The memory is not enough to put the query into " | ||
1031 | 167 | "SQL_TIMEOUT queue"); | ||
1032 | 168 | } | ||
1033 | 169 | else | ||
1034 | 170 | mysql_cond_broadcast(&COND_queue); | ||
1035 | 171 | |||
1036 | 172 | mysql_mutex_unlock(&LOCK_queue); | ||
1037 | 173 | } | ||
1038 | 174 | |||
1039 | 175 | |||
1040 | 176 | |||
1041 | 177 | /** | ||
1042 | 178 | Remove connection thread from the SQL_TIMEOUT monitor. | ||
1043 | 179 | |||
1044 | 180 | Remove connection thread from the SQL_TIMEOUT monitor. | ||
1045 | 181 | Do nothing if the thread is not added. | ||
1046 | 182 | |||
1047 | 183 | @param thd pointer to the thread to remove | ||
1048 | 184 | */ | ||
1049 | 185 | |||
1050 | 186 | void Sql_timeout_monitor::remove(THD *thd) | ||
1051 | 187 | { | ||
1052 | 188 | size_t i; | ||
1053 | 189 | |||
1054 | 190 | DBUG_ASSERT(thd); | ||
1055 | 191 | |||
1056 | 192 | if (!thd->sql_timeout_expire) | ||
1057 | 193 | return; | ||
1058 | 194 | |||
1059 | 195 | mysql_mutex_lock(&LOCK_queue); | ||
1060 | 196 | |||
1061 | 197 | for (i= 0; i < queue.elements; ++i) | ||
1062 | 198 | if (((THD *) queue_element(&queue, i)) == thd) | ||
1063 | 199 | break; | ||
1064 | 200 | /* | ||
1065 | 201 | It may be deleted in monitor thread between thd->sql_timeout_expire == 0 | ||
1066 | 202 | condition checking and mutex locking in current thread. | ||
1067 | 203 | */ | ||
1068 | 204 | if (i < queue.elements) | ||
1069 | 205 | queue_remove(&queue, i); | ||
1070 | 206 | |||
1071 | 207 | thd->sql_timeout_expire= 0; | ||
1072 | 208 | |||
1073 | 209 | mysql_mutex_unlock(&LOCK_queue); | ||
1074 | 210 | } | ||
1075 | 211 | |||
1076 | 212 | |||
1077 | 213 | /** | ||
1078 | 214 | Signal to the monitor thread to exit . | ||
1079 | 215 | */ | ||
1080 | 216 | |||
1081 | 217 | void Sql_timeout_monitor::exit() | ||
1082 | 218 | { | ||
1083 | 219 | need_to_exit= true; | ||
1084 | 220 | if (completed) | ||
1085 | 221 | return; | ||
1086 | 222 | mysql_mutex_lock(&LOCK_queue); | ||
1087 | 223 | mysql_cond_broadcast(&COND_queue); | ||
1088 | 224 | mysql_mutex_unlock(&LOCK_queue); | ||
1089 | 225 | } | ||
1090 | 226 | |||
1091 | 227 | /* The global SQL_TIMEOUT monitor object */ | ||
1092 | 228 | Sql_timeout_monitor sql_timeout_monitor; | ||
1093 | 0 | 229 | ||
1094 | === added file 'Percona-Server/sql/sql_timeout.h' | |||
1095 | --- Percona-Server/sql/sql_timeout.h 1970-01-01 00:00:00 +0000 | |||
1096 | +++ Percona-Server/sql/sql_timeout.h 2012-04-26 09:57:20 +0000 | |||
1097 | @@ -0,0 +1,55 @@ | |||
1098 | 1 | #ifndef SQL_TIMEOUT_INCLUDED | ||
1099 | 2 | #define SQL_TIMEOUT_INCLUDED | ||
1100 | 3 | #include "sql_class.h" | ||
1101 | 4 | #include "my_pthread.h" | ||
1102 | 5 | #include "queues.h" | ||
1103 | 6 | #include "hash.h" | ||
1104 | 7 | |||
1105 | 8 | /** | ||
1106 | 9 | @class Sql_timeout_monitor | ||
1107 | 10 | The class to monitor threads for query execution time | ||
1108 | 11 | in case of SQL_TIMEOUT session variable is set. | ||
1109 | 12 | |||
1110 | 13 | EXAMPLE | ||
1111 | 14 | @verbatim | ||
1112 | 15 | SET @@SESSION.SQL_TIMEOUT=5; | ||
1113 | 16 | SELECT SLEEP(10); | ||
1114 | 17 | @endverbatim | ||
1115 | 18 | */ | ||
1116 | 19 | |||
1117 | 20 | class Sql_timeout_monitor | ||
1118 | 21 | { | ||
1119 | 22 | public: | ||
1120 | 23 | void init(); | ||
1121 | 24 | void deinit(); | ||
1122 | 25 | |||
1123 | 26 | void monitor(); | ||
1124 | 27 | void add(THD *thd); | ||
1125 | 28 | void remove(THD *thd); | ||
1126 | 29 | void exit(); | ||
1127 | 30 | |||
1128 | 31 | private: | ||
1129 | 32 | int find(THD *thd); | ||
1130 | 33 | /* Is locked during work with queue. */ | ||
1131 | 34 | mysql_mutex_t LOCK_queue; | ||
1132 | 35 | /* | ||
1133 | 36 | Condition variable to wake up monitor | ||
1134 | 37 | thread when item is added to the queue | ||
1135 | 38 | or exit from monitor() function | ||
1136 | 39 | is requered. | ||
1137 | 40 | */ | ||
1138 | 41 | mysql_cond_t COND_queue; | ||
1139 | 42 | /* | ||
1140 | 43 | The flag for notifying the monitor thread | ||
1141 | 44 | about exit is requred. | ||
1142 | 45 | */ | ||
1143 | 46 | volatile bool need_to_exit; | ||
1144 | 47 | /* Shows that monitor thread is completed. */ | ||
1145 | 48 | volatile bool completed; | ||
1146 | 49 | /* Priority queue of Sql_timeout_info objects */ | ||
1147 | 50 | QUEUE queue; | ||
1148 | 51 | }; | ||
1149 | 52 | |||
1150 | 53 | /* The global SQL_TIMEOUT monitor object */ | ||
1151 | 54 | extern Sql_timeout_monitor sql_timeout_monitor; | ||
1152 | 55 | #endif /* SQL_TIMEOUT_INCLUDED */ | ||
1153 | 0 | 56 | ||
1154 | === modified file 'Percona-Server/sql/sys_vars.cc' | |||
1155 | --- Percona-Server/sql/sys_vars.cc 2012-04-19 16:51:34 +0000 | |||
1156 | +++ Percona-Server/sql/sys_vars.cc 2012-04-26 09:57:20 +0000 | |||
1157 | @@ -2825,6 +2825,12 @@ | |||
1158 | 2825 | SESSION_VAR(group_concat_max_len), CMD_LINE(REQUIRED_ARG), | 2825 | SESSION_VAR(group_concat_max_len), CMD_LINE(REQUIRED_ARG), |
1159 | 2826 | VALID_RANGE(4, ULONG_MAX), DEFAULT(1024), BLOCK_SIZE(1)); | 2826 | VALID_RANGE(4, ULONG_MAX), DEFAULT(1024), BLOCK_SIZE(1)); |
1160 | 2827 | 2827 | ||
1161 | 2828 | static Sys_var_ulong Sys_sql_timeout( | ||
1162 | 2829 | "sql_timeout", | ||
1163 | 2830 | "Timeout in seconds to wait before killing query.", | ||
1164 | 2831 | SESSION_VAR(sql_timeout), CMD_LINE(REQUIRED_ARG), | ||
1165 | 2832 | VALID_RANGE(0, ULONG_MAX), DEFAULT(0), BLOCK_SIZE(1)); | ||
1166 | 2833 | |||
1167 | 2828 | static char *glob_hostname_ptr; | 2834 | static char *glob_hostname_ptr; |
1168 | 2829 | static Sys_var_charptr Sys_hostname( | 2835 | static Sys_var_charptr Sys_hostname( |
1169 | 2830 | "hostname", "Server host name", | 2836 | "hostname", "Server host name", |
The name of option should be the same in all case.
If it is:
SET SESSION SQL_TIMEOUT = 100;
Then it should be:
SELECT SLEEP(20) /*! SQL_TIMEOUT = 10 */;