Merge lp:~dingqi-lxb/percona-server/5.5_log_queries_in_memory into lp:percona-server/5.5
- 5.5_log_queries_in_memory
- Merge into 5.5
Status: | Work in progress |
---|---|
Proposed branch: | lp:~dingqi-lxb/percona-server/5.5_log_queries_in_memory |
Merge into: | lp:percona-server/5.5 |
Diff against target: |
896 lines (+879/-0) 3 files modified
doc/source/diagnostics/slow_log_in_memory.rst (+74/-0) patches/series (+1/-0) patches/slowlog_in_memory.patch (+804/-0) |
To merge this branch: | bzr merge lp:~dingqi-lxb/percona-server/5.5_log_queries_in_memory |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Oleg Tsarev (community) | Needs Fixing | ||
Review via email: mp+87244@code.launchpad.net |
This proposal supersedes a proposal from 2011-12-29.
Commit message
Description of the change
http://
patch for https:/
add a variable 'slowlog_
If the current_memory grows larger than max_memory, the eldest ones will be wash out.
Same action happens when max_mamory are set to a new value that is less than current_memory.
Oleg Tsarev (tsarev) wrote : Posted in a previous version of this proposal | # |
Oleg Tsarev (tsarev) wrote : Posted in a previous version of this proposal | # |
8.
+ ulonglong utime_of_query= thd->current_
+ if (utime_of_query <= thd->variables.
+ return;
Please look into the slow_extended.
static inline ulonglong get_query_
...
thd->server_
Please better use this status variable, instead of calculate query execution time directly.
林晓斌 (dingqi-lxb) wrote : Posted in a previous version of this proposal | # |
Thank you. Oleg, I have some items to discuss.
2. About innodb_trx_id. Please look to two following cases
In these two cases, the variable thd->innodb_trx_id is set to 0. It seems that I have to show it in the result table as 0, is there other result even use innodb_was_used ?
8.About calculating query execution time directly, it is because that I have to get the query_time, the status is not enough.
* Why plugin doesn't uninstall in test?
You mean that it shows " Plugin is busy and will be uninstalled on shutdown" in result-file? It is the same with the demo for audit plugin "null_audit", the strategy decided by mysqld
Oleg Tsarev (tsarev) wrote : Posted in a previous version of this proposal | # |
On Mon, Dec 12, 2011 at 12:05 PM, 林晓斌 <email address hidden> wrote:
> Thank you. Oleg, I have some items to discuss.
>
> 2. About innodb_trx_id. Please look to two following cases
> In these two cases, the variable thd->innodb_trx_id is set to 0. It seems that I have to show it in the result table as 0, is there other result even use innodb_was_used ?
I think right decision is "NULL" value instead of 0.
>
> 8.About calculating query execution time directly, it is because that I have to get the query_time, the status is not enough.
>
> * Why plugin doesn't uninstall in test?
> You mean that it shows " Plugin is busy and will be uninstalled on shutdown" in result-file? It is the same with the demo for audit plugin "null_audit", the strategy decided by mysqld
Ok
> --
> https:/
> You are reviewing the proposed merge of lp:~dingqi-lxb/percona-server/5.5_log_queries_in_memory into lp:percona-server.
--
Oleg Tsarev, Software Engineer, Percona Inc.
林晓斌 (dingqi-lxb) wrote : Posted in a previous version of this proposal | # |
2. About innodb_trx_id. Generally, when the thd->innodb_trx_id is 0, the value of "INNODB_TRX_ID" should show NULL, so the thd->innodb_
7. Please add tests to sys_vars suite for the all added variables.
The variable add in this plugin will not be seen in other test-case, it can only be seen the plugin is installed. So, is test-case in sys_vars suits necessary?
Stewart Smith (stewart) wrote : Posted in a previous version of this proposal | # |
On Wed, 21 Dec 2011 02:50:35 -0000, 林晓斌 <email address hidden> wrote:
> +There are two plugins in the feature. They can be installed by
> command ``"install plugin SLOWLOG_
> 'slowlog_
> 'slowlog_
I think we should be consistent in naming. SLOW_LOG instead of SLOWLOG
and slow_log instead of slowlog.
--
Stewart Smith
Baron Schwartz (baron-xaprb) wrote : Posted in a previous version of this proposal | # |
I'm sorry that I haven't noticed this discussion before, but I believe that it would be best to avoid a query time in milliseconds:
1. It should have microsecond resolution. Milliseconds is not enough.
2. It should be named EXEC_TIME and should be a floating-point value in seconds so the user does not have to convert the value to seconds.
Oleg Tsarev (tsarev) wrote : | # |
About documentation:
1) Please link to page page "Slow Log In Memory" to the index of documentation (to "Diagnostic" article)
2) "MS_QUERY_TIME – The query_exec_time of the query, in second."
But looks like time in the milliseconds
About the patch:
3) You avoid the "quiltrc" config file from the root of branch. As result your patch has incorrect format.
Please, use "quilt --quiltrc=quiltrc ..." while you touch the patches
About the feature:
4) I think, we should add at least following:
* User
* Query_time (microseconds)
About the tests:
5) Here is little example of incorrect work (JUST EXAMPLE):
http://
So, your implementation avoid all variables related to slow query log, except long_query_time.
* How to right test: modify all tests provided by slow_extended.
About the implementation:
6) Incorrect works with query exec time:
ulonglong utime_of_query= thd->current_
* Possible scenario: query doesn't pass to slow query log, but pass to INFORMATION_
* How to fix: you shoud use thd->server_status variable for detect insert or don't insert event to SLOW_LOG table. This allows to support all related options from PS.
* What requires the modify: slow_extended.
7) Separatelly about this:
+ ulonglong utime_of_query= thd->current_
+
+#ifndef DBUG_OFF
+ if (thd->variables
+ utime_of_query= thd->lex-
+#endif
+
+ if (utime_of_query <= thd->variables.
+ return;
Copy-paste - not a very good idea.
8) Class slow_log_list. Some methods lock/unlock mutexes, some not (pop_front). It think this is a bad contract-
9) Event Id can be missordered (different from order of events in the list)
10) Order of event can be missordered (different from slow query log)
11) Class slow_log_list. Why "first" and "last" are public members?
12) Please also note: subunit has a #bug 911237 - according to 5.5 testing not a work right now. Please merge fix then it will be merged to lp:percona-server
Oleg Tsarev (tsarev) wrote : | # |
To 12) - fix already in lp:percona-server, just need a merge before future tests
林晓斌 (dingqi-lxb) wrote : | # |
4)There is Query_time already, will be shown as 1.1234, in senconds, what does this Query_time mean?
6) ok, before recored it, I will check thd->server_status before. But the result of utime_of_query has to be re-calculated here all the same.
7) what does this mean?
9) Yes, the procedure of assigning event_id and putting into the list is not locked as a whole, for performance consideration. Ok, I will lock them as a whole.
10) This can not be confirmed. Because the procedre of logging into slow log and loging into memory are different plugins. Is there any proposal?
11) Because the "first" and "last" needs to be accessed at i_s_fill_
Oleg Tsarev (tsarev) wrote : | # |
4) This is Ok. Also please ask Baron about Lock_time
6) Not a "before", but "instead". You should not use direct utime_of_query calculation. Please replace any calculation by check of flag thd->server_status
7) This is mean you should not use copy-paste. Never.
9) Any perfomance consideration should not break the correct work
10) You can modify the slow_extended.patch and create event id on server-side. But this is requires consideration
11) Why you didn't add public interface for iteration instead of access to members?
林晓斌 (dingqi-lxb) wrote : | # |
6) Check can use thd->server_status, but I need to calculate the utime_of_query if the thd->server_status & SERVER_
10) It will make the plugin depart from the concept that it can be used in both Percona-server and Oracle-mysql directly. I propose that it remains the current strategy, if the misorder between memory and slow log can be tolerant.
Preview Diff
1 | === added file 'doc/source/diagnostics/slow_log_in_memory.rst' | |||
2 | --- doc/source/diagnostics/slow_log_in_memory.rst 1970-01-01 00:00:00 +0000 | |||
3 | +++ doc/source/diagnostics/slow_log_in_memory.rst 2012-01-02 12:24:34 +0000 | |||
4 | @@ -0,0 +1,74 @@ | |||
5 | 1 | .. _slow_log_in_memory: | ||
6 | 2 | |||
7 | 3 | ================= | ||
8 | 4 | Slow Log In Memory | ||
9 | 5 | ================= | ||
10 | 6 | |||
11 | 7 | The feature is used to save slow queries in memory. This feature adds an ``INFORMATION_SCHEMA.SLOW_LOG`` table to show the latest queries, a variable to limit the max memory used, and status to show the status of memory used. | ||
12 | 8 | |||
13 | 9 | There are two plugins in the feature. They can be installed by command ``"install plugin SLOWLOG_IN_MEMORY_AUDIT soname 'slowlog_in_memory.so'"`` and ``"install plugin SLOW_LOG soname 'slowlog_in_memory.so'"``, they work by keeping one list in memory. | ||
14 | 10 | |||
15 | 11 | |||
16 | 12 | Other Information | ||
17 | 13 | ================= | ||
18 | 14 | |||
19 | 15 | * Author/Origin: | ||
20 | 16 | *Percona*; *Percona* added an ``INFORMATION_SCHEMA`` table and the :variable:`slowlog_in_memory_audit_max_memory` and the :status:`slow_log_current_memory`. | ||
21 | 17 | |||
22 | 18 | System Variables | ||
23 | 19 | ================ | ||
24 | 20 | |||
25 | 21 | .. variable:: slowlog_in_memory_audit_max_memory | ||
26 | 22 | |||
27 | 23 | :cli: Yes | ||
28 | 24 | :conf: Yes | ||
29 | 25 | :scope: Global | ||
30 | 26 | :dyn: Yes | ||
31 | 27 | :vartype: ULONG | ||
32 | 28 | :default: 1M | ||
33 | 29 | :range: 0 - 1G | ||
34 | 30 | |||
35 | 31 | The variable is used to limit the max-memory used for slow log. If a new slow query will make the `current_memory` bigger than this value, the most eldest items will be discarded, until there is enough memory for new item. When the value is decrease dynamically, it behaves the same. | ||
36 | 32 | |||
37 | 33 | Status Variables | ||
38 | 34 | ================ | ||
39 | 35 | |||
40 | 36 | One new status variable was introduced by this feature. | ||
41 | 37 | |||
42 | 38 | .. variable:: slow_log_current_memory | ||
43 | 39 | |||
44 | 40 | :vartype: ULONG | ||
45 | 41 | :scope: Global | ||
46 | 42 | |||
47 | 43 | The variable showes the current memory used for the slow queries. It can never be bigger than the `slowlog_in_memory_audit_max_memory` variable. | ||
48 | 44 | |||
49 | 45 | |||
50 | 46 | INFORMATION_SCHEMA Tables | ||
51 | 47 | ========================= | ||
52 | 48 | |||
53 | 49 | .. table:: INFORMATION_SCHEMA.SLOW_LOG | ||
54 | 50 | |||
55 | 51 | :column EVENT_ID: A global increment id for every record in the table, can be used to identify every one. | ||
56 | 52 | :column TIMESTAMP: The timestamp when the query stop. | ||
57 | 53 | :column THREAD_ID: The thread_id of the query. | ||
58 | 54 | :column DB: The current database() of the query, may be NULL. | ||
59 | 55 | :column INNODB_TRX_ID: The Innodb_trx_id if InnoDB is used, may be NULL. | ||
60 | 56 | :column ERROR: The errno of the query, 0 means no error. | ||
61 | 57 | :column MS_QUERY_TIME: The query_exec_time of the query, in second. | ||
62 | 58 | :column QUERY: The query statement. | ||
63 | 59 | |||
64 | 60 | This table holds the lastest slow queries. | ||
65 | 61 | |||
66 | 62 | Example: :: | ||
67 | 63 | |||
68 | 64 | mysql> select * from information_schema.slow_log \G | ||
69 | 65 | *************************** 1. row *************************** | ||
70 | 66 | EVENT_ID: 1 | ||
71 | 67 | TIMESTAMP: 1323753896 | ||
72 | 68 | THREAD_ID: 2 | ||
73 | 69 | DB: test | ||
74 | 70 | INNODB_TRX_ID: NULL | ||
75 | 71 | ERRNO: 0 | ||
76 | 72 | MS_QUERY_TIME: 3001 | ||
77 | 73 | QUERY: select sleep(3) | ||
78 | 74 | |||
79 | 0 | 75 | ||
80 | === modified file 'patches/series' | |||
81 | --- patches/series 2011-12-16 09:37:26 +0000 | |||
82 | +++ patches/series 2012-01-02 12:24:34 +0000 | |||
83 | @@ -62,3 +62,4 @@ | |||
84 | 62 | bug45702.patch | 62 | bug45702.patch |
85 | 63 | group_commit.patch | 63 | group_commit.patch |
86 | 64 | warning_fixes.patch | 64 | warning_fixes.patch |
87 | 65 | slowlog_in_memory.patch | ||
88 | 65 | 66 | ||
89 | === added file 'patches/slowlog_in_memory.patch' | |||
90 | --- patches/slowlog_in_memory.patch 1970-01-01 00:00:00 +0000 | |||
91 | +++ patches/slowlog_in_memory.patch 2012-01-02 12:24:34 +0000 | |||
92 | @@ -0,0 +1,804 @@ | |||
93 | 1 | --- a/plugin/slowlog_in_memory/CMakeLists.txt 1970-01-01 08:00:00.000000000 +0800 | ||
94 | 2 | +++ b/plugin/slowlog_in_memory/CMakeLists.txt 2011-12-22 21:08:28.000000000 +0800 | ||
95 | 3 | @@ -0,0 +1,17 @@ | ||
96 | 4 | +# Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved. | ||
97 | 5 | +# | ||
98 | 6 | +# This program is free software; you can redistribute it and/or modify | ||
99 | 7 | +# it under the terms of the GNU General Public License as published by | ||
100 | 8 | +# the Free Software Foundation; version 2 of the License. | ||
101 | 9 | +# | ||
102 | 10 | +# This program is distributed in the hope that it will be useful, | ||
103 | 11 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
104 | 12 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
105 | 13 | +# GNU General Public License for more details. | ||
106 | 14 | +# | ||
107 | 15 | +# You should have received a copy of the GNU General Public License | ||
108 | 16 | +# along with this program; if not, write to the Free Software | ||
109 | 17 | +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
110 | 18 | + | ||
111 | 19 | +MYSQL_ADD_PLUGIN(slowlog_in_memory slowlog_in_memory.cc | ||
112 | 20 | + MODULE_ONLY MODULE_OUTPUT_NAME "slowlog_in_memory") | ||
113 | 21 | --- a/plugin/slowlog_in_memory/slowlog_in_memory.cc 1970-01-01 08:00:00.000000000 +0800 | ||
114 | 22 | +++ b/plugin/slowlog_in_memory/slowlog_in_memory.cc 2011-12-22 21:09:34.000000000 +0800 | ||
115 | 23 | @@ -0,0 +1,295 @@ | ||
116 | 24 | +/* Copyright (c) 2006, 2011, Oracle and/or its affiliates. All rights reserved. | ||
117 | 25 | + | ||
118 | 26 | + This program is free software; you can redistribute it and/or | ||
119 | 27 | + modify it under the terms of the GNU General Public License | ||
120 | 28 | + as published by the Free Software Foundation; version 2 of | ||
121 | 29 | + the License. | ||
122 | 30 | + | ||
123 | 31 | + This program is distributed in the hope that it will be useful, | ||
124 | 32 | + but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
125 | 33 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
126 | 34 | + GNU General Public License for more details. | ||
127 | 35 | + | ||
128 | 36 | + You should have received a copy of the GNU General Public License | ||
129 | 37 | + along with this program; if not, write to the Free Software | ||
130 | 38 | + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ | ||
131 | 39 | + | ||
132 | 40 | +#include "ut_slow_log_list.h" | ||
133 | 41 | + | ||
134 | 42 | +#if !defined(__attribute__) && (defined(__cplusplus) || !defined(__GNUC__) || __GNUC__ == 2 && __GNUC_MINOR__ < 8) | ||
135 | 43 | +#define __attribute__(A) | ||
136 | 44 | +#endif | ||
137 | 45 | +typedef struct st_mysql_sys_var SYS_VAR; | ||
138 | 46 | +uint max_memory_for_slow_log; | ||
139 | 47 | + | ||
140 | 48 | +/* lock management */ | ||
141 | 49 | + | ||
142 | 50 | +slow_log_list *global_slow_log_list= NULL; | ||
143 | 51 | + | ||
144 | 52 | +/* | ||
145 | 53 | + Initialize the plugin at server start or plugin installation. | ||
146 | 54 | + | ||
147 | 55 | + SYNOPSIS | ||
148 | 56 | + slow_log_in_memory_plugin_init() | ||
149 | 57 | + | ||
150 | 58 | + DESCRIPTION | ||
151 | 59 | + Does nothing. | ||
152 | 60 | + | ||
153 | 61 | + RETURN VALUE | ||
154 | 62 | + 0 success | ||
155 | 63 | + 1 failure (cannot happen) | ||
156 | 64 | +*/ | ||
157 | 65 | + | ||
158 | 66 | +static int slow_log_in_memory_plugin_init(void *arg __attribute__((unused))) | ||
159 | 67 | +{ | ||
160 | 68 | +#ifdef HAVE_PSI_INTERFACE | ||
161 | 69 | + init_semisync_psi_keys(); | ||
162 | 70 | +#endif | ||
163 | 71 | + | ||
164 | 72 | + mysql_mutex_init(key_ss_mutex_LOCK_slow_event_id_, | ||
165 | 73 | + &LOCK_slow_event_id_, MY_MUTEX_INIT_FAST); | ||
166 | 74 | + global_slow_log_list= new slow_log_list(max_memory_for_slow_log); | ||
167 | 75 | + | ||
168 | 76 | + return 0; | ||
169 | 77 | +} | ||
170 | 78 | + | ||
171 | 79 | + | ||
172 | 80 | +/* | ||
173 | 81 | + Terminate the plugin at server shutdown or plugin deinstallation. | ||
174 | 82 | + | ||
175 | 83 | + SYNOPSIS | ||
176 | 84 | + slow_log_in_memory_plugin_deinit() | ||
177 | 85 | + Does nothing. | ||
178 | 86 | + | ||
179 | 87 | + RETURN VALUE | ||
180 | 88 | + 0 success | ||
181 | 89 | + 1 failure (cannot happen) | ||
182 | 90 | +*/ | ||
183 | 91 | + | ||
184 | 92 | +static int slow_log_in_memory_plugin_deinit(void *arg __attribute__((unused))) | ||
185 | 93 | +{ | ||
186 | 94 | + if (global_slow_log_list) | ||
187 | 95 | + { | ||
188 | 96 | + delete global_slow_log_list; | ||
189 | 97 | + global_slow_log_list= NULL; | ||
190 | 98 | + } | ||
191 | 99 | + | ||
192 | 100 | + mysql_mutex_destroy(&LOCK_slow_event_id_); | ||
193 | 101 | + return 0; | ||
194 | 102 | +} | ||
195 | 103 | + | ||
196 | 104 | +/* | ||
197 | 105 | + Foo | ||
198 | 106 | + | ||
199 | 107 | + SYNOPSIS | ||
200 | 108 | + slow_log_in_memory_notify() | ||
201 | 109 | + thd connection context | ||
202 | 110 | + | ||
203 | 111 | + DESCRIPTION | ||
204 | 112 | +*/ | ||
205 | 113 | + | ||
206 | 114 | +static void slow_log_in_memory_notify(MYSQL_THD thd __attribute__((unused)), | ||
207 | 115 | + unsigned int event_class, | ||
208 | 116 | + const void *event) | ||
209 | 117 | +{ | ||
210 | 118 | + if (max_memory_for_slow_log == 0) return; | ||
211 | 119 | + | ||
212 | 120 | + if (event_class == MYSQL_AUDIT_GENERAL_CLASS) | ||
213 | 121 | + { | ||
214 | 122 | + const struct mysql_event_general *event_general= | ||
215 | 123 | + (const struct mysql_event_general *) event; | ||
216 | 124 | + if (event_general->event_subclass != MYSQL_AUDIT_GENERAL_STATUS) | ||
217 | 125 | + return; | ||
218 | 126 | + | ||
219 | 127 | + ulonglong utime_of_query= thd->current_utime() - thd->utime_after_lock; | ||
220 | 128 | + | ||
221 | 129 | +#ifndef DBUG_OFF | ||
222 | 130 | + if (thd->variables.query_exec_time != 0) | ||
223 | 131 | + utime_of_query= thd->lex->sql_command != SQLCOM_SET_OPTION ? thd->variables.query_exec_time : 0; | ||
224 | 132 | +#endif | ||
225 | 133 | + | ||
226 | 134 | + if (utime_of_query <= thd->variables.long_query_time) | ||
227 | 135 | + return; | ||
228 | 136 | + | ||
229 | 137 | + slow_log_t *tmp= new slow_log_t(event_general->general_time, event_general->general_thread_id, thd->db, thd->innodb_trx_id, event_general->general_error_code, (double)utime_of_query/1000000, event_general->general_query); | ||
230 | 138 | + global_slow_log_list->push_back(tmp); | ||
231 | 139 | + } | ||
232 | 140 | +} | ||
233 | 141 | + | ||
234 | 142 | + | ||
235 | 143 | +/* | ||
236 | 144 | + Plugin type-specific descriptor | ||
237 | 145 | +*/ | ||
238 | 146 | + | ||
239 | 147 | +static struct st_mysql_audit slow_log_in_memory_descriptor= | ||
240 | 148 | +{ | ||
241 | 149 | + MYSQL_AUDIT_INTERFACE_VERSION, /* interface version */ | ||
242 | 150 | + NULL, /* release_thd function */ | ||
243 | 151 | + slow_log_in_memory_notify, /* notify function */ | ||
244 | 152 | + { (unsigned long) MYSQL_AUDIT_GENERAL_CLASSMASK } /* class mask */ | ||
245 | 153 | +}; | ||
246 | 154 | + | ||
247 | 155 | +static void change_max_memory_for_slow_log(MYSQL_THD thd, | ||
248 | 156 | + SYS_VAR *var, | ||
249 | 157 | + void *ptr, | ||
250 | 158 | + const void *val) | ||
251 | 159 | +{ | ||
252 | 160 | + uint new_len= *(uint *)val; | ||
253 | 161 | + *(uint *)ptr= new_len; | ||
254 | 162 | + | ||
255 | 163 | + global_slow_log_list->change_max_memory(new_len); | ||
256 | 164 | + return; | ||
257 | 165 | +} | ||
258 | 166 | + | ||
259 | 167 | +static MYSQL_SYSVAR_UINT(max_memory, max_memory_for_slow_log, | ||
260 | 168 | + PLUGIN_VAR_OPCMDARG, | ||
261 | 169 | + "The max memory that can be allocated for slow log.", | ||
262 | 170 | + NULL, // check | ||
263 | 171 | + &change_max_memory_for_slow_log, // update | ||
264 | 172 | + 1024*1024, 0, 1024*1024*1024, 1); | ||
265 | 173 | + | ||
266 | 174 | +static SYS_VAR* slow_log_in_memory_system_vars[]= { | ||
267 | 175 | + MYSQL_SYSVAR(max_memory), | ||
268 | 176 | + NULL, | ||
269 | 177 | +}; | ||
270 | 178 | + | ||
271 | 179 | +static uint slow_log_current_memory(MYSQL_THD thd, SHOW_VAR *var, char *buff) | ||
272 | 180 | +{ | ||
273 | 181 | + var->type= SHOW_INT; | ||
274 | 182 | + var->value= (char*)&global_slow_log_list->current_memory; | ||
275 | 183 | + return 0; | ||
276 | 184 | +} | ||
277 | 185 | + | ||
278 | 186 | +/* plugin status variables */ | ||
279 | 187 | +static SHOW_VAR slow_log_in_memory_status_vars[]= { | ||
280 | 188 | + {"slow_log_current_memory", | ||
281 | 189 | + (char*) &slow_log_current_memory, | ||
282 | 190 | + SHOW_FUNC}, | ||
283 | 191 | + {NULL, NULL, SHOW_LONG}, | ||
284 | 192 | +}; | ||
285 | 193 | + | ||
286 | 194 | + | ||
287 | 195 | +/* | ||
288 | 196 | + I_S_SLOW_LOG | ||
289 | 197 | +*/ | ||
290 | 198 | +static struct st_mysql_information_schema i_s_slow_log= | ||
291 | 199 | +{ | ||
292 | 200 | + MYSQL_INFORMATION_SCHEMA_INTERFACE_VERSION | ||
293 | 201 | +}; | ||
294 | 202 | + | ||
295 | 203 | +static ST_FIELD_INFO i_s_slow_log_fields[] = | ||
296 | 204 | +{ | ||
297 | 205 | + {"EVENT_ID", 11, MYSQL_TYPE_LONGLONG, 0, 0, 0, SKIP_OPEN_TABLE}, | ||
298 | 206 | + {"TIMESTAMP", 11, MYSQL_TYPE_LONGLONG, 0, 0, 0, SKIP_OPEN_TABLE}, | ||
299 | 207 | + {"THREAD_ID", 11, MYSQL_TYPE_LONG, 0, 0, 0, SKIP_OPEN_TABLE}, | ||
300 | 208 | + {"DB", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 1, 0, SKIP_OPEN_TABLE}, | ||
301 | 209 | + {"INNODB_TRX_ID", 11, MYSQL_TYPE_LONGLONG, 0, 1, 0, SKIP_OPEN_TABLE}, | ||
302 | 210 | + {"ERRNO", 11, MYSQL_TYPE_LONG, 0, 0, 0, SKIP_OPEN_TABLE}, | ||
303 | 211 | + {"MS_QUERY_TIME", 11, MYSQL_TYPE_FLOAT, 0, 0, 0, SKIP_OPEN_TABLE}, | ||
304 | 212 | + | ||
305 | 213 | + {"QUERY", 255, MYSQL_TYPE_STRING, 0, 1, 0, SKIP_OPEN_TABLE}, | ||
306 | 214 | + {0, 0, MYSQL_TYPE_STRING, 0, 0, 0, SKIP_OPEN_TABLE} | ||
307 | 215 | +}; | ||
308 | 216 | + | ||
309 | 217 | + | ||
310 | 218 | +int i_s_fill_table_slow_log(THD* thd, TABLE_LIST* tables, COND* cond) | ||
311 | 219 | +{ | ||
312 | 220 | + if (!global_slow_log_list) return 0; | ||
313 | 221 | + | ||
314 | 222 | + TABLE *table= tables->table; | ||
315 | 223 | + | ||
316 | 224 | + mysql_mutex_lock(&global_slow_log_list->LOCK_slow_log_); | ||
317 | 225 | + | ||
318 | 226 | + slow_log_t *item= global_slow_log_list->first; | ||
319 | 227 | + while (item) | ||
320 | 228 | + { | ||
321 | 229 | + restore_record(table, s->default_values); | ||
322 | 230 | + | ||
323 | 231 | + table->field[0]->store(item->event_id, TRUE); | ||
324 | 232 | + table->field[1]->store(item->timestamp, TRUE); | ||
325 | 233 | + table->field[2]->store(item->thread_id, TRUE); | ||
326 | 234 | + | ||
327 | 235 | + if (item->schema) | ||
328 | 236 | + { | ||
329 | 237 | + table->field[3]->store(item->schema, item->schema_len-1, system_charset_info); | ||
330 | 238 | + table->field[3]->set_notnull(); | ||
331 | 239 | + } | ||
332 | 240 | + | ||
333 | 241 | + if (item->innodb_trx_id) | ||
334 | 242 | + { | ||
335 | 243 | + table->field[4]->store(item->innodb_trx_id, TRUE); | ||
336 | 244 | + table->field[4]->set_notnull(); | ||
337 | 245 | + } | ||
338 | 246 | + | ||
339 | 247 | + table->field[5]->store(item->cmd_errno, TRUE); | ||
340 | 248 | + table->field[6]->store(item->time_of_query); | ||
341 | 249 | + | ||
342 | 250 | + if (item->general_query) | ||
343 | 251 | + { | ||
344 | 252 | + table->field[7]->store(item->general_query, item->general_query_len-1, system_charset_info); | ||
345 | 253 | + table->field[7]->set_notnull(); | ||
346 | 254 | + } | ||
347 | 255 | + | ||
348 | 256 | + schema_table_store_record(thd, table); | ||
349 | 257 | + item= item->next; | ||
350 | 258 | + } | ||
351 | 259 | + | ||
352 | 260 | + mysql_mutex_unlock(&global_slow_log_list->LOCK_slow_log_); | ||
353 | 261 | + return 0; | ||
354 | 262 | +} | ||
355 | 263 | + | ||
356 | 264 | + | ||
357 | 265 | +static int i_s_slow_log_plugin_init(void *arg __attribute__((unused))) | ||
358 | 266 | +{ | ||
359 | 267 | + ST_SCHEMA_TABLE* schema; | ||
360 | 268 | + | ||
361 | 269 | + schema = (ST_SCHEMA_TABLE*) arg; | ||
362 | 270 | + | ||
363 | 271 | + schema->fields_info = i_s_slow_log_fields; | ||
364 | 272 | + schema->fill_table = i_s_fill_table_slow_log; | ||
365 | 273 | + return 0; | ||
366 | 274 | +} | ||
367 | 275 | + | ||
368 | 276 | + | ||
369 | 277 | +static int i_s_slow_log_plugin_deinit(void *arg __attribute__((unused))) | ||
370 | 278 | +{ | ||
371 | 279 | + return(0); | ||
372 | 280 | +} | ||
373 | 281 | + | ||
374 | 282 | +/* | ||
375 | 283 | + Plugin library descriptor | ||
376 | 284 | +*/ | ||
377 | 285 | + | ||
378 | 286 | +mysql_declare_plugin(slow_log_in_memory) | ||
379 | 287 | +{ | ||
380 | 288 | + MYSQL_AUDIT_PLUGIN, /* type */ | ||
381 | 289 | + &slow_log_in_memory_descriptor, /* descriptor */ | ||
382 | 290 | + "SLOW_LOG_IN_MEMORY_AUDIT", /* name */ | ||
383 | 291 | + "Percona", /* author */ | ||
384 | 292 | + "Error code histogram Audit", /* description */ | ||
385 | 293 | + PLUGIN_LICENSE_GPL, | ||
386 | 294 | + slow_log_in_memory_plugin_init, /* init function (when loaded) */ | ||
387 | 295 | + slow_log_in_memory_plugin_deinit, /* deinit function (when unloaded) */ | ||
388 | 296 | + 0x0001, /* version */ | ||
389 | 297 | + slow_log_in_memory_status_vars, /* status variables */ | ||
390 | 298 | + slow_log_in_memory_system_vars, /* system variables */ | ||
391 | 299 | + NULL, | ||
392 | 300 | + 0, | ||
393 | 301 | +}, | ||
394 | 302 | +{ | ||
395 | 303 | + MYSQL_INFORMATION_SCHEMA_PLUGIN, /* type */ | ||
396 | 304 | + &i_s_slow_log, /* descriptor */ | ||
397 | 305 | + "SLOW_LOG", /* name */ | ||
398 | 306 | + "Percona", /* author */ | ||
399 | 307 | + "latest slow log in memory", /* description */ | ||
400 | 308 | + PLUGIN_LICENSE_GPL, | ||
401 | 309 | + i_s_slow_log_plugin_init, /* init function (when loaded) */ | ||
402 | 310 | + i_s_slow_log_plugin_deinit, /* deinit function (when unloaded) */ | ||
403 | 311 | + 0x0001, /* version */ | ||
404 | 312 | + NULL, /* status variables */ | ||
405 | 313 | + NULL, /* system variables */ | ||
406 | 314 | + NULL, | ||
407 | 315 | + 0, | ||
408 | 316 | +} | ||
409 | 317 | +mysql_declare_plugin_end; | ||
410 | 318 | + | ||
411 | 319 | --- a/plugin/slowlog_in_memory/ut_slow_log_list.h 1970-01-01 08:00:00.000000000 +0800 | ||
412 | 320 | +++ b/plugin/slowlog_in_memory/ut_slow_log_list.h 2011-12-22 21:09:34.000000000 +0800 | ||
413 | 321 | @@ -0,0 +1,230 @@ | ||
414 | 322 | +#ifndef UT_SLOW_LOG_LIST_H | ||
415 | 323 | +#define UT_SLOW_LOG_LIST_H | ||
416 | 324 | + | ||
417 | 325 | +#define MYSQL_SERVER | ||
418 | 326 | +#include <mysql/plugin_audit.h> | ||
419 | 327 | +#include "unireg.h" | ||
420 | 328 | +#include "sql_show.h" | ||
421 | 329 | +#include "sql_class.h" | ||
422 | 330 | + | ||
423 | 331 | +mysql_mutex_t LOCK_slow_event_id_; | ||
424 | 332 | + | ||
425 | 333 | +#ifdef HAVE_PSI_INTERFACE | ||
426 | 334 | +PSI_mutex_key key_ss_mutex_LOCK_slow_log_; | ||
427 | 335 | +PSI_mutex_key key_ss_mutex_LOCK_slow_event_id_; | ||
428 | 336 | + | ||
429 | 337 | +static PSI_mutex_info all_semisync_mutexes[]= | ||
430 | 338 | +{ | ||
431 | 339 | + {&key_ss_mutex_LOCK_slow_log_, "LOCK_slow_log_", 0}, | ||
432 | 340 | + {&key_ss_mutex_LOCK_slow_event_id_, "LOCK_slow_event_id_", 0} | ||
433 | 341 | +}; | ||
434 | 342 | + | ||
435 | 343 | +static void init_semisync_psi_keys(void) | ||
436 | 344 | +{ | ||
437 | 345 | + const char* category= "semisync"; | ||
438 | 346 | + int count; | ||
439 | 347 | + | ||
440 | 348 | + if (PSI_server == NULL) | ||
441 | 349 | + return; | ||
442 | 350 | + | ||
443 | 351 | + count= array_elements(all_semisync_mutexes); | ||
444 | 352 | + PSI_server->register_mutex(category, all_semisync_mutexes, count); | ||
445 | 353 | + | ||
446 | 354 | +} | ||
447 | 355 | +#endif /* HAVE_PSI_INTERFACE */ | ||
448 | 356 | + | ||
449 | 357 | +/* unique event id for each slow query */ | ||
450 | 358 | +ulonglong global_event_id= 0; | ||
451 | 359 | + | ||
452 | 360 | +const uint MAX_QUERY_LEN= 255; | ||
453 | 361 | + | ||
454 | 362 | +class slow_log_t | ||
455 | 363 | +{ | ||
456 | 364 | +public: | ||
457 | 365 | + ulonglong event_id; | ||
458 | 366 | + ulonglong timestamp; | ||
459 | 367 | + ulong thread_id; | ||
460 | 368 | + char *schema; | ||
461 | 369 | + ulonglong innodb_trx_id; | ||
462 | 370 | + int cmd_errno; | ||
463 | 371 | + double time_of_query; | ||
464 | 372 | + char *general_query; | ||
465 | 373 | + | ||
466 | 374 | + uint schema_len; | ||
467 | 375 | + uint general_query_len; | ||
468 | 376 | + | ||
469 | 377 | + slow_log_t *next; | ||
470 | 378 | + | ||
471 | 379 | + slow_log_t(ulonglong timestamp, ulong thread_id, const char *schema, | ||
472 | 380 | + ulonglong innodb_trx_id, int cmd_errno, double time_of_query, const char *general_query):next(NULL) | ||
473 | 381 | + { | ||
474 | 382 | + this->timestamp= timestamp; | ||
475 | 383 | + this->thread_id= thread_id; | ||
476 | 384 | + | ||
477 | 385 | + if (schema) | ||
478 | 386 | + { | ||
479 | 387 | + this->schema_len= strlen(schema) + 1; | ||
480 | 388 | + this->schema= strndup(schema, this->schema_len); | ||
481 | 389 | + } | ||
482 | 390 | + else | ||
483 | 391 | + { | ||
484 | 392 | + this->schema= NULL; | ||
485 | 393 | + this->schema_len= 0; | ||
486 | 394 | + } | ||
487 | 395 | + | ||
488 | 396 | + this->innodb_trx_id= innodb_trx_id; | ||
489 | 397 | + this->cmd_errno= cmd_errno; | ||
490 | 398 | + this->time_of_query= time_of_query; | ||
491 | 399 | + | ||
492 | 400 | + if (general_query) | ||
493 | 401 | + { | ||
494 | 402 | + this->general_query_len= strlen(general_query) + 1; | ||
495 | 403 | + | ||
496 | 404 | + if (this->general_query_len > MAX_QUERY_LEN) | ||
497 | 405 | + { | ||
498 | 406 | + this->general_query_len= MAX_QUERY_LEN; | ||
499 | 407 | + } | ||
500 | 408 | + | ||
501 | 409 | + this->general_query= strndup(general_query, this->general_query_len); | ||
502 | 410 | + this->general_query[this->general_query_len-1]= '\0'; | ||
503 | 411 | + } | ||
504 | 412 | + else | ||
505 | 413 | + { | ||
506 | 414 | + this->general_query= NULL; | ||
507 | 415 | + this->general_query_len= 0; | ||
508 | 416 | + } | ||
509 | 417 | + | ||
510 | 418 | + this->real_size= sizeof(slow_log_t) + this->schema_len + this->general_query_len; | ||
511 | 419 | + | ||
512 | 420 | + mysql_mutex_lock(&LOCK_slow_event_id_); | ||
513 | 421 | + this->event_id= ++global_event_id; | ||
514 | 422 | + mysql_mutex_unlock(&LOCK_slow_event_id_); | ||
515 | 423 | + } | ||
516 | 424 | + | ||
517 | 425 | + ~slow_log_t() | ||
518 | 426 | + { | ||
519 | 427 | + if (schema) | ||
520 | 428 | + { | ||
521 | 429 | + free(schema); | ||
522 | 430 | + schema= NULL; | ||
523 | 431 | + } | ||
524 | 432 | + | ||
525 | 433 | + if (general_query) | ||
526 | 434 | + { | ||
527 | 435 | + free(general_query); | ||
528 | 436 | + general_query= NULL; | ||
529 | 437 | + } | ||
530 | 438 | + } | ||
531 | 439 | + | ||
532 | 440 | + uint size_of_instance() | ||
533 | 441 | + { | ||
534 | 442 | + return real_size; | ||
535 | 443 | + } | ||
536 | 444 | + | ||
537 | 445 | + uint real_size; | ||
538 | 446 | +}; | ||
539 | 447 | + | ||
540 | 448 | +class slow_log_list | ||
541 | 449 | +{ | ||
542 | 450 | +public: | ||
543 | 451 | + slow_log_t *first, *last; | ||
544 | 452 | + mysql_mutex_t LOCK_slow_log_; | ||
545 | 453 | + | ||
546 | 454 | + uint current_memory; | ||
547 | 455 | + | ||
548 | 456 | + void change_max_memory(uint new_len) | ||
549 | 457 | + { | ||
550 | 458 | + mysql_mutex_lock(&LOCK_slow_log_); | ||
551 | 459 | + | ||
552 | 460 | + max_memory= new_len; | ||
553 | 461 | + | ||
554 | 462 | + /* if the size is larger than current size, just change the value*/ | ||
555 | 463 | + if (max_memory >= current_memory) | ||
556 | 464 | + { | ||
557 | 465 | + mysql_mutex_unlock(&LOCK_slow_log_); | ||
558 | 466 | + return; | ||
559 | 467 | + } | ||
560 | 468 | + | ||
561 | 469 | + while (current_memory > max_memory) | ||
562 | 470 | + { | ||
563 | 471 | + pop_front(); | ||
564 | 472 | + } | ||
565 | 473 | + | ||
566 | 474 | + mysql_mutex_unlock(&LOCK_slow_log_); | ||
567 | 475 | + } | ||
568 | 476 | + | ||
569 | 477 | + slow_log_list(uint max_memory) | ||
570 | 478 | + { | ||
571 | 479 | + first= NULL; | ||
572 | 480 | + last= NULL; | ||
573 | 481 | + current_memory= 0; | ||
574 | 482 | + this->max_memory= max_memory; | ||
575 | 483 | + | ||
576 | 484 | + mysql_mutex_init(key_ss_mutex_LOCK_slow_log_, | ||
577 | 485 | + &LOCK_slow_log_, MY_MUTEX_INIT_FAST); | ||
578 | 486 | + } | ||
579 | 487 | + | ||
580 | 488 | + ~slow_log_list() | ||
581 | 489 | + { | ||
582 | 490 | + mysql_mutex_lock(&LOCK_slow_log_); | ||
583 | 491 | + while (first) | ||
584 | 492 | + { | ||
585 | 493 | + pop_front(); | ||
586 | 494 | + } | ||
587 | 495 | + mysql_mutex_unlock(&LOCK_slow_log_); | ||
588 | 496 | + | ||
589 | 497 | + mysql_mutex_destroy(&LOCK_slow_log_); | ||
590 | 498 | + } | ||
591 | 499 | + | ||
592 | 500 | + void push_back(slow_log_t * item) | ||
593 | 501 | + { | ||
594 | 502 | + mysql_mutex_lock(&LOCK_slow_log_); | ||
595 | 503 | + | ||
596 | 504 | + uint size= item->size_of_instance(); | ||
597 | 505 | + | ||
598 | 506 | + if (size > max_memory) | ||
599 | 507 | + { | ||
600 | 508 | + sql_print_warning("the insert item size %u > %u discarded", size, max_memory); | ||
601 | 509 | + mysql_mutex_unlock(&LOCK_slow_log_); | ||
602 | 510 | + return; | ||
603 | 511 | + } | ||
604 | 512 | + | ||
605 | 513 | + while (current_memory + size > max_memory) | ||
606 | 514 | + { | ||
607 | 515 | + pop_front(); | ||
608 | 516 | + } | ||
609 | 517 | + | ||
610 | 518 | + if (!first) | ||
611 | 519 | + { | ||
612 | 520 | + first= item; | ||
613 | 521 | + last= item; | ||
614 | 522 | + } | ||
615 | 523 | + else | ||
616 | 524 | + { | ||
617 | 525 | + last->next= item; | ||
618 | 526 | + last= item; | ||
619 | 527 | + } | ||
620 | 528 | + | ||
621 | 529 | + current_memory+= size; | ||
622 | 530 | + mysql_mutex_unlock(&LOCK_slow_log_); | ||
623 | 531 | + } | ||
624 | 532 | + | ||
625 | 533 | + /*functions call pop_front should have hold LOCK_slow_log_*/ | ||
626 | 534 | + void pop_front() | ||
627 | 535 | + { | ||
628 | 536 | + if (!first) return; | ||
629 | 537 | + | ||
630 | 538 | + slow_log_t *item= first; | ||
631 | 539 | + first= first->next; | ||
632 | 540 | + | ||
633 | 541 | + if (!first) last= NULL; | ||
634 | 542 | + | ||
635 | 543 | + current_memory-= item->size_of_instance(); | ||
636 | 544 | + delete item; | ||
637 | 545 | + } | ||
638 | 546 | + | ||
639 | 547 | +private: | ||
640 | 548 | + uint max_memory; | ||
641 | 549 | +}; | ||
642 | 550 | +#endif | ||
643 | 551 | + | ||
644 | 552 | --- a/mysql-test/include/have_slog_log_in_memory_audit_plugin.inc 1970-01-01 08:00:00.000000000 +0800 | ||
645 | 553 | +++ b/mysql-test/include/have_slog_log_in_memory_audit_plugin.inc 2011-12-22 21:08:28.000000000 +0800 | ||
646 | 554 | @@ -0,0 +1,21 @@ | ||
647 | 555 | +# | ||
648 | 556 | +# Check if server has support for loading plugins | ||
649 | 557 | +# | ||
650 | 558 | +if (`SELECT @@have_dynamic_loading != 'YES'`) { | ||
651 | 559 | + --skip Requires dynamic loading | ||
652 | 560 | +} | ||
653 | 561 | + | ||
654 | 562 | +# | ||
655 | 563 | +# Check if the variable SLOW_LOG_IN_MEMORY_AUDIT is set | ||
656 | 564 | +# | ||
657 | 565 | +if (!$SLOW_LOG_IN_MEMORY_AUDIT) | ||
658 | 566 | +{ | ||
659 | 567 | + skip Need slow_log_in_memory plugins; | ||
660 | 568 | +} | ||
661 | 569 | + | ||
662 | 570 | +# | ||
663 | 571 | +# Check if --plugin-dir was setup for slow_log_in_memory | ||
664 | 572 | +# | ||
665 | 573 | +if (`SELECT CONCAT('--plugin-dir=', @@plugin_dir) != '$SLOW_LOG_IN_MEMORY_AUDIT_OPT'`) { | ||
666 | 574 | + --skip SLOW_LOG plugin requires that --plugin-dir is set to the slow_log_in_memory plugin dir (either the .opt file does not contain \$SLOW_LOG_IN_MEMORY_AUDIT_OPT or another plugin is in use) | ||
667 | 575 | +} | ||
668 | 576 | --- a/mysql-test/include/plugin.defs 2011-12-19 14:44:49.000000000 +0800 | ||
669 | 577 | +++ b/mysql-test/include/plugin.defs 2011-12-22 21:08:28.000000000 +0800 | ||
670 | 578 | @@ -40,3 +40,5 @@ | ||
671 | 579 | ha_federated storage/federated FEDERATED_PLUGIN | ||
672 | 580 | mypluglib plugin/fulltext SIMPLE_PARSER | ||
673 | 581 | libdaemon_example plugin/daemon_example DAEMONEXAMPLE | ||
674 | 582 | +slowlog_in_memory plugin/slowlog_in_memory SLOW_LOG | ||
675 | 583 | +slowlog_in_memory plugin/slowlog_in_memory SLOW_LOG_IN_MEMORY_AUDIT | ||
676 | 584 | --- a/mysql-test/r/slow_log_in_memory.result 1970-01-01 08:00:00.000000000 +0800 | ||
677 | 585 | +++ b/mysql-test/r/slow_log_in_memory.result 2011-12-22 21:10:53.000000000 +0800 | ||
678 | 586 | @@ -0,0 +1,69 @@ | ||
679 | 587 | +# | ||
680 | 588 | +# feature: slow log show in information_schema.slow_log | ||
681 | 589 | +# | ||
682 | 590 | +install plugin SLOW_LOG_IN_MEMORY_AUDIT soname 'slowlog_in_memory.so'; | ||
683 | 591 | +install plugin SLOW_LOG soname 'slowlog_in_memory.so'; | ||
684 | 592 | +show variables like 'slow_log_in_memory_audit_max_memory'; | ||
685 | 593 | +Variable_name Value | ||
686 | 594 | +slow_log_in_memory_audit_max_memory 1048576 | ||
687 | 595 | +SET long_query_time=2; | ||
688 | 596 | +SET query_exec_time=2.123456; | ||
689 | 597 | +select 1; | ||
690 | 598 | +1 | ||
691 | 599 | +1 | ||
692 | 600 | +SET query_exec_time=0; | ||
693 | 601 | +SET long_query_time=2; | ||
694 | 602 | +SET query_exec_time=2.1; | ||
695 | 603 | +select 1; | ||
696 | 604 | +1 | ||
697 | 605 | +1 | ||
698 | 606 | +SET query_exec_time=0; | ||
699 | 607 | +SET long_query_time=2; | ||
700 | 608 | +SET query_exec_time=2.1; | ||
701 | 609 | +select 1; | ||
702 | 610 | +1 | ||
703 | 611 | +1 | ||
704 | 612 | +SET query_exec_time=0; | ||
705 | 613 | +show global status like 'slow_log_current_memory'; | ||
706 | 614 | +Variable_name Value | ||
707 | 615 | +slow_log_current_memory XX | ||
708 | 616 | +select * from information_schema.slow_log; | ||
709 | 617 | +EVENT_ID TIMESTAMP THREAD_ID DB INNODB_TRX_ID ERRNO MS_QUERY_TIME QUERY | ||
710 | 618 | +1 XX XX test XX 0 2.123456 select 1 | ||
711 | 619 | +2 XX XX test XX 0 2.1 select 1 | ||
712 | 620 | +3 XX XX test XX 0 2.1 select 1 | ||
713 | 621 | +# decrease max_memory and wash eldest | ||
714 | 622 | +set global slow_log_in_memory_audit_max_memory=240; | ||
715 | 623 | +use information_schema; | ||
716 | 624 | +SET long_query_time=2; | ||
717 | 625 | +SET query_exec_time=2.1; | ||
718 | 626 | +select 1; | ||
719 | 627 | +1 | ||
720 | 628 | +1 | ||
721 | 629 | +SET query_exec_time=0; | ||
722 | 630 | +show global status like 'slow_log_current_memory'; | ||
723 | 631 | +Variable_name Value | ||
724 | 632 | +slow_log_current_memory XX | ||
725 | 633 | +select * from information_schema.slow_log; | ||
726 | 634 | +EVENT_ID TIMESTAMP THREAD_ID DB INNODB_TRX_ID ERRNO MS_QUERY_TIME QUERY | ||
727 | 635 | +3 XX XX test XX 0 2.1 select 1 | ||
728 | 636 | +4 XX XX information_schema XX 0 2.1 select 1 | ||
729 | 637 | +# set to zero to disable audit | ||
730 | 638 | +set global slow_log_in_memory_audit_max_memory=0; | ||
731 | 639 | +SET long_query_time=2; | ||
732 | 640 | +SET query_exec_time=2.1; | ||
733 | 641 | +select 1; | ||
734 | 642 | +1 | ||
735 | 643 | +1 | ||
736 | 644 | +SET query_exec_time=0; | ||
737 | 645 | +show global status like 'slow_log_current_memory'; | ||
738 | 646 | +Variable_name Value | ||
739 | 647 | +slow_log_current_memory 0 | ||
740 | 648 | +select * from information_schema.slow_log; | ||
741 | 649 | +EVENT_ID TIMESTAMP THREAD_ID DB INNODB_TRX_ID ERRNO MS_QUERY_TIME QUERY | ||
742 | 650 | +uninstall plugin SLOW_LOG; | ||
743 | 651 | +uninstall plugin SLOW_LOG_IN_MEMORY_AUDIT; | ||
744 | 652 | +Warnings: | ||
745 | 653 | +Warning 1620 Plugin is busy and will be uninstalled on shutdown | ||
746 | 654 | +SET SESSION query_exec_time=default; | ||
747 | 655 | +SET long_query_time=default; | ||
748 | 656 | --- a/mysql-test/suite/sys_vars/r/slow_log_in_memory_audit.result 1970-01-01 08:00:00.000000000 +0800 | ||
749 | 657 | +++ b/mysql-test/suite/sys_vars/r/slow_log_in_memory_audit.result 2011-12-22 21:08:28.000000000 +0800 | ||
750 | 658 | @@ -0,0 +1,31 @@ | ||
751 | 659 | +install plugin SLOW_LOG_IN_MEMORY_AUDIT soname 'slowlog_in_memory.so'; | ||
752 | 660 | +install plugin SLOW_LOG soname 'slowlog_in_memory.so'; | ||
753 | 661 | +select @@global.slow_log_in_memory_audit_max_memory; | ||
754 | 662 | +@@global.slow_log_in_memory_audit_max_memory | ||
755 | 663 | +1048576 | ||
756 | 664 | +show global variables like 'slow_log_in_memory_audit_max_memory'; | ||
757 | 665 | +Variable_name Value | ||
758 | 666 | +slow_log_in_memory_audit_max_memory 1048576 | ||
759 | 667 | +select * from information_schema.global_variables where variable_name='slow_log_in_memory_audit_max_memory'; | ||
760 | 668 | +VARIABLE_NAME VARIABLE_VALUE | ||
761 | 669 | +SLOW_LOG_IN_MEMORY_AUDIT_MAX_MEMORY 1048576 | ||
762 | 670 | +set global slow_log_in_memory_audit_max_memory=2097152; | ||
763 | 671 | +select @@global.slow_log_in_memory_audit_max_memory; | ||
764 | 672 | +@@global.slow_log_in_memory_audit_max_memory | ||
765 | 673 | +2097152 | ||
766 | 674 | +show global variables like 'slow_log_in_memory_audit_max_memory'; | ||
767 | 675 | +Variable_name Value | ||
768 | 676 | +slow_log_in_memory_audit_max_memory 2097152 | ||
769 | 677 | +set global slow_log_in_memory_audit_max_memory=1.1; | ||
770 | 678 | +ERROR 42000: Incorrect argument type to variable 'slow_log_in_memory_audit_max_memory' | ||
771 | 679 | +set global slow_log_in_memory_audit_max_memory=1e1; | ||
772 | 680 | +ERROR 42000: Incorrect argument type to variable 'slow_log_in_memory_audit_max_memory' | ||
773 | 681 | +set global slow_log_in_memory_audit_max_memory="some text"; | ||
774 | 682 | +ERROR 42000: Incorrect argument type to variable 'slow_log_in_memory_audit_max_memory' | ||
775 | 683 | +select @@global.slow_log_in_memory_audit_max_memory; | ||
776 | 684 | +@@global.slow_log_in_memory_audit_max_memory | ||
777 | 685 | +2097152 | ||
778 | 686 | +UNINSTALL PLUGIN SLOW_LOG; | ||
779 | 687 | +UNINSTALL PLUGIN SLOW_LOG_IN_MEMORY_AUDIT; | ||
780 | 688 | +Warnings: | ||
781 | 689 | +Warning 1620 Plugin is busy and will be uninstalled on shutdown | ||
782 | 690 | --- a/mysql-test/suite/sys_vars/t/slow_log_in_memory_audit-master.opt 1970-01-01 08:00:00.000000000 +0800 | ||
783 | 691 | +++ b/mysql-test/suite/sys_vars/t/slow_log_in_memory_audit-master.opt 2011-12-22 21:08:28.000000000 +0800 | ||
784 | 692 | @@ -0,0 +1 @@ | ||
785 | 693 | +$SLOW_LOG_IN_MEMORY_AUDIT_OPT | ||
786 | 694 | --- a/mysql-test/suite/sys_vars/t/slow_log_in_memory_audit.test 1970-01-01 08:00:00.000000000 +0800 | ||
787 | 695 | +++ b/mysql-test/suite/sys_vars/t/slow_log_in_memory_audit.test 2011-12-22 21:08:28.000000000 +0800 | ||
788 | 696 | @@ -0,0 +1,40 @@ | ||
789 | 697 | + | ||
790 | 698 | +# | ||
791 | 699 | +# exists as a global only | ||
792 | 700 | +# | ||
793 | 701 | +source include/not_embedded.inc; | ||
794 | 702 | +source include/have_slog_log_in_memory_audit_plugin.inc; | ||
795 | 703 | +# The following is to prevent a mis-match on windows that has the name of of the lib ending with 'dll' | ||
796 | 704 | +--replace_regex /\.dll/.so/ | ||
797 | 705 | +install plugin SLOW_LOG_IN_MEMORY_AUDIT soname 'slowlog_in_memory.so'; | ||
798 | 706 | +install plugin SLOW_LOG soname 'slowlog_in_memory.so'; | ||
799 | 707 | +select @@global.slow_log_in_memory_audit_max_memory; | ||
800 | 708 | + | ||
801 | 709 | +show global variables like 'slow_log_in_memory_audit_max_memory'; | ||
802 | 710 | +select * from information_schema.global_variables where variable_name='slow_log_in_memory_audit_max_memory'; | ||
803 | 711 | + | ||
804 | 712 | +# | ||
805 | 713 | +# show that it's writable | ||
806 | 714 | +# | ||
807 | 715 | +set global slow_log_in_memory_audit_max_memory=2097152; | ||
808 | 716 | +select @@global.slow_log_in_memory_audit_max_memory; | ||
809 | 717 | +show global variables like 'slow_log_in_memory_audit_max_memory'; | ||
810 | 718 | + | ||
811 | 719 | +# | ||
812 | 720 | +# incorrect types | ||
813 | 721 | +# | ||
814 | 722 | +--error ER_WRONG_TYPE_FOR_VAR | ||
815 | 723 | +set global slow_log_in_memory_audit_max_memory=1.1; | ||
816 | 724 | +--error ER_WRONG_TYPE_FOR_VAR | ||
817 | 725 | +set global slow_log_in_memory_audit_max_memory=1e1; | ||
818 | 726 | +--error ER_WRONG_TYPE_FOR_VAR | ||
819 | 727 | +set global slow_log_in_memory_audit_max_memory="some text"; | ||
820 | 728 | + | ||
821 | 729 | + | ||
822 | 730 | +# | ||
823 | 731 | +# Cleanup | ||
824 | 732 | +# | ||
825 | 733 | +select @@global.slow_log_in_memory_audit_max_memory; | ||
826 | 734 | +UNINSTALL PLUGIN SLOW_LOG; | ||
827 | 735 | +UNINSTALL PLUGIN SLOW_LOG_IN_MEMORY_AUDIT; | ||
828 | 736 | + | ||
829 | 737 | --- a/mysql-test/t/slow_log_in_memory-master.opt 1970-01-01 08:00:00.000000000 +0800 | ||
830 | 738 | +++ b/mysql-test/t/slow_log_in_memory-master.opt 2011-12-22 21:08:28.000000000 +0800 | ||
831 | 739 | @@ -0,0 +1 @@ | ||
832 | 740 | +$SLOW_LOG_IN_MEMORY_AUDIT_OPT | ||
833 | 741 | --- a/mysql-test/t/slow_log_in_memory.test 1970-01-01 08:00:00.000000000 +0800 | ||
834 | 742 | +++ b/mysql-test/t/slow_log_in_memory.test 2011-12-22 21:10:45.000000000 +0800 | ||
835 | 743 | @@ -0,0 +1,61 @@ | ||
836 | 744 | +--source include/have_debug.inc | ||
837 | 745 | +--source include/have_slog_log_in_memory_audit_plugin.inc | ||
838 | 746 | + | ||
839 | 747 | +--echo # | ||
840 | 748 | +--echo # feature: slow log show in information_schema.slow_log | ||
841 | 749 | +--echo # | ||
842 | 750 | + | ||
843 | 751 | +install plugin SLOW_LOG_IN_MEMORY_AUDIT soname 'slowlog_in_memory.so'; | ||
844 | 752 | +install plugin SLOW_LOG soname 'slowlog_in_memory.so'; | ||
845 | 753 | +show variables like 'slow_log_in_memory_audit_max_memory'; | ||
846 | 754 | + | ||
847 | 755 | +SET long_query_time=2; | ||
848 | 756 | +SET query_exec_time=2.123456; | ||
849 | 757 | +select 1; | ||
850 | 758 | +SET query_exec_time=0; | ||
851 | 759 | + | ||
852 | 760 | +connect (con1,localhost,root,,); | ||
853 | 761 | + | ||
854 | 762 | +SET long_query_time=2; | ||
855 | 763 | +SET query_exec_time=2.1; | ||
856 | 764 | +select 1; | ||
857 | 765 | +SET query_exec_time=0; | ||
858 | 766 | + | ||
859 | 767 | +connect (con2,localhost,root,,); | ||
860 | 768 | + | ||
861 | 769 | +SET long_query_time=2; | ||
862 | 770 | +SET query_exec_time=2.1; | ||
863 | 771 | +select 1; | ||
864 | 772 | +SET query_exec_time=0; | ||
865 | 773 | +--replace_column 2 XX | ||
866 | 774 | +show global status like 'slow_log_current_memory'; | ||
867 | 775 | +--replace_column 2 XX 3 XX 5 XX | ||
868 | 776 | +select * from information_schema.slow_log; | ||
869 | 777 | + | ||
870 | 778 | +--echo # decrease max_memory and wash eldest | ||
871 | 779 | +set global slow_log_in_memory_audit_max_memory=240; | ||
872 | 780 | +connection con1; | ||
873 | 781 | +use information_schema; | ||
874 | 782 | +SET long_query_time=2; | ||
875 | 783 | +SET query_exec_time=2.1; | ||
876 | 784 | +select 1; | ||
877 | 785 | +SET query_exec_time=0; | ||
878 | 786 | +--replace_column 2 XX | ||
879 | 787 | +show global status like 'slow_log_current_memory'; | ||
880 | 788 | +--replace_column 2 XX 3 XX 5 XX | ||
881 | 789 | +select * from information_schema.slow_log; | ||
882 | 790 | + | ||
883 | 791 | +--echo # set to zero to disable audit | ||
884 | 792 | +connection con1; | ||
885 | 793 | +set global slow_log_in_memory_audit_max_memory=0; | ||
886 | 794 | +SET long_query_time=2; | ||
887 | 795 | +SET query_exec_time=2.1; | ||
888 | 796 | +select 1; | ||
889 | 797 | +SET query_exec_time=0; | ||
890 | 798 | +show global status like 'slow_log_current_memory'; | ||
891 | 799 | +select * from information_schema.slow_log; | ||
892 | 800 | + | ||
893 | 801 | +uninstall plugin SLOW_LOG; | ||
894 | 802 | +uninstall plugin SLOW_LOG_IN_MEMORY_AUDIT; | ||
895 | 803 | +SET SESSION query_exec_time=default; | ||
896 | 804 | +SET long_query_time=default; |
1. Please add patch name to the "patches/series" file
2. About innodb_trx_id. Please look to two following cases:
* log_slow_verbosity doesn't set "innodb"
* query doesn't use the InnoDB
In first case slow query log will has no information about InnoDB
In second case slow query will have line "# No InnoDB statistics available for this query\n"
In this two cases innodb_trx_id will be incorrect, and you can't use and setup it.
Please handle variable innodb_was_used correctly (at least for innodb_trx_id)
3. Following is very, very bad: query= "NULL"; query_len= 5; SCHEMA. I_S_SLOW_ LOG WHERE QUERY IS NULL
+ if (general_query)
+ {
....
+ }
+ else
+ {
+ this->general_
+ this->general_
+ }
You are break SQL semantic. For example query:
SELECT * FROM INSFORMATION_
or any join will not work correctly.
You are break SQL language semantic by string "NULL" instead of NULL
Same for Schema.
4. I_S_SLOW_LOG not very good name. Why SLOW_LOG bad?
5. Please add documentation to the doc/
6. Sleep in the test file - bad idea. Please replace this by debug variable query_exec_time.
7. Please add tests to sys_vars suite for the all added variables.
Please fix this, and I will review again.