Percona Server with XtraDB

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

Proposed by 林晓斌 on 2011-12-12
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
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) 2011-12-12 Needs Information on 2011-12-14
Vadim Tkachenko 2011-12-12 Pending
Stewart Smith 2011-12-12 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.
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
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
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
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
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
林晓斌 (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 林晓斌 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

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-20 19:11:35 +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-20 19:11:35 +0000
48@@ -0,0 +1,410 @@
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-19 13:15:13.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_LONGLONG, 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((longlong)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-19 13:15:13.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/include/have_errcode_histogram.inc 1970-01-01 08:00:00.000000000 +0800
381++++ b/mysql-test/include/have_errcode_histogram.inc 2011-12-19 13:18:28.000000000 +0800
382+@@ -0,0 +1,21 @@
383++#
384++# Check if server has support for loading plugins
385++#
386++if (`SELECT @@have_dynamic_loading != 'YES'`) {
387++ --skip Requires dynamic loading
388++}
389++
390++#
391++# Check if the variable ERRCODE_AUDIT is set
392++#
393++if (!$ERRCODE_AUDIT)
394++{
395++ skip Need errcode_audit plugins;
396++}
397++
398++#
399++# Check if --plugin-dir was setup for errcode_audit
400++#
401++if (`SELECT CONCAT('--plugin-dir=', @@plugin_dir) != '$ERRCODE_AUDIT_OPT'`) {
402++ --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)
403++}
404+--- a/mysql-test/include/plugin.defs 2011-12-13 17:00:43.000000000 +0800
405++++ b/mysql-test/include/plugin.defs 2011-12-19 13:15:56.000000000 +0800
406+@@ -40,3 +40,5 @@
407+ ha_federated storage/federated FEDERATED_PLUGIN
408+ mypluglib plugin/fulltext SIMPLE_PARSER
409+ libdaemon_example plugin/daemon_example DAEMONEXAMPLE
410++adt_errcode_histogram plugin/audit_errcode_histogram ERRCODE_AUDIT
411++adt_errcode_histogram plugin/audit_errcode_histogram ERRCODE_HISTOGRAM
412+--- a/mysql-test/r/error_code_histogram.result 1970-01-01 08:00:00.000000000 +0800
413++++ b/mysql-test/r/error_code_histogram.result 2011-12-19 13:15:13.000000000 +0800
414+@@ -0,0 +1,19 @@
415++#
416++# feature: error code histogram
417++#
418++install plugin ERRCODE_AUDIT soname 'adt_errcode_histogram.so';
419++install plugin ERRCODE_HISTOGRAM soname 'adt_errcode_histogram.so';
420++use db_not_exists;
421++ERROR 42000: Unknown database 'db_not_exists'
422++error_syntax_command;
423++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
424++use db_not_exists2;
425++ERROR 42000: Unknown database 'db_not_exists2'
426++SELECT * from information_schema.errcode_histogram;
427++ERROR COUNT
428++1049 2
429++1064 1
430++uninstall plugin ERRCODE_HISTOGRAM;
431++uninstall plugin ERRCODE_AUDIT;
432++Warnings:
433++Warning 1620 Plugin is busy and will be uninstalled on shutdown
434+--- a/mysql-test/t/error_code_histogram-master.opt 1970-01-01 08:00:00.000000000 +0800
435++++ b/mysql-test/t/error_code_histogram-master.opt 2011-12-19 13:15:35.000000000 +0800
436+@@ -0,0 +1 @@
437++$ERRCODE_AUDIT_OPT
438+--- a/mysql-test/t/error_code_histogram.test 1970-01-01 08:00:00.000000000 +0800
439++++ b/mysql-test/t/error_code_histogram.test 2011-12-19 13:19:37.000000000 +0800
440+@@ -0,0 +1,18 @@
441++--source include/not_embedded.inc
442++--source include/have_errcode_histogram.inc
443++--echo #
444++--echo # feature: error code histogram
445++--echo #
446++install plugin ERRCODE_AUDIT soname 'adt_errcode_histogram.so';
447++install plugin ERRCODE_HISTOGRAM soname 'adt_errcode_histogram.so';
448++
449++--error 1049
450++use db_not_exists;
451++--error 1064
452++error_syntax_command;
453++--error 1049
454++use db_not_exists2;
455++SELECT * from information_schema.errcode_histogram;
456++
457++uninstall plugin ERRCODE_HISTOGRAM;
458++uninstall plugin ERRCODE_AUDIT;
459
460=== modified file 'patches/series'
461--- patches/series 2011-12-16 09:37:26 +0000
462+++ patches/series 2011-12-20 19:11:35 +0000
463@@ -62,3 +62,4 @@
464 bug45702.patch
465 group_commit.patch
466 warning_fixes.patch
467+error_code_histogram.patch

Subscribers

People subscribed via source and target branches