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: | Rejected |
---|---|
Rejected by: | 林晓斌 |
Proposed branch: | lp:~dingqi-lxb/percona-server/5.5_log_queries_in_memory |
Merge into: | lp:percona-server/5.5 |
Diff against target: |
898 lines (+879/-0) (has conflicts) 3 files modified
doc/source/diagnostics/slow_log_in_memory.rst (+74/-0) patches/series (+4/-0) patches/slowlog_in_memory.patch (+801/-0) Text conflict in patches/series |
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+85251@code.launchpad.net |
This proposal has been superseded by a proposal from 2011-12-20.
Commit message
Description of the change
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 : | # |
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 : | # |
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 : | # |
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 : | # |
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?
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 2011-12-20 02:47:23 +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 millisecond. | ||
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 2011-12-20 02:47:23 +0000 | |||
83 | @@ -60,5 +60,9 @@ | |||
84 | 60 | subunit.patch | 60 | subunit.patch |
85 | 61 | bug860910.patch | 61 | bug860910.patch |
86 | 62 | bug45702.patch | 62 | bug45702.patch |
87 | 63 | <<<<<<< TREE | ||
88 | 63 | group_commit.patch | 64 | group_commit.patch |
89 | 64 | warning_fixes.patch | 65 | warning_fixes.patch |
90 | 66 | ======= | ||
91 | 67 | slowlog_in_memory.patch | ||
92 | 68 | >>>>>>> MERGE-SOURCE | ||
93 | 65 | 69 | ||
94 | === added file 'patches/slowlog_in_memory.patch' | |||
95 | --- patches/slowlog_in_memory.patch 1970-01-01 00:00:00 +0000 | |||
96 | +++ patches/slowlog_in_memory.patch 2011-12-20 02:47:23 +0000 | |||
97 | @@ -0,0 +1,801 @@ | |||
98 | 1 | --- a/plugin/slowlog_in_memory/CMakeLists.txt 1970-01-01 08:00:00.000000000 +0800 | ||
99 | 2 | +++ b/plugin/slowlog_in_memory/CMakeLists.txt 2011-12-19 14:45:40.000000000 +0800 | ||
100 | 3 | @@ -0,0 +1,17 @@ | ||
101 | 4 | +# Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved. | ||
102 | 5 | +# | ||
103 | 6 | +# This program is free software; you can redistribute it and/or modify | ||
104 | 7 | +# it under the terms of the GNU General Public License as published by | ||
105 | 8 | +# the Free Software Foundation; version 2 of the License. | ||
106 | 9 | +# | ||
107 | 10 | +# This program is distributed in the hope that it will be useful, | ||
108 | 11 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
109 | 12 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
110 | 13 | +# GNU General Public License for more details. | ||
111 | 14 | +# | ||
112 | 15 | +# You should have received a copy of the GNU General Public License | ||
113 | 16 | +# along with this program; if not, write to the Free Software | ||
114 | 17 | +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
115 | 18 | + | ||
116 | 19 | +MYSQL_ADD_PLUGIN(slowlog_in_memory slowlog_in_memory.cc | ||
117 | 20 | + MODULE_ONLY MODULE_OUTPUT_NAME "slowlog_in_memory") | ||
118 | 21 | --- a/plugin/slowlog_in_memory/slowlog_in_memory.cc 1970-01-01 08:00:00.000000000 +0800 | ||
119 | 22 | +++ b/plugin/slowlog_in_memory/slowlog_in_memory.cc 2011-12-19 14:45:40.000000000 +0800 | ||
120 | 23 | @@ -0,0 +1,295 @@ | ||
121 | 24 | +/* Copyright (c) 2006, 2011, Oracle and/or its affiliates. All rights reserved. | ||
122 | 25 | + | ||
123 | 26 | + This program is free software; you can redistribute it and/or | ||
124 | 27 | + modify it under the terms of the GNU General Public License | ||
125 | 28 | + as published by the Free Software Foundation; version 2 of | ||
126 | 29 | + the License. | ||
127 | 30 | + | ||
128 | 31 | + This program is distributed in the hope that it will be useful, | ||
129 | 32 | + but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
130 | 33 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
131 | 34 | + GNU General Public License for more details. | ||
132 | 35 | + | ||
133 | 36 | + You should have received a copy of the GNU General Public License | ||
134 | 37 | + along with this program; if not, write to the Free Software | ||
135 | 38 | + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ | ||
136 | 39 | + | ||
137 | 40 | +#include "ut_slow_log_list.h" | ||
138 | 41 | + | ||
139 | 42 | +#if !defined(__attribute__) && (defined(__cplusplus) || !defined(__GNUC__) || __GNUC__ == 2 && __GNUC_MINOR__ < 8) | ||
140 | 43 | +#define __attribute__(A) | ||
141 | 44 | +#endif | ||
142 | 45 | +typedef struct st_mysql_sys_var SYS_VAR; | ||
143 | 46 | +uint max_memory_for_slowlog; | ||
144 | 47 | + | ||
145 | 48 | +/* lock management */ | ||
146 | 49 | + | ||
147 | 50 | +slow_log_list *global_slow_log_list= NULL; | ||
148 | 51 | + | ||
149 | 52 | +/* | ||
150 | 53 | + Initialize the plugin at server start or plugin installation. | ||
151 | 54 | + | ||
152 | 55 | + SYNOPSIS | ||
153 | 56 | + slowlog_in_memory_plugin_init() | ||
154 | 57 | + | ||
155 | 58 | + DESCRIPTION | ||
156 | 59 | + Does nothing. | ||
157 | 60 | + | ||
158 | 61 | + RETURN VALUE | ||
159 | 62 | + 0 success | ||
160 | 63 | + 1 failure (cannot happen) | ||
161 | 64 | +*/ | ||
162 | 65 | + | ||
163 | 66 | +static int slowlog_in_memory_plugin_init(void *arg __attribute__((unused))) | ||
164 | 67 | +{ | ||
165 | 68 | +#ifdef HAVE_PSI_INTERFACE | ||
166 | 69 | + init_semisync_psi_keys(); | ||
167 | 70 | +#endif | ||
168 | 71 | + | ||
169 | 72 | + mysql_mutex_init(key_ss_mutex_LOCK_slow_event_id_, | ||
170 | 73 | + &LOCK_slow_event_id_, MY_MUTEX_INIT_FAST); | ||
171 | 74 | + global_slow_log_list= new slow_log_list(max_memory_for_slowlog); | ||
172 | 75 | + | ||
173 | 76 | + return 0; | ||
174 | 77 | +} | ||
175 | 78 | + | ||
176 | 79 | + | ||
177 | 80 | +/* | ||
178 | 81 | + Terminate the plugin at server shutdown or plugin deinstallation. | ||
179 | 82 | + | ||
180 | 83 | + SYNOPSIS | ||
181 | 84 | + slowlog_in_memory_plugin_deinit() | ||
182 | 85 | + Does nothing. | ||
183 | 86 | + | ||
184 | 87 | + RETURN VALUE | ||
185 | 88 | + 0 success | ||
186 | 89 | + 1 failure (cannot happen) | ||
187 | 90 | +*/ | ||
188 | 91 | + | ||
189 | 92 | +static int slowlog_in_memory_plugin_deinit(void *arg __attribute__((unused))) | ||
190 | 93 | +{ | ||
191 | 94 | + if (global_slow_log_list) | ||
192 | 95 | + { | ||
193 | 96 | + delete global_slow_log_list; | ||
194 | 97 | + global_slow_log_list= NULL; | ||
195 | 98 | + } | ||
196 | 99 | + | ||
197 | 100 | + mysql_mutex_destroy(&LOCK_slow_event_id_); | ||
198 | 101 | + return 0; | ||
199 | 102 | +} | ||
200 | 103 | + | ||
201 | 104 | +/* | ||
202 | 105 | + Foo | ||
203 | 106 | + | ||
204 | 107 | + SYNOPSIS | ||
205 | 108 | + slowlog_in_memory_notify() | ||
206 | 109 | + thd connection context | ||
207 | 110 | + | ||
208 | 111 | + DESCRIPTION | ||
209 | 112 | +*/ | ||
210 | 113 | + | ||
211 | 114 | +static void slowlog_in_memory_notify(MYSQL_THD thd __attribute__((unused)), | ||
212 | 115 | + unsigned int event_class, | ||
213 | 116 | + const void *event) | ||
214 | 117 | +{ | ||
215 | 118 | + if (max_memory_for_slowlog == 0) return; | ||
216 | 119 | + | ||
217 | 120 | + if (event_class == MYSQL_AUDIT_GENERAL_CLASS) | ||
218 | 121 | + { | ||
219 | 122 | + const struct mysql_event_general *event_general= | ||
220 | 123 | + (const struct mysql_event_general *) event; | ||
221 | 124 | + if (event_general->event_subclass != MYSQL_AUDIT_GENERAL_STATUS) | ||
222 | 125 | + return; | ||
223 | 126 | + | ||
224 | 127 | + ulonglong utime_of_query= thd->current_utime() - thd->utime_after_lock; | ||
225 | 128 | + | ||
226 | 129 | +#ifndef DBUG_OFF | ||
227 | 130 | + if (thd->variables.query_exec_time != 0) | ||
228 | 131 | + utime_of_query= thd->lex->sql_command != SQLCOM_SET_OPTION ? thd->variables.query_exec_time : 0; | ||
229 | 132 | +#endif | ||
230 | 133 | + | ||
231 | 134 | + if (utime_of_query <= thd->variables.long_query_time) | ||
232 | 135 | + return; | ||
233 | 136 | + | ||
234 | 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, utime_of_query/1000, event_general->general_query); | ||
235 | 138 | + global_slow_log_list->push_back(tmp); | ||
236 | 139 | + } | ||
237 | 140 | +} | ||
238 | 141 | + | ||
239 | 142 | + | ||
240 | 143 | +/* | ||
241 | 144 | + Plugin type-specific descriptor | ||
242 | 145 | +*/ | ||
243 | 146 | + | ||
244 | 147 | +static struct st_mysql_audit slowlog_in_memory_descriptor= | ||
245 | 148 | +{ | ||
246 | 149 | + MYSQL_AUDIT_INTERFACE_VERSION, /* interface version */ | ||
247 | 150 | + NULL, /* release_thd function */ | ||
248 | 151 | + slowlog_in_memory_notify, /* notify function */ | ||
249 | 152 | + { (unsigned long) MYSQL_AUDIT_GENERAL_CLASSMASK } /* class mask */ | ||
250 | 153 | +}; | ||
251 | 154 | + | ||
252 | 155 | +static void change_max_memory_for_slowlog(MYSQL_THD thd, | ||
253 | 156 | + SYS_VAR *var, | ||
254 | 157 | + void *ptr, | ||
255 | 158 | + const void *val) | ||
256 | 159 | +{ | ||
257 | 160 | + uint new_len= *(uint *)val; | ||
258 | 161 | + *(uint *)ptr= new_len; | ||
259 | 162 | + | ||
260 | 163 | + global_slow_log_list->change_max_memory(new_len); | ||
261 | 164 | + return; | ||
262 | 165 | +} | ||
263 | 166 | + | ||
264 | 167 | +static MYSQL_SYSVAR_UINT(max_memory, max_memory_for_slowlog, | ||
265 | 168 | + PLUGIN_VAR_OPCMDARG, | ||
266 | 169 | + "The max memory that can be allocated for slow log.", | ||
267 | 170 | + NULL, // check | ||
268 | 171 | + &change_max_memory_for_slowlog, // update | ||
269 | 172 | + 1024*1024, 0, 1024*1024*1024, 1); | ||
270 | 173 | + | ||
271 | 174 | +static SYS_VAR* slowlog_in_memory_system_vars[]= { | ||
272 | 175 | + MYSQL_SYSVAR(max_memory), | ||
273 | 176 | + NULL, | ||
274 | 177 | +}; | ||
275 | 178 | + | ||
276 | 179 | +static uint slow_log_current_memory(MYSQL_THD thd, SHOW_VAR *var, char *buff) | ||
277 | 180 | +{ | ||
278 | 181 | + var->type= SHOW_INT; | ||
279 | 182 | + var->value= (char*)&global_slow_log_list->current_memory; | ||
280 | 183 | + return 0; | ||
281 | 184 | +} | ||
282 | 185 | + | ||
283 | 186 | +/* plugin status variables */ | ||
284 | 187 | +static SHOW_VAR slowlog_in_memory_status_vars[]= { | ||
285 | 188 | + {"slow_log_current_memory", | ||
286 | 189 | + (char*) &slow_log_current_memory, | ||
287 | 190 | + SHOW_FUNC}, | ||
288 | 191 | + {NULL, NULL, SHOW_LONG}, | ||
289 | 192 | +}; | ||
290 | 193 | + | ||
291 | 194 | + | ||
292 | 195 | +/* | ||
293 | 196 | + I_S_SLOW_LOG | ||
294 | 197 | +*/ | ||
295 | 198 | +static struct st_mysql_information_schema i_s_slow_log= | ||
296 | 199 | +{ | ||
297 | 200 | + MYSQL_INFORMATION_SCHEMA_INTERFACE_VERSION | ||
298 | 201 | +}; | ||
299 | 202 | + | ||
300 | 203 | +static ST_FIELD_INFO i_s_slow_log_fields[] = | ||
301 | 204 | +{ | ||
302 | 205 | + {"EVENT_ID", 11, MYSQL_TYPE_LONGLONG, 0, 0, 0, SKIP_OPEN_TABLE}, | ||
303 | 206 | + {"TIMESTAMP", 11, MYSQL_TYPE_LONGLONG, 0, 0, 0, SKIP_OPEN_TABLE}, | ||
304 | 207 | + {"THREAD_ID", 11, MYSQL_TYPE_LONG, 0, 0, 0, SKIP_OPEN_TABLE}, | ||
305 | 208 | + {"DB", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 1, 0, SKIP_OPEN_TABLE}, | ||
306 | 209 | + {"INNODB_TRX_ID", 11, MYSQL_TYPE_LONGLONG, 0, 1, 0, SKIP_OPEN_TABLE}, | ||
307 | 210 | + {"ERRNO", 11, MYSQL_TYPE_LONG, 0, 0, 0, SKIP_OPEN_TABLE}, | ||
308 | 211 | + {"MS_QUERY_TIME", 11, MYSQL_TYPE_LONGLONG, 0, 0, 0, SKIP_OPEN_TABLE}, | ||
309 | 212 | + | ||
310 | 213 | + {"QUERY", 255, MYSQL_TYPE_STRING, 0, 1, 0, SKIP_OPEN_TABLE}, | ||
311 | 214 | + {0, 0, MYSQL_TYPE_STRING, 0, 0, 0, SKIP_OPEN_TABLE} | ||
312 | 215 | +}; | ||
313 | 216 | + | ||
314 | 217 | + | ||
315 | 218 | +int i_s_fill_table_slow_log(THD* thd, TABLE_LIST* tables, COND* cond) | ||
316 | 219 | +{ | ||
317 | 220 | + if (!global_slow_log_list) return 0; | ||
318 | 221 | + | ||
319 | 222 | + TABLE *table= tables->table; | ||
320 | 223 | + | ||
321 | 224 | + mysql_mutex_lock(&global_slow_log_list->LOCK_slowlog_); | ||
322 | 225 | + | ||
323 | 226 | + slow_log_t *item= global_slow_log_list->first; | ||
324 | 227 | + while (item) | ||
325 | 228 | + { | ||
326 | 229 | + restore_record(table, s->default_values); | ||
327 | 230 | + | ||
328 | 231 | + table->field[0]->store(item->event_id, TRUE); | ||
329 | 232 | + table->field[1]->store(item->timestamp, TRUE); | ||
330 | 233 | + table->field[2]->store(item->thread_id, TRUE); | ||
331 | 234 | + | ||
332 | 235 | + if (item->schema) | ||
333 | 236 | + { | ||
334 | 237 | + table->field[3]->store(item->schema, item->schema_len-1, system_charset_info); | ||
335 | 238 | + table->field[3]->set_notnull(); | ||
336 | 239 | + } | ||
337 | 240 | + | ||
338 | 241 | + if (item->innodb_trx_id) | ||
339 | 242 | + { | ||
340 | 243 | + table->field[4]->store(item->innodb_trx_id, TRUE); | ||
341 | 244 | + table->field[4]->set_notnull(); | ||
342 | 245 | + } | ||
343 | 246 | + | ||
344 | 247 | + table->field[5]->store(item->cmd_errno, TRUE); | ||
345 | 248 | + table->field[6]->store(item->mstime_of_query, TRUE); | ||
346 | 249 | + | ||
347 | 250 | + if (item->general_query) | ||
348 | 251 | + { | ||
349 | 252 | + table->field[7]->store(item->general_query, item->general_query_len-1, system_charset_info); | ||
350 | 253 | + table->field[7]->set_notnull(); | ||
351 | 254 | + } | ||
352 | 255 | + | ||
353 | 256 | + schema_table_store_record(thd, table); | ||
354 | 257 | + item= item->next; | ||
355 | 258 | + } | ||
356 | 259 | + | ||
357 | 260 | + mysql_mutex_unlock(&global_slow_log_list->LOCK_slowlog_); | ||
358 | 261 | + return 0; | ||
359 | 262 | +} | ||
360 | 263 | + | ||
361 | 264 | + | ||
362 | 265 | +static int i_s_slow_log_plugin_init(void *arg __attribute__((unused))) | ||
363 | 266 | +{ | ||
364 | 267 | + ST_SCHEMA_TABLE* schema; | ||
365 | 268 | + | ||
366 | 269 | + schema = (ST_SCHEMA_TABLE*) arg; | ||
367 | 270 | + | ||
368 | 271 | + schema->fields_info = i_s_slow_log_fields; | ||
369 | 272 | + schema->fill_table = i_s_fill_table_slow_log; | ||
370 | 273 | + return 0; | ||
371 | 274 | +} | ||
372 | 275 | + | ||
373 | 276 | + | ||
374 | 277 | +static int i_s_slow_log_plugin_deinit(void *arg __attribute__((unused))) | ||
375 | 278 | +{ | ||
376 | 279 | + return(0); | ||
377 | 280 | +} | ||
378 | 281 | + | ||
379 | 282 | +/* | ||
380 | 283 | + Plugin library descriptor | ||
381 | 284 | +*/ | ||
382 | 285 | + | ||
383 | 286 | +mysql_declare_plugin(slowlog_in_memory) | ||
384 | 287 | +{ | ||
385 | 288 | + MYSQL_AUDIT_PLUGIN, /* type */ | ||
386 | 289 | + &slowlog_in_memory_descriptor, /* descriptor */ | ||
387 | 290 | + "SLOWLOG_IN_MEMORY_AUDIT", /* name */ | ||
388 | 291 | + "Percona", /* author */ | ||
389 | 292 | + "Error code histogram Audit", /* description */ | ||
390 | 293 | + PLUGIN_LICENSE_GPL, | ||
391 | 294 | + slowlog_in_memory_plugin_init, /* init function (when loaded) */ | ||
392 | 295 | + slowlog_in_memory_plugin_deinit, /* deinit function (when unloaded) */ | ||
393 | 296 | + 0x0001, /* version */ | ||
394 | 297 | + slowlog_in_memory_status_vars, /* status variables */ | ||
395 | 298 | + slowlog_in_memory_system_vars, /* system variables */ | ||
396 | 299 | + NULL, | ||
397 | 300 | + 0, | ||
398 | 301 | +}, | ||
399 | 302 | +{ | ||
400 | 303 | + MYSQL_INFORMATION_SCHEMA_PLUGIN, /* type */ | ||
401 | 304 | + &i_s_slow_log, /* descriptor */ | ||
402 | 305 | + "SLOW_LOG", /* name */ | ||
403 | 306 | + "Percona", /* author */ | ||
404 | 307 | + "latest slow log in memory", /* description */ | ||
405 | 308 | + PLUGIN_LICENSE_GPL, | ||
406 | 309 | + i_s_slow_log_plugin_init, /* init function (when loaded) */ | ||
407 | 310 | + i_s_slow_log_plugin_deinit, /* deinit function (when unloaded) */ | ||
408 | 311 | + 0x0001, /* version */ | ||
409 | 312 | + NULL, /* status variables */ | ||
410 | 313 | + NULL, /* system variables */ | ||
411 | 314 | + NULL, | ||
412 | 315 | + 0, | ||
413 | 316 | +} | ||
414 | 317 | +mysql_declare_plugin_end; | ||
415 | 318 | + | ||
416 | 319 | --- a/plugin/slowlog_in_memory/ut_slow_log_list.h 1970-01-01 08:00:00.000000000 +0800 | ||
417 | 320 | +++ b/plugin/slowlog_in_memory/ut_slow_log_list.h 2011-12-19 14:45:40.000000000 +0800 | ||
418 | 321 | @@ -0,0 +1,230 @@ | ||
419 | 322 | +#ifndef UT_SLOW_LOG_LIST_H | ||
420 | 323 | +#define UT_SLOW_LOG_LIST_H | ||
421 | 324 | + | ||
422 | 325 | +#define MYSQL_SERVER | ||
423 | 326 | +#include <mysql/plugin_audit.h> | ||
424 | 327 | +#include "unireg.h" | ||
425 | 328 | +#include "sql_show.h" | ||
426 | 329 | +#include "sql_class.h" | ||
427 | 330 | + | ||
428 | 331 | +mysql_mutex_t LOCK_slow_event_id_; | ||
429 | 332 | + | ||
430 | 333 | +#ifdef HAVE_PSI_INTERFACE | ||
431 | 334 | +PSI_mutex_key key_ss_mutex_LOCK_slowlog_; | ||
432 | 335 | +PSI_mutex_key key_ss_mutex_LOCK_slow_event_id_; | ||
433 | 336 | + | ||
434 | 337 | +static PSI_mutex_info all_semisync_mutexes[]= | ||
435 | 338 | +{ | ||
436 | 339 | + {&key_ss_mutex_LOCK_slowlog_, "LOCK_slowlog_", 0}, | ||
437 | 340 | + {&key_ss_mutex_LOCK_slow_event_id_, "LOCK_slow_event_id_", 0} | ||
438 | 341 | +}; | ||
439 | 342 | + | ||
440 | 343 | +static void init_semisync_psi_keys(void) | ||
441 | 344 | +{ | ||
442 | 345 | + const char* category= "semisync"; | ||
443 | 346 | + int count; | ||
444 | 347 | + | ||
445 | 348 | + if (PSI_server == NULL) | ||
446 | 349 | + return; | ||
447 | 350 | + | ||
448 | 351 | + count= array_elements(all_semisync_mutexes); | ||
449 | 352 | + PSI_server->register_mutex(category, all_semisync_mutexes, count); | ||
450 | 353 | + | ||
451 | 354 | +} | ||
452 | 355 | +#endif /* HAVE_PSI_INTERFACE */ | ||
453 | 356 | + | ||
454 | 357 | +/* unique event id for each slow query */ | ||
455 | 358 | +ulonglong global_event_id= 0; | ||
456 | 359 | + | ||
457 | 360 | +const uint MAX_QUERY_LEN= 255; | ||
458 | 361 | + | ||
459 | 362 | +class slow_log_t | ||
460 | 363 | +{ | ||
461 | 364 | +public: | ||
462 | 365 | + ulonglong event_id; | ||
463 | 366 | + ulonglong timestamp; | ||
464 | 367 | + ulong thread_id; | ||
465 | 368 | + char *schema; | ||
466 | 369 | + ulonglong innodb_trx_id; | ||
467 | 370 | + int cmd_errno; | ||
468 | 371 | + ulonglong mstime_of_query; | ||
469 | 372 | + char *general_query; | ||
470 | 373 | + | ||
471 | 374 | + uint schema_len; | ||
472 | 375 | + uint general_query_len; | ||
473 | 376 | + | ||
474 | 377 | + slow_log_t *next; | ||
475 | 378 | + | ||
476 | 379 | + slow_log_t(ulonglong timestamp, ulong thread_id, const char *schema, | ||
477 | 380 | + ulonglong innodb_trx_id, int cmd_errno, ulonglong mstime_of_query, const char *general_query):next(NULL) | ||
478 | 381 | + { | ||
479 | 382 | + this->timestamp= timestamp; | ||
480 | 383 | + this->thread_id= thread_id; | ||
481 | 384 | + | ||
482 | 385 | + if (schema) | ||
483 | 386 | + { | ||
484 | 387 | + this->schema_len= strlen(schema) + 1; | ||
485 | 388 | + this->schema= strndup(schema, this->schema_len); | ||
486 | 389 | + } | ||
487 | 390 | + else | ||
488 | 391 | + { | ||
489 | 392 | + this->schema= NULL; | ||
490 | 393 | + this->schema_len= 0; | ||
491 | 394 | + } | ||
492 | 395 | + | ||
493 | 396 | + this->innodb_trx_id= innodb_trx_id; | ||
494 | 397 | + this->cmd_errno= cmd_errno; | ||
495 | 398 | + this->mstime_of_query= mstime_of_query; | ||
496 | 399 | + | ||
497 | 400 | + if (general_query) | ||
498 | 401 | + { | ||
499 | 402 | + this->general_query_len= strlen(general_query) + 1; | ||
500 | 403 | + | ||
501 | 404 | + if (this->general_query_len > MAX_QUERY_LEN) | ||
502 | 405 | + { | ||
503 | 406 | + this->general_query_len= MAX_QUERY_LEN; | ||
504 | 407 | + } | ||
505 | 408 | + | ||
506 | 409 | + this->general_query= strndup(general_query, this->general_query_len); | ||
507 | 410 | + this->general_query[this->general_query_len-1]= '\0'; | ||
508 | 411 | + } | ||
509 | 412 | + else | ||
510 | 413 | + { | ||
511 | 414 | + this->general_query= NULL; | ||
512 | 415 | + this->general_query_len= 0; | ||
513 | 416 | + } | ||
514 | 417 | + | ||
515 | 418 | + this->real_size= sizeof(slow_log_t) + this->schema_len + this->general_query_len; | ||
516 | 419 | + | ||
517 | 420 | + mysql_mutex_lock(&LOCK_slow_event_id_); | ||
518 | 421 | + this->event_id= ++global_event_id; | ||
519 | 422 | + mysql_mutex_unlock(&LOCK_slow_event_id_); | ||
520 | 423 | + } | ||
521 | 424 | + | ||
522 | 425 | + ~slow_log_t() | ||
523 | 426 | + { | ||
524 | 427 | + if (schema) | ||
525 | 428 | + { | ||
526 | 429 | + free(schema); | ||
527 | 430 | + schema= NULL; | ||
528 | 431 | + } | ||
529 | 432 | + | ||
530 | 433 | + if (general_query) | ||
531 | 434 | + { | ||
532 | 435 | + free(general_query); | ||
533 | 436 | + general_query= NULL; | ||
534 | 437 | + } | ||
535 | 438 | + } | ||
536 | 439 | + | ||
537 | 440 | + uint size_of_instance() | ||
538 | 441 | + { | ||
539 | 442 | + return real_size; | ||
540 | 443 | + } | ||
541 | 444 | + | ||
542 | 445 | + uint real_size; | ||
543 | 446 | +}; | ||
544 | 447 | + | ||
545 | 448 | +class slow_log_list | ||
546 | 449 | +{ | ||
547 | 450 | +public: | ||
548 | 451 | + slow_log_t *first, *last; | ||
549 | 452 | + mysql_mutex_t LOCK_slowlog_; | ||
550 | 453 | + | ||
551 | 454 | + uint current_memory; | ||
552 | 455 | + | ||
553 | 456 | + void change_max_memory(uint new_len) | ||
554 | 457 | + { | ||
555 | 458 | + mysql_mutex_lock(&LOCK_slowlog_); | ||
556 | 459 | + | ||
557 | 460 | + max_memory= new_len; | ||
558 | 461 | + | ||
559 | 462 | + /* if the size is larger than current size, just change the value*/ | ||
560 | 463 | + if (max_memory >= current_memory) | ||
561 | 464 | + { | ||
562 | 465 | + mysql_mutex_unlock(&LOCK_slowlog_); | ||
563 | 466 | + return; | ||
564 | 467 | + } | ||
565 | 468 | + | ||
566 | 469 | + while (current_memory > max_memory) | ||
567 | 470 | + { | ||
568 | 471 | + pop_front(); | ||
569 | 472 | + } | ||
570 | 473 | + | ||
571 | 474 | + mysql_mutex_unlock(&LOCK_slowlog_); | ||
572 | 475 | + } | ||
573 | 476 | + | ||
574 | 477 | + slow_log_list(uint max_memory) | ||
575 | 478 | + { | ||
576 | 479 | + first= NULL; | ||
577 | 480 | + last= NULL; | ||
578 | 481 | + current_memory= 0; | ||
579 | 482 | + this->max_memory= max_memory; | ||
580 | 483 | + | ||
581 | 484 | + mysql_mutex_init(key_ss_mutex_LOCK_slowlog_, | ||
582 | 485 | + &LOCK_slowlog_, MY_MUTEX_INIT_FAST); | ||
583 | 486 | + } | ||
584 | 487 | + | ||
585 | 488 | + ~slow_log_list() | ||
586 | 489 | + { | ||
587 | 490 | + mysql_mutex_lock(&LOCK_slowlog_); | ||
588 | 491 | + while (first) | ||
589 | 492 | + { | ||
590 | 493 | + pop_front(); | ||
591 | 494 | + } | ||
592 | 495 | + mysql_mutex_unlock(&LOCK_slowlog_); | ||
593 | 496 | + | ||
594 | 497 | + mysql_mutex_destroy(&LOCK_slowlog_); | ||
595 | 498 | + } | ||
596 | 499 | + | ||
597 | 500 | + void push_back(slow_log_t * item) | ||
598 | 501 | + { | ||
599 | 502 | + mysql_mutex_lock(&LOCK_slowlog_); | ||
600 | 503 | + | ||
601 | 504 | + uint size= item->size_of_instance(); | ||
602 | 505 | + | ||
603 | 506 | + if (size > max_memory) | ||
604 | 507 | + { | ||
605 | 508 | + sql_print_warning("the insert item size %u > %u discarded", size, max_memory); | ||
606 | 509 | + mysql_mutex_unlock(&LOCK_slowlog_); | ||
607 | 510 | + return; | ||
608 | 511 | + } | ||
609 | 512 | + | ||
610 | 513 | + while (current_memory + size > max_memory) | ||
611 | 514 | + { | ||
612 | 515 | + pop_front(); | ||
613 | 516 | + } | ||
614 | 517 | + | ||
615 | 518 | + if (!first) | ||
616 | 519 | + { | ||
617 | 520 | + first= item; | ||
618 | 521 | + last= item; | ||
619 | 522 | + } | ||
620 | 523 | + else | ||
621 | 524 | + { | ||
622 | 525 | + last->next= item; | ||
623 | 526 | + last= item; | ||
624 | 527 | + } | ||
625 | 528 | + | ||
626 | 529 | + current_memory+= size; | ||
627 | 530 | + mysql_mutex_unlock(&LOCK_slowlog_); | ||
628 | 531 | + } | ||
629 | 532 | + | ||
630 | 533 | + /*functions call pop_front should have hold LOCK_slowlog_*/ | ||
631 | 534 | + void pop_front() | ||
632 | 535 | + { | ||
633 | 536 | + if (!first) return; | ||
634 | 537 | + | ||
635 | 538 | + slow_log_t *item= first; | ||
636 | 539 | + first= first->next; | ||
637 | 540 | + | ||
638 | 541 | + if (!first) last= NULL; | ||
639 | 542 | + | ||
640 | 543 | + current_memory-= item->size_of_instance(); | ||
641 | 544 | + delete item; | ||
642 | 545 | + } | ||
643 | 546 | + | ||
644 | 547 | +private: | ||
645 | 548 | + uint max_memory; | ||
646 | 549 | +}; | ||
647 | 550 | +#endif | ||
648 | 551 | + | ||
649 | 552 | --- a/mysql-test/include/have_slog_log_in_memory_audit_plugin.inc 1970-01-01 08:00:00.000000000 +0800 | ||
650 | 553 | +++ b/mysql-test/include/have_slog_log_in_memory_audit_plugin.inc 2011-12-19 19:13:34.000000000 +0800 | ||
651 | 554 | @@ -0,0 +1,21 @@ | ||
652 | 555 | +# | ||
653 | 556 | +# Check if server has support for loading plugins | ||
654 | 557 | +# | ||
655 | 558 | +if (`SELECT @@have_dynamic_loading != 'YES'`) { | ||
656 | 559 | + --skip Requires dynamic loading | ||
657 | 560 | +} | ||
658 | 561 | + | ||
659 | 562 | +# | ||
660 | 563 | +# Check if the variable SLOW_LOG_IN_MEMORY_AUDIT is set | ||
661 | 564 | +# | ||
662 | 565 | +if (!$SLOW_LOG_IN_MEMORY_AUDIT) | ||
663 | 566 | +{ | ||
664 | 567 | + skip Need slow_log_in_memory plugins; | ||
665 | 568 | +} | ||
666 | 569 | + | ||
667 | 570 | +# | ||
668 | 571 | +# Check if --plugin-dir was setup for slow_log_in_memory | ||
669 | 572 | +# | ||
670 | 573 | +if (`SELECT CONCAT('--plugin-dir=', @@plugin_dir) != '$SLOW_LOG_IN_MEMORY_AUDIT_OPT'`) { | ||
671 | 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) | ||
672 | 575 | +} | ||
673 | 576 | --- a/mysql-test/include/plugin.defs 2011-12-19 14:44:49.000000000 +0800 | ||
674 | 577 | +++ b/mysql-test/include/plugin.defs 2011-12-19 19:15:18.000000000 +0800 | ||
675 | 578 | @@ -40,3 +40,5 @@ | ||
676 | 579 | ha_federated storage/federated FEDERATED_PLUGIN | ||
677 | 580 | mypluglib plugin/fulltext SIMPLE_PARSER | ||
678 | 581 | libdaemon_example plugin/daemon_example DAEMONEXAMPLE | ||
679 | 582 | +slowlog_in_memory plugin/slowlog_in_memory SLOW_LOG | ||
680 | 583 | +slowlog_in_memory plugin/slowlog_in_memory SLOW_LOG_IN_MEMORY_AUDIT | ||
681 | 584 | --- a/mysql-test/r/slow_log_in_memory.result 1970-01-01 08:00:00.000000000 +0800 | ||
682 | 585 | +++ b/mysql-test/r/slow_log_in_memory.result 2011-12-19 19:10:14.000000000 +0800 | ||
683 | 586 | @@ -0,0 +1,67 @@ | ||
684 | 587 | +# | ||
685 | 588 | +# feature: slow log show in information_schema.slow_log | ||
686 | 589 | +# | ||
687 | 590 | +install plugin SLOWLOG_IN_MEMORY_AUDIT soname 'slowlog_in_memory.so'; | ||
688 | 591 | +install plugin SLOW_LOG soname 'slowlog_in_memory.so'; | ||
689 | 592 | +show variables like 'slowlog_in_memory_audit_max_memory'; | ||
690 | 593 | +Variable_name Value | ||
691 | 594 | +slowlog_in_memory_audit_max_memory 1048576 | ||
692 | 595 | +SET long_query_time=2; | ||
693 | 596 | +SET query_exec_time=2.1; | ||
694 | 597 | +select 1; | ||
695 | 598 | +1 | ||
696 | 599 | +1 | ||
697 | 600 | +SET query_exec_time=0; | ||
698 | 601 | +SET long_query_time=2; | ||
699 | 602 | +SET query_exec_time=2.1; | ||
700 | 603 | +select 1; | ||
701 | 604 | +1 | ||
702 | 605 | +1 | ||
703 | 606 | +SET query_exec_time=0; | ||
704 | 607 | +SET long_query_time=2; | ||
705 | 608 | +SET query_exec_time=2.1; | ||
706 | 609 | +select 1; | ||
707 | 610 | +1 | ||
708 | 611 | +1 | ||
709 | 612 | +SET query_exec_time=0; | ||
710 | 613 | +show global status like 'slow_log_current_memory'; | ||
711 | 614 | +Variable_name Value | ||
712 | 615 | +slow_log_current_memory XX | ||
713 | 616 | +select * from information_schema.slow_log; | ||
714 | 617 | +EVENT_ID TIMESTAMP THREAD_ID DB INNODB_TRX_ID ERRNO MS_QUERY_TIME QUERY | ||
715 | 618 | +1 XX 1 test XX 0 2100 select 1 | ||
716 | 619 | +2 XX 2 test XX 0 2100 select 1 | ||
717 | 620 | +3 XX 3 test XX 0 2100 select 1 | ||
718 | 621 | +# decrease max_memory and wash eldest | ||
719 | 622 | +set global slowlog_in_memory_audit_max_memory=240; | ||
720 | 623 | +use information_schema; | ||
721 | 624 | +SET long_query_time=2; | ||
722 | 625 | +SET query_exec_time=2.1; | ||
723 | 626 | +select 1; | ||
724 | 627 | +1 | ||
725 | 628 | +1 | ||
726 | 629 | +SET query_exec_time=0; | ||
727 | 630 | +show global status like 'slow_log_current_memory'; | ||
728 | 631 | +Variable_name Value | ||
729 | 632 | +slow_log_current_memory XX | ||
730 | 633 | +select * from information_schema.slow_log; | ||
731 | 634 | +EVENT_ID TIMESTAMP THREAD_ID DB INNODB_TRX_ID ERRNO MS_QUERY_TIME QUERY | ||
732 | 635 | +3 XX 3 test XX 0 2100 select 1 | ||
733 | 636 | +4 XX 2 information_schema XX 0 2100 select 1 | ||
734 | 637 | +# set to zero to disable audit | ||
735 | 638 | +set global slowlog_in_memory_audit_max_memory=0; | ||
736 | 639 | +SET long_query_time=2; | ||
737 | 640 | +SET query_exec_time=2.1; | ||
738 | 641 | +select 1; | ||
739 | 642 | +1 | ||
740 | 643 | +1 | ||
741 | 644 | +SET query_exec_time=0; | ||
742 | 645 | +show global status like 'slow_log_current_memory'; | ||
743 | 646 | +Variable_name Value | ||
744 | 647 | +slow_log_current_memory 0 | ||
745 | 648 | +select * from information_schema.slow_log; | ||
746 | 649 | +EVENT_ID TIMESTAMP THREAD_ID DB INNODB_TRX_ID ERRNO MS_QUERY_TIME QUERY | ||
747 | 650 | +uninstall plugin SLOW_LOG; | ||
748 | 651 | +uninstall plugin SLOWLOG_IN_MEMORY_AUDIT; | ||
749 | 652 | +Warnings: | ||
750 | 653 | +Warning 1620 Plugin is busy and will be uninstalled on shutdown | ||
751 | 654 | --- a/mysql-test/suite/sys_vars/r/slow_log_in_memory_audit.result 1970-01-01 08:00:00.000000000 +0800 | ||
752 | 655 | +++ b/mysql-test/suite/sys_vars/r/slow_log_in_memory_audit.result 2011-12-19 19:12:14.000000000 +0800 | ||
753 | 656 | @@ -0,0 +1,31 @@ | ||
754 | 657 | +install plugin SLOWLOG_IN_MEMORY_AUDIT soname 'slowlog_in_memory.so'; | ||
755 | 658 | +install plugin SLOW_LOG soname 'slowlog_in_memory.so'; | ||
756 | 659 | +select @@global.slowlog_in_memory_audit_max_memory; | ||
757 | 660 | +@@global.slowlog_in_memory_audit_max_memory | ||
758 | 661 | +1048576 | ||
759 | 662 | +show global variables like 'slowlog_in_memory_audit_max_memory'; | ||
760 | 663 | +Variable_name Value | ||
761 | 664 | +slowlog_in_memory_audit_max_memory 1048576 | ||
762 | 665 | +select * from information_schema.global_variables where variable_name='slowlog_in_memory_audit_max_memory'; | ||
763 | 666 | +VARIABLE_NAME VARIABLE_VALUE | ||
764 | 667 | +SLOWLOG_IN_MEMORY_AUDIT_MAX_MEMORY 1048576 | ||
765 | 668 | +set global slowlog_in_memory_audit_max_memory=2097152; | ||
766 | 669 | +select @@global.slowlog_in_memory_audit_max_memory; | ||
767 | 670 | +@@global.slowlog_in_memory_audit_max_memory | ||
768 | 671 | +2097152 | ||
769 | 672 | +show global variables like 'slowlog_in_memory_audit_max_memory'; | ||
770 | 673 | +Variable_name Value | ||
771 | 674 | +slowlog_in_memory_audit_max_memory 2097152 | ||
772 | 675 | +set global slowlog_in_memory_audit_max_memory=1.1; | ||
773 | 676 | +ERROR 42000: Incorrect argument type to variable 'slowlog_in_memory_audit_max_memory' | ||
774 | 677 | +set global slowlog_in_memory_audit_max_memory=1e1; | ||
775 | 678 | +ERROR 42000: Incorrect argument type to variable 'slowlog_in_memory_audit_max_memory' | ||
776 | 679 | +set global slowlog_in_memory_audit_max_memory="some text"; | ||
777 | 680 | +ERROR 42000: Incorrect argument type to variable 'slowlog_in_memory_audit_max_memory' | ||
778 | 681 | +select @@global.slowlog_in_memory_audit_max_memory; | ||
779 | 682 | +@@global.slowlog_in_memory_audit_max_memory | ||
780 | 683 | +2097152 | ||
781 | 684 | +UNINSTALL PLUGIN SLOW_LOG; | ||
782 | 685 | +UNINSTALL PLUGIN SLOWLOG_IN_MEMORY_AUDIT; | ||
783 | 686 | +Warnings: | ||
784 | 687 | +Warning 1620 Plugin is busy and will be uninstalled on shutdown | ||
785 | 688 | --- a/mysql-test/suite/sys_vars/t/slow_log_in_memory_audit-master.opt 1970-01-01 08:00:00.000000000 +0800 | ||
786 | 689 | +++ b/mysql-test/suite/sys_vars/t/slow_log_in_memory_audit-master.opt 2011-12-19 19:12:02.000000000 +0800 | ||
787 | 690 | @@ -0,0 +1 @@ | ||
788 | 691 | +$SLOW_LOG_IN_MEMORY_AUDIT_OPT | ||
789 | 692 | --- a/mysql-test/suite/sys_vars/t/slow_log_in_memory_audit.test 1970-01-01 08:00:00.000000000 +0800 | ||
790 | 693 | +++ b/mysql-test/suite/sys_vars/t/slow_log_in_memory_audit.test 2011-12-19 19:12:02.000000000 +0800 | ||
791 | 694 | @@ -0,0 +1,40 @@ | ||
792 | 695 | + | ||
793 | 696 | +# | ||
794 | 697 | +# exists as a global only | ||
795 | 698 | +# | ||
796 | 699 | +source include/not_embedded.inc; | ||
797 | 700 | +source include/have_slog_log_in_memory_audit_plugin.inc; | ||
798 | 701 | +# The following is to prevent a mis-match on windows that has the name of of the lib ending with 'dll' | ||
799 | 702 | +--replace_regex /\.dll/.so/ | ||
800 | 703 | +install plugin SLOWLOG_IN_MEMORY_AUDIT soname 'slowlog_in_memory.so'; | ||
801 | 704 | +install plugin SLOW_LOG soname 'slowlog_in_memory.so'; | ||
802 | 705 | +select @@global.slowlog_in_memory_audit_max_memory; | ||
803 | 706 | + | ||
804 | 707 | +show global variables like 'slowlog_in_memory_audit_max_memory'; | ||
805 | 708 | +select * from information_schema.global_variables where variable_name='slowlog_in_memory_audit_max_memory'; | ||
806 | 709 | + | ||
807 | 710 | +# | ||
808 | 711 | +# show that it's writable | ||
809 | 712 | +# | ||
810 | 713 | +set global slowlog_in_memory_audit_max_memory=2097152; | ||
811 | 714 | +select @@global.slowlog_in_memory_audit_max_memory; | ||
812 | 715 | +show global variables like 'slowlog_in_memory_audit_max_memory'; | ||
813 | 716 | + | ||
814 | 717 | +# | ||
815 | 718 | +# incorrect types | ||
816 | 719 | +# | ||
817 | 720 | +--error ER_WRONG_TYPE_FOR_VAR | ||
818 | 721 | +set global slowlog_in_memory_audit_max_memory=1.1; | ||
819 | 722 | +--error ER_WRONG_TYPE_FOR_VAR | ||
820 | 723 | +set global slowlog_in_memory_audit_max_memory=1e1; | ||
821 | 724 | +--error ER_WRONG_TYPE_FOR_VAR | ||
822 | 725 | +set global slowlog_in_memory_audit_max_memory="some text"; | ||
823 | 726 | + | ||
824 | 727 | + | ||
825 | 728 | +# | ||
826 | 729 | +# Cleanup | ||
827 | 730 | +# | ||
828 | 731 | +select @@global.slowlog_in_memory_audit_max_memory; | ||
829 | 732 | +UNINSTALL PLUGIN SLOW_LOG; | ||
830 | 733 | +UNINSTALL PLUGIN SLOWLOG_IN_MEMORY_AUDIT; | ||
831 | 734 | + | ||
832 | 735 | --- a/mysql-test/t/slow_log_in_memory-master.opt 1970-01-01 08:00:00.000000000 +0800 | ||
833 | 736 | +++ b/mysql-test/t/slow_log_in_memory-master.opt 2011-12-19 19:10:07.000000000 +0800 | ||
834 | 737 | @@ -0,0 +1 @@ | ||
835 | 738 | +$SLOW_LOG_IN_MEMORY_AUDIT_OPT | ||
836 | 739 | --- a/mysql-test/t/slow_log_in_memory.test 1970-01-01 08:00:00.000000000 +0800 | ||
837 | 740 | +++ b/mysql-test/t/slow_log_in_memory.test 2011-12-19 19:10:07.000000000 +0800 | ||
838 | 741 | @@ -0,0 +1,60 @@ | ||
839 | 742 | +--source include/have_debug.inc | ||
840 | 743 | +--source include/have_slog_log_in_memory_audit_plugin.inc | ||
841 | 744 | + | ||
842 | 745 | +--echo # | ||
843 | 746 | +--echo # feature: slow log show in information_schema.slow_log | ||
844 | 747 | +--echo # | ||
845 | 748 | + | ||
846 | 749 | +-- source include/restart_mysqld.inc | ||
847 | 750 | +install plugin SLOWLOG_IN_MEMORY_AUDIT soname 'slowlog_in_memory.so'; | ||
848 | 751 | +install plugin SLOW_LOG soname 'slowlog_in_memory.so'; | ||
849 | 752 | +show variables like 'slowlog_in_memory_audit_max_memory'; | ||
850 | 753 | + | ||
851 | 754 | +SET long_query_time=2; | ||
852 | 755 | +SET query_exec_time=2.1; | ||
853 | 756 | +select 1; | ||
854 | 757 | +SET query_exec_time=0; | ||
855 | 758 | + | ||
856 | 759 | +connect (con1,localhost,root,,); | ||
857 | 760 | + | ||
858 | 761 | +SET long_query_time=2; | ||
859 | 762 | +SET query_exec_time=2.1; | ||
860 | 763 | +select 1; | ||
861 | 764 | +SET query_exec_time=0; | ||
862 | 765 | + | ||
863 | 766 | +connect (con2,localhost,root,,); | ||
864 | 767 | + | ||
865 | 768 | +SET long_query_time=2; | ||
866 | 769 | +SET query_exec_time=2.1; | ||
867 | 770 | +select 1; | ||
868 | 771 | +SET query_exec_time=0; | ||
869 | 772 | +--replace_column 2 XX | ||
870 | 773 | +show global status like 'slow_log_current_memory'; | ||
871 | 774 | +--replace_column 2 XX 5 XX | ||
872 | 775 | +select * from information_schema.slow_log; | ||
873 | 776 | + | ||
874 | 777 | +--echo # decrease max_memory and wash eldest | ||
875 | 778 | +set global slowlog_in_memory_audit_max_memory=240; | ||
876 | 779 | +connection con1; | ||
877 | 780 | +use information_schema; | ||
878 | 781 | +SET long_query_time=2; | ||
879 | 782 | +SET query_exec_time=2.1; | ||
880 | 783 | +select 1; | ||
881 | 784 | +SET query_exec_time=0; | ||
882 | 785 | +--replace_column 2 XX | ||
883 | 786 | +show global status like 'slow_log_current_memory'; | ||
884 | 787 | +--replace_column 2 XX 5 XX | ||
885 | 788 | +select * from information_schema.slow_log; | ||
886 | 789 | + | ||
887 | 790 | +--echo # set to zero to disable audit | ||
888 | 791 | +connection con1; | ||
889 | 792 | +set global slowlog_in_memory_audit_max_memory=0; | ||
890 | 793 | +SET long_query_time=2; | ||
891 | 794 | +SET query_exec_time=2.1; | ||
892 | 795 | +select 1; | ||
893 | 796 | +SET query_exec_time=0; | ||
894 | 797 | +show global status like 'slow_log_current_memory'; | ||
895 | 798 | +select * from information_schema.slow_log; | ||
896 | 799 | + | ||
897 | 800 | +uninstall plugin SLOW_LOG; | ||
898 | 801 | +uninstall plugin SLOWLOG_IN_MEMORY_AUDIT; |
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.