Merge lp:~dingqi-lxb/percona-server/5.5_error_code_histogram into lp:percona-server/5.5

Proposed by 林晓斌 on 2011-12-07
Status: Superseded
Proposed branch: lp:~dingqi-lxb/percona-server/5.5_error_code_histogram
Merge into: lp:percona-server/5.5
Diff against target: 431 lines (+414/-0)
3 files modified
doc/source/diagnostics/error_code_histogram.rst (+39/-0)
patches/error_code_histogram.patch (+374/-0)
patches/series (+1/-0)
To merge this branch: bzr merge lp:~dingqi-lxb/percona-server/5.5_error_code_histogram
Reviewer Review Type Date Requested Status
Oleg Tsarev (community) Needs Information on 2011-12-14
Stewart Smith 2011-12-08 Pending
Vadim Tkachenko 2011-12-07 Pending
Review via email: mp+84807@code.launchpad.net

This proposal has been superseded by a proposal from 2011-12-12.

To post a comment you must log in.
200. By 林晓斌 on 2011-12-08

add init psi_keys

Oleg Tsarev (tsarev) wrote :

1. Please add patch name to the patches/series file
2. Why plugin doesn't uninstall in test?
3. Please add documentation to the doc/ dir
4. s/syntex/syntax/g

review: Needs Fixing
201. By 林晓斌 on 2011-12-12

modfication based on code-review

Oleg Tsarev (tsarev) wrote :

Xiaobin,

May be better just patch the code instead of two plugins?
Installing of two plugins is overkill for this simple feature.

Let me know what you think about this

review: Needs Information
202. By 林晓斌 on 2011-12-19

update test-case

203. By 林晓斌 on 2011-12-20

modify column type

204. By 林晓斌 on 2011-12-20

modify column type

Unmerged revisions

204. By 林晓斌 on 2011-12-20

modify column type

203. By 林晓斌 on 2011-12-20

modify column type

202. By 林晓斌 on 2011-12-19

update test-case

201. By 林晓斌 on 2011-12-12

modfication based on code-review

200. By 林晓斌 on 2011-12-08

add init psi_keys

199. By 林晓斌 on 2011-12-07

add error_code_histogram.patch

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added file 'doc/source/diagnostics/error_code_histogram.rst'
2--- doc/source/diagnostics/error_code_histogram.rst 1970-01-01 00:00:00 +0000
3+++ doc/source/diagnostics/error_code_histogram.rst 2011-12-12 09:32:13 +0000
4@@ -0,0 +1,39 @@
5+.. _errcode_histogram:
6+
7+=================
8+ Error Code Histogram
9+=================
10+
11+This feature adds two plugins and a table ``INFORMATION_SCHEMA.ERRCODE_HISTOGRAM`` . The table can be used to understand the error code distribution of the server.
12+
13+The two plugins should be installed by command ``"install plugin ERRCODE_AUDIT soname 'adt_errcode_histogram.so'"`` and ``"install plugin ERRCODE_HISTOGRAM soname 'adt_errcode_histogram.so'"``, they work by keeping one hash table in memory. All connections visit and change the same hash table, so global mutex is used.
14+
15+
16+Other Information
17+=================
18+
19+ * Author/Origin:
20+ *Percona*; *Percona* added the ``INFORMATION_SCHEMA.ERRCODE_HISTOGRAM`` table .
21+
22+
23+INFORMATION_SCHEMA Tables
24+=========================
25+
26+.. table:: INFORMATION_SCHEMA.ERRCODE_HISTOGRAM
27+
28+ :column ERROR: The error code which occurd at least once from last start.
29+ :column COUNT: The appear times of the error code.
30+
31+This table holds statistics about error code histogram.
32+
33+Example: ::
34+
35+ mysql> SELECT * FROM INFORMATION_SCHEMA.ERRCODE_HISTOGRAM;
36+ +-------+-------+
37+ | ERROR | COUNT |
38+ +-------+-------+
39+ | 1062 | 1 |
40+ | 1159 | 1 |
41+ | 1054 | 6 |
42+ +-------+-------+
43+
44
45=== added file 'patches/error_code_histogram.patch'
46--- patches/error_code_histogram.patch 1970-01-01 00:00:00 +0000
47+++ patches/error_code_histogram.patch 2011-12-12 09:32:13 +0000
48@@ -0,0 +1,374 @@
49+--- a/plugin/audit_errcode_histogram/audit_errcode_histogram.cc 1970-01-01 08:00:00.000000000 +0800
50++++ b/plugin/audit_errcode_histogram/audit_errcode_histogram.cc 2011-12-08 22:22:41.000000000 +0800
51+@@ -0,0 +1,308 @@
52++/* Copyright (c) 2006, 2011, Oracle and/or its affiliates. All rights reserved.
53++
54++ This program is free software; you can redistribute it and/or
55++ modify it under the terms of the GNU General Public License
56++ as published by the Free Software Foundation; version 2 of
57++ the License.
58++
59++ This program is distributed in the hope that it will be useful,
60++ but WITHOUT ANY WARRANTY; without even the implied warranty of
61++ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
62++ GNU General Public License for more details.
63++
64++ You should have received a copy of the GNU General Public License
65++ along with this program; if not, write to the Free Software
66++ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
67++
68++#include <mysql/plugin_audit.h>
69++#include "unireg.h"
70++#include "sql_show.h"
71++
72++#if !defined(__attribute__) && (defined(__cplusplus) || !defined(__GNUC__) || __GNUC__ == 2 && __GNUC_MINOR__ < 8)
73++#define __attribute__(A)
74++#endif
75++
76++/* lock management */
77++
78++mysql_mutex_t LOCK_errcode_;
79++
80++#ifdef HAVE_PSI_INTERFACE
81++PSI_mutex_key key_ss_mutex_LOCK_errcode_;
82++static PSI_mutex_info all_semisync_mutexes[]=
83++{
84++ { &key_ss_mutex_LOCK_errcode_, "LOCK_errcode_", 0}
85++};
86++
87++static void init_semisync_psi_keys(void)
88++{
89++ const char* category= "semisync";
90++ int count;
91++
92++ if (PSI_server == NULL)
93++ return;
94++
95++ count= array_elements(all_semisync_mutexes);
96++ PSI_server->register_mutex(category, all_semisync_mutexes, count);
97++
98++}
99++#endif /* HAVE_PSI_INTERFACE */
100++
101++/* hash management */
102++static HASH error_code_hash;
103++
104++struct st_errcode_item
105++{
106++ uint error_code;
107++ ulonglong count;
108++};
109++
110++void free_errcode_hash_item(st_errcode_item *entry)
111++{
112++ my_free(entry);
113++}
114++
115++const uchar *get_errcode_key(st_errcode_item *entry, size_t *length,
116++ my_bool not_used __attribute__((unused)))
117++{
118++ *length= sizeof(int);
119++ return (const uchar *)&entry->error_code;
120++}
121++
122++void add_notify_error_code(int error_code)
123++{
124++ mysql_mutex_lock(&LOCK_errcode_);
125++
126++ st_errcode_item *item= (st_errcode_item*) my_hash_search(&error_code_hash, (const uchar*)&error_code, sizeof(int));
127++ if (item)
128++ {
129++ item->count++;
130++ }
131++ else
132++ {
133++ item= new st_errcode_item;
134++ item->error_code= error_code;
135++ item->count= 1;
136++
137++ if (my_hash_insert(&error_code_hash, (uchar*)item))
138++ {
139++ my_error(ER_OUT_OF_RESOURCES, MYF(0));
140++ }
141++ }
142++
143++ mysql_mutex_unlock(&LOCK_errcode_);
144++}
145++
146++/*
147++ Initialize the plugin at server start or plugin installation.
148++
149++ SYNOPSIS
150++ audit_errcode_histogram_plugin_init()
151++
152++ DESCRIPTION
153++ Does nothing.
154++
155++ RETURN VALUE
156++ 0 success
157++ 1 failure (cannot happen)
158++*/
159++
160++static int audit_errcode_histogram_plugin_init(void *arg __attribute__((unused)))
161++{
162++#ifdef HAVE_PSI_INTERFACE
163++ init_semisync_psi_keys();
164++#endif
165++
166++ mysql_mutex_init(key_ss_mutex_LOCK_errcode_,
167++ &LOCK_errcode_, MY_MUTEX_INIT_FAST);
168++
169++ if (my_hash_init(&error_code_hash, system_charset_info, 200, 0, 0,
170++ (my_hash_get_key) get_errcode_key,(my_hash_free_key) free_errcode_hash_item, 0))
171++ return 1;
172++
173++ return 0;
174++}
175++
176++
177++/*
178++ Terminate the plugin at server shutdown or plugin deinstallation.
179++
180++ SYNOPSIS
181++ audit_errcode_histogram_plugin_deinit()
182++ Does nothing.
183++
184++ RETURN VALUE
185++ 0 success
186++ 1 failure (cannot happen)
187++*/
188++
189++static int audit_errcode_histogram_plugin_deinit(void *arg __attribute__((unused)))
190++{
191++ mysql_mutex_lock(&LOCK_errcode_);
192++ my_hash_free(&error_code_hash);
193++ mysql_mutex_unlock(&LOCK_errcode_);
194++
195++ mysql_mutex_destroy(&LOCK_errcode_);
196++ return 0;
197++}
198++
199++
200++/*
201++ Foo
202++
203++ SYNOPSIS
204++ audit_errcode_histogram_notify()
205++ thd connection context
206++
207++ DESCRIPTION
208++*/
209++
210++static void audit_errcode_histogram_notify(MYSQL_THD thd __attribute__((unused)),
211++ unsigned int event_class,
212++ const void *event)
213++{
214++ if (event_class == MYSQL_AUDIT_GENERAL_CLASS)
215++ {
216++ const struct mysql_event_general *event_general=
217++ (const struct mysql_event_general *) event;
218++ if (event_general->event_subclass != MYSQL_AUDIT_GENERAL_ERROR)
219++ return;
220++
221++ add_notify_error_code(event_general->general_error_code);
222++ }
223++}
224++
225++
226++/*
227++ Plugin type-specific descriptor
228++*/
229++
230++static struct st_mysql_audit audit_errcode_histogram_descriptor=
231++{
232++ MYSQL_AUDIT_INTERFACE_VERSION, /* interface version */
233++ NULL, /* release_thd function */
234++ audit_errcode_histogram_notify, /* notify function */
235++ { (unsigned long) MYSQL_AUDIT_GENERAL_CLASSMASK } /* class mask */
236++};
237++
238++
239++static ST_FIELD_INFO i_s_errcode_histogram_fields[] =
240++{
241++#define I_S_ERROR_CODE 0
242++ {"ERROR", 21 , MYSQL_TYPE_LONG, 0, 0, 0, SKIP_OPEN_TABLE},
243++#define I_S_ERROR_CODE_COUNT 1
244++ {"COUNT", 21, MYSQL_TYPE_LONGLONG, 0, 0, 0, SKIP_OPEN_TABLE}
245++};
246++
247++
248++int i_s_fill_table_errcode_histogram(THD* thd, TABLE_LIST* tables, COND* cond)
249++{
250++ TABLE *table= tables->table;
251++
252++ st_errcode_item *item= NULL;
253++ uint i;
254++ for (i= 0; i < error_code_hash.records; i++)
255++ {
256++ mysql_mutex_lock(&LOCK_errcode_);
257++ item= (st_errcode_item*) my_hash_element(&error_code_hash, i);
258++ mysql_mutex_unlock(&LOCK_errcode_);
259++
260++ table->field[I_S_ERROR_CODE]->store((int)item->error_code, TRUE);
261++ table->field[I_S_ERROR_CODE_COUNT]->store((longlong)item->count, TRUE);
262++ schema_table_store_record(thd, table);
263++ }
264++ return 0;
265++}
266++
267++
268++/*
269++ Initialize the plugin at server start or plugin installation.
270++
271++ SYNOPSIS
272++ audit_errcode_histogram_plugin_init()
273++
274++ DESCRIPTION
275++ Does nothing.
276++
277++ RETURN VALUE
278++ 0 success
279++ 1 failure (cannot happen)
280++*/
281++
282++static int i_s_errcode_histogram_plugin_init(void *arg __attribute__((unused)))
283++{
284++ ST_SCHEMA_TABLE* schema;
285++
286++ schema = (ST_SCHEMA_TABLE*) arg;
287++
288++ schema->fields_info = i_s_errcode_histogram_fields;
289++ schema->fill_table = i_s_fill_table_errcode_histogram;
290++ return 0;
291++}
292++
293++
294++/*
295++ Terminate the plugin at server shutdown or plugin deinstallation.
296++
297++ SYNOPSIS
298++ audit_errcode_histogram_plugin_deinit()
299++ Does nothing.
300++
301++ RETURN VALUE
302++ 0 success
303++ 1 failure (cannot happen)
304++
305++*/
306++
307++static int i_s_errcode_histogram_plugin_deinit(void *arg __attribute__((unused)))
308++{
309++ return(0);
310++}
311++
312++/*
313++ Plugin type-specific descriptor
314++*/
315++
316++static struct st_mysql_information_schema i_s_error_histogram=
317++{
318++ MYSQL_INFORMATION_SCHEMA_INTERFACE_VERSION
319++};
320++
321++
322++/*
323++ Plugin library descriptor
324++*/
325++
326++mysql_declare_plugin(adt_errcode_histogram)
327++{
328++ MYSQL_AUDIT_PLUGIN, /* type */
329++ &audit_errcode_histogram_descriptor, /* descriptor */
330++ "ERRCODE_AUDIT", /* name */
331++ "Percona", /* author */
332++ "Error code histogram Audit", /* description */
333++ PLUGIN_LICENSE_GPL,
334++ audit_errcode_histogram_plugin_init, /* init function (when loaded) */
335++ audit_errcode_histogram_plugin_deinit, /* deinit function (when unloaded) */
336++ 0x0001, /* version */
337++ NULL, /* status variables */
338++ NULL, /* system variables */
339++ NULL,
340++ 0,
341++},
342++{
343++ MYSQL_INFORMATION_SCHEMA_PLUGIN, /* type */
344++ &i_s_error_histogram, /* descriptor */
345++ "ERRCODE_HISTOGRAM", /* name */
346++ "Percona", /* author */
347++ "Error code histogram in memory", /* description */
348++ PLUGIN_LICENSE_GPL,
349++ i_s_errcode_histogram_plugin_init, /* init function (when loaded) */
350++ i_s_errcode_histogram_plugin_deinit, /* deinit function (when unloaded) */
351++ 0x0001, /* version */
352++ NULL, /* status variables */
353++ NULL, /* system variables */
354++ NULL,
355++ 0,
356++}
357++
358++mysql_declare_plugin_end;
359++
360+--- a/plugin/audit_errcode_histogram/CMakeLists.txt 1970-01-01 08:00:00.000000000 +0800
361++++ b/plugin/audit_errcode_histogram/CMakeLists.txt 2011-12-08 22:21:34.000000000 +0800
362+@@ -0,0 +1,17 @@
363++# Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved.
364++#
365++# This program is free software; you can redistribute it and/or modify
366++# it under the terms of the GNU General Public License as published by
367++# the Free Software Foundation; version 2 of the License.
368++#
369++# This program is distributed in the hope that it will be useful,
370++# but WITHOUT ANY WARRANTY; without even the implied warranty of
371++# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
372++# GNU General Public License for more details.
373++#
374++# You should have received a copy of the GNU General Public License
375++# along with this program; if not, write to the Free Software
376++# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
377++
378++MYSQL_ADD_PLUGIN(audit_errcode_histogram audit_errcode_histogram.cc
379++ MODULE_ONLY MODULE_OUTPUT_NAME "adt_errcode_histogram")
380+--- a/mysql-test/t/error_code_histogram.test 1970-01-01 08:00:00.000000000 +0800
381++++ b/mysql-test/t/error_code_histogram.test 2011-12-08 22:21:34.000000000 +0800
382+@@ -0,0 +1,18 @@
383++--source include/not_embedded.inc
384++
385++--echo #
386++--echo # feature: error code histogram
387++--echo #
388++install plugin ERRCODE_AUDIT soname 'adt_errcode_histogram.so';
389++install plugin ERRCODE_HISTOGRAM soname 'adt_errcode_histogram.so';
390++
391++--error 1049
392++use db_not_exists;
393++--error 1064
394++error_syntax_command;
395++--error 1049
396++use db_not_exists2;
397++SELECT * from information_schema.errcode_histogram;
398++
399++uninstall plugin ERRCODE_HISTOGRAM;
400++uninstall plugin ERRCODE_AUDIT;
401+--- a/mysql-test/r/error_code_histogram.result 1970-01-01 08:00:00.000000000 +0800
402++++ b/mysql-test/r/error_code_histogram.result 2011-12-08 22:21:34.000000000 +0800
403+@@ -0,0 +1,19 @@
404++#
405++# feature: error code histogram
406++#
407++install plugin ERRCODE_AUDIT soname 'adt_errcode_histogram.so';
408++install plugin ERRCODE_HISTOGRAM soname 'adt_errcode_histogram.so';
409++use db_not_exists;
410++ERROR 42000: Unknown database 'db_not_exists'
411++error_syntax_command;
412++ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'error_syntax_command' at line 1
413++use db_not_exists2;
414++ERROR 42000: Unknown database 'db_not_exists2'
415++SELECT * from information_schema.errcode_histogram;
416++ERROR COUNT
417++1049 2
418++1064 1
419++uninstall plugin ERRCODE_HISTOGRAM;
420++uninstall plugin ERRCODE_AUDIT;
421++Warnings:
422++Warning 1620 Plugin is busy and will be uninstalled on shutdown
423
424=== modified file 'patches/series'
425--- patches/series 2011-10-27 07:33:15 +0000
426+++ patches/series 2011-12-12 09:32:13 +0000
427@@ -60,3 +60,4 @@
428 subunit.patch
429 bug860910.patch
430 bug45702.patch
431+error_code_histogram.patch

Subscribers

People subscribed via source and target branches