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

Proposed by 林晓斌
Status: Work in progress
Proposed branch: lp:~dingqi-lxb/percona-server/5.5_error_code_histogram
Merge into: lp:percona-server/5.5
Diff against target: 467 lines (+450/-0)
3 files modified
doc/source/diagnostics/error_code_histogram.rst (+39/-0)
patches/error_code_histogram.patch (+410/-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
Vadim Tkachenko Pending
Stewart Smith Pending
Review via email: mp+85305@code.launchpad.net

This proposal supersedes a proposal from 2011-12-07.

To post a comment you must log in.
Revision history for this message
Oleg Tsarev (tsarev) wrote : Posted in a previous version of this proposal

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
Revision history for this message
Oleg Tsarev (tsarev) wrote : Posted in a previous version of this proposal

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
Revision history for this message
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
Revision history for this message
Oleg Tsarev (tsarev) wrote :

Test failed in Jenkins:
http://jenkins.percona.com/view/Percona%20Server%205.5/job/percona-server-5.5-param/219/

I canceled the build (Doesn't make sense wait another platforms)

review: Needs Fixing
Revision history for this message
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
Revision history for this message
林晓斌 (dingqi-lxb) 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

The feature needs an audit_plugin to "audit" and an INFORMATION_SCHEMA table to show the result.

Using plugin is the result discussed with Vadim , for the patch can be used in both Percona and original MySQL-Server.
Both patching the code and plugin form is ok to me.

202. By 林晓斌

update test-case

203. By 林晓斌

modify column type

204. By 林晓斌

modify column type

Unmerged revisions

204. By 林晓斌

modify column type

203. By 林晓斌

modify column type

202. By 林晓斌

update test-case

201. By 林晓斌

modfication based on code-review

200. By 林晓斌

add init psi_keys

199. By 林晓斌

add error_code_histogram.patch

Preview Diff

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

Subscribers

People subscribed via source and target branches