Merge lp:~vlad-lesin/percona-server/5.6-sql_timeout into lp:percona-server/5.6

Proposed by Vlad Lesin on 2013-01-09
Status: Work in progress
Proposed branch: lp:~vlad-lesin/percona-server/5.6-sql_timeout
Merge into: lp:percona-server/5.6
Diff against target: 3089 lines (+857/-266)
61 files modified
Percona-Server/mysql-test/r/mysqld--help-notwin.result (+2/-0)
Percona-Server/mysql-test/r/percona_sql_timeout.result (+120/-0)
Percona-Server/mysql-test/suite/sys_vars/r/sql_timeout_basic.result (+151/-0)
Percona-Server/mysql-test/suite/sys_vars/t/sql_timeout_basic.test (+194/-0)
Percona-Server/mysql-test/t/percona_sql_timeout.test (+82/-0)
Percona-Server/sql/binlog.cc (+3/-3)
Percona-Server/sql/debug_sync.cc (+12/-12)
Percona-Server/sql/event_queue.cc (+3/-3)
Percona-Server/sql/event_scheduler.cc (+1/-1)
Percona-Server/sql/filesort.cc (+4/-7)
Percona-Server/sql/ha_ndbcluster.cc (+12/-12)
Percona-Server/sql/ha_ndbcluster_binlog.cc (+14/-14)
Percona-Server/sql/handler.cc (+5/-5)
Percona-Server/sql/item_func.cc (+10/-5)
Percona-Server/sql/item_subselect.cc (+1/-1)
Percona-Server/sql/lock.cc (+2/-2)
Percona-Server/sql/log.cc (+2/-2)
Percona-Server/sql/log_event.cc (+1/-1)
Percona-Server/sql/mysqld.cc (+2/-2)
Percona-Server/sql/opt_range.cc (+1/-1)
Percona-Server/sql/records.cc (+3/-3)
Percona-Server/sql/rpl_gtid_execution.cc (+2/-2)
Percona-Server/sql/rpl_gtid_state.cc (+1/-1)
Percona-Server/sql/rpl_master.cc (+2/-2)
Percona-Server/sql/rpl_rli.cc (+5/-5)
Percona-Server/sql/rpl_rli_pdb.cc (+9/-9)
Percona-Server/sql/rpl_slave.cc (+9/-9)
Percona-Server/sql/signal_handler.cc (+1/-1)
Percona-Server/sql/sp.cc (+2/-2)
Percona-Server/sql/sp_head.cc (+6/-6)
Percona-Server/sql/sp_instr.cc (+1/-1)
Percona-Server/sql/sp_rcontext.cc (+1/-1)
Percona-Server/sql/sql_admin.cc (+1/-1)
Percona-Server/sql/sql_base.cc (+5/-5)
Percona-Server/sql/sql_cache.cc (+2/-2)
Percona-Server/sql/sql_class.cc (+15/-14)
Percona-Server/sql/sql_class.h (+31/-4)
Percona-Server/sql/sql_connect.cc (+4/-4)
Percona-Server/sql/sql_db.cc (+5/-5)
Percona-Server/sql/sql_delete.cc (+8/-8)
Percona-Server/sql/sql_executor.cc (+12/-12)
Percona-Server/sql/sql_insert.cc (+27/-27)
Percona-Server/sql/sql_join_buffer.cc (+4/-4)
Percona-Server/sql/sql_load.cc (+9/-9)
Percona-Server/sql/sql_optimizer.cc (+2/-2)
Percona-Server/sql/sql_parse.cc (+20/-12)
Percona-Server/sql/sql_planner.cc (+2/-2)
Percona-Server/sql/sql_prepare.cc (+1/-1)
Percona-Server/sql/sql_reload.cc (+2/-2)
Percona-Server/sql/sql_servers.cc (+3/-3)
Percona-Server/sql/sql_show.cc (+5/-5)
Percona-Server/sql/sql_table.cc (+3/-3)
Percona-Server/sql/sql_update.cc (+8/-8)
Percona-Server/sql/sys_vars.cc (+6/-0)
Percona-Server/sql/table.cc (+1/-1)
Percona-Server/storage/innobase/row/row0mysql.cc (+1/-1)
Percona-Server/storage/myisam/ha_myisam.cc (+6/-6)
Percona-Server/storage/myisam/mi_check.c (+5/-5)
Percona-Server/storage/myisam/myisamchk.c (+2/-4)
Percona-Server/storage/myisam/myisamdef.h (+1/-1)
Percona-Server/storage/myisam/sort.c (+2/-2)
To merge this branch: bzr merge lp:~vlad-lesin/percona-server/5.6-sql_timeout
Reviewer Review Type Date Requested Status
Alexey Kopytov (community) 2013-01-09 Needs Fixing on 2013-01-21
Review via email: mp+142497@code.launchpad.net

Description of the change

New system variable "SQL_TIMEOUT" allows to set limit for query execution time.
If this limit is exceeded the query is killed. SQL_TIMEOUT can be global or
session variable.

The timeout expiration is checked on each db-thread killed state check. If timeout
expires the function that returns thread killed status will return the value which
corresponds to "killed query" status.

Jenkins: http://jenkins.percona.com/view/PS%205.6/job/percona-server-5.6-param/19
Clean 5.6: http://jenkins.percona.com/view/PS%205.6/job/percona-server-5.6-param/20

There can be some issues during merging as THD::killed was renamed to THD::killed_status and became private. But there are getter THD::get_killed() and setter THD::set_killed() which can be used to resolve issues if some new code work with THD::killed.

To post a comment you must log in.
311. By Vlad Lesin on 2013-01-09

New system variable "SQL_TIMEOUT" allows to set limit for query execution time.
If this limit is exceeded the query is killed. SQL_TIMEOUT can be global or
session variable.

The timeout expiration is checked on each db-thread killed state check. If timeout
expires the function that returns thread killed status will return the value which
corresponds to "killed query" status.

Vlad Lesin (vlad-lesin) wrote :

Failed perfschema.threads_mysql test is fixed now.

Alexey Kopytov (akopytov) wrote :

Vlad,

  - generally I would use check_killed() instead of get_killed(). yes,
    that would be a bit inconsistent naming with set_killed(), but that
    would also make porting APC easier, should we need to do so.
  - mysqld--help-win.result also needs an adjustment
  - setting sql_timeout_expire in mysql_parse() prevents the feature
    from working with client API prepared statements. this check should
    be done in dispatch_command()
  - doing it in dispatch_command() will also make statement-based
    replication immune to sql_timeout. which is good.
  - many lines use tabs for indentation. you can get them with the
    following command:

  bzr diff -c-1 | grep "+\t"

  - changes in merge_buffers() in filesort.cc break the logic it used
    previously, i.e. check the killed state on each iteration in the
    "while" loop, unless param->not_killable is set.

    What we do now is: check the killed state before executing the loop,
    reset it if param->not_killable is set, then check the same value
    inside the loop. See how that code has been changed in MariaDB to
    support APC.

  - same problem as above in storage/myisam/sort.c

  - in Interruptible_wait::wait() we check for the killed status, but
    only after waiting for the full timeout value, which means up to 5
    seconds. Why not do a similar check as with the m_abs_timeout? In
    this case you don't even need a call to m_thd->get_killed() as it
    will be checked by the caller.

  - another problem from the above code is that checking get_killed()
    and resetting the error in Interruptible_wait::wait() returns a
    normal status to the user. I.e. SELECT SLEEP(N) should fail "ERROR
    1317 (70100): Query execution was interrupted" when the timeout is
    exceeded, but it doesn't. Same with user-level locks.

  - in get_killed(), I'd rewrite it like this to not rely on how smart
    is the compiler:

    if (!sql_timeout_expire)
      return killed_status;
    return (my_micro_time() >= sql_timeout_expire) ? THD::KILL_QUERY :
                                                     killed_status;

  - I wonder if we really need my_micro_time() for this. my_time() has
    1 second resolution (which is sufficient in this case) and is also
    faster.

  - in MyISAM code, I would use thd_killed() and keep the killed_ptr()
    name in the same way it is implemented in MariaDB.

review: Needs Fixing
Alexey Kopytov (akopytov) wrote :

Vlad,

Please also update the BP. It should contain everything Hrvoje needs to know to document the feature.

Unmerged revisions

311. By Vlad Lesin on 2013-01-09

New system variable "SQL_TIMEOUT" allows to set limit for query execution time.
If this limit is exceeded the query is killed. SQL_TIMEOUT can be global or
session variable.

The timeout expiration is checked on each db-thread killed state check. If timeout
expires the function that returns thread killed status will return the value which
corresponds to "killed query" status.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'Percona-Server/mysql-test/r/mysqld--help-notwin.result'
2--- Percona-Server/mysql-test/r/mysqld--help-notwin.result 2012-12-04 08:24:59 +0000
3+++ Percona-Server/mysql-test/r/mysqld--help-notwin.result 2013-01-09 13:41:38 +0000
4@@ -894,6 +894,7 @@
5 replication.
6 --sql-mode=name Syntax: sql-mode=mode[,mode[,mode...]]. See the manual
7 for the complete list of valid sql modes
8+ --sql-timeout=# Timeout in seconds to wait before killing query.
9 --stored-program-cache=#
10 The soft upper limit for number of cached stored routines
11 for one connection.
12@@ -1233,6 +1234,7 @@
13 sort-buffer-size 262144
14 sporadic-binlog-dump-fail FALSE
15 sql-mode NO_ENGINE_SUBSTITUTION
16+sql-timeout 0
17 stored-program-cache 256
18 symbolic-links FALSE
19 sync-binlog 0
20
21=== added file 'Percona-Server/mysql-test/r/percona_sql_timeout.result'
22--- Percona-Server/mysql-test/r/percona_sql_timeout.result 1970-01-01 00:00:00 +0000
23+++ Percona-Server/mysql-test/r/percona_sql_timeout.result 2013-01-09 13:41:38 +0000
24@@ -0,0 +1,120 @@
25+SLEEP(1)
26+0
27+SLEEP(1000)
28+1
29+SLEEP(2)
30+0
31+SLEEP(1)
32+0
33+SLEEP(1000)
34+1
35+SLEEP(2)
36+0
37+SLEEP(1)
38+0
39+SLEEP(1000)
40+1
41+SLEEP(2)
42+0
43+SLEEP(1)
44+0
45+SLEEP(1000)
46+1
47+SLEEP(2)
48+0
49+SLEEP(1)
50+0
51+SLEEP(1000)
52+1
53+SLEEP(2)
54+0
55+SLEEP(1)
56+0
57+SLEEP(1000)
58+1
59+SLEEP(2)
60+0
61+SLEEP(1)
62+0
63+SLEEP(1000)
64+1
65+SLEEP(2)
66+0
67+SLEEP(1)
68+0
69+SLEEP(1000)
70+1
71+SLEEP(2)
72+0
73+SLEEP(1)
74+0
75+SLEEP(1000)
76+1
77+SLEEP(2)
78+0
79+SLEEP(1)
80+0
81+SLEEP(1000)
82+1
83+SLEEP(2)
84+0
85+SLEEP(1)
86+0
87+SLEEP(1000)
88+1
89+SLEEP(2)
90+0
91+SLEEP(1)
92+0
93+SLEEP(1000)
94+1
95+SLEEP(2)
96+0
97+SLEEP(1)
98+0
99+SLEEP(1000)
100+1
101+SLEEP(2)
102+0
103+SLEEP(1)
104+0
105+SLEEP(1000)
106+1
107+SLEEP(2)
108+0
109+SLEEP(1)
110+0
111+SLEEP(1000)
112+1
113+SLEEP(2)
114+0
115+SLEEP(1)
116+0
117+SLEEP(1000)
118+1
119+SLEEP(2)
120+0
121+SLEEP(1)
122+0
123+SLEEP(1000)
124+1
125+SLEEP(2)
126+0
127+SLEEP(1)
128+0
129+SLEEP(1000)
130+1
131+SLEEP(2)
132+0
133+SLEEP(1)
134+0
135+SLEEP(1000)
136+1
137+SLEEP(2)
138+0
139+SLEEP(1)
140+0
141+SLEEP(1000)
142+1
143+SLEEP(2)
144+0
145
146=== added file 'Percona-Server/mysql-test/suite/sys_vars/r/sql_timeout_basic.result'
147--- Percona-Server/mysql-test/suite/sys_vars/r/sql_timeout_basic.result 1970-01-01 00:00:00 +0000
148+++ Percona-Server/mysql-test/suite/sys_vars/r/sql_timeout_basic.result 2013-01-09 13:41:38 +0000
149@@ -0,0 +1,151 @@
150+SET @start_global_value = @@global.sql_timeout;
151+SELECT @start_global_value;
152+@start_global_value
153+0
154+SET @start_session_value = @@session.sql_timeout;
155+SELECT @start_session_value;
156+@start_session_value
157+0
158+'#--------------------FN_DYNVARS_083_01-------------------------#'
159+SET @@global.sql_timeout = 100;
160+SET @@global.sql_timeout = DEFAULT;
161+SELECT @@global.sql_timeout;
162+@@global.sql_timeout
163+0
164+SET @@session.sql_timeout = 200;
165+SET @@session.sql_timeout = DEFAULT;
166+SELECT @@session.sql_timeout;
167+@@session.sql_timeout
168+0
169+'#--------------------FN_DYNVARS_083_03-------------------------#'
170+SET @@global.sql_timeout = 100;
171+SELECT @@global.sql_timeout;
172+@@global.sql_timeout
173+100
174+SET @@global.sql_timeout = 200;
175+SELECT @@global.sql_timeout;
176+@@global.sql_timeout
177+200
178+SET @@global.sql_timeout = 65536;
179+SELECT @@global.sql_timeout;
180+@@global.sql_timeout
181+65536
182+SET @@global.sql_timeout = 4294967295;
183+SELECT @@global.sql_timeout;
184+@@global.sql_timeout
185+4294967295
186+SET @@global.sql_timeout = 4294967294;
187+SELECT @@global.sql_timeout;
188+@@global.sql_timeout
189+4294967294
190+'#--------------------FN_DYNVARS_083_04-------------------------#'
191+SET @@session.sql_timeout = 100;
192+SELECT @@session.sql_timeout;
193+@@session.sql_timeout
194+100
195+SET @@session.sql_timeout = 200;
196+SELECT @@session.sql_timeout;
197+@@session.sql_timeout
198+200
199+SET @@session.sql_timeout = 4294967295;
200+SELECT @@session.sql_timeout;
201+@@session.sql_timeout
202+4294967295
203+SET @@session.sql_timeout = 4294967294;
204+SELECT @@session.sql_timeout;
205+@@session.sql_timeout
206+4294967294
207+SET @@session.sql_timeout = 65535;
208+SELECT @@session.sql_timeout;
209+@@session.sql_timeout
210+65535
211+'#------------------FN_DYNVARS_083_05-----------------------#'
212+SET @@global.sql_timeout = 0;
213+SELECT @@global.sql_timeout;
214+@@global.sql_timeout
215+0
216+SET @@global.sql_timeout = -1024;
217+Warnings:
218+Warning 1292 Truncated incorrect sql_timeout value: '-1024'
219+SELECT @@global.sql_timeout;
220+@@global.sql_timeout
221+0
222+SET @@global.sql_timeout = 65530.34;
223+ERROR 42000: Incorrect argument type to variable 'sql_timeout'
224+SELECT @@global.sql_timeout;
225+@@global.sql_timeout
226+0
227+SET @@global.sql_timeout = test;
228+ERROR 42000: Incorrect argument type to variable 'sql_timeout'
229+SELECT @@global.sql_timeout;
230+@@global.sql_timeout
231+0
232+SET @@session.sql_timeout = 0;
233+SELECT @@session.sql_timeout;
234+@@session.sql_timeout
235+0
236+SET @@session.sql_timeout = -2;
237+Warnings:
238+Warning 1292 Truncated incorrect sql_timeout value: '-2'
239+SELECT @@session.sql_timeout;
240+@@session.sql_timeout
241+0
242+SET @@session.sql_timeout = 65530.34;
243+ERROR 42000: Incorrect argument type to variable 'sql_timeout'
244+SELECT @@session.sql_timeout;
245+@@session.sql_timeout
246+0
247+SET @@session.sql_timeout = test;
248+ERROR 42000: Incorrect argument type to variable 'sql_timeout'
249+SELECT @@session.sql_timeout;
250+@@session.sql_timeout
251+0
252+'#------------------FN_DYNVARS_083_06-----------------------#'
253+SELECT @@global.sql_timeout = VARIABLE_VALUE
254+FROM INFORMATION_SCHEMA.GLOBAL_VARIABLES
255+WHERE VARIABLE_NAME='sql_timeout';
256+@@global.sql_timeout = VARIABLE_VALUE
257+1
258+'#------------------FN_DYNVARS_083_07-----------------------#'
259+SELECT @@session.sql_timeout = VARIABLE_VALUE
260+FROM INFORMATION_SCHEMA.SESSION_VARIABLES
261+WHERE VARIABLE_NAME='sql_timeout';
262+@@session.sql_timeout = VARIABLE_VALUE
263+1
264+'#------------------FN_DYNVARS_083_08-----------------------#'
265+SET @@global.sql_timeout = FALSE;
266+SELECT @@global.sql_timeout;
267+@@global.sql_timeout
268+0
269+'#---------------------FN_DYNVARS_083_09----------------------#'
270+SET @@global.sql_timeout = 100;
271+SELECT @@sql_timeout = @@global.sql_timeout;
272+@@sql_timeout = @@global.sql_timeout
273+0
274+'#---------------------FN_DYNVARS_083_10----------------------#'
275+SET @@sql_timeout = 1000;
276+SELECT @@sql_timeout = @@local.sql_timeout;
277+@@sql_timeout = @@local.sql_timeout
278+1
279+SELECT @@local.sql_timeout = @@session.sql_timeout;
280+@@local.sql_timeout = @@session.sql_timeout
281+1
282+'#---------------------FN_DYNVARS_083_11----------------------#'
283+SET sql_timeout = 100;
284+SELECT @@sql_timeout;
285+@@sql_timeout
286+100
287+SELECT local.sql_timeout;
288+ERROR 42S02: Unknown table 'local' in field list
289+SELECT session.sql_timeout;
290+ERROR 42S02: Unknown table 'session' in field list
291+SELECT sql_timeout = @@session.sql_timeout;
292+ERROR 42S22: Unknown column 'sql_timeout' in 'field list'
293+SET @@global.sql_timeout = @start_global_value;
294+SELECT @@global.sql_timeout;
295+@@global.sql_timeout
296+0
297+SET @@session.sql_timeout = @start_session_value;
298+SELECT @@session.sql_timeout;
299+@@session.sql_timeout
300+0
301
302=== added file 'Percona-Server/mysql-test/suite/sys_vars/t/sql_timeout_basic.test'
303--- Percona-Server/mysql-test/suite/sys_vars/t/sql_timeout_basic.test 1970-01-01 00:00:00 +0000
304+++ Percona-Server/mysql-test/suite/sys_vars/t/sql_timeout_basic.test 2013-01-09 13:41:38 +0000
305@@ -0,0 +1,194 @@
306+############mysql-test\suite\sysvars\t\sql_timeout_basic.test##################
307+# #
308+# Variable Name: sql_timeout #
309+# Scope: GLOBAL | SESSION #
310+# Access Type: Dynamic #
311+# Data Type: numeric #
312+# Default Value: 0 #
313+# Range: 1-4294967295 #
314+# #
315+# #
316+# Creation Date: 2012-02-08 #
317+# Author: Vlad Lesin #
318+# #
319+# Description: Test Cases of Dynamic System Variable sql_timeout #
320+# that checks the behavior of this variable in the following ways#
321+# * Default Value #
322+# * Valid & Invalid values #
323+# * Scope & Access method #
324+# * Data Integrity #
325+# #
326+# Reference: none #
327+# https://blueprints.launchpad.net/percona-server/+spec/sql-timeout #
328+# #
329+# #
330+###############################################################################
331+
332+############################################################
333+# START OF sql_timeout TESTS #
334+############################################################
335+
336+
337+#############################################################
338+# Save initial value #
339+#############################################################
340+
341+SET @start_global_value = @@global.sql_timeout;
342+SELECT @start_global_value;
343+SET @start_session_value = @@session.sql_timeout;
344+SELECT @start_session_value;
345+
346+
347+--echo '#--------------------FN_DYNVARS_083_01-------------------------#'
348+#################################################################
349+# Display the DEFAULT value of sql_timeout #
350+#################################################################
351+
352+SET @@global.sql_timeout = 100;
353+SET @@global.sql_timeout = DEFAULT;
354+SELECT @@global.sql_timeout;
355+
356+SET @@session.sql_timeout = 200;
357+SET @@session.sql_timeout = DEFAULT;
358+SELECT @@session.sql_timeout;
359+
360+--echo '#--------------------FN_DYNVARS_083_03-------------------------#'
361+###########################################################################
362+# Change the value of sql_timeout to a valid value for GLOBAL Scope #
363+###########################################################################
364+
365+SET @@global.sql_timeout = 100;
366+SELECT @@global.sql_timeout;
367+SET @@global.sql_timeout = 200;
368+SELECT @@global.sql_timeout;
369+SET @@global.sql_timeout = 65536;
370+SELECT @@global.sql_timeout;
371+SET @@global.sql_timeout = 4294967295;
372+SELECT @@global.sql_timeout;
373+SET @@global.sql_timeout = 4294967294;
374+SELECT @@global.sql_timeout;
375+
376+
377+--echo '#--------------------FN_DYNVARS_083_04-------------------------#'
378+############################################################################
379+# Change the value of sql_timeout to a valid value for SESSION Scope #
380+############################################################################
381+SET @@session.sql_timeout = 100;
382+SELECT @@session.sql_timeout;
383+SET @@session.sql_timeout = 200;
384+SELECT @@session.sql_timeout;
385+SET @@session.sql_timeout = 4294967295;
386+SELECT @@session.sql_timeout;
387+SET @@session.sql_timeout = 4294967294;
388+SELECT @@session.sql_timeout;
389+SET @@session.sql_timeout = 65535;
390+SELECT @@session.sql_timeout;
391+
392+
393+--echo '#------------------FN_DYNVARS_083_05-----------------------#'
394+#############################################################
395+# Change the value of sql_timeout to an invalid value #
396+#############################################################
397+
398+SET @@global.sql_timeout = 0;
399+SELECT @@global.sql_timeout;
400+SET @@global.sql_timeout = -1024;
401+SELECT @@global.sql_timeout;
402+--Error ER_WRONG_TYPE_FOR_VAR
403+SET @@global.sql_timeout = 65530.34;
404+SELECT @@global.sql_timeout;
405+--Error ER_WRONG_TYPE_FOR_VAR
406+SET @@global.sql_timeout = test;
407+SELECT @@global.sql_timeout;
408+
409+SET @@session.sql_timeout = 0;
410+SELECT @@session.sql_timeout;
411+SET @@session.sql_timeout = -2;
412+SELECT @@session.sql_timeout;
413+--Error ER_WRONG_TYPE_FOR_VAR
414+SET @@session.sql_timeout = 65530.34;
415+SELECT @@session.sql_timeout;
416+
417+--Error ER_WRONG_TYPE_FOR_VAR
418+SET @@session.sql_timeout = test;
419+SELECT @@session.sql_timeout;
420+
421+
422+--echo '#------------------FN_DYNVARS_083_06-----------------------#'
423+####################################################################
424+# Check if the value in GLOBAL Table matches value in variable #
425+####################################################################
426+
427+
428+SELECT @@global.sql_timeout = VARIABLE_VALUE
429+FROM INFORMATION_SCHEMA.GLOBAL_VARIABLES
430+WHERE VARIABLE_NAME='sql_timeout';
431+
432+--echo '#------------------FN_DYNVARS_083_07-----------------------#'
433+####################################################################
434+# Check if the value in SESSION Table matches value in variable #
435+####################################################################
436+
437+SELECT @@session.sql_timeout = VARIABLE_VALUE
438+FROM INFORMATION_SCHEMA.SESSION_VARIABLES
439+WHERE VARIABLE_NAME='sql_timeout';
440+
441+
442+--echo '#------------------FN_DYNVARS_083_08-----------------------#'
443+####################################################################
444+# Check if FALSE value can be used on variable #
445+####################################################################
446+
447+SET @@global.sql_timeout = FALSE;
448+SELECT @@global.sql_timeout;
449+
450+
451+--echo '#---------------------FN_DYNVARS_083_09----------------------#'
452+#############################################################################
453+# Check if accessing variable with and without GLOBAL point #
454+# to same variable #
455+#############################################################################
456+
457+SET @@global.sql_timeout = 100;
458+SELECT @@sql_timeout = @@global.sql_timeout;
459+
460+
461+--echo '#---------------------FN_DYNVARS_083_10----------------------#'
462+#############################################################################
463+# Check if accessing variable with SESSION,LOCAL and without SCOPE points #
464+# to same session variable #
465+#############################################################################
466+
467+SET @@sql_timeout = 1000;
468+SELECT @@sql_timeout = @@local.sql_timeout;
469+SELECT @@local.sql_timeout = @@session.sql_timeout;
470+
471+
472+--echo '#---------------------FN_DYNVARS_083_11----------------------#'
473+############################################################################
474+# Check if sql_timeout can be accessed with and without @@ sign #
475+############################################################################
476+
477+SET sql_timeout = 100;
478+SELECT @@sql_timeout;
479+--Error ER_UNKNOWN_TABLE
480+SELECT local.sql_timeout;
481+--Error ER_UNKNOWN_TABLE
482+SELECT session.sql_timeout;
483+--Error ER_BAD_FIELD_ERROR
484+SELECT sql_timeout = @@session.sql_timeout;
485+
486+
487+####################################
488+# Restore initial value #
489+####################################
490+
491+SET @@global.sql_timeout = @start_global_value;
492+SELECT @@global.sql_timeout;
493+SET @@session.sql_timeout = @start_session_value;
494+SELECT @@session.sql_timeout;
495+
496+
497+#############################################################
498+# END OF sql_timeout TESTS #
499+#############################################################
500
501=== added file 'Percona-Server/mysql-test/t/percona_sql_timeout.test'
502--- Percona-Server/mysql-test/t/percona_sql_timeout.test 1970-01-01 00:00:00 +0000
503+++ Percona-Server/mysql-test/t/percona_sql_timeout.test 2013-01-09 13:41:38 +0000
504@@ -0,0 +1,82 @@
505+#
506+# SQL_TIMEOUT test
507+#
508+# SQL_TIMEOUT is a session variable or
509+# query keyword which sets the time
510+# limit for query execution.
511+
512+# Save the initial number of concurrent sessions
513+--source include/count_sessions.inc
514+
515+
516+--disable_query_log
517+
518+--let $sessions_count=10
519+--let $sessions_prepared_count=10
520+
521+--let $i=$sessions_count
522+while ($i) {
523+--dec $i
524+--let $connection_name=connection_$i
525+--connect ($connection_name,localhost,root,,)
526+--delimiter +++
527+ let $statement=
528+ SELECT SLEEP(1);
529+ SET @@SESSION.SQL_TIMEOUT = 1;
530+ SELECT SLEEP(1000);
531+ SET @@SESSION.SQL_TIMEOUT = 0;
532+ SELECT SLEEP(2);
533++++
534+--delimiter ;
535+--send_eval $statement
536+}
537+
538+--let $i=$sessions_prepared_count
539+while ($i) {
540+--dec $i
541+--let $ti=$sessions_count+$i
542+--let $connection_name=connection_$ti
543+--connect ($connection_name,localhost,root,,)
544+--delimiter +++
545+ let $statement=
546+ PREPARE P_1_$i FROM 'SELECT SLEEP(1)';
547+ PREPARE P_2_$i FROM 'SET @@SESSION.SQL_TIMEOUT = 1';
548+ PREPARE P_3_$i FROM 'SELECT SLEEP(1000)';
549+ PREPARE P_4_$i FROM 'SET @@SESSION.SQL_TIMEOUT = 0';
550+ PREPARE P_5_$i FROM 'SELECT SLEEP(2)';
551+ EXECUTE P_1_$i;
552+ EXECUTE P_2_$i;
553+ EXECUTE P_3_$i;
554+ EXECUTE P_4_$i;
555+ EXECUTE P_5_$i;
556++++
557+--delimiter ;
558+--send_eval $statement
559+}
560+
561+--let $i=$sessions_count
562+while ($i) {
563+--dec $i
564+--let $connection_name=connection_$i
565+--connection $connection_name
566+--reap
567+--disconnect $connection_name
568+}
569+
570+--let $i=$sessions_prepared_count
571+while ($i) {
572+--dec $i
573+--let $ti=$sessions_count+$i
574+--let $connection_name=connection_$ti
575+--connection $connection_name
576+--reap
577+--eval DROP PREPARE P_1_$i
578+--eval DROP PREPARE P_2_$i
579+--eval DROP PREPARE P_3_$i
580+--eval DROP PREPARE P_4_$i
581+--eval DROP PREPARE P_5_$i
582+--disconnect $connection_name
583+}
584+
585+--connection default
586+--source include/wait_until_count_sessions.inc
587
588=== modified file 'Percona-Server/sql/binlog.cc'
589--- Percona-Server/sql/binlog.cc 2012-12-04 08:24:59 +0000
590+++ Percona-Server/sql/binlog.cc 2013-01-09 13:41:38 +0000
591@@ -1573,7 +1573,7 @@
592 append_identifier(thd, &log_query, thd->lex->ident.str,
593 thd->lex->ident.length);
594
595- int errcode= query_error_code(thd, thd->killed == THD::NOT_KILLED);
596+ int errcode= query_error_code(thd, thd->get_killed() == THD::NOT_KILLED);
597 Query_log_event qinfo(thd, log_query.c_ptr_safe(), log_query.length(),
598 TRUE, FALSE, TRUE, errcode);
599 /*
600@@ -1615,7 +1615,7 @@
601 log_query.append(thd->lex->ident.str, thd->lex->ident.length) ||
602 log_query.append("`"))
603 DBUG_RETURN(1);
604- int errcode= query_error_code(thd, thd->killed == THD::NOT_KILLED);
605+ int errcode= query_error_code(thd, thd->get_killed() == THD::NOT_KILLED);
606 Query_log_event qinfo(thd, log_query.c_ptr_safe(), log_query.length(),
607 TRUE, FALSE, TRUE, errcode);
608 DBUG_RETURN(mysql_bin_log.write_event(&qinfo));
609@@ -1930,7 +1930,7 @@
610 {
611 int error;
612
613- if (not_killed || (thd->killed == THD::KILL_BAD_DATA))
614+ if (not_killed || (thd->get_killed() == THD::KILL_BAD_DATA))
615 {
616 error= thd->is_error() ? thd->get_stmt_da()->sql_errno() : 0;
617
618
619=== modified file 'Percona-Server/sql/debug_sync.cc'
620--- Percona-Server/sql/debug_sync.cc 2012-08-22 01:40:20 +0000
621+++ Percona-Server/sql/debug_sync.cc 2013-01-09 13:41:38 +0000
622@@ -224,10 +224,10 @@
623 mysql_mutex_lock(&mutex);
624 thd->enter_cond(&condition_variable, &mutex, new_message);
625 #if defined(ENABLE_DEBUG_SYNC)
626- if (!thd->killed && !end_of_wait_condition)
627+ if (!thd->get_killed() && !end_of_wait_condition)
628 DEBUG_SYNC(thd, "sync_point_name");
629 #endif
630- while (!thd->killed && !end_of_wait_condition)
631+ while (!thd->get_killed() && !end_of_wait_condition)
632 mysql_cond_wait(&condition_variable, &mutex);
633 thd->exit_cond(old_message);
634
635@@ -262,11 +262,11 @@
636 A bit off-topic: At some places, the loop is taken around the whole
637 synchronization pattern:
638
639- while (!thd->killed && !end_of_wait_condition)
640+ while (!thd->get_killed() && !end_of_wait_condition)
641 {
642 mysql_mutex_lock(&mutex);
643 thd->enter_cond(&condition_variable, &mutex, new_message);
644- if (!thd->killed [&& !end_of_wait_condition])
645+ if (!thd->get_killed() [&& !end_of_wait_condition])
646 {
647 [DEBUG_SYNC(thd, "sync_point_name");]
648 mysql_cond_wait(&condition_variable, &mutex);
649@@ -274,9 +274,9 @@
650 thd->exit_cond(old_message);
651 }
652
653- Note that it is important to repeat the test for thd->killed after
654+ Note that it is important to repeat the test for thd->get_killed() after
655 enter_cond(). Otherwise the killing thread may kill this thread after
656- it tested thd->killed in the loop condition and before it registered
657+ it tested thd->get_killed() in the loop condition and before it registered
658 the condition variable and mutex in enter_cond(). In this case, the
659 killing thread does not know that this thread is going to wait on a
660 condition variable. It would just set THD::killed. But if we would not
661@@ -1123,13 +1123,13 @@
662 point decremented it to 0. In this case the following happened:
663
664 - an error message was reported with my_error() and
665- - the statement was killed with thd->killed= THD::KILL_QUERY.
666+ - the statement was killed with thd->get_killed()= THD::KILL_QUERY.
667
668 If a statement reports an error, it must not call send_ok().
669 The calling functions will not call send_ok(), if we return TRUE
670 from this function.
671
672- thd->killed is also set if the wait is interrupted from a
673+ thd->get_killed() is also set if the wait is interrupted from a
674 KILL or KILL QUERY statement. In this case, no error is reported
675 and shall not be reported as a result of SET DEBUG_SYNC.
676 Hence, we check for the first condition above.
677@@ -1775,7 +1775,7 @@
678 the required dynamic memory allocated.
679 */
680 while (stringcmp(&debug_sync_global.ds_signal, &action->wait_for) &&
681- !thd->killed && opt_debug_sync_timeout)
682+ !thd->get_killed() && opt_debug_sync_timeout)
683 {
684 error= mysql_cond_timedwait(&debug_sync_global.ds_cond,
685 &debug_sync_global.ds_mutex,
686@@ -1800,10 +1800,10 @@
687 error= 0;
688 }
689 DBUG_EXECUTE("debug_sync_exec",
690- if (thd->killed)
691+ if (thd->get_killed())
692 DBUG_PRINT("debug_sync_exec",
693 ("killed %d from '%s' at: '%s'",
694- thd->killed, sig_wait, dsp_name));
695+ thd->get_killed(), sig_wait, dsp_name));
696 else
697 DBUG_PRINT("debug_sync_exec",
698 ("%s from '%s' at: '%s'",
699@@ -1842,7 +1842,7 @@
700 {
701 if (!--action->hit_limit)
702 {
703- thd->killed= THD::KILL_QUERY;
704+ thd->set_killed(THD::KILL_QUERY);
705 my_error(ER_DEBUG_SYNC_HIT_LIMIT, MYF(0));
706 }
707 DBUG_PRINT("debug_sync_exec", ("hit_limit: %lu at: '%s'",
708
709=== modified file 'Percona-Server/sql/event_queue.cc'
710--- Percona-Server/sql/event_queue.cc 2011-09-07 10:08:09 +0000
711+++ Percona-Server/sql/event_queue.cc 2013-01-09 13:41:38 +0000
712@@ -575,9 +575,9 @@
713 Event_queue_element *top= NULL;
714
715 /* Break loop if thd has been killed */
716- if (thd->killed)
717+ if (thd->get_killed())
718 {
719- DBUG_PRINT("info", ("thd->killed=%d", thd->killed));
720+ DBUG_PRINT("info", ("thd->get_killed()=%d", thd->get_killed()));
721 goto end;
722 }
723
724@@ -754,7 +754,7 @@
725
726 thd->enter_cond(&COND_queue_state, &LOCK_event_queue, stage, NULL, src_func, src_file, src_line);
727
728- if (!thd->killed)
729+ if (!thd->get_killed())
730 {
731 if (!abstime)
732 mysql_cond_wait(&COND_queue_state, &LOCK_event_queue);
733
734=== modified file 'Percona-Server/sql/event_scheduler.cc'
735--- Percona-Server/sql/event_scheduler.cc 2012-08-22 01:40:20 +0000
736+++ Percona-Server/sql/event_scheduler.cc 2013-01-09 13:41:38 +0000
737@@ -495,7 +495,7 @@
738 }
739 else
740 {
741- DBUG_ASSERT(thd->killed);
742+ DBUG_ASSERT(thd->get_killed());
743 DBUG_PRINT("info", ("job_data is NULL, the thread was killed"));
744 }
745 DBUG_PRINT("info", ("state=%s", scheduler_states_names[state].str));
746
747=== modified file 'Percona-Server/sql/filesort.cc'
748--- Percona-Server/sql/filesort.cc 2012-12-04 08:24:59 +0000
749+++ Percona-Server/sql/filesort.cc 2013-01-09 13:41:38 +0000
750@@ -684,7 +684,6 @@
751 my_off_t record;
752 TABLE *sort_form;
753 THD *thd= current_thd;
754- volatile THD::killed_state *killed= &thd->killed;
755 handler *file;
756 MY_BITMAP *save_read_set, *save_write_set;
757 bool skip_record;
758@@ -774,7 +773,7 @@
759 break;
760 }
761
762- if (*killed)
763+ if (thd->get_killed())
764 {
765 DBUG_PRINT("info",("Sort killed by user"));
766 if (!quick_select)
767@@ -1567,15 +1566,13 @@
768 QUEUE queue;
769 qsort2_cmp cmp;
770 void *first_cmp_arg;
771- volatile THD::killed_state *killed= &current_thd->killed;
772- THD::killed_state not_killable;
773+ THD::killed_state killed= current_thd->get_killed();
774 DBUG_ENTER("merge_buffers");
775
776 current_thd->inc_status_sort_merge_passes();
777 if (param->not_killable)
778 {
779- killed= &not_killable;
780- not_killable= THD::NOT_KILLED;
781+ killed= THD::NOT_KILLED;
782 }
783
784 error=0;
785@@ -1646,7 +1643,7 @@
786
787 while (queue.elements > 1)
788 {
789- if (*killed)
790+ if (killed)
791 {
792 error= 1; goto err; /* purecov: inspected */
793 }
794
795=== modified file 'Percona-Server/sql/ha_ndbcluster.cc'
796--- Percona-Server/sql/ha_ndbcluster.cc 2012-08-22 01:40:20 +0000
797+++ Percona-Server/sql/ha_ndbcluster.cc 2013-01-09 13:41:38 +0000
798@@ -4971,7 +4971,7 @@
799 Ndb_tuple_id_range_guard g(m_share);
800 if (ndb->getAutoIncrementValue(m_table, g.range, auto_value, 1000) == -1)
801 {
802- if (--retries && !thd->killed &&
803+ if (--retries && !thd->get_killed() &&
804 ndb->getNdbError().status == NdbError::TemporaryError)
805 {
806 do_retry_sleep(retry_sleep);
807@@ -8998,7 +8998,7 @@
808 Ndb_tuple_id_range_guard g(m_share);
809 if (ndb->readAutoIncrementValue(ndbtab, g.range, auto_value))
810 {
811- if (--retries && !thd->killed &&
812+ if (--retries && !thd->get_killed() &&
813 ndb->getNdbError().status == NdbError::TemporaryError)
814 {
815 do_retry_sleep(retry_sleep);
816@@ -9628,7 +9628,7 @@
817 Failed to create an index,
818 drop the table (and all it's indexes)
819 */
820- while (!thd->killed)
821+ while (!thd->get_killed())
822 {
823 if (dict->beginSchemaTrans() == -1)
824 goto cleanup_failed;
825@@ -9637,7 +9637,7 @@
826 switch (dict->getNdbError().status)
827 {
828 case NdbError::TemporaryError:
829- if (!thd->killed)
830+ if (!thd->get_killed())
831 {
832 if (dict->endSchemaTrans(NdbDictionary::Dictionary::SchemaTransAbort)
833 == -1)
834@@ -10238,7 +10238,7 @@
835 switch (dict->getNdbError().status)
836 {
837 case NdbError::TemporaryError:
838- if (!thd->killed)
839+ if (!thd->get_killed())
840 goto retry_temporary_error1; // retry indefinitly
841 break;
842 default:
843@@ -10270,7 +10270,7 @@
844 switch (dict->getNdbError().status)
845 {
846 case NdbError::TemporaryError:
847- if (!thd->killed)
848+ if (!thd->get_killed())
849 goto retry_temporary_error2; // retry indefinitly
850 break;
851 default:
852@@ -10426,7 +10426,7 @@
853 Uint32(m_autoincrement_prefetch),
854 increment, offset))
855 {
856- if (--retries && !thd->killed &&
857+ if (--retries && !thd->get_killed() &&
858 ndb->getNdbError().status == NdbError::TemporaryError)
859 {
860 do_retry_sleep(retry_sleep);
861@@ -10734,7 +10734,7 @@
862 }
863 while((result= th.next()) == 1)
864 {
865- if (thd->killed)
866+ if (thd->get_killed())
867 DBUG_RETURN(-1);
868 my_sleep(1000*delay);
869 }
870@@ -10746,7 +10746,7 @@
871 };
872 for (i= 0; i < MAX_KEY; i++)
873 {
874- if (thd->killed)
875+ if (thd->get_killed())
876 DBUG_RETURN(-1);
877 if (m_index[i].status == ACTIVE)
878 {
879@@ -10765,7 +10765,7 @@
880 }
881 while((result= ih.next()) == 1)
882 {
883- if (thd->killed)
884+ if (thd->get_killed())
885 DBUG_RETURN(-1);
886 my_sleep(1000*delay);
887 }
888@@ -10787,7 +10787,7 @@
889 }
890 while((result= ih.next()) == 1)
891 {
892- if (thd->killed)
893+ if (thd->get_killed())
894 DBUG_RETURN(-1);
895 my_sleep(1000*delay);
896 }
897@@ -13451,7 +13451,7 @@
898 pTrans= NULL;
899 }
900 if (error.status == NdbError::TemporaryError &&
901- retries-- && !thd->killed)
902+ retries-- && !thd->get_killed())
903 {
904 do_retry_sleep(retry_sleep);
905 continue;
906
907=== modified file 'Percona-Server/sql/ha_ndbcluster_binlog.cc'
908--- Percona-Server/sql/ha_ndbcluster_binlog.cc 2012-12-04 08:24:59 +0000
909+++ Percona-Server/sql/ha_ndbcluster_binlog.cc 2013-01-09 13:41:38 +0000
910@@ -485,7 +485,7 @@
911 thd->proc_info= "Waiting for ndbcluster binlog update to "
912 "reach current position";
913 pthread_mutex_lock(&injector_mutex);
914- while (!(thd && thd->killed) && count && ndb_binlog_running &&
915+ while (!(thd && thd->get_killed()) && count && ndb_binlog_running &&
916 (ndb_latest_handled_binlog_epoch == 0 ||
917 ndb_latest_handled_binlog_epoch < wait_epoch))
918 {
919@@ -1291,7 +1291,7 @@
920 ndb->closeTransaction(trans);
921 trans= NULL;
922 }
923- if (ndb_error.status == NdbError::TemporaryError && !thd->killed)
924+ if (ndb_error.status == NdbError::TemporaryError && !thd->get_killed())
925 {
926 if (retries--)
927 {
928@@ -1302,7 +1302,7 @@
929 continue; // retry
930 }
931 }
932- if (!thd->killed)
933+ if (!thd->get_killed())
934 {
935 sql_print_error("NDB: ndbcluster_find_all_databases fail: %u - %s",
936 ndb_error.code,
937@@ -1663,7 +1663,7 @@
938 err:
939 const NdbError *this_error= trans ?
940 &trans->getNdbError() : &ndb->getNdbError();
941- if (this_error->status == NdbError::TemporaryError && !thd->killed)
942+ if (this_error->status == NdbError::TemporaryError && !thd->get_killed())
943 {
944 if (retries--)
945 {
946@@ -2128,7 +2128,7 @@
947 err:
948 const NdbError *this_error= trans ?
949 &trans->getNdbError() : &ndb->getNdbError();
950- if (this_error->status == NdbError::TemporaryError && !thd->killed)
951+ if (this_error->status == NdbError::TemporaryError && !thd->get_killed())
952 {
953 if (retries--)
954 {
955@@ -2183,7 +2183,7 @@
956 int ret= pthread_cond_timedwait(&injector_cond,
957 &ndb_schema_object->mutex,
958 &abstime);
959- if (thd->killed)
960+ if (thd->get_killed())
961 break;
962
963 /* begin protect ndb_schema_share */
964@@ -2424,7 +2424,7 @@
965 char *thd_db_save= thd->db;
966 thd->server_id = loggedServerId;
967 thd->db= schema->db;
968- int errcode = query_error_code(thd, thd->killed == THD::NOT_KILLED);
969+ int errcode = query_error_code(thd, thd->get_killed() == THD::NOT_KILLED);
970 thd->binlog_query(THD::STMT_QUERY_TYPE, schema->query,
971 schema->query_length, FALSE,
972 #ifdef NDB_THD_BINLOG_QUERY_HAS_DIRECT
973@@ -3253,7 +3253,7 @@
974 MYSQL_LOCK_IGNORE_TIMEOUT; /* Wait for lock "infinitely" */
975 if (open_and_lock_tables(thd, &tables, derived, flags))
976 {
977- if (thd->killed)
978+ if (thd->get_killed())
979 sql_print_error("NDB Binlog: Opening ndb_binlog_index: killed");
980 else
981 sql_print_error("NDB Binlog: Opening ndb_binlog_index: %d, '%s'",
982@@ -5392,7 +5392,7 @@
983 share->event_data= event_data;
984 op->setCustomData(NULL);
985 ndb->dropEventOperation(op);
986- if (retries && !thd->killed)
987+ if (retries && !thd->get_killed())
988 {
989 do_retry_sleep(retry_sleep);
990 continue;
991@@ -5530,7 +5530,7 @@
992 int ret= pthread_cond_timedwait(&injector_cond,
993 &share->mutex,
994 &abstime);
995- if (thd->killed ||
996+ if (thd->get_killed() ||
997 share->op == 0)
998 break;
999 if (ret)
1000@@ -7206,15 +7206,15 @@
1001 Writing to ndb_binlog_index failed, check if we are
1002 being killed and retry
1003 */
1004- if (thd->killed)
1005+ if (thd->get_killed())
1006 {
1007 (void) mysql_mutex_lock(&LOCK_thread_count);
1008- volatile THD::killed_state killed= thd->killed;
1009+ volatile THD::killed_state killed= thd->get_killed();
1010 /* We are cleaning up, allow for flushing last epoch */
1011- thd->killed= THD::NOT_KILLED;
1012+ thd->set_killed(THD::NOT_KILLED);
1013 ndb_binlog_index_table__write_rows(thd, rows);
1014 /* Restore kill flag */
1015- thd->killed= killed;
1016+ thd->set_killed(killed);
1017 (void) mysql_mutex_unlock(&LOCK_thread_count);
1018 }
1019 }
1020
1021=== modified file 'Percona-Server/sql/handler.cc'
1022--- Percona-Server/sql/handler.cc 2012-12-04 08:24:59 +0000
1023+++ Percona-Server/sql/handler.cc 2013-01-09 13:41:38 +0000
1024@@ -1603,7 +1603,7 @@
1025 #endif
1026 if ((all || thd->transaction.stmt.ha_list == 0) &&
1027 thd->transaction.all.cannot_safely_rollback() &&
1028- !thd->slave_thread && thd->killed != THD::KILL_CONNECTION)
1029+ !thd->slave_thread && thd->get_killed() != THD::KILL_CONNECTION)
1030 thd->transaction.push_unsafe_rollback_warnings(thd);
1031 DBUG_RETURN(error);
1032 }
1033@@ -3210,7 +3210,7 @@
1034 /*
1035 first test if the query was aborted due to strict mode constraints
1036 */
1037- if (thd->killed == THD::KILL_BAD_DATA)
1038+ if (thd->get_killed() == THD::KILL_BAD_DATA)
1039 DBUG_RETURN(HA_ERR_AUTOINC_ERANGE);
1040
1041 /*
1042@@ -5452,7 +5452,7 @@
1043
1044 @note
1045 This method (or an overriding one in a derived class) must check for
1046- thd->killed and return HA_POS_ERROR if it is not zero. This is required
1047+ thd->get_killed() and return HA_POS_ERROR if it is not zero. This is required
1048 for a user to be able to interrupt the calculation by killing the
1049 connection/query.
1050
1051@@ -5479,12 +5479,12 @@
1052 /* Default MRR implementation doesn't need buffer */
1053 *bufsz= 0;
1054
1055- DBUG_EXECUTE_IF("bug13822652_2", thd->killed= THD::KILL_QUERY;);
1056+ DBUG_EXECUTE_IF("bug13822652_2", thd->set_killed(THD::KILL_QUERY););
1057
1058 seq_it= seq->init(seq_init_param, n_ranges, *flags);
1059 while (!seq->next(seq_it, &range))
1060 {
1061- if (unlikely(thd->killed != 0))
1062+ if (unlikely(thd->get_killed() != 0))
1063 return HA_POS_ERROR;
1064
1065 n_ranges++;
1066
1067=== modified file 'Percona-Server/sql/item_func.cc'
1068--- Percona-Server/sql/item_func.cc 2012-12-04 08:24:59 +0000
1069+++ Percona-Server/sql/item_func.cc 2013-01-09 13:41:38 +0000
1070@@ -4215,6 +4215,11 @@
1071 error= mysql_cond_timedwait(cond, mutex, &timeout);
1072 if (error == ETIMEDOUT || error == ETIME)
1073 {
1074+ if (m_thd->get_killed())
1075+ {
1076+ error= 0;
1077+ break;
1078+ }
1079 /* Return error if timed out or connection is broken. */
1080 if (!cmp_timespec(timeout, m_abs_timeout) || !m_thd->is_connected())
1081 break;
1082@@ -4312,7 +4317,7 @@
1083
1084 error= 0;
1085 thd_wait_begin(thd, THD_WAIT_USER_LOCK);
1086- while (ull->locked && !thd->killed)
1087+ while (ull->locked && !thd->get_killed())
1088 {
1089 DBUG_PRINT("info", ("waiting on lock"));
1090 error= timed_cond.wait(&ull->cond, &LOCK_user_locks);
1091@@ -4332,7 +4337,7 @@
1092 DBUG_ASSERT(0);
1093 delete ull; // Should never happen
1094 }
1095- if (!error) // Killed (thd->killed != 0)
1096+ if (!error) // Killed (thd->get_killed() != 0)
1097 {
1098 error=1;
1099 null_value=1; // Return NULL
1100@@ -4469,7 +4474,7 @@
1101 }
1102
1103 null_value=0;
1104- for (ulonglong loop=0 ; loop < loop_count && !thd->killed; loop++)
1105+ for (ulonglong loop=0 ; loop < loop_count && !thd->get_killed(); loop++)
1106 {
1107 switch (args[1]->result_type()) {
1108 case REAL_RESULT:
1109@@ -4541,7 +4546,7 @@
1110
1111 error= 0;
1112 thd_wait_begin(thd, THD_WAIT_SLEEP);
1113- while (!thd->killed)
1114+ while (!thd->get_killed())
1115 {
1116 error= timed_cond.wait(&cond, &LOCK_user_locks);
1117 if (error == ETIMEDOUT || error == ETIME)
1118@@ -6742,7 +6747,7 @@
1119 {
1120 null_value= 1;
1121 context->process_error(thd);
1122- if (thd->killed)
1123+ if (thd->get_killed())
1124 thd->send_kill_message();
1125 return TRUE;
1126 }
1127
1128=== modified file 'Percona-Server/sql/item_subselect.cc'
1129--- Percona-Server/sql/item_subselect.cc 2012-12-04 08:24:59 +0000
1130+++ Percona-Server/sql/item_subselect.cc 2013-01-09 13:41:38 +0000
1131@@ -572,7 +572,7 @@
1132 or if the query has been killed.
1133 */
1134 THD * const thd= unit->thd;
1135- if (thd->is_error() || thd->killed)
1136+ if (thd->is_error() || thd->get_killed())
1137 DBUG_RETURN(true);
1138
1139 DBUG_ASSERT(!thd->lex->context_analysis_only);
1140
1141=== modified file 'Percona-Server/sql/lock.cc'
1142--- Percona-Server/sql/lock.cc 2012-03-06 14:29:42 +0000
1143+++ Percona-Server/sql/lock.cc 2013-01-09 13:41:38 +0000
1144@@ -324,11 +324,11 @@
1145 if (sql_lock->table_count)
1146 (void) unlock_external(thd, sql_lock->table, sql_lock->table_count);
1147 reset_lock_data_and_free(&sql_lock);
1148- if (! thd->killed)
1149+ if (! thd->get_killed())
1150 my_error(rc, MYF(0));
1151 }
1152 end:
1153- if (thd->killed)
1154+ if (thd->get_killed())
1155 {
1156 thd->send_kill_message();
1157 if (sql_lock)
1158
1159=== modified file 'Percona-Server/sql/log.cc'
1160--- Percona-Server/sql/log.cc 2012-12-04 08:24:59 +0000
1161+++ Percona-Server/sql/log.cc 2013-01-09 13:41:38 +0000
1162@@ -501,7 +501,7 @@
1163 result= FALSE;
1164
1165 err:
1166- if (result && !thd->killed)
1167+ if (result && !thd->get_killed())
1168 sql_print_error("Failed to write to mysql.general_log: %s",
1169 error_handler.message());
1170
1171@@ -699,7 +699,7 @@
1172 err:
1173 thd->pop_internal_handler();
1174
1175- if (result && !thd->killed)
1176+ if (result && !thd->get_killed())
1177 sql_print_error("Failed to write to mysql.slow_log: %s",
1178 error_handler.message());
1179
1180
1181=== modified file 'Percona-Server/sql/log_event.cc'
1182--- Percona-Server/sql/log_event.cc 2012-12-04 08:24:59 +0000
1183+++ Percona-Server/sql/log_event.cc 2013-01-09 13:41:38 +0000
1184@@ -4799,7 +4799,7 @@
1185 get_type_str(), thd->get_stmt_da()->message());
1186 }
1187 clear_all_errors(thd, const_cast<Relay_log_info*>(rli));
1188- thd->killed= THD::NOT_KILLED;
1189+ thd->set_killed(THD::NOT_KILLED);
1190 }
1191 /*
1192 Other cases: mostly we expected no error and get one.
1193
1194=== modified file 'Percona-Server/sql/mysqld.cc'
1195--- Percona-Server/sql/mysqld.cc 2012-12-04 08:24:59 +0000
1196+++ Percona-Server/sql/mysqld.cc 2013-01-09 13:41:38 +0000
1197@@ -1376,7 +1376,7 @@
1198 if (tmp->slave_thread)
1199 continue;
1200
1201- tmp->killed= THD::KILL_CONNECTION;
1202+ tmp->set_killed(THD::KILL_CONNECTION);
1203 MYSQL_CALLBACK(thread_scheduler, post_kill_notification, (tmp));
1204 mysql_mutex_lock(&tmp->LOCK_thd_data);
1205 if (tmp->mysys_var)
1206@@ -5933,7 +5933,7 @@
1207 DBUG_PRINT("error",
1208 ("Can't create thread to handle request (error %d)",
1209 error));
1210- thd->killed= THD::KILL_CONNECTION; // Safety
1211+ thd->set_killed(THD::KILL_CONNECTION); // Safety
1212 mysql_mutex_unlock(&LOCK_thread_count);
1213
1214 mysql_mutex_lock(&LOCK_connection_count);
1215
1216=== modified file 'Percona-Server/sql/opt_range.cc'
1217--- Percona-Server/sql/opt_range.cc 2012-12-04 08:24:59 +0000
1218+++ Percona-Server/sql/opt_range.cc 2013-01-09 13:41:38 +0000
1219@@ -9866,7 +9866,7 @@
1220 break;
1221 }
1222
1223- if (thd->killed)
1224+ if (thd->get_killed())
1225 DBUG_RETURN(1);
1226
1227 /* skip row if it will be retrieved by clustered PK scan */
1228
1229=== modified file 'Percona-Server/sql/records.cc'
1230--- Percona-Server/sql/records.cc 2012-12-04 08:24:59 +0000
1231+++ Percona-Server/sql/records.cc 2013-01-09 13:41:38 +0000
1232@@ -340,7 +340,7 @@
1233
1234 static int rr_handle_error(READ_RECORD *info, int error)
1235 {
1236- if (info->thd->killed)
1237+ if (info->thd->get_killed())
1238 {
1239 info->thd->send_kill_message();
1240 return 1;
1241@@ -366,7 +366,7 @@
1242 int tmp;
1243 while ((tmp= info->select->quick->get_next()))
1244 {
1245- if (info->thd->killed || (tmp != HA_ERR_RECORD_DELETED))
1246+ if (info->thd->get_killed() || (tmp != HA_ERR_RECORD_DELETED))
1247 {
1248 tmp= rr_handle_error(info, tmp);
1249 break;
1250@@ -481,7 +481,7 @@
1251 ha_rnd_next can return RECORD_DELETED for MyISAM when one thread is
1252 reading and another deleting without locks.
1253 */
1254- if (info->thd->killed || (tmp != HA_ERR_RECORD_DELETED))
1255+ if (info->thd->get_killed() || (tmp != HA_ERR_RECORD_DELETED))
1256 {
1257 tmp= rr_handle_error(info, tmp);
1258 break;
1259
1260=== modified file 'Percona-Server/sql/rpl_gtid_execution.cc'
1261--- Percona-Server/sql/rpl_gtid_execution.cc 2012-09-17 18:49:38 +0000
1262+++ Percona-Server/sql/rpl_gtid_execution.cc 2013-01-09 13:41:38 +0000
1263@@ -78,7 +78,7 @@
1264 // global_sid_lock and mutex are now released
1265
1266 // Check if thread was killed.
1267- if (thd->killed || abort_loop)
1268+ if (thd->get_killed() || abort_loop)
1269 DBUG_RETURN(1);
1270 #ifdef HAVE_REPLICATION
1271 // If this thread is a slave SQL thread or slave SQL worker
1272@@ -159,7 +159,7 @@
1273
1274 // at this point, we don't hold any locks. re-acquire the global
1275 // read lock that was held when this function was invoked
1276- if (thd->killed || abort_loop)
1277+ if (thd->get_killed() || abort_loop)
1278 DBUG_RETURN(1);
1279 #ifdef HAVE_REPLICATION
1280 // If this thread is a slave SQL thread or slave SQL worker
1281
1282=== modified file 'Percona-Server/sql/rpl_gtid_state.cc'
1283--- Percona-Server/sql/rpl_gtid_state.cc 2012-09-17 18:49:38 +0000
1284+++ Percona-Server/sql/rpl_gtid_state.cc 2013-01-09 13:41:38 +0000
1285@@ -262,7 +262,7 @@
1286 sid_locks.enter_cond(thd, gtid.sidno,
1287 &stage_waiting_for_gtid_to_be_written_to_binary_log,
1288 &old_stage);
1289- //while (get_owner(g.sidno, g.gno) != 0 && !thd->killed && !abort_loop)
1290+ //while (get_owner(g.sidno, g.gno) != 0 && !thd->get_killed() && !abort_loop)
1291 sid_locks.wait(gtid.sidno);
1292 thd->EXIT_COND(&old_stage);
1293
1294
1295=== modified file 'Percona-Server/sql/rpl_master.cc'
1296--- Percona-Server/sql/rpl_master.cc 2012-10-16 06:21:51 +0000
1297+++ Percona-Server/sql/rpl_master.cc 2013-01-09 13:41:38 +0000
1298@@ -1090,7 +1090,7 @@
1299 /* seek to the requested position, to start the requested dump */
1300 my_b_seek(&log, pos); // Seek will done on next read
1301
1302- while (!net->error && net->vio != 0 && !thd->killed)
1303+ while (!net->error && net->vio != 0 && !thd->get_killed())
1304 {
1305 Log_event_type event_type= UNKNOWN_EVENT;
1306
1307@@ -1430,7 +1430,7 @@
1308 {
1309 DBUG_PRINT("wait",("binary log received update or a broadcast signal caught"));
1310 }
1311- } while (signal_cnt == mysql_bin_log.signal_cnt && !thd->killed);
1312+ } while (signal_cnt == mysql_bin_log.signal_cnt && !thd->get_killed());
1313 thd->EXIT_COND(&old_stage);
1314 }
1315 break;
1316
1317=== modified file 'Percona-Server/sql/rpl_rli.cc'
1318--- Percona-Server/sql/rpl_rli.cc 2012-12-04 08:24:59 +0000
1319+++ Percona-Server/sql/rpl_rli.cc 2013-01-09 13:41:38 +0000
1320@@ -675,7 +675,7 @@
1321 }
1322
1323 /* The "compare and wait" main loop */
1324- while (!thd->killed &&
1325+ while (!thd->get_killed() &&
1326 init_abort_pos_wait == abort_pos_wait &&
1327 slave_running)
1328 {
1329@@ -727,7 +727,7 @@
1330
1331 pos_reached= ((!cmp_result && group_master_log_pos >= (ulonglong)log_pos) ||
1332 cmp_result > 0);
1333- if (pos_reached || thd->killed)
1334+ if (pos_reached || thd->get_killed())
1335 break;
1336 }
1337
1338@@ -785,7 +785,7 @@
1339 (int) slave_running,
1340 (int) (error == -2),
1341 (int) (error == -1)));
1342- if (thd->killed || init_abort_pos_wait != abort_pos_wait ||
1343+ if (thd->get_killed() || init_abort_pos_wait != abort_pos_wait ||
1344 !slave_running)
1345 {
1346 error= -2;
1347@@ -845,7 +845,7 @@
1348 global_sid_lock->unlock();
1349
1350 /* The "compare and wait" main loop */
1351- while (!thd->killed &&
1352+ while (!thd->get_killed() &&
1353 init_abort_pos_wait == abort_pos_wait &&
1354 slave_running)
1355 {
1356@@ -931,7 +931,7 @@
1357 (int) slave_running,
1358 (int) (error == -2),
1359 (int) (error == -1)));
1360- if (thd->killed || init_abort_pos_wait != abort_pos_wait ||
1361+ if (thd->get_killed() || init_abort_pos_wait != abort_pos_wait ||
1362 !slave_running)
1363 {
1364 error= -2;
1365
1366=== modified file 'Percona-Server/sql/rpl_rli_pdb.cc'
1367--- Percona-Server/sql/rpl_rli_pdb.cc 2012-12-04 08:24:59 +0000
1368+++ Percona-Server/sql/rpl_rli_pdb.cc 2013-01-09 13:41:38 +0000
1369@@ -887,10 +887,10 @@
1370 &stage_slave_waiting_worker_to_release_partition,
1371 &old_stage);
1372 mysql_cond_wait(&slave_worker_hash_cond, &slave_worker_hash_lock);
1373- } while (entry->usage != 0 && !thd->killed);
1374+ } while (entry->usage != 0 && !thd->get_killed());
1375
1376 thd->EXIT_COND(&old_stage);
1377- if (thd->killed)
1378+ if (thd->get_killed())
1379 {
1380 entry= NULL;
1381 goto err;
1382@@ -1500,7 +1500,7 @@
1383 continue;
1384 }
1385
1386- if (entry->usage > 0 && !thd->killed)
1387+ if (entry->usage > 0 && !thd->get_killed())
1388 {
1389 PSI_stage_info old_stage;
1390 Slave_worker *w_entry= entry->worker;
1391@@ -1517,7 +1517,7 @@
1392 ("Either got awakened of notified: "
1393 "entry %p, usage %lu, worker %lu",
1394 entry, entry->usage, w_entry->id));
1395- } while (entry->usage != 0 && !thd->killed);
1396+ } while (entry->usage != 0 && !thd->get_killed());
1397 entry->worker= w_entry; // restoring last association, needed only for assert
1398 thd->EXIT_COND(&old_stage);
1399 ret++;
1400@@ -1659,7 +1659,7 @@
1401 &stage_slave_waiting_worker_to_free_events, &old_stage);
1402 mysql_cond_wait(&rli->pending_jobs_cond, &rli->pending_jobs_lock);
1403 thd->EXIT_COND(&old_stage);
1404- if (thd->killed)
1405+ if (thd->get_killed())
1406 return true;
1407 if (log_warnings > 1 && (rli->wq_size_waits_cnt % 10 == 1))
1408 sql_print_information("Multi-threaded slave: Coordinator has waited "
1409@@ -1701,7 +1701,7 @@
1410 mysql_mutex_lock(&worker->jobs_lock);
1411
1412 // possible WQ overfill
1413- while (worker->running_status == Slave_worker::RUNNING && !thd->killed &&
1414+ while (worker->running_status == Slave_worker::RUNNING && !thd->get_killed() &&
1415 (ret= en_queue(&worker->jobs, job_item)) == -1)
1416 {
1417 thd->ENTER_COND(&worker->jobs_cond, &worker->jobs_lock,
1418@@ -1752,7 +1752,7 @@
1419
1420 mysql_mutex_lock(&worker->jobs_lock);
1421
1422- while (!job_item->data && !thd->killed &&
1423+ while (!job_item->data && !thd->get_killed() &&
1424 worker->running_status == Slave_worker::RUNNING)
1425 {
1426 PSI_stage_info old_stage;
1427@@ -1805,7 +1805,7 @@
1428 DBUG_ENTER("slave_worker_exec_job");
1429
1430 job_item= pop_jobs_item(worker, job_item);
1431- if (thd->killed || worker->running_status != Slave_worker::RUNNING)
1432+ if (thd->get_killed() || worker->running_status != Slave_worker::RUNNING)
1433 {
1434 // de-queueing and decrement counters is in the caller's exit branch
1435 error= -1;
1436@@ -1978,7 +1978,7 @@
1437 if (log_warnings > 1)
1438 sql_print_information("Worker %lu is exiting: killed %i, error %i, "
1439 "running_status %d",
1440- worker->id, thd->killed, thd->is_error(),
1441+ worker->id, thd->get_killed(), thd->is_error(),
1442 worker->running_status);
1443 worker->slave_worker_ends_group(ev, error);
1444 }
1445
1446=== modified file 'Percona-Server/sql/rpl_slave.cc'
1447--- Percona-Server/sql/rpl_slave.cc 2012-12-04 08:24:59 +0000
1448+++ Percona-Server/sql/rpl_slave.cc 2013-01-09 13:41:38 +0000
1449@@ -1034,15 +1034,15 @@
1450 /*
1451 It is not sufficient to test this at loop bottom. We must test
1452 it after registering the mutex in enter_cond(). If the kill
1453- happens after testing of thd->killed and before the mutex is
1454- registered, we could otherwise go waiting though thd->killed is
1455+ happens after testing of thd->get_killed() and before the mutex is
1456+ registered, we could otherwise go waiting though thd->get_killed() is
1457 set.
1458 */
1459- if (!thd->killed)
1460+ if (!thd->get_killed())
1461 mysql_cond_wait(start_cond, cond_lock);
1462 thd->EXIT_COND(& saved_stage);
1463 mysql_mutex_lock(cond_lock); // re-acquire it as exit_cond() released
1464- if (thd->killed)
1465+ if (thd->get_killed())
1466 {
1467 if (start_lock)
1468 mysql_mutex_unlock(start_lock);
1469@@ -1192,7 +1192,7 @@
1470
1471 DBUG_ASSERT(mi->info_thd == thd);
1472 DBUG_ASSERT(mi->slave_running); // tracking buffer overrun
1473- DBUG_RETURN(mi->abort_slave || abort_loop || thd->killed);
1474+ DBUG_RETURN(mi->abort_slave || abort_loop || thd->get_killed());
1475 }
1476
1477 /**
1478@@ -1223,10 +1223,10 @@
1479
1480 DBUG_ASSERT(rli->info_thd == thd);
1481 DBUG_ASSERT(rli->slave_running == 1);
1482- if (abort_loop || thd->killed || rli->abort_slave)
1483+ if (abort_loop || thd->get_killed() || rli->abort_slave)
1484 {
1485 is_parallel_warn= (rli->is_parallel_exec() &&
1486- (rli->is_mts_in_group() || thd->killed));
1487+ (rli->is_mts_in_group() || thd->get_killed()));
1488 /*
1489 Slave can execute stop being in one of two MTS or Single-Threaded mode.
1490 The modes define different criteria to accept the stop.
1491@@ -5153,7 +5153,7 @@
1492 commit-events of last assigned groups.
1493 */
1494 if (rli->mts_group_status != Relay_log_info::MTS_KILLED_GROUP &&
1495- thd->killed == THD::NOT_KILLED)
1496+ thd->get_killed() == THD::NOT_KILLED)
1497 {
1498 DBUG_ASSERT(rli->mts_group_status != Relay_log_info::MTS_IN_GROUP ||
1499 thd->is_error());
1500@@ -7166,7 +7166,7 @@
1501 set_timespec_nsec(waittime, period);
1502 ret= rli->relay_log.wait_for_update_relay_log(thd, &waittime);
1503 } while ((ret == ETIMEDOUT || ret == ETIME) /* todo:remove */ &&
1504- signal_cnt == rli->relay_log.signal_cnt && !thd->killed);
1505+ signal_cnt == rli->relay_log.signal_cnt && !thd->get_killed());
1506 }
1507 else
1508 {
1509
1510=== modified file 'Percona-Server/sql/signal_handler.cc'
1511--- Percona-Server/sql/signal_handler.cc 2012-08-22 01:40:20 +0000
1512+++ Percona-Server/sql/signal_handler.cc 2013-01-09 13:41:38 +0000
1513@@ -165,7 +165,7 @@
1514 if (thd)
1515 {
1516 const char *kreason= "UNKNOWN";
1517- switch (thd->killed) {
1518+ switch (thd->get_killed()) {
1519 case THD::NOT_KILLED:
1520 kreason= "NOT_KILLED";
1521 break;
1522
1523=== modified file 'Percona-Server/sql/sp.cc'
1524--- Percona-Server/sql/sp.cc 2012-12-04 08:24:59 +0000
1525+++ Percona-Server/sql/sp.cc 2013-01-09 13:41:38 +0000
1526@@ -1484,7 +1484,7 @@
1527 or is outdated. We therefore only abort mysql_rm_db() if we
1528 have errors not handled by the error handler.
1529 */
1530- DBUG_RETURN(thd->is_error() || thd->killed);
1531+ DBUG_RETURN(thd->is_error() || thd->get_killed());
1532 }
1533
1534 table->field[MYSQL_PROC_FIELD_DB]->store(db, strlen(db), system_charset_info);
1535@@ -2077,7 +2077,7 @@
1536 break;
1537 default:
1538 /* Query might have been killed, don't set error. */
1539- if (thd->killed)
1540+ if (thd->get_killed())
1541 break;
1542 /*
1543 Any error when loading an existing routine is either some problem
1544
1545=== modified file 'Percona-Server/sql/sp_head.cc'
1546--- Percona-Server/sql/sp_head.cc 2012-10-16 06:21:51 +0000
1547+++ Percona-Server/sql/sp_head.cc 2013-01-09 13:41:38 +0000
1548@@ -675,7 +675,7 @@
1549 /* Reset sp_rcontext::end_partial_result_set flag. */
1550 thd->sp_runtime_ctx->end_partial_result_set= FALSE;
1551
1552- } while (!err_status && !thd->killed && !thd->is_fatal_error);
1553+ } while (!err_status && !thd->get_killed() && !thd->is_fatal_error);
1554
1555 #if defined(ENABLED_PROFILING)
1556 thd->profiling.finish_current_query();
1557@@ -751,16 +751,16 @@
1558
1559 done:
1560 DBUG_PRINT("info", ("err_status: %d killed: %d is_slave_error: %d report_error: %d",
1561- err_status, thd->killed, thd->is_slave_error,
1562+ err_status, thd->get_killed(), thd->is_slave_error,
1563 thd->is_error()));
1564
1565- if (thd->killed)
1566+ if (thd->get_killed())
1567 err_status= TRUE;
1568 /*
1569 If the DB has changed, the pointer has changed too, but the
1570 original thd->db will then have been freed
1571 */
1572- if (cur_db_changed && thd->killed != THD::KILL_CONNECTION)
1573+ if (cur_db_changed && thd->get_killed() != THD::KILL_CONNECTION)
1574 {
1575 /*
1576 Force switching back to the saved current database, because it may be
1577@@ -901,7 +901,7 @@
1578 free_root(&call_mem_root, MYF(0));
1579 thd->sp_runtime_ctx= parent_sp_runtime_ctx;
1580
1581- if (thd->killed)
1582+ if (thd->get_killed())
1583 thd->send_kill_message();
1584
1585 DBUG_RETURN(err_status);
1586@@ -1096,7 +1096,7 @@
1587 thd->variables.option_bits= binlog_save_options;
1588 if (thd->binlog_evt_union.unioned_events)
1589 {
1590- int errcode = query_error_code(thd, thd->killed == THD::NOT_KILLED);
1591+ int errcode = query_error_code(thd, thd->get_killed() == THD::NOT_KILLED);
1592 Query_log_event qinfo(thd, binlog_buf.ptr(), binlog_buf.length(),
1593 thd->binlog_evt_union.unioned_events_trans, FALSE, FALSE, errcode);
1594 if (mysql_bin_log.write_event(&qinfo) &&
1595
1596=== modified file 'Percona-Server/sql/sp_instr.cc'
1597--- Percona-Server/sql/sp_instr.cc 2012-07-16 15:43:41 +0000
1598+++ Percona-Server/sql/sp_instr.cc 2013-01-09 13:41:38 +0000
1599@@ -630,7 +630,7 @@
1600 */
1601 if (stmt_reprepare_observer &&
1602 !thd->is_fatal_error &&
1603- !thd->killed &&
1604+ !thd->get_killed() &&
1605 thd->get_stmt_da()->sql_errno() == ER_NEED_REPREPARE &&
1606 reprepare_attempt++ < 3)
1607 {
1608
1609=== modified file 'Percona-Server/sql/sp_rcontext.cc'
1610--- Percona-Server/sql/sp_rcontext.cc 2012-12-04 08:24:59 +0000
1611+++ Percona-Server/sql/sp_rcontext.cc 2013-01-09 13:41:38 +0000
1612@@ -353,7 +353,7 @@
1613
1614 /* Reset error state. */
1615 thd->clear_error();
1616- thd->killed= THD::NOT_KILLED; // Some errors set thd->killed
1617+ thd->set_killed(THD::NOT_KILLED); // Some errors set thd->get_killed()
1618 // (e.g. "bad data").
1619
1620 /* Add a frame to handler-call-stack. */
1621
1622=== modified file 'Percona-Server/sql/sql_admin.cc'
1623--- Percona-Server/sql/sql_admin.cc 2012-10-16 06:21:51 +0000
1624+++ Percona-Server/sql/sql_admin.cc 2013-01-09 13:41:38 +0000
1625@@ -804,7 +804,7 @@
1626 protocol->store(operator_name, system_charset_info);
1627 if (result_code) // either mysql_recreate_table or analyze failed
1628 {
1629- DBUG_ASSERT(thd->is_error() || thd->killed);
1630+ DBUG_ASSERT(thd->is_error() || thd->get_killed());
1631 if (thd->is_error())
1632 {
1633 const char *err_msg= thd->get_stmt_da()->message();
1634
1635=== modified file 'Percona-Server/sql/sql_base.cc'
1636--- Percona-Server/sql/sql_base.cc 2012-12-04 08:24:59 +0000
1637+++ Percona-Server/sql/sql_base.cc 2013-01-09 13:41:38 +0000
1638@@ -850,9 +850,9 @@
1639 THD *in_use= tab->in_use;
1640
1641 if ((in_use->system_thread & SYSTEM_THREAD_DELAYED_INSERT) &&
1642- ! in_use->killed)
1643+ ! in_use->get_killed())
1644 {
1645- in_use->killed= THD::KILL_CONNECTION;
1646+ in_use->set_killed(THD::KILL_CONNECTION);
1647 mysql_mutex_lock(&in_use->mysys_var->mutex);
1648 if (in_use->mysys_var->current_cond)
1649 {
1650@@ -983,7 +983,7 @@
1651 /* Wait until all threads have closed all the tables we are flushing. */
1652 DBUG_PRINT("info", ("Waiting for other threads to close their open tables"));
1653
1654- while (found && ! thd->killed)
1655+ while (found && ! thd->get_killed())
1656 {
1657 TABLE_SHARE *share;
1658 found= FALSE;
1659@@ -2594,7 +2594,7 @@
1660 if (check_stack_overrun(thd, STACK_MIN_SIZE_FOR_OPEN, (uchar *)&alias))
1661 DBUG_RETURN(TRUE);
1662
1663- if (thd->killed)
1664+ if (thd->get_killed())
1665 DBUG_RETURN(TRUE);
1666
1667 key_length= get_table_def_key(table_list, &key);
1668@@ -3530,7 +3530,7 @@
1669 mysql_lock_merge(thd->lock, lock)) == NULL)
1670 {
1671 unlink_all_closed_tables(thd, lock, reopen_count);
1672- if (! thd->killed)
1673+ if (! thd->get_killed())
1674 my_error(ER_LOCK_DEADLOCK, MYF(0));
1675 return TRUE;
1676 }
1677
1678=== modified file 'Percona-Server/sql/sql_cache.cc'
1679--- Percona-Server/sql/sql_cache.cc 2012-10-03 12:51:45 +0000
1680+++ Percona-Server/sql/sql_cache.cc 2013-01-09 13:41:38 +0000
1681@@ -1001,7 +1001,7 @@
1682 if (query_cache_tls->first_query_block == NULL)
1683 DBUG_VOID_RETURN;
1684
1685- if (thd->killed || thd->is_error())
1686+ if (thd->get_killed() || thd->is_error())
1687 {
1688 query_cache_abort(&thd->query_cache_tls);
1689 DBUG_VOID_RETURN;
1690@@ -4239,7 +4239,7 @@
1691 DBUG_PRINT("warning", ("%5d QUERY CACHE WRECK => DISABLED",line));
1692 DBUG_PRINT("warning", ("=================================="));
1693 if (thd)
1694- thd->killed= THD::KILL_CONNECTION;
1695+ thd->set_killed(THD::KILL_CONNECTION);
1696 cache_dump();
1697 /* check_integrity(0); */ /* Can't call it here because of locks */
1698 bins_dump();
1699
1700=== modified file 'Percona-Server/sql/sql_class.cc'
1701--- Percona-Server/sql/sql_class.cc 2012-12-04 08:24:59 +0000
1702+++ Percona-Server/sql/sql_class.cc 2013-01-09 13:41:38 +0000
1703@@ -273,7 +273,7 @@
1704 */
1705 void thd_set_killed(THD *thd)
1706 {
1707- thd->killed= THD::KILL_CONNECTION;
1708+ thd->set_killed(THD::KILL_CONNECTION);
1709 }
1710
1711 /**
1712@@ -928,7 +928,7 @@
1713 password= 0;
1714 query_start_used= query_start_usec_used= 0;
1715 count_cuted_fields= CHECK_FIELD_IGNORE;
1716- killed= NOT_KILLED;
1717+ set_killed(NOT_KILLED);
1718 col_access=0;
1719 is_slave_error= thread_specific_used= FALSE;
1720 my_hash_clear(&handler_tables_hash);
1721@@ -945,6 +945,7 @@
1722 start_time.tv_sec= 0;
1723 start_time.tv_usec= 0;
1724 start_utime= prior_thr_create_utime= 0L;
1725+ sql_timeout_expire= 0;
1726 utime_after_lock= 0L;
1727 current_linfo = 0;
1728 slave_thread = 0;
1729@@ -1227,7 +1228,7 @@
1730 push_warning and strict SQL_MODE case.
1731 */
1732 level= Sql_condition::WARN_LEVEL_ERROR;
1733- killed= THD::KILL_BAD_DATA;
1734+ set_killed(THD::KILL_BAD_DATA);
1735 }
1736
1737 switch (level)
1738@@ -1433,7 +1434,7 @@
1739 mysql_mutex_unlock(&LOCK_status);
1740
1741 cleanup();
1742- killed= NOT_KILLED;
1743+ set_killed(NOT_KILLED);
1744 cleanup_done= 0;
1745 init();
1746 stmt_map.reset();
1747@@ -1454,7 +1455,7 @@
1748 DBUG_ENTER("THD::cleanup");
1749 DBUG_ASSERT(cleanup_done == 0);
1750
1751- killed= KILL_CONNECTION;
1752+ set_killed(KILL_CONNECTION);
1753 #ifdef ENABLE_WHEN_BINLOG_WILL_BE_ABLE_TO_PREPARE
1754 if (transaction.xid_state.xa_state == XA_PREPARED)
1755 {
1756@@ -1692,7 +1693,7 @@
1757 mysql_mutex_assert_owner(&LOCK_thd_data);
1758
1759 /* Set the 'killed' flag of 'this', which is the target THD object. */
1760- killed= state_to_set;
1761+ set_killed(state_to_set);
1762
1763 if (state_to_set != THD::KILL_QUERY)
1764 {
1765@@ -1713,7 +1714,7 @@
1766
1767 On the other hand, without closing the socket we have a race
1768 condition. If "this" target thread passes the check of
1769- thd->killed, and then the current thread runs through
1770+ thd->get_killed(), and then the current thread runs through
1771 THD::awake(), sets the 'killed' flag and completes the
1772 signaling, and then the target thread runs into read(), it will
1773 block on the socket. As a result of the discussions around
1774@@ -1721,7 +1722,7 @@
1775 condition. A second KILL awakes the target from read().
1776
1777 If we are killing ourselves, we know that we are not blocked.
1778- We also know that we will check thd->killed before we go for
1779+ We also know that we will check thd->get_killed() before we go for
1780 reading the next statement.
1781 */
1782
1783@@ -1759,7 +1760,7 @@
1784 current_cond and current_mutex are 0), then the victim will not get
1785 a signal and it may wait "forever" on the cond (until
1786 we issue a second KILL or the status it's waiting for happens).
1787- It's true that we have set its thd->killed but it may not
1788+ It's true that we have set its thd->get_killed() but it may not
1789 see it immediately and so may have time to reach the cond_wait().
1790
1791 However, where possible, we test for killed once again after
1792@@ -1792,7 +1793,7 @@
1793
1794 mysql_mutex_lock(&LOCK_thd_data);
1795
1796- killed= THD::KILL_CONNECTION;
1797+ set_killed(THD::KILL_CONNECTION);
1798
1799 #ifdef SIGNAL_WITH_VIO_CLOSE
1800 /*
1801@@ -1820,9 +1821,9 @@
1802 THD *in_use= ctx_in_use->get_thd();
1803 bool signalled= FALSE;
1804 if ((in_use->system_thread & SYSTEM_THREAD_DELAYED_INSERT) &&
1805- !in_use->killed)
1806+ !in_use->get_killed())
1807 {
1808- in_use->killed= THD::KILL_CONNECTION;
1809+ in_use->set_killed(THD::KILL_CONNECTION);
1810 mysql_mutex_lock(&in_use->mysys_var->mutex);
1811 if (in_use->mysys_var->current_cond)
1812 mysql_cond_broadcast(in_use->mysys_var->current_cond);
1813@@ -2185,7 +2186,7 @@
1814 {
1815 my_error(EE_OUTOFMEMORY, MYF(ME_BELL),
1816 ALIGN_SIZE(sizeof(TABLE_LIST)) + key_length + 1);
1817- killed= KILL_CONNECTION;
1818+ set_killed(KILL_CONNECTION);
1819 return 0;
1820 }
1821
1822@@ -3992,7 +3993,7 @@
1823 */
1824 extern "C" int thd_killed(const MYSQL_THD thd)
1825 {
1826- return(thd->killed);
1827+ return(thd->get_killed());
1828 }
1829
1830 /**
1831
1832=== modified file 'Percona-Server/sql/sql_class.h'
1833--- Percona-Server/sql/sql_class.h 2012-12-04 08:24:59 +0000
1834+++ Percona-Server/sql/sql_class.h 2013-01-09 13:41:38 +0000
1835@@ -481,6 +481,7 @@
1836 ulong trans_alloc_block_size;
1837 ulong trans_prealloc_size;
1838 ulong group_concat_max_len;
1839+ ulong sql_timeout;
1840
1841 ulong binlog_format; ///< binlog format for this thd (see enum_binlog_format)
1842 my_bool binlog_direct_non_trans_update;
1843@@ -2124,6 +2125,12 @@
1844 uint16 peer_port;
1845 struct timeval start_time;
1846 struct timeval user_time;
1847+ /*
1848+ Expire time in microseconds for sql_timeout monitor thread. The 0 value
1849+ means the current thread is not monitored by sql_timeout monitor.
1850+ */
1851+ ulonglong sql_timeout_expire;
1852+
1853 // track down slow pthread_create
1854 ulonglong prior_thr_create_utime, thr_create_utime;
1855 ulonglong start_utime, utime_after_lock;
1856@@ -2807,7 +2814,27 @@
1857 KILL_QUERY=ER_QUERY_INTERRUPTED,
1858 KILLED_NO_VALUE /* means neither of the states */
1859 };
1860- killed_state volatile killed;
1861+
1862+private:
1863+ killed_state volatile killed_status;
1864+
1865+public:
1866+ killed_state get_killed() const
1867+ {
1868+ if (killed_status)
1869+ return killed_status;
1870+ if (sql_timeout_expire &&
1871+ (my_micro_time() >= sql_timeout_expire))
1872+ {
1873+ return THD::KILL_QUERY;
1874+ }
1875+ return killed_status;
1876+ }
1877+
1878+ void set_killed(killed_state new_killed)
1879+ {
1880+ killed_status= new_killed;
1881+ }
1882
1883 /* scramble - random string sent to client on handshake */
1884 char scramble[SCRAMBLE_LENGTH+1];
1885@@ -3080,7 +3107,7 @@
1886 DBUG_VOID_RETURN;
1887 }
1888
1889- virtual int is_killed() { return killed; }
1890+ virtual int is_killed() { return get_killed(); }
1891 virtual THD* get_thd() { return this; }
1892
1893 /**
1894@@ -3331,7 +3358,7 @@
1895 */
1896 inline void fatal_error()
1897 {
1898- DBUG_ASSERT(get_stmt_da()->is_error() || killed);
1899+ DBUG_ASSERT(get_stmt_da()->is_error() || get_killed());
1900 is_fatal_error= 1;
1901 DBUG_PRINT("error",("Fatal error set"));
1902 }
1903@@ -3420,7 +3447,7 @@
1904 inline int killed_errno() const
1905 {
1906 killed_state killed_val; /* to cache the volatile 'killed' */
1907- return (killed_val= killed) != KILL_BAD_DATA ? killed_val : 0;
1908+ return (killed_val= get_killed()) != KILL_BAD_DATA ? killed_val : 0;
1909 }
1910 inline void send_kill_message() const
1911 {
1912
1913=== modified file 'Percona-Server/sql/sql_connect.cc'
1914--- Percona-Server/sql/sql_connect.cc 2012-12-04 08:24:59 +0000
1915+++ Percona-Server/sql/sql_connect.cc 2013-01-09 13:41:38 +0000
1916@@ -768,14 +768,14 @@
1917 */
1918 release_user_connection(thd);
1919
1920- if (thd->killed || (net->error && net->vio != 0))
1921+ if (thd->get_killed() || (net->error && net->vio != 0))
1922 {
1923 statistic_increment(aborted_threads,&LOCK_status);
1924 }
1925
1926 if (net->error && net->vio != 0)
1927 {
1928- if (!thd->killed && log_warnings > 1)
1929+ if (!thd->get_killed() && log_warnings > 1)
1930 {
1931 Security_context *sctx= thd->security_ctx;
1932
1933@@ -846,7 +846,7 @@
1934
1935 thd->server_status&= ~SERVER_STATUS_CLEAR_SET;
1936 thd->protocol->end_statement();
1937- thd->killed = THD::KILL_CONNECTION;
1938+ thd->set_killed(THD::KILL_CONNECTION);
1939 errors.m_init_connect= 1;
1940 inc_host_errors(thd->main_security_ctx.ip, &errors);
1941 return;
1942@@ -907,7 +907,7 @@
1943 NET *net= &thd->net;
1944 if (!net->error &&
1945 net->vio != 0 &&
1946- !(thd->killed == THD::KILL_CONNECTION))
1947+ !(thd->get_killed() == THD::KILL_CONNECTION))
1948 return TRUE;
1949 return FALSE;
1950 }
1951
1952=== modified file 'Percona-Server/sql/sql_db.cc'
1953--- Percona-Server/sql/sql_db.cc 2012-12-04 08:24:59 +0000
1954+++ Percona-Server/sql/sql_db.cc 2013-01-09 13:41:38 +0000
1955@@ -840,7 +840,7 @@
1956 }
1957
1958 thd->push_internal_handler(&err_handler);
1959- if (!thd->killed &&
1960+ if (!thd->get_killed() &&
1961 !(tables &&
1962 mysql_rm_table_no_locks(thd, tables, true, false, true, true)))
1963 {
1964@@ -1025,7 +1025,7 @@
1965 tot_list_next_local= tot_list_next_global= &tot_list;
1966
1967 for (uint idx=0 ;
1968- idx < (uint) dirp->number_off_files && !thd->killed ;
1969+ idx < (uint) dirp->number_off_files && !thd->get_killed() ;
1970 idx++)
1971 {
1972 FILEINFO *file=dirp->dir_entry+idx;
1973@@ -1206,7 +1206,7 @@
1974 DBUG_PRINT("enter", ("path: %s", org_path));
1975
1976 for (uint idx=0 ;
1977- idx < (uint) dirp->number_off_files && !thd->killed ;
1978+ idx < (uint) dirp->number_off_files && !thd->get_killed() ;
1979 idx++)
1980 {
1981 FILEINFO *file=dirp->dir_entry+idx;
1982@@ -1241,7 +1241,7 @@
1983 }
1984 deleted++;
1985 }
1986- if (thd->killed)
1987+ if (thd->get_killed())
1988 goto err;
1989
1990 my_dirend(dirp);
1991@@ -1710,7 +1710,7 @@
1992 if ((dirp = my_dir(path,MYF(MY_DONT_SORT))))
1993 {
1994 uint nfiles= (uint) dirp->number_off_files;
1995- for (uint idx=0 ; idx < nfiles && !thd->killed ; idx++)
1996+ for (uint idx=0 ; idx < nfiles && !thd->get_killed() ; idx++)
1997 {
1998 FILEINFO *file= dirp->dir_entry + idx;
1999 char *extension, tname[FN_REFLEN + 1];
2000
2001=== modified file 'Percona-Server/sql/sql_delete.cc'
2002--- Percona-Server/sql/sql_delete.cc 2012-12-04 08:24:59 +0000
2003+++ Percona-Server/sql/sql_delete.cc 2013-01-09 13:41:38 +0000
2004@@ -350,7 +350,7 @@
2005 select && select->quick && select->quick->index != MAX_KEY)
2006 read_removal= table->check_read_removal(select->quick->index);
2007
2008- while (!(error=info.read_record(&info)) && !thd->killed &&
2009+ while (!(error=info.read_record(&info)) && !thd->get_killed() &&
2010 ! thd->is_error())
2011 {
2012 thd->inc_examined_row_count(1);
2013@@ -406,7 +406,7 @@
2014 else
2015 break;
2016 }
2017- killed_status= thd->killed;
2018+ killed_status= thd->get_killed();
2019 if (killed_status != THD::NOT_KILLED || thd->is_error())
2020 error= 1; // Aborted
2021 if (will_batch && (loc_error= table->file->end_bulk_delete()))
2022@@ -479,7 +479,7 @@
2023 my_ok(thd, deleted);
2024 DBUG_PRINT("info",("%ld records deleted",(long) deleted));
2025 }
2026- DBUG_RETURN(thd->is_error() || thd->killed);
2027+ DBUG_RETURN(thd->is_error() || thd->get_killed());
2028
2029 #ifdef WITH_PARTITION_STORAGE_ENGINE
2030 exit_all_parts_pruned_away:
2031@@ -496,7 +496,7 @@
2032 delete select;
2033 free_underlaid_joins(thd, select_lex);
2034 table->set_keyread(false);
2035- DBUG_RETURN((err || thd->is_error() || thd->killed) ? 1 : 0);
2036+ DBUG_RETURN((err || thd->is_error() || thd->get_killed()) ? 1 : 0);
2037 }
2038
2039
2040@@ -893,7 +893,7 @@
2041 */
2042 if (mysql_bin_log.is_open())
2043 {
2044- int errcode= query_error_code(thd, thd->killed == THD::NOT_KILLED);
2045+ int errcode= query_error_code(thd, thd->get_killed() == THD::NOT_KILLED);
2046 /* possible error of writing binary log is ignored deliberately */
2047 (void) thd->binlog_query(THD::ROW_QUERY_TYPE,
2048 thd->query(), thd->query_length(),
2049@@ -938,7 +938,7 @@
2050 int local_error=
2051 do_table_deletes(table, thd->lex->current_select->no_error);
2052
2053- if (thd->killed && !local_error)
2054+ if (thd->get_killed() && !local_error)
2055 DBUG_RETURN(1);
2056
2057 if (local_error == -1) // End of file
2058@@ -980,7 +980,7 @@
2059 */
2060 info.ignore_not_found_rows= 1;
2061 bool will_batch= !table->file->start_bulk_delete();
2062- while (!(local_error= info.read_record(&info)) && !thd->killed)
2063+ while (!(local_error= info.read_record(&info)) && !thd->get_killed())
2064 {
2065 if (table->triggers &&
2066 table->triggers->process_triggers(thd, TRG_EVENT_DELETE,
2067@@ -1048,7 +1048,7 @@
2068
2069 /* compute a total error to know if something failed */
2070 local_error= local_error || error;
2071- killed_status= (local_error == 0)? THD::NOT_KILLED : thd->killed;
2072+ killed_status= (local_error == 0)? THD::NOT_KILLED : thd->get_killed();
2073 /* reset used flags */
2074 THD_STAGE_INFO(thd, stage_end);
2075
2076
2077=== modified file 'Percona-Server/sql/sql_executor.cc'
2078--- Percona-Server/sql/sql_executor.cc 2012-12-04 08:24:59 +0000
2079+++ Percona-Server/sql/sql_executor.cc 2013-01-09 13:41:38 +0000
2080@@ -1033,7 +1033,7 @@
2081
2082 DBUG_ENTER("sub_select_op");
2083
2084- if (join->thd->killed)
2085+ if (join->thd->get_killed())
2086 {
2087 /* The user has aborted the execution of the query */
2088 join->thd->send_kill_message();
2089@@ -1248,13 +1248,13 @@
2090 else
2091 error= info->read_record(info);
2092
2093- DBUG_EXECUTE_IF("bug13822652_1", join->thd->killed= THD::KILL_QUERY;);
2094+ DBUG_EXECUTE_IF("bug13822652_1", join->thd->set_killed(THD::KILL_QUERY););
2095
2096 if (error > 0 || (join->thd->is_error())) // Fatal error
2097 rc= NESTED_LOOP_ERROR;
2098 else if (error < 0)
2099 break;
2100- else if (join->thd->killed) // Aborted by user
2101+ else if (join->thd->get_killed()) // Aborted by user
2102 {
2103 join->thd->send_kill_message();
2104 rc= NESTED_LOOP_KILLED;
2105@@ -1450,7 +1450,7 @@
2106 {
2107 found= test(condition->val_int());
2108
2109- if (join->thd->killed)
2110+ if (join->thd->get_killed())
2111 {
2112 join->thd->send_kill_message();
2113 DBUG_RETURN(NESTED_LOOP_KILLED);
2114@@ -1737,7 +1737,7 @@
2115 if (error != HA_ERR_LOCK_DEADLOCK &&
2116 error != HA_ERR_LOCK_WAIT_TIMEOUT &&
2117 error != HA_ERR_TABLE_DEF_CHANGED &&
2118- !table->in_use->killed)
2119+ !table->in_use->get_killed())
2120 sql_print_error("Got error %d when reading table '%s'",
2121 error, table->s->path.str);
2122 table->file->print_error(error,MYF(0));
2123@@ -2922,7 +2922,7 @@
2124 TABLE *const table= join_tab->table;
2125 DBUG_ENTER("end_write");
2126
2127- if (join->thd->killed) // Aborted by user
2128+ if (join->thd->get_killed()) // Aborted by user
2129 {
2130 join->thd->send_kill_message();
2131 DBUG_RETURN(NESTED_LOOP_KILLED); /* purecov: inspected */
2132@@ -2977,7 +2977,7 @@
2133
2134 if (end_of_records)
2135 DBUG_RETURN(NESTED_LOOP_OK);
2136- if (join->thd->killed) // Aborted by user
2137+ if (join->thd->get_killed()) // Aborted by user
2138 {
2139 join->thd->send_kill_message();
2140 DBUG_RETURN(NESTED_LOOP_KILLED); /* purecov: inspected */
2141@@ -3057,7 +3057,7 @@
2142
2143 if (end_of_records)
2144 DBUG_RETURN(NESTED_LOOP_OK);
2145- if (join->thd->killed) // Aborted by user
2146+ if (join->thd->get_killed()) // Aborted by user
2147 {
2148 join->thd->send_kill_message();
2149 DBUG_RETURN(NESTED_LOOP_KILLED); /* purecov: inspected */
2150@@ -3103,7 +3103,7 @@
2151 int idx= -1;
2152 DBUG_ENTER("end_write_group");
2153
2154- if (join->thd->killed)
2155+ if (join->thd->get_killed())
2156 { // Aborted by user
2157 join->thd->send_kill_message();
2158 DBUG_RETURN(NESTED_LOOP_KILLED); /* purecov: inspected */
2159@@ -3406,7 +3406,7 @@
2160 error=file->ha_rnd_next(record);
2161 for (;;)
2162 {
2163- if (thd->killed)
2164+ if (thd->get_killed())
2165 {
2166 thd->send_kill_message();
2167 error=0;
2168@@ -3538,7 +3538,7 @@
2169 for (;;)
2170 {
2171 uchar *org_key_pos;
2172- if (thd->killed)
2173+ if (thd->get_killed())
2174 {
2175 thd->send_kill_message();
2176 error=0;
2177@@ -4298,7 +4298,7 @@
2178 rc= NESTED_LOOP_ERROR;
2179 else if (error < 0)
2180 break;
2181- else if (join->thd->killed) // Aborted by user
2182+ else if (join->thd->get_killed()) // Aborted by user
2183 {
2184 join->thd->send_kill_message();
2185 rc= NESTED_LOOP_KILLED;
2186
2187=== modified file 'Percona-Server/sql/sql_insert.cc'
2188--- Percona-Server/sql/sql_insert.cc 2012-12-04 08:24:59 +0000
2189+++ Percona-Server/sql/sql_insert.cc 2013-01-09 13:41:38 +0000
2190@@ -1106,7 +1106,7 @@
2191 thd->clear_error();
2192 }
2193 else
2194- errcode= query_error_code(thd, thd->killed == THD::NOT_KILLED);
2195+ errcode= query_error_code(thd, thd->get_killed() == THD::NOT_KILLED);
2196
2197 /* bug#22725:
2198
2199@@ -1120,7 +1120,7 @@
2200 routines did not result in any error due to the KILLED. In
2201 such case the flag is ignored for constructing binlog event.
2202 */
2203- DBUG_ASSERT(thd->killed != THD::KILL_BAD_DATA || error > 0);
2204+ DBUG_ASSERT(thd->get_killed() != THD::KILL_BAD_DATA || error > 0);
2205 if (was_insert_delayed && table_list->lock_type == TL_WRITE)
2206 {
2207 /* Binlog INSERT DELAYED as INSERT without DELAYED. */
2208@@ -2201,7 +2201,7 @@
2209 if (!--locks_in_memory)
2210 {
2211 mysql_mutex_lock(&mutex);
2212- if (thd.killed && ! stacked_inserts && ! tables_in_use)
2213+ if (thd.get_killed() && ! stacked_inserts && ! tables_in_use)
2214 {
2215 mysql_cond_signal(&cond);
2216 status=1;
2217@@ -2370,18 +2370,18 @@
2218 */
2219 THD_STAGE_INFO(thd, stage_waiting_for_handler_open);
2220 while (!di->handler_thread_initialized ||
2221- (!di->thd.killed && !di->table && !thd->killed))
2222+ (!di->thd.get_killed() && !di->table && !thd->get_killed()))
2223 {
2224 mysql_cond_wait(&di->cond_client, &di->mutex);
2225 }
2226 mysql_mutex_unlock(&di->mutex);
2227 THD_STAGE_INFO(thd, stage_got_old_table);
2228- if (thd->killed)
2229+ if (thd->get_killed())
2230 {
2231 di->unlock();
2232 goto end_create;
2233 }
2234- if (di->thd.killed)
2235+ if (di->thd.get_killed())
2236 {
2237 if (di->thd.is_error())
2238 {
2239@@ -2459,14 +2459,14 @@
2240 {
2241 THD_STAGE_INFO(client_thd, stage_waiting_for_handler_lock);
2242 mysql_cond_signal(&cond); // Tell handler to lock table
2243- while (!thd.killed && !thd.lock && ! client_thd->killed)
2244+ while (!thd.get_killed() && !thd.lock && ! client_thd->get_killed())
2245 {
2246 mysql_cond_wait(&cond_client, &mutex);
2247 }
2248 THD_STAGE_INFO(client_thd, stage_got_handler_lock);
2249- if (client_thd->killed)
2250+ if (client_thd->get_killed())
2251 goto error;
2252- if (thd.killed)
2253+ if (thd.get_killed())
2254 {
2255 /*
2256 Copy the error message. Note that we don't treat fatal
2257@@ -2598,11 +2598,11 @@
2258
2259 THD_STAGE_INFO(thd, stage_waiting_for_handler_insert);
2260 mysql_mutex_lock(&di->mutex);
2261- while (di->stacked_inserts >= delayed_queue_size && !thd->killed)
2262+ while (di->stacked_inserts >= delayed_queue_size && !thd->get_killed())
2263 mysql_cond_wait(&di->cond_client, &di->mutex);
2264 THD_STAGE_INFO(thd, stage_storing_row_into_queue);
2265
2266- if (thd->killed)
2267+ if (thd->get_killed())
2268 goto err;
2269
2270 /*
2271@@ -2652,7 +2652,7 @@
2272 Delayed_insert *di=thd->di;
2273 mysql_mutex_lock(&di->mutex);
2274 DBUG_PRINT("info",("tables in use: %d",di->tables_in_use));
2275- if (!--di->tables_in_use || di->thd.killed)
2276+ if (!--di->tables_in_use || di->thd.get_killed())
2277 { // Unlock table
2278 di->status=1;
2279 mysql_cond_signal(&di->cond);
2280@@ -2672,7 +2672,7 @@
2281 Delayed_insert *di;
2282 while ((di= it++))
2283 {
2284- di->thd.killed= THD::KILL_CONNECTION;
2285+ di->thd.set_killed(THD::KILL_CONNECTION);
2286 if (di->thd.mysys_var)
2287 {
2288 mysql_mutex_lock(&di->thd.mysys_var->mutex);
2289@@ -2809,7 +2809,7 @@
2290 thd->thread_id= thd->variables.pseudo_thread_id= thread_id++;
2291 thd->set_current_time();
2292 add_global_thread(thd);
2293- thd->killed=abort_loop ? THD::KILL_CONNECTION : THD::NOT_KILLED;
2294+ thd->set_killed(abort_loop ? THD::KILL_CONNECTION : THD::NOT_KILLED);
2295 mysql_mutex_unlock(&LOCK_thread_count);
2296
2297 mysql_thread_set_psi_id(thd->thread_id);
2298@@ -2882,7 +2882,7 @@
2299
2300 for (;;)
2301 {
2302- if (thd->killed)
2303+ if (thd->get_killed())
2304 {
2305 uint lock_count;
2306 /*
2307@@ -2900,7 +2900,7 @@
2308 }
2309
2310 /* Shouldn't wait if killed or an insert is waiting. */
2311- if (!thd->killed && !di->status && !di->stacked_inserts)
2312+ if (!thd->get_killed() && !di->status && !di->stacked_inserts)
2313 {
2314 struct timespec abstime;
2315 set_timespec(abstime, delayed_insert_timeout);
2316@@ -2911,7 +2911,7 @@
2317 THD_STAGE_INFO(&(di->thd), stage_waiting_for_insert);
2318
2319 DBUG_PRINT("info",("Waiting for someone to insert rows"));
2320- while (!thd->killed && !di->status)
2321+ while (!thd->get_killed() && !di->status)
2322 {
2323 int error;
2324 mysql_audit_release(thd);
2325@@ -2929,7 +2929,7 @@
2326 #endif
2327 #endif
2328 if (error == ETIMEDOUT || error == ETIME)
2329- thd->killed= THD::KILL_CONNECTION;
2330+ thd->set_killed(THD::KILL_CONNECTION);
2331 }
2332 /* We can't lock di->mutex and mysys_var->mutex at the same time */
2333 mysql_mutex_unlock(&di->mutex);
2334@@ -2940,7 +2940,7 @@
2335 mysql_mutex_lock(&di->mutex);
2336 }
2337
2338- if (di->tables_in_use && ! thd->lock && !thd->killed)
2339+ if (di->tables_in_use && ! thd->lock && !thd->get_killed())
2340 {
2341 /*
2342 Request for new delayed insert.
2343@@ -2955,7 +2955,7 @@
2344 if (! (thd->lock= mysql_lock_tables(thd, &di->table, 1, 0)))
2345 {
2346 /* Fatal error */
2347- thd->killed= THD::KILL_CONNECTION;
2348+ thd->set_killed(THD::KILL_CONNECTION);
2349 }
2350 mysql_cond_broadcast(&di->cond_client);
2351 }
2352@@ -2964,7 +2964,7 @@
2353 if (di->handle_inserts())
2354 {
2355 /* Some fatal error */
2356- thd->killed= THD::KILL_CONNECTION;
2357+ thd->set_killed(THD::KILL_CONNECTION);
2358 }
2359 }
2360 di->status=0;
2361@@ -2999,7 +2999,7 @@
2362 close_thread_tables(thd); // Free the table
2363 thd->mdl_context.release_transactional_locks();
2364 di->table=0;
2365- thd->killed= THD::KILL_CONNECTION; // If error
2366+ thd->set_killed(THD::KILL_CONNECTION); // If error
2367 mysql_cond_broadcast(&di->cond_client); // Safety
2368 mysql_mutex_unlock(&di->mutex);
2369
2370@@ -3079,9 +3079,9 @@
2371
2372 THD_STAGE_INFO(&thd, stage_insert);
2373 max_rows= delayed_insert_limit;
2374- if (thd.killed || table->s->has_old_version())
2375+ if (thd.get_killed() || table->s->has_old_version())
2376 {
2377- thd.killed= THD::KILL_CONNECTION;
2378+ thd.set_killed(THD::KILL_CONNECTION);
2379 max_rows= ULONG_MAX; // Do as much as possible
2380 }
2381
2382@@ -3691,7 +3691,7 @@
2383 bool const trans_table= table->file->has_transactions();
2384 ulonglong id, row_count;
2385 bool changed;
2386- THD::killed_state killed_status= thd->killed;
2387+ THD::killed_state killed_status= thd->get_killed();
2388 DBUG_ENTER("select_insert::send_eof");
2389 DBUG_PRINT("enter", ("trans_table=%d, table_type='%s'",
2390 trans_table, table->file->table_type()));
2391@@ -3812,7 +3812,7 @@
2392 {
2393 if (mysql_bin_log.is_open())
2394 {
2395- int errcode= query_error_code(thd, thd->killed == THD::NOT_KILLED);
2396+ int errcode= query_error_code(thd, thd->get_killed() == THD::NOT_KILLED);
2397 /* error of writing binary log is ignored */
2398 (void) thd->binlog_query(THD::ROW_QUERY_TYPE, thd->query(),
2399 thd->query_length(),
2400@@ -4221,7 +4221,7 @@
2401
2402 if (mysql_bin_log.is_open())
2403 {
2404- int errcode= query_error_code(thd, thd->killed == THD::NOT_KILLED);
2405+ int errcode= query_error_code(thd, thd->get_killed() == THD::NOT_KILLED);
2406 result= thd->binlog_query(THD::STMT_QUERY_TYPE,
2407 query.ptr(), query.length(),
2408 /* is_trans */ TRUE,
2409
2410=== modified file 'Percona-Server/sql/sql_join_buffer.cc'
2411--- Percona-Server/sql/sql_join_buffer.cc 2012-10-16 06:21:51 +0000
2412+++ Percona-Server/sql/sql_join_buffer.cc 2013-01-09 13:41:38 +0000
2413@@ -1839,7 +1839,7 @@
2414 if (join_tab->keep_current_rowid)
2415 join_tab->table->file->position(join_tab->table->record[0]);
2416
2417- if (join->thd->killed)
2418+ if (join->thd->get_killed())
2419 {
2420 /* The user has aborted the execution of the query */
2421 join->thd->send_kill_message();
2422@@ -2121,7 +2121,7 @@
2423
2424 for ( ; cnt; cnt--)
2425 {
2426- if (join->thd->killed)
2427+ if (join->thd->get_killed())
2428 {
2429 /* The user has aborted the execution of the query */
2430 join->thd->send_kill_message();
2431@@ -2331,7 +2331,7 @@
2432
2433 while (!(error= file->multi_range_read_next((char **) &rec_ptr)))
2434 {
2435- if (join->thd->killed)
2436+ if (join->thd->get_killed())
2437 {
2438 /* The user has aborted the execution of the query */
2439 join->thd->send_kill_message();
2440@@ -3261,7 +3261,7 @@
2441 next_rec_ref_ptr= get_next_rec_ref(next_rec_ref_ptr);
2442 uchar *rec_ptr= next_rec_ref_ptr+rec_fields_offset;
2443
2444- if (join->thd->killed)
2445+ if (join->thd->get_killed())
2446 {
2447 /* The user has aborted the execution of the query */
2448 join->thd->send_kill_message();
2449
2450=== modified file 'Percona-Server/sql/sql_load.cc'
2451--- Percona-Server/sql/sql_load.cc 2012-12-04 08:24:59 +0000
2452+++ Percona-Server/sql/sql_load.cc 2013-01-09 13:41:38 +0000
2453@@ -526,11 +526,11 @@
2454 DBUG_EXECUTE_IF("simulate_kill_bug27571",
2455 {
2456 error=1;
2457- thd->killed= THD::KILL_QUERY;
2458+ thd->set_killed(THD::KILL_QUERY);
2459 };);
2460
2461 #ifndef EMBEDDED_LIBRARY
2462- killed_status= (error == 0) ? THD::NOT_KILLED : thd->killed;
2463+ killed_status= (error == 0) ? THD::NOT_KILLED : thd->get_killed();
2464 #endif
2465
2466 /*
2467@@ -795,7 +795,7 @@
2468
2469 while (!read_info.read_fixed_length())
2470 {
2471- if (thd->killed)
2472+ if (thd->get_killed())
2473 {
2474 thd->send_kill_message();
2475 DBUG_RETURN(1);
2476@@ -870,7 +870,7 @@
2477 thd->get_stmt_da()->current_row_for_warning());
2478 }
2479
2480- if (thd->killed ||
2481+ if (thd->get_killed() ||
2482 fill_record_n_invoke_before_triggers(thd, set_fields, set_values,
2483 ignore_check_option_errors,
2484 table->triggers,
2485@@ -931,7 +931,7 @@
2486
2487 for (;;it.rewind())
2488 {
2489- if (thd->killed)
2490+ if (thd->get_killed())
2491 {
2492 thd->send_kill_message();
2493 DBUG_RETURN(1);
2494@@ -1080,7 +1080,7 @@
2495 }
2496 }
2497
2498- if (thd->killed ||
2499+ if (thd->get_killed() ||
2500 fill_record_n_invoke_before_triggers(thd, set_fields, set_values,
2501 ignore_check_option_errors,
2502 table->triggers,
2503@@ -1112,7 +1112,7 @@
2504 push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN,
2505 ER_WARN_TOO_MANY_RECORDS, ER(ER_WARN_TOO_MANY_RECORDS),
2506 thd->get_stmt_da()->current_row_for_warning());
2507- if (thd->killed)
2508+ if (thd->get_killed())
2509 DBUG_RETURN(1);
2510 }
2511 thd->get_stmt_da()->inc_current_row_for_warning();
2512@@ -1140,7 +1140,7 @@
2513
2514 for ( ; ; it.rewind())
2515 {
2516- if (thd->killed)
2517+ if (thd->get_killed())
2518 {
2519 thd->send_kill_message();
2520 DBUG_RETURN(1);
2521@@ -1254,7 +1254,7 @@
2522 }
2523 }
2524
2525- if (thd->killed ||
2526+ if (thd->get_killed() ||
2527 fill_record_n_invoke_before_triggers(thd, set_fields, set_values,
2528 ignore_check_option_errors,
2529 table->triggers,
2530
2531=== modified file 'Percona-Server/sql/sql_optimizer.cc'
2532--- Percona-Server/sql/sql_optimizer.cc 2012-12-04 08:24:59 +0000
2533+++ Percona-Server/sql/sql_optimizer.cc 2013-01-09 13:41:38 +0000
2534@@ -3730,8 +3730,8 @@
2535 if (Optimize_table_order(thd, join, NULL).choose_table_order())
2536 DBUG_RETURN(true);
2537
2538- DBUG_EXECUTE_IF("bug13820776_1", thd->killed= THD::KILL_QUERY;);
2539- if (thd->killed || thd->is_error())
2540+ DBUG_EXECUTE_IF("bug13820776_1", thd->set_killed(THD::KILL_QUERY););
2541+ if (thd->get_killed() || thd->is_error())
2542 DBUG_RETURN(true);
2543
2544 if (join->decide_subquery_strategy())
2545
2546=== modified file 'Percona-Server/sql/sql_parse.cc'
2547--- Percona-Server/sql/sql_parse.cc 2012-12-04 08:24:59 +0000
2548+++ Percona-Server/sql/sql_parse.cc 2013-01-09 13:41:38 +0000
2549@@ -942,7 +942,7 @@
2550 /*
2551 Synchronization point for testing of KILL_CONNECTION.
2552 This sync point can wait here, to simulate slow code execution
2553- between the last test of thd->killed and blocking in read().
2554+ between the last test of thd->get_killed() and blocking in read().
2555
2556 The goal of this test is to verify that a connection does not
2557 hang, if it is killed at this point of execution.
2558@@ -1311,7 +1311,7 @@
2559
2560 mysql_parse(thd, thd->query(), thd->query_length(), &parser_state);
2561
2562- while (!thd->killed && (parser_state.m_lip.found_semicolon != NULL) &&
2563+ while (!thd->get_killed() && (parser_state.m_lip.found_semicolon != NULL) &&
2564 ! thd->is_error())
2565 {
2566 /*
2567@@ -1690,7 +1690,7 @@
2568
2569 /* Finalize server status flags after executing a command. */
2570 thd->update_server_status();
2571- if (thd->killed)
2572+ if (thd->get_killed())
2573 thd->send_kill_message();
2574 thd->protocol->end_statement();
2575 query_cache_end_of_result(thd);
2576@@ -4179,7 +4179,7 @@
2577 }
2578 /* Disconnect the current client connection. */
2579 if (tx_release)
2580- thd->killed= THD::KILL_CONNECTION;
2581+ thd->set_killed(THD::KILL_CONNECTION);
2582 my_ok(thd);
2583 break;
2584 }
2585@@ -4210,7 +4210,7 @@
2586 }
2587 /* Disconnect the current client connection. */
2588 if (tx_release)
2589- thd->killed= THD::KILL_CONNECTION;
2590+ thd->set_killed(THD::KILL_CONNECTION);
2591 my_ok(thd);
2592 break;
2593 }
2594@@ -4469,7 +4469,7 @@
2595 }
2596 else
2597 {
2598- DBUG_ASSERT(thd->is_error() || thd->killed);
2599+ DBUG_ASSERT(thd->is_error() || thd->get_killed());
2600 goto error; // Substatement should already have sent error
2601 }
2602 }
2603@@ -4495,7 +4495,7 @@
2604 /* Conditionally writes to binlog */
2605 int sp_result= sp_update_routine(thd, sp_type, lex->spname,
2606 &lex->sp_chistics);
2607- if (thd->killed)
2608+ if (thd->get_killed())
2609 goto error;
2610 switch (sp_result)
2611 {
2612@@ -4808,7 +4808,7 @@
2613 drop_server() can fail without reporting an error
2614 due to IF EXISTS clause. In this case, call my_ok().
2615 */
2616- if (thd->is_error() || thd->killed)
2617+ if (thd->is_error() || thd->get_killed())
2618 goto error;
2619 DBUG_ASSERT(lex->drop_if_exists);
2620 my_ok(thd, 0);
2621@@ -4883,9 +4883,9 @@
2622 /* report error issued during command execution */
2623 if (thd->killed_errno())
2624 thd->send_kill_message();
2625- if (thd->killed == THD::KILL_QUERY || thd->killed == THD::KILL_BAD_DATA)
2626+ if (thd->get_killed() == THD::KILL_QUERY || thd->get_killed() == THD::KILL_BAD_DATA)
2627 {
2628- thd->killed= THD::NOT_KILLED;
2629+ thd->set_killed(THD::NOT_KILLED);
2630 thd->mysys_var->abort= 0;
2631 }
2632 if (thd->is_error() || (thd->variables.option_bits & OPTION_MASTER_SQL_ERROR))
2633@@ -6096,7 +6096,15 @@
2634 error= 1;
2635 }
2636 else
2637- error= mysql_execute_command(thd);
2638+ {
2639+ if (thd->variables.sql_timeout)
2640+ thd->sql_timeout_expire= my_micro_time() +
2641+ (ulonglong)thd->variables.sql_timeout*1000000;
2642+
2643+ error= mysql_execute_command(thd);
2644+
2645+ thd->sql_timeout_expire= 0;
2646+ }
2647 if (error == 0 &&
2648 thd->variables.gtid_next.type == GTID_GROUP &&
2649 thd->owned_gtid.sidno != 0 &&
2650@@ -7009,7 +7017,7 @@
2651 uint error;
2652 if (!(error= kill_one_thread(thd, id, only_kill_query)))
2653 {
2654- if (! thd->killed)
2655+ if (! thd->get_killed())
2656 my_ok(thd);
2657 }
2658 else
2659
2660=== modified file 'Percona-Server/sql/sql_planner.cc'
2661--- Percona-Server/sql/sql_planner.cc 2012-10-16 06:21:51 +0000
2662+++ Percona-Server/sql/sql_planner.cc 2013-01-09 13:41:38 +0000
2663@@ -1768,8 +1768,8 @@
2664 {
2665 DBUG_ENTER("Optimize_table_order::best_extension_by_limited_search");
2666
2667- DBUG_EXECUTE_IF("bug13820776_2", thd->killed= THD::KILL_QUERY;);
2668- if (thd->killed) // Abort
2669+ DBUG_EXECUTE_IF("bug13820776_2", thd->set_killed(THD::KILL_QUERY););
2670+ if (thd->get_killed()) // Abort
2671 DBUG_RETURN(true);
2672 Opt_trace_context * const trace= &thd->opt_trace;
2673
2674
2675=== modified file 'Percona-Server/sql/sql_prepare.cc'
2676--- Percona-Server/sql/sql_prepare.cc 2012-12-04 08:24:59 +0000
2677+++ Percona-Server/sql/sql_prepare.cc 2013-01-09 13:41:38 +0000
2678@@ -3553,7 +3553,7 @@
2679 thd->pop_reprepare_observer();
2680
2681 if ((sql_command_flags[lex->sql_command] & CF_REEXECUTION_FRAGILE) &&
2682- error && !thd->is_fatal_error && !thd->killed &&
2683+ error && !thd->is_fatal_error && !thd->get_killed() &&
2684 reprepare_observer.is_invalidated() &&
2685 reprepare_attempt++ < MAX_REPREPARE_ATTEMPTS)
2686 {
2687
2688=== modified file 'Percona-Server/sql/sql_reload.cc'
2689--- Percona-Server/sql/sql_reload.cc 2012-08-22 01:40:20 +0000
2690+++ Percona-Server/sql/sql_reload.cc 2013-01-09 13:41:38 +0000
2691@@ -50,7 +50,7 @@
2692
2693 @return Error status code
2694 @retval 0 Ok
2695- @retval !=0 Error; thd->killed is set or thd->is_error() is true
2696+ @retval !=0 Error; thd->get_killed() is set or thd->is_error() is true
2697 */
2698
2699 bool reload_acl_and_cache(THD *thd, unsigned long options,
2700@@ -340,7 +340,7 @@
2701 /*
2702 If the query was killed then this function must fail.
2703 */
2704- return result || (thd ? thd->killed : 0);
2705+ return result || (thd ? thd->get_killed() : 0);
2706 }
2707
2708
2709
2710=== modified file 'Percona-Server/sql/sql_servers.cc'
2711--- Percona-Server/sql/sql_servers.cc 2012-07-30 13:28:51 +0000
2712+++ Percona-Server/sql/sql_servers.cc 2013-01-09 13:41:38 +0000
2713@@ -607,7 +607,7 @@
2714 }
2715
2716 mysql_rwlock_unlock(&THR_LOCK_servers);
2717- DBUG_RETURN(error || thd->killed);
2718+ DBUG_RETURN(error || thd->get_killed());
2719 }
2720
2721
2722@@ -936,7 +936,7 @@
2723
2724 end:
2725 mysql_rwlock_unlock(&THR_LOCK_servers);
2726- DBUG_RETURN(error || thd->killed);
2727+ DBUG_RETURN(error || thd->get_killed());
2728 }
2729
2730
2731@@ -984,7 +984,7 @@
2732
2733 end:
2734 mysql_rwlock_unlock(&THR_LOCK_servers);
2735- DBUG_RETURN(error || thd->killed);
2736+ DBUG_RETURN(error || thd->get_killed());
2737 }
2738
2739
2740
2741=== modified file 'Percona-Server/sql/sql_show.cc'
2742--- Percona-Server/sql/sql_show.cc 2012-12-04 08:24:59 +0000
2743+++ Percona-Server/sql/sql_show.cc 2013-01-09 13:41:38 +0000
2744@@ -859,7 +859,7 @@
2745 MYSQL_OPEN_FORCE_SHARED_HIGH_PRIO_MDL) ||
2746 mysql_handle_derived(thd->lex, &mysql_derived_prepare);
2747 thd->pop_internal_handler();
2748- if (open_error && (thd->killed || thd->is_error()))
2749+ if (open_error && (thd->get_killed() || thd->is_error()))
2750 goto exit;
2751 }
2752
2753@@ -2040,7 +2040,7 @@
2754 Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF))
2755 DBUG_VOID_RETURN;
2756
2757- if (!thd->killed)
2758+ if (!thd->get_killed())
2759 {
2760 mysql_mutex_lock(&LOCK_thread_count);
2761 Thread_iterator it= global_thread_list_begin();
2762@@ -2076,7 +2076,7 @@
2763 mysql_mutex_lock(&tmp->LOCK_thd_data);
2764 if ((mysys_var= tmp->mysys_var))
2765 mysql_mutex_lock(&mysys_var->mutex);
2766- thd_info->proc_info= (char*) (tmp->killed == THD::KILL_CONNECTION? "Killed" : 0);
2767+ thd_info->proc_info= (char*) (tmp->get_killed() == THD::KILL_CONNECTION? "Killed" : 0);
2768 thd_info->state_info= thread_state_info(tmp);
2769 if (mysys_var)
2770 mysql_mutex_unlock(&mysys_var->mutex);
2771@@ -2137,7 +2137,7 @@
2772 user= thd->security_ctx->master_access & PROCESS_ACL ?
2773 NullS : thd->security_ctx->priv_user;
2774
2775- if (!thd->killed)
2776+ if (!thd->get_killed())
2777 {
2778 mysql_mutex_lock(&LOCK_thread_count);
2779 Thread_iterator it= global_thread_list_begin();
2780@@ -2183,7 +2183,7 @@
2781 if ((mysys_var= tmp->mysys_var))
2782 mysql_mutex_lock(&mysys_var->mutex);
2783 /* COMMAND */
2784- if ((val= (char *) (tmp->killed == THD::KILL_CONNECTION? "Killed" : 0)))
2785+ if ((val= (char *) (tmp->get_killed() == THD::KILL_CONNECTION? "Killed" : 0)))
2786 table->field[4]->store(val, strlen(val), cs);
2787 else
2788 table->field[4]->store(command_name[tmp->get_command()].str,
2789
2790=== modified file 'Percona-Server/sql/sql_table.cc'
2791--- Percona-Server/sql/sql_table.cc 2012-12-04 08:24:59 +0000
2792+++ Percona-Server/sql/sql_table.cc 2013-01-09 13:41:38 +0000
2793@@ -2335,7 +2335,7 @@
2794 DBUG_ASSERT(thd->mdl_context.is_lock_owner(MDL_key::TABLE, table->db,
2795 table->table_name,
2796 MDL_EXCLUSIVE));
2797- if (thd->killed)
2798+ if (thd->get_killed())
2799 {
2800 error= -1;
2801 goto err;
2802@@ -8513,7 +8513,7 @@
2803 restore_record(to, s->default_values); // Create empty record
2804 while (!(error=info.read_record(&info)))
2805 {
2806- if (thd->killed)
2807+ if (thd->get_killed())
2808 {
2809 thd->send_kill_message();
2810 error= 1;
2811@@ -8760,7 +8760,7 @@
2812 {
2813 for (;;)
2814 {
2815- if (thd->killed)
2816+ if (thd->get_killed())
2817 {
2818 /*
2819 we've been killed; let handler clean up, and remove the
2820
2821=== modified file 'Percona-Server/sql/sql_update.cc'
2822--- Percona-Server/sql/sql_update.cc 2012-12-04 08:24:59 +0000
2823+++ Percona-Server/sql/sql_update.cc 2013-01-09 13:41:38 +0000
2824@@ -622,7 +622,7 @@
2825 THD_STAGE_INFO(thd, stage_searching_rows_for_update);
2826 ha_rows tmp_limit= limit;
2827
2828- while (!(error=info.read_record(&info)) && !thd->killed)
2829+ while (!(error=info.read_record(&info)) && !thd->get_killed())
2830 {
2831 thd->inc_examined_row_count(1);
2832 bool skip_record= FALSE;
2833@@ -653,7 +653,7 @@
2834 else
2835 table->file->unlock_row();
2836 }
2837- if (thd->killed && !error)
2838+ if (thd->get_killed() && !error)
2839 error= 1; // Aborted
2840 limit= tmp_limit;
2841 table->file->try_semi_consistent_read(0);
2842@@ -724,7 +724,7 @@
2843 check_constant_expressions(values))
2844 read_removal= table->check_read_removal(select->quick->index);
2845
2846- while (!(error=info.read_record(&info)) && !thd->killed)
2847+ while (!(error=info.read_record(&info)) && !thd->get_killed())
2848 {
2849 thd->inc_examined_row_count(1);
2850 bool skip_record;
2851@@ -897,11 +897,11 @@
2852 It's assumed that if an error was set in combination with an effective
2853 killed status then the error is due to killing.
2854 */
2855- killed_status= thd->killed; // get the status of the volatile
2856+ killed_status= thd->get_killed(); // get the status of the volatile
2857 // simulated killing after the loop must be ineffective for binlogging
2858 DBUG_EXECUTE_IF("simulate_kill_bug27571",
2859 {
2860- thd->killed= THD::KILL_QUERY;
2861+ thd->set_killed(THD::KILL_QUERY);
2862 };);
2863 error= (killed_status == THD::NOT_KILLED)? error : 1;
2864
2865@@ -2185,7 +2185,7 @@
2866 got caught and if happens later the killed error is written
2867 into repl event.
2868 */
2869- int errcode= query_error_code(thd, thd->killed == THD::NOT_KILLED);
2870+ int errcode= query_error_code(thd, thd->get_killed() == THD::NOT_KILLED);
2871 /* the error of binary logging is ignored */
2872 (void)thd->binlog_query(THD::ROW_QUERY_TYPE,
2873 thd->query(), thd->query_length(),
2874@@ -2249,7 +2249,7 @@
2875
2876 for (;;)
2877 {
2878- if (thd->killed && trans_safe)
2879+ if (thd->get_killed() && trans_safe)
2880 goto err;
2881 if ((local_error=tmp_table->file->ha_rnd_next(tmp_table->record[0])))
2882 {
2883@@ -2389,7 +2389,7 @@
2884 if local_error is not set ON until after do_updates() then
2885 later carried out killing should not affect binlogging.
2886 */
2887- killed_status= (local_error == 0)? THD::NOT_KILLED : thd->killed;
2888+ killed_status= (local_error == 0)? THD::NOT_KILLED : thd->get_killed();
2889 THD_STAGE_INFO(thd, stage_end);
2890
2891 /* We must invalidate the query cache before binlog writing and
2892
2893=== modified file 'Percona-Server/sql/sys_vars.cc'
2894--- Percona-Server/sql/sys_vars.cc 2012-12-04 08:24:59 +0000
2895+++ Percona-Server/sql/sys_vars.cc 2013-01-09 13:41:38 +0000
2896@@ -3519,6 +3519,12 @@
2897 SESSION_VAR(group_concat_max_len), CMD_LINE(REQUIRED_ARG),
2898 VALID_RANGE(4, ULONG_MAX), DEFAULT(1024), BLOCK_SIZE(1));
2899
2900+static Sys_var_ulong Sys_sql_timeout(
2901+ "sql_timeout",
2902+ "Timeout in seconds to wait before killing query.",
2903+ SESSION_VAR(sql_timeout), CMD_LINE(REQUIRED_ARG),
2904+ VALID_RANGE(0, ULONG_MAX), DEFAULT(0), BLOCK_SIZE(1));
2905+
2906 static char *glob_hostname_ptr;
2907 static Sys_var_charptr Sys_hostname(
2908 "hostname", "Server host name",
2909
2910=== modified file 'Percona-Server/sql/table.cc'
2911--- Percona-Server/sql/table.cc 2012-12-04 08:24:59 +0000
2912+++ Percona-Server/sql/table.cc 2013-01-09 13:41:38 +0000
2913@@ -3941,7 +3941,7 @@
2914
2915 void TABLE_LIST::hide_view_error(THD *thd)
2916 {
2917- if (thd->killed || thd->get_internal_handler())
2918+ if (thd->get_killed() || thd->get_internal_handler())
2919 return;
2920 /* Hide "Unknown column" or "Unknown function" error */
2921 DBUG_ASSERT(thd->is_error());
2922
2923=== modified file 'Percona-Server/storage/innobase/row/row0mysql.cc'
2924--- Percona-Server/storage/innobase/row/row0mysql.cc 2012-12-17 22:22:38 +0000
2925+++ Percona-Server/storage/innobase/row/row0mysql.cc 2013-01-09 13:41:38 +0000
2926@@ -5062,7 +5062,7 @@
2927
2928 ret = row_search_for_mysql(buf, PAGE_CUR_G, prebuilt, 0, 0);
2929 loop:
2930- /* Check thd->killed every 1,000 scanned rows */
2931+ /* Check thd->get_killed() every 1,000 scanned rows */
2932 if (--cnt == 0) {
2933 if (trx_is_interrupted(prebuilt->trx)) {
2934 goto func_exit;
2935
2936=== modified file 'Percona-Server/storage/myisam/ha_myisam.cc'
2937--- Percona-Server/storage/myisam/ha_myisam.cc 2012-10-16 06:21:51 +0000
2938+++ Percona-Server/storage/myisam/ha_myisam.cc 2013-01-09 13:41:38 +0000
2939@@ -118,7 +118,7 @@
2940 THD *thd;
2941 thd= current_thd;
2942 prev_info= thd_proc_info(thd, info);
2943- while(!thd->killed)
2944+ while(!thd->get_killed())
2945 my_sleep(1000);
2946 DBUG_PRINT("info", ("Exit debug_wait_for_kill"));
2947 thd_proc_info(thd, prev_info);
2948@@ -562,10 +562,10 @@
2949
2950 extern "C" {
2951
2952-volatile int *killed_ptr(MI_CHECK *param)
2953+int killed_status(MI_CHECK *param)
2954 {
2955 /* In theory Unsafe conversion, but should be ok for now */
2956- return (int*) &(((THD *)(param->thd))->killed);
2957+ return (int) (((THD *)(param->thd))->get_killed());
2958 }
2959
2960 void mi_check_print_error(MI_CHECK *param, const char *fmt,...)
2961@@ -902,7 +902,7 @@
2962 HA_STATUS_CONST);
2963 }
2964 }
2965- else if (!mi_is_crashed(file) && !thd->killed)
2966+ else if (!mi_is_crashed(file) && !thd->get_killed())
2967 {
2968 mi_mark_crashed(file);
2969 file->update |= HA_STATE_CHANGED | HA_STATE_ROW_CHANGED;
2970@@ -945,7 +945,7 @@
2971 error=update_state_info(&param,file,UPDATE_STAT);
2972 mysql_mutex_unlock(&share->intern_lock);
2973 }
2974- else if (!mi_is_crashed(file) && !thd->killed)
2975+ else if (!mi_is_crashed(file) && !thd->get_killed())
2976 mi_mark_crashed(file);
2977 return error ? HA_ADMIN_CORRUPT : HA_ADMIN_OK;
2978 }
2979@@ -1537,7 +1537,7 @@
2980 */
2981
2982 if (((err= enable_indexes(HA_KEY_SWITCH_NONUNIQ_SAVE)) != 0) &&
2983- current_thd->killed)
2984+ current_thd->get_killed())
2985 {
2986 delete_all_rows();
2987 /* not crashed, despite being killed during repair */
2988
2989=== modified file 'Percona-Server/storage/myisam/mi_check.c'
2990--- Percona-Server/storage/myisam/mi_check.c 2012-09-12 14:19:10 +0000
2991+++ Percona-Server/storage/myisam/mi_check.c 2013-01-09 13:41:38 +0000
2992@@ -164,7 +164,7 @@
2993 empty=0;
2994 for (i= info->state->del ; i > 0L && next_link != HA_OFFSET_ERROR ; i--)
2995 {
2996- if (*killed_ptr(param))
2997+ if (killed_status(param))
2998 DBUG_RETURN(1);
2999 if (test_flag & T_VERBOSE)
3000 printf(" %9s",llstr(next_link,buff));
3001@@ -259,7 +259,7 @@
3002 records= (ha_rows) (info->state->key_file_length / block_size);
3003 while (next_link != HA_OFFSET_ERROR && records > 0)
3004 {
3005- if (*killed_ptr(param))
3006+ if (killed_status(param))
3007 DBUG_RETURN(1);
3008 if (param->testflag & T_VERBOSE)
3009 printf("%16s",llstr(next_link,llbuff));
3010@@ -773,7 +773,7 @@
3011 }
3012 for ( ;; )
3013 {
3014- if (*killed_ptr(param))
3015+ if (killed_status(param))
3016 goto err;
3017 memcpy((char*) info->lastkey,(char*) key,key_length);
3018 info->lastkey_length=key_length;
3019@@ -985,7 +985,7 @@
3020 memset(key_checksum, 0, info->s->base.keys * sizeof(key_checksum[0]));
3021 while (pos < info->state->data_file_length)
3022 {
3023- if (*killed_ptr(param))
3024+ if (killed_status(param))
3025 goto err2;
3026 switch (info->s->data_file_type) {
3027 case STATIC_RECORD:
3028@@ -3253,7 +3253,7 @@
3029 char llbuff[22],llbuff2[22];
3030 DBUG_ENTER("sort_get_next_record");
3031
3032- if (*killed_ptr(param))
3033+ if (killed_status(param))
3034 DBUG_RETURN(1);
3035
3036 switch (share->data_file_type) {
3037
3038=== modified file 'Percona-Server/storage/myisam/myisamchk.c'
3039--- Percona-Server/storage/myisam/myisamchk.c 2012-08-22 01:40:20 +0000
3040+++ Percona-Server/storage/myisam/myisamchk.c 2013-01-09 13:41:38 +0000
3041@@ -1702,11 +1702,9 @@
3042 sorting
3043 */
3044
3045-static int not_killed= 0;
3046-
3047-volatile int *killed_ptr(MI_CHECK *param __attribute__((unused)))
3048+int killed_status(MI_CHECK *param __attribute__((unused)))
3049 {
3050- return &not_killed; /* always NULL */
3051+ return 0; /* always NULL */
3052 }
3053
3054 /* print warnings and errors */
3055
3056=== modified file 'Percona-Server/storage/myisam/myisamdef.h'
3057--- Percona-Server/storage/myisam/myisamdef.h 2012-03-06 14:29:42 +0000
3058+++ Percona-Server/storage/myisam/myisamdef.h 2013-01-09 13:41:38 +0000
3059@@ -769,7 +769,7 @@
3060 int mi_check_index_cond(register MI_INFO *info, uint keynr, uchar *record);
3061
3062 /* Functions needed by mi_check */
3063-volatile int *killed_ptr(MI_CHECK *param);
3064+int killed_status(MI_CHECK *param);
3065 void mi_check_print_error(MI_CHECK *param, const char *fmt,...);
3066 void mi_check_print_warning(MI_CHECK *param, const char *fmt,...);
3067 void mi_check_print_info(MI_CHECK *param, const char *fmt,...);
3068
3069=== modified file 'Percona-Server/storage/myisam/sort.c'
3070--- Percona-Server/storage/myisam/sort.c 2012-03-06 14:29:42 +0000
3071+++ Percona-Server/storage/myisam/sort.c 2013-01-09 13:41:38 +0000
3072@@ -910,7 +910,7 @@
3073 uchar *strpos;
3074 BUFFPEK *buffpek,**refpek;
3075 QUEUE queue;
3076- volatile int *killed= killed_ptr(info->sort_info->param);
3077+ int killed= killed_status(info->sort_info->param);
3078 DBUG_ENTER("merge_buffers");
3079
3080 count=error=0;
3081@@ -943,7 +943,7 @@
3082 {
3083 for (;;)
3084 {
3085- if (*killed)
3086+ if (killed)
3087 {
3088 error=1; goto err;
3089 }

Subscribers

People subscribed via source and target branches