<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-6299571792602348259</id><updated>2024-10-10T21:43:33.768-04:00</updated><category term="mysql"/><category term="mysqlproxy"/><category term="Lua"/><category term="launchpad"/><category term="drizzle"/><category term="replication"/><category term="plugin"/><category term="c++"/><category term="gearman"/><category term="mem"/><category term="perl"/><category term="HA"/><category term="crash"/><category term="debugger"/><category term="debugging"/><category term="gdb"/><category term="javascript"/><category term="json"/><category term="memcached"/><category term="monitoring"/><category term="mysqlsandbox"/><category term="planet"/><category term="planetmysql"/><category term="rss"/><category term="sandbox"/><title type='text'>MySQL Proxy and other thoughts</title><subtitle type='html'>For posts about Scala, Lift and Go (Golang), please go to &lt;a href=&quot;http://blog.fmpwizard.com&quot;&gt;http://blog.fmpwizard.com&lt;/a&gt;</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://fmpwizard.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6299571792602348259/posts/default/-/drizzle'/><link rel='alternate' type='text/html' href='http://fmpwizard.blogspot.com/search/label/drizzle'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/16354403712237460832</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>4</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-6299571792602348259.post-4893546775335304788</id><published>2009-09-02T20:20:00.003-04:00</published><updated>2009-09-02T20:28:50.985-04:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="c++"/><category scheme="http://www.blogger.com/atom/ns#" term="debugger"/><category scheme="http://www.blogger.com/atom/ns#" term="debugging"/><category scheme="http://www.blogger.com/atom/ns#" term="drizzle"/><category scheme="http://www.blogger.com/atom/ns#" term="gdb"/><category scheme="http://www.blogger.com/atom/ns#" term="mysql"/><title type='text'>How GDB helped me fix a Drizzle Bug</title><content type='html'>&lt;a onblur=&quot;try {parent.deselectBloggerImageGracefully();} catch(e) {}&quot; href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhgNMtvoOHzzjiofGMK9fEbz7rIDJfNY2OL6o8EHNx_G0ft2umUj3CYI1krZhMs-4zYrS3MebhzVkG9Ry5oeNTvnqzXVNIslAzEyCk4ztlkjdD8uBA7L8YaX8Nv6Zjwmuty0vlzybMfmvuW/s1600-h/gdb_blog_post.png&quot;&gt;&lt;img style=&quot;display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 320px; height: 210px;&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhgNMtvoOHzzjiofGMK9fEbz7rIDJfNY2OL6o8EHNx_G0ft2umUj3CYI1krZhMs-4zYrS3MebhzVkG9Ry5oeNTvnqzXVNIslAzEyCk4ztlkjdD8uBA7L8YaX8Nv6Zjwmuty0vlzybMfmvuW/s320/gdb_blog_post.png&quot; border=&quot;0&quot; alt=&quot;&quot; id=&quot;BLOGGER_PHOTO_ID_5376940502511714466&quot; /&gt;&lt;/a&gt;&lt;br /&gt;&lt;div&gt;The other day I found a nice surprise on my inbox. &lt;a href=&quot;http://jpipes.com/&quot;&gt;Jay Pipes&lt;/a&gt; asked me if I&#39;d like to try fixing a &lt;a href=&quot;https://bugs.launchpad.net/drizzle/+bug/377826&quot;&gt;small bug on Drizzle&lt;/a&gt;. It looked pretty simple, and the bug report included a big part of the fix. I accepted without a doubt.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;I decided to first change trans_prealloc_size from uint32_t to uint64_t. That was done on &lt;i&gt;&lt;a href=&quot;http://bazaar.launchpad.net/~diego-fmpwizard/drizzle/bug-fixes/revision/1125#drizzled/session.h&quot;&gt;drizzled/session.h&lt;/a&gt;&lt;/i&gt;.&lt;/div&gt;&lt;div&gt;Then, I went to &lt;i&gt;&lt;a href=&quot;http://bazaar.launchpad.net/~diego-fmpwizard/drizzle/bug-fixes/revision/1125#drizzled/set_var.cc&quot;&gt;drizzle/set_var.cc&lt;/a&gt;&lt;/i&gt; and changed sys_trans_prealloc_size from sys_var_session_uint32_t to sys_var_session_uint64_t (and removed the two extra parameters).&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;At first, that looked like it was everything I needed to do. I compiled drizzle, executed the queries that were included on the bug report, and that almost worked!&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;code&gt;set session transaction_prealloc_size=1024*1024*1024*4;&lt;/code&gt;&lt;/div&gt;&lt;div&gt;&lt;code&gt;&lt;/code&gt;&lt;code&gt;set session transaction_prealloc_size=1024*1024*1024*5;&lt;/code&gt;&lt;/div&gt;&lt;div&gt;&lt;code&gt;&lt;/code&gt;and &lt;/div&gt;&lt;div&gt;&lt;code&gt;set session transaction_prealloc_size=1024*1024*1024*6; &lt;/code&gt; were all being truncated to &quot;&lt;b&gt;4294966272&lt;/b&gt;&quot;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;The pending problem was that I no longer received a warning telling me that those values had been truncated.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;I looked again at the code, used &lt;a href=&quot;http://www.gnu.org/software/gdb/documentation/&quot;&gt;gdb&lt;/a&gt; to &lt;a href=&quot;http://drizzle.org/wiki/Debugging_Drizzle_with_GDB&quot;&gt;step through the code&lt;/a&gt;, but I just couldn&#39;t tell what the problem was.&lt;/div&gt;&lt;div&gt;I was then forced to do what I do when I&#39;m stuck on a computer problem, I had to take a break :).&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;... And that was a great idea, because while away from the computer, I thought of looking at sys_var_session_uint64_t::update, and compare it to sys_var_session_uint32_t::update.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;It turned out that sys_var_session_uint64_t::update was missing a call to throw_bounds_warning(), no wonder I wasn&#39;t getting the truncation warnings.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;It was time to enable the &lt;a href=&quot;http://bazaar.launchpad.net/~diego-fmpwizard/drizzle/bug-fixes/revision/1125#tests/suite/big/t/variables-big.test&quot;&gt;test suite that targeted this bug&lt;/a&gt;, run this particular test, commit, push .... and I suddenly thought that I should also run the regular tests, you know, make test. And I was glad I did. There were about 7 test cases that failed.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;The firs thought was that these changes I just made uncovered some mysterious bugs on Drizzle. But after looking closely at the test cases, I noticed that there was something else going on.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;If I executed this query: &lt;code&gt;set group_concat_max_len = 4;&lt;/code&gt;, the session variable &lt;b&gt;group_concat_max_len&lt;/b&gt; ended up with a value of &lt;b&gt;4294967295&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-weight: normal; &quot;&gt;.&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;It was time for some serious GDB&#39;ing. There are a few articles &lt;a href=&quot;http://drizzle.org/wiki/Debugging_Drizzle_with_GDB&quot;&gt;here&lt;/a&gt;, &lt;a href=&quot;http://posulliv.com/?p=113&quot;&gt;here&lt;/a&gt; and &lt;a href=&quot;http://torum.net/2009/03/drizzle-gdb-osx/&quot;&gt;here&lt;/a&gt; that explain how to use gdb and Drizzle, but I start it a little different.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:large;&quot;&gt;Starting GDB and Drizzle&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;On the terminal, I run:&lt;/div&gt;&lt;div&gt;&lt;pre&gt;[wizard]$ gdb --args /Applications/drizzle/sbin/drizzled --port=3306 --basedir=/Applications/drizzle --datadir=/Applications/drizzle/var&lt;/pre&gt; &lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;After a few seconds, I am at the (gdb) prompt. This is the time to set breakpoints, which would help me find this little issue.&lt;div&gt;I tried doing this:&lt;/div&gt;&lt;div&gt;&lt;pre&gt;(gdb)break drizzled/set_var.cc:744&lt;/pre&gt;&lt;/div&gt;&lt;div&gt;but gdb told me: &quot;&lt;b&gt;No source file named drizzled/set_var.cc&lt;/b&gt;&quot;, I had this same problem trying to use gdb on the MySQL Proxy, and after trying different things, I found the correct way to specify the file name:&lt;/div&gt;&lt;div&gt;&lt;pre&gt;(gdb)break set_var.cc:744&lt;/pre&gt;&lt;br /&gt;*&lt;b&gt;Note:&lt;/b&gt; when debugging plugins, you specify the filenames like this:&lt;/div&gt;&lt;div&gt;&lt;pre&gt;(gdb)break plugin/logging_gearman/logging_gearman.cc:150&lt;/pre&gt;&lt;br /&gt;(include the plugin folder)&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;That one breakpoint was all I needed, I then started drizzle by typing:&lt;/div&gt;&lt;div&gt;&lt;pre&gt;(gdb)run&lt;/pre&gt;&lt;/div&gt;&lt;div&gt;After pressing enter, you see many lines, but the last few are (similar to)&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;pre&gt;&lt;br /&gt;. done&lt;br /&gt;InnoDB: The InnoDB memory heap is disabled&lt;br /&gt;InnoDB: Mutexes and rw_locks use GCC atomic builtins.&lt;br /&gt;090827 23:45:16  InnoDB: highest supported file format is Barracuda.&lt;br /&gt;090827 23:45:16 InnoDB Plugin 1.0.3 started; log sequence number 46439&lt;br /&gt;Listening on :::3306&lt;br /&gt;Listening on 0.0.0.0:3306&lt;br /&gt;/Applications/mysql/enterprise/drizzle/sbin/drizzled: ready for connections.&lt;br /&gt;Version: &#39;2009.08.1124&#39; Source distribution (bug-fixes)&lt;br /&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Drizzle was ready for my tests. I went to a new terminal and executed&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;pre&gt;set group_concat_max_len = 4;&lt;/pre&gt;&lt;/div&gt;&lt;div&gt;The drizzle prompt hanged there (waiting on the breakpoint I set earlier)&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;This is the code near the breakpoint&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;pre&gt;bool sys_var_session_uint64_t::update(Session *session, set_var *var)&lt;br /&gt;{&lt;br /&gt;uint64_t tmp= var-&gt;save_result.uint64_t_value;&lt;br /&gt;&lt;br /&gt;if (tmp &gt; max_system_variables.*offset) // &lt;-- this was line 744 &lt;/pre&gt;&lt;pre&gt;  throw_bounds_warning(session, true, true, getName(), (int64_t) tmp);&lt;/pre&gt;&lt;pre&gt;  tmp= max_system_variables.*offset;&lt;/pre&gt;&lt;pre&gt;if (option_limits)&lt;/pre&gt;&lt;pre&gt;  tmp= fix_unsigned(session, tmp, option_limits);&lt;/pre&gt;&lt;pre&gt;if (var-&gt;type == OPT_GLOBAL)&lt;br /&gt;{&lt;br /&gt;/* Lock is needed to make things safe on 32 bit systems */&lt;br /&gt;pthread_mutex_lock(&amp;amp;LOCK_global_system_variables);&lt;br /&gt;global_system_variables.*offset= (uint64_t) tmp;&lt;br /&gt;pthread_mutex_unlock(&amp;amp;LOCK_global_system_variables);&lt;br /&gt;}&lt;br /&gt;else&lt;br /&gt;session-&gt;variables.*offset= (uint64_t) tmp;&lt;br /&gt;return 0;&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;div&gt;&lt;br /&gt;Back on the GDB terminal, I saw:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;Breakpoint 1, sys_var_session_uint64_t::update (this=0x4dec60, session=0x1044e00, var=0x10470c8) at set_var.cc:744&lt;br /&gt;744       if (tmp &gt; max_system_variables.*offset)&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;It was time to look at the value of tmp, so I typed&lt;br /&gt;&lt;pre&gt;(gdb) print tmp&lt;br /&gt;$4 = 4&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;So far, so good, I wanted to see 4 as the result, let&#39;s step through the code, and see when tmp gets a much higher value.&lt;br /&gt;&lt;pre&gt;(gdb) step&lt;br /&gt;746         tmp= max_system_variables.*offset;&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;Check the value of tmp&lt;/div&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;(gdb) print tmp&lt;br /&gt;$5 = 4&lt;br /&gt;(gdb) step&lt;br /&gt;748       if (option_limits)&lt;br /&gt;(gdb) print tmp&lt;br /&gt;$6 = 4294967295&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;div&gt;There it was, whatever happened between &lt;b&gt;line 746&lt;/b&gt; and &lt;b&gt;748&lt;/b&gt; is causing the problem. By now you may have already spotted the issue, but I just didn&#39;t see it. I stared at that piece of code for about a minute, and then I realized what the problem was.&lt;/div&gt;&lt;div&gt;The &lt;b&gt;if statement&lt;/b&gt; on line 744 was a &lt;b&gt;single line statement&lt;/b&gt;, before I added the call to &lt;b&gt;throw_bounds_warning()&lt;/b&gt;. Because I am so used to having brackets, even for single line if statement, I forgot to add a pair of {}.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;*Note:&lt;/b&gt; For completeness, once you are done stepping through the code, you can type &lt;/div&gt;&lt;pre&gt;(gdb)cont&lt;/pre&gt;&lt;div&gt;and the program will continue to run as normal. On my case, I could then run on the drizzle terminal:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;pre&gt;drizzle&gt; show variables like &quot;group_concat_max_len&quot;;&lt;br /&gt;+----------------------+------------+&lt;br /&gt;| Variable_name | Value |&lt;br /&gt;+----------------------+------------+&lt;br /&gt;| group_concat_max_len | 4294967295 |&lt;br /&gt;+----------------------+------------+&lt;br /&gt;1 row in set (0.01 sec)&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:large;&quot;&gt;&lt;b&gt;Conclusion&lt;/b&gt;&lt;/span&gt;.&lt;/div&gt;&lt;div&gt;If you don&#39;t have another pair of eyes to look over your code, you could ask gdb for some help :)&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://fmpwizard.blogspot.com/feeds/4893546775335304788/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://fmpwizard.blogspot.com/2009/09/how-gdb-helped-me-fix-drizzle-bug.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6299571792602348259/posts/default/4893546775335304788'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6299571792602348259/posts/default/4893546775335304788'/><link rel='alternate' type='text/html' href='http://fmpwizard.blogspot.com/2009/09/how-gdb-helped-me-fix-drizzle-bug.html' title='How GDB helped me fix a Drizzle Bug'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/16354403712237460832</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhgNMtvoOHzzjiofGMK9fEbz7rIDJfNY2OL6o8EHNx_G0ft2umUj3CYI1krZhMs-4zYrS3MebhzVkG9Ry5oeNTvnqzXVNIslAzEyCk4ztlkjdD8uBA7L8YaX8Nv6Zjwmuty0vlzybMfmvuW/s72-c/gdb_blog_post.png" height="72" width="72"/><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6299571792602348259.post-949480159174027085</id><published>2009-08-28T11:35:00.000-04:00</published><updated>2009-08-28T11:41:06.967-04:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="drizzle"/><category scheme="http://www.blogger.com/atom/ns#" term="gearman"/><category scheme="http://www.blogger.com/atom/ns#" term="mem"/><category scheme="http://www.blogger.com/atom/ns#" term="perl"/><category scheme="http://www.blogger.com/atom/ns#" term="plugin"/><title type='text'>Drizzle and the Gearman logging plug-in</title><content type='html'>&lt;div&gt;&lt;b&gt;Disclaimer:&lt;/b&gt; &lt;blockquote&gt;This blog post is about things I did on my own free time, not endorsed by my employer.&lt;/blockquote&gt;&lt;/div&gt;&lt;br /&gt;I have been meaning to look at Gearman for a long time, but I just couldn&#39;t find any project where I could use it.&lt;br /&gt;&lt;br /&gt;Well, that was true until &lt;strike&gt;last week&lt;/strike&gt; a couple of weeks ago, when I started to put together &lt;a href=&quot;http://drizzle.org/wiki/Starting_drizzled&quot;&gt;Drizzle&lt;/a&gt;, the &lt;a href=&quot;http://gearman.org/index.php&quot;&gt;Gearman&lt;/a&gt; logging plug-in, Perl and the &lt;a href=&quot;http://www.mysql.com/products/enterprise/monitor.html&quot;&gt;Enterprise Monitor&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;As I was finishing writing the agent.pl script, I thought that it would be a good idea to split the script in at least two components: one that would just collect the queries, and another component that would do the processing of the log entries (replacing the literals for &quot;?&quot;, grouping queries by query text, etc).&lt;div&gt;&lt;br /&gt;It was right there when I realized that this was my chance to look at Gearman! The first thought was to still use the regular query logging plug-in.&lt;br /&gt;But there is already a Gearman logging plugin, and I was curious about how that worked.&lt;br /&gt;&lt;br /&gt;A quick Google search returned very little information, but I did find the &lt;a href=&quot;http://drizzle.org/doxygen/d7/d55/logging__gearman_8cc-source.html&quot;&gt;doxygen docs&lt;/a&gt;, and reading the code was fairly straight forward.&lt;br /&gt;&lt;br /&gt;By reading the code, I found out that the plug-in registers the function &lt;span style=&quot;font-weight: bold;&quot;&gt;drizzlelog&lt;/span&gt; with the Gearman Job server, and that it passes the same string that the &lt;a href=&quot;http://ronaldbradford.com/blog/drizzle-query-logging-2009-07-21/&quot;&gt;query logging plug-in&lt;/a&gt; sends to the log file.&lt;br /&gt;&lt;br /&gt;Next step was to find a hello world Perl + Gearman example. And I found a sample for the &lt;a href=&quot;http://search.cpan.org/~bradfitz/Gearman-1.09/lib/Gearman/Client.pm&quot;&gt;client&lt;/a&gt; and the &lt;a href=&quot;http://search.cpan.org/~bradfitz/Gearman-1.09/lib/Gearman/Worker.pm&quot;&gt;worker&lt;/a&gt;. That almost worked out of the box, but I got this error:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;Can&#39;t call method &quot;syswrite&quot; on an undefined value at /Library/Perl/5.8.8/Gearman/Taskset.pm line 201.&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;A little google search and I found an example where the port was appended to the host. I then added the port 4730 to worker.pl and client.pl and it all worked as expected.&lt;br /&gt;&lt;br /&gt;Once I got the simple example working, I added most of the &lt;a href=&quot;http://forge.mysql.com/tools/tool.php?id=226&quot;&gt;agent.pl&lt;/a&gt; code to the &lt;a href=&quot;http://forge.mysql.com/tools/tool.php?id=227&quot;&gt;worker.pl&lt;/a&gt; script, made a few small changes, and added comments. I was done!&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;The Gearman logging plugin sends query logs to the job server, and the job server asks the worker to do the actual job.&lt;/div&gt;&lt;div&gt;In the end, the service manager ends up with all the information related to the queries that go to the Drizzle server.&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-size:130%;&quot;&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;Layout.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;For this initial version, one worker cannot handle jobs for more than one drizzle server, this is not a Gearman limitation. When I wrote this script, there was no way to tell the worker, which Drizzle server was sending the log entry.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;And that was an excellent excuse to &lt;a href=&quot;http://bazaar.launchpad.net/~diego-fmpwizard/drizzle/logging_x_plugin_additions/revision/1121#plugin/logging_gearman/logging_gearman.cc&quot;&gt;add a few more fields&lt;/a&gt; to the Gearman logging plugin. (That patch was already &lt;a href=&quot;https://code.launchpad.net/~diego-fmpwizard/drizzle/logging_x_plugin_additions/+merge/10550&quot;&gt;approved and will soon be part of the main Drizzle source&lt;/a&gt;.)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;a onblur=&quot;try {parent.deselectBloggerImageGracefully();} catch(e) {}&quot; href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgZtcK9K6NbBHd43u6shkFESBTxFUdRAjOw628vFF4YPQ-atcSgl8nUhKoJg7I7AO936dGcY0w6L4MWy-McChO6USEdr95wytNFCdOxLD1h-h4FYgZds4qSzHduNKnKT1TvLYGIibZCa8iK/s1600-h/gearman-drizzle-mem.png&quot;&gt;&lt;img style=&quot;margin: 0px auto 10px; display: block; text-align: center; cursor: pointer; width: 400px; height: 125px;&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgZtcK9K6NbBHd43u6shkFESBTxFUdRAjOw628vFF4YPQ-atcSgl8nUhKoJg7I7AO936dGcY0w6L4MWy-McChO6USEdr95wytNFCdOxLD1h-h4FYgZds4qSzHduNKnKT1TvLYGIibZCa8iK/s400/gearman-drizzle-mem.png&quot; alt=&quot;&quot; id=&quot;BLOGGER_PHOTO_ID_5372261778191908178&quot; border=&quot;0&quot; /&gt;&lt;/a&gt;&lt;br /&gt;worker-1 handles requests for drizzled-1 and worker-2 handles jobs for drizzled-2. I am already looking into ways to change this.&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-size:130%;&quot;&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;Where is the code?&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;As usual, I posted the &lt;a href=&quot;http://forge.mysql.com/tools/tool.php?id=227&quot;&gt;worker.pl&lt;/a&gt; script on the MySQL Forge.&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;font-size:130%;&quot;&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;How do I start the worker?&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;Like this:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;$ DEBUG=1 perl worker.pl  --serveruuid=&quot;22222222-5555-5555-5555-222222222211&quot;\&lt;br /&gt;--serverhostuuid=&quot;ssh:{11:11:11:11:11:11:11:11:11:11:11:11:11:11:11:21}&quot; \&lt;br /&gt;--serverdisplayname=&quot;Main-Drizzle-web2&quot;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-size:130%;&quot;&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;How do I start the client?&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;In this case, the Gearman client is the drizzle plug-in, so, all you need to do is add these lines to your drizzle.cnf&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;$ cat /etc/drizzle/drizzled.cnf&lt;br /&gt;[drizzled]&lt;br /&gt;logging_gearman_host = 127.0.0.1&lt;br /&gt;logging_gearman_enable = true&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Restart the Drizzle server and you are ready to go (well, you also need the &lt;a href=&quot;http://www.mysql.com/trials/&quot;&gt;MySQL Enterprise Monitor&lt;/a&gt;)&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:large;&quot;&gt;&lt;b&gt;Final Note.&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;I was amazed at how easy it was to have it all working, I will keep looking for other projects where I could use Gearman.&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://fmpwizard.blogspot.com/feeds/949480159174027085/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://fmpwizard.blogspot.com/2009/08/drizzle-and-gearman-logging-plug-in.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6299571792602348259/posts/default/949480159174027085'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6299571792602348259/posts/default/949480159174027085'/><link rel='alternate' type='text/html' href='http://fmpwizard.blogspot.com/2009/08/drizzle-and-gearman-logging-plug-in.html' title='Drizzle and the Gearman logging plug-in'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/16354403712237460832</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgZtcK9K6NbBHd43u6shkFESBTxFUdRAjOw628vFF4YPQ-atcSgl8nUhKoJg7I7AO936dGcY0w6L4MWy-McChO6USEdr95wytNFCdOxLD1h-h4FYgZds4qSzHduNKnKT1TvLYGIibZCa8iK/s72-c/gearman-drizzle-mem.png" height="72" width="72"/><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6299571792602348259.post-3718072697455236720</id><published>2009-08-27T22:10:00.002-04:00</published><updated>2009-08-27T22:14:33.357-04:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="drizzle"/><category scheme="http://www.blogger.com/atom/ns#" term="gearman"/><category scheme="http://www.blogger.com/atom/ns#" term="json"/><category scheme="http://www.blogger.com/atom/ns#" term="mem"/><category scheme="http://www.blogger.com/atom/ns#" term="mysql"/><category scheme="http://www.blogger.com/atom/ns#" term="perl"/><category scheme="http://www.blogger.com/atom/ns#" term="plugin"/><title type='text'>Drizzle query monitoring</title><content type='html'>&lt;div&gt;&lt;b&gt;Disclaimer:&lt;/b&gt; &lt;blockquote&gt;This blog post is about things I did on my own free time, not endorsed by my employer.&lt;/blockquote&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;A little over a month ago, &lt;a href=&quot;http://ronaldbradford.com/blog/drizzle-query-logging-2009-07-21/&quot;&gt;Ronald posted&lt;/a&gt; a blog about the different query logging plug-ins that are available for &lt;a href=&quot;http://drizzle.org/wiki/Main_Page&quot;&gt;Drizzle&lt;/a&gt;. This was pretty exciting news, especially when I saw the details that were included in the logs.&lt;br /&gt;&lt;br /&gt;Meanwhile, a few weeks ago, I started looking at the &lt;a href=&quot;http://coalface.mcslp.com/2008/11/15/feeding-query-analyzer-from-dtrace/&quot;&gt;REST API&lt;/a&gt; that comes with the&lt;a href=&quot;http://www.mysql.com/products/enterprise/monitor.html&quot;&gt; MySQL Enterprise Monitor&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;The result is that we can now see most of the information returned by the plug-in, on the Dashboard.&lt;br /&gt;&lt;br /&gt;&lt;a onblur=&quot;try {parent.deselectBloggerImageGracefully();} catch(e) {}&quot; href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi58reO_Ei9iaCLoXD4mx7yhwkdLELA6AGzR6YLK0PvpBwGhDvvErDnE_r1DsVIenFCT5oMsbjAM9ERmvmoKrGaBlpETYAp5YPskfyuumDNlwj4GiBNvTckcyoKyVoWlBtWP53xQM1KfUJJ/s1600-h/drizzle-quan.png&quot;&gt;&lt;img style=&quot;margin: 0px auto 10px; display: block; text-align: center; cursor: pointer; width: 658px; height: 202px;&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi58reO_Ei9iaCLoXD4mx7yhwkdLELA6AGzR6YLK0PvpBwGhDvvErDnE_r1DsVIenFCT5oMsbjAM9ERmvmoKrGaBlpETYAp5YPskfyuumDNlwj4GiBNvTckcyoKyVoWlBtWP53xQM1KfUJJ/s400/drizzle-quan.png&quot; alt=&quot;&quot; id=&quot;BLOGGER_PHOTO_ID_5372234713266253586&quot; border=&quot;0&quot; /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-size:130%;&quot;&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;How?&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;A &lt;a href=&quot;http://darren.oldag.net/&quot;&gt;colleague&lt;/a&gt; at work, wrote a little Perl script that interacts with the REST API, and I took his work as the foundation for my &lt;a href=&quot;http://forge.mysql.com/tools/tool.php?id=226&quot;&gt;agent.pl&lt;/a&gt; script.&lt;br /&gt;&lt;br /&gt;The next problem was to find a way to call this script as soon as there was a new entry on the log. After a little Google search, I went ahead and decided to ask my friend &lt;a href=&quot;http://www.whisperthis.com/&quot;&gt;Adriano Di Paulo&lt;/a&gt; (who among other things, introduced me to MySQL).&lt;div&gt;A few minutes later, he showed me a working example of the &lt;a href=&quot;http://search.cpan.org/~mgrabnar/File-Tail-0.99.3/Tail.pm&quot;&gt;Tail&lt;/a&gt; Perl module.&lt;div&gt;That was exactly what I needed, as soon as there is a new entry, I call the function &lt;span style=&quot;font-weight: bold;&quot;&gt;assemble_queries()&lt;/span&gt; and I pass the new log entry as the parameter.&lt;div&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;sub tail_log {&lt;br /&gt; my $file=File::Tail-&gt;new(name=&gt;$log_file, maxinterval=&gt;1, reset_tail=&gt;0);&lt;br /&gt; while( defined (my $line=$file-&gt;read ) ) {&lt;br /&gt;   print &quot;\n&quot; . $line . &quot;\n&quot; if $DEBUG &gt; 3;&lt;br /&gt;   assemble_queries( $line );&lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;The &lt;span style=&quot;font-weight: bold;&quot;&gt;assemble_queries()&lt;/span&gt; function is mostly based on what MC &lt;a href=&quot;http://coalface.mcslp.com/2008/11/15/feeding-query-analyzer-from-dtrace/&quot;&gt;blogged&lt;/a&gt; about some time ago. On his blog post, he shows how to collect query related data using Dtrace and Perl.&lt;br /&gt;&lt;br /&gt;Then, every &lt;span style=&quot;font-style: italic;&quot;&gt;n&lt;/span&gt; number of queries, I use &lt;span style=&quot;font-weight: bold;&quot;&gt;send_json_data()&lt;/span&gt; to send the query information to the Dashboard, delete the sent data and it is ready to process more queries.&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Now that I&#39;m writing this, I realized that if &lt;span style=&quot;font-weight: bold;&quot;&gt;send_json_data()&lt;/span&gt; fails, the information related to the queries are lost :|. (Note to self, fix it).&lt;br /&gt;&lt;br /&gt;There are other functions in there, but they are mostly for housekeeping.&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-size:130%;&quot;&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;How do I use it?&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;Very simple, get the &lt;a href=&quot;http://forge.mysql.com/tools/tool.php?id=226&quot;&gt;agent.pl&lt;/a&gt; script from the &lt;a href=&quot;http://forge.mysql.com/tools/tool.php?id=226&quot;&gt;MySQL Forge&lt;/a&gt; website, edit the credentials, hosts, and ports to fit your needs (Future versions would include some kind of config file).&lt;br /&gt;&lt;br /&gt;And then you call the script like this:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;$ DEBUG=1 perl agent.pl  --serveruuid=&quot;22222222-5555-5555-5555-222222222211&quot; \&lt;br /&gt;--serverhostuuid=&quot;ssh:{11:11:11:11:11:11:11:11:11:11:11:11:11:11:11:21}&quot;\&lt;br /&gt;--serverdisplayname=&quot;Main-Drizzle-web2&quot; \&lt;br /&gt;--log-file=/path/to/log/file&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;As soon as the scripts starts, it will add the drizzle server to the service manager, and once you start sending queries to drizzle, those queries will end up on the UI.&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;Next?&lt;/span&gt;&lt;br /&gt;Next is already done :). I modified the agent.pl script to use the &lt;a href=&quot;http://bazaar.launchpad.net/~drizzle-developers/drizzle/development/files/head:/plugin/logging_gearman/&quot;&gt;gearman logging plugin&lt;/a&gt;. I&#39;ll write a blog about it very soon.&lt;br /&gt;&lt;br /&gt;Thanks for reading and enjoy!&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://fmpwizard.blogspot.com/feeds/3718072697455236720/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://fmpwizard.blogspot.com/2009/08/drizzle-query-monitoring.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6299571792602348259/posts/default/3718072697455236720'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6299571792602348259/posts/default/3718072697455236720'/><link rel='alternate' type='text/html' href='http://fmpwizard.blogspot.com/2009/08/drizzle-query-monitoring.html' title='Drizzle query monitoring'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/16354403712237460832</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi58reO_Ei9iaCLoXD4mx7yhwkdLELA6AGzR6YLK0PvpBwGhDvvErDnE_r1DsVIenFCT5oMsbjAM9ERmvmoKrGaBlpETYAp5YPskfyuumDNlwj4GiBNvTckcyoKyVoWlBtWP53xQM1KfUJJ/s72-c/drizzle-quan.png" height="72" width="72"/><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6299571792602348259.post-6536099810616316040</id><published>2009-08-24T22:46:00.001-04:00</published><updated>2009-08-24T22:49:47.877-04:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="c++"/><category scheme="http://www.blogger.com/atom/ns#" term="drizzle"/><category scheme="http://www.blogger.com/atom/ns#" term="launchpad"/><category scheme="http://www.blogger.com/atom/ns#" term="mysql"/><category scheme="http://www.blogger.com/atom/ns#" term="plugin"/><title type='text'>More Drizzle plug-ins</title><content type='html'>Last weekend, I finally got some time to look around &lt;a href=&quot;https://launchpad.net/drizzle&quot;&gt;Drizzle&lt;/a&gt;. I had already compiled it on my laptop, but hadn&#39;t really looked at the &lt;a href=&quot;https://code.launchpad.net/drizzle&quot;&gt;code&lt;/a&gt;.&lt;div&gt;Then, I thought that looking over some of the &lt;a href=&quot;https://blueprints.launchpad.net/drizzle&quot;&gt;blueprints&lt;/a&gt; on Launchpad, would be a good way to get familiar with the code base.&lt;/div&gt;&lt;div&gt;After a quick search, I found &lt;a href=&quot;https://blueprints.launchpad.net/drizzle/+spec/time-functions-as-plugin&quot;&gt;move function/time/ functions into plugin(s)&lt;/a&gt;&lt;br /&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;This blueprint is basically to create UDF plug-ins for the different time related functions.&lt;/div&gt;&lt;div&gt;There was no priority assigned and it was on the &lt;i&gt;&lt;a href=&quot;https://blueprints.launchpad.net/drizzle/+milestone/low-hanging-fruit&quot;&gt;low hanging fruit&lt;/a&gt;&lt;/i&gt; milestone. Which was perfect for someone who doesn&#39;t really know how much time he could spend, and wants to get to know the code.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;The first step was to read a bit about the process to contribute to the Drizzle project, I went to the wiki &lt;a href=&quot;http://drizzle.org/wiki/Contributing_Code&quot;&gt;here&lt;/a&gt; and read about the &lt;a href=&quot;http://drizzle.org/wiki/Coding_Standards&quot;&gt;coding standards&lt;/a&gt;. &lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;I then, went ahead and saw how &lt;strike&gt;difficult&lt;/strike&gt; easy the code looked like. And proceeded to &lt;a href=&quot;https://lists.launchpad.net/drizzle-discuss/msg04888.html&quot;&gt;email the list&lt;/a&gt;, asking for feedback and also to tell others what I was up to. This is important, to avoid duplicating the work of others.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:large;&quot;&gt;Code?&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;This is where the fun began. I had a fresh branch, and it was time to pick the first function to make into an UDF plugin.&lt;/div&gt;&lt;div&gt;By luck (and you will know why luck), I picked to move &lt;a href=&quot;http://bazaar.launchpad.net/~diego-fmpwizard/drizzle/time-plugins/revision/1123#drizzled/function/time/unix_timestamp.cc&quot;&gt;unix_timestamp()&lt;/a&gt; first.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:large;&quot;&gt;The Process&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;There are already some &lt;a href=&quot;http://bazaar.launchpad.net/~drizzle-developers/drizzle/development/files/head:/plugin/&quot;&gt;great plugins&lt;/a&gt; on the Drizzle branch. I went ahead and duplicated the &lt;b&gt;md5&lt;/b&gt; plugin (in &lt;i&gt;plugin/md5&lt;/i&gt;). Renamed the folder &lt;b&gt;unix_timestamp&lt;/b&gt;, also renamed the &lt;i&gt;md5.cc&lt;/i&gt; to&lt;i&gt; unix_timestamp.cc&lt;/i&gt; and edited the &lt;i&gt;plugin.ini&lt;/i&gt; file that was on the same folder.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;The md5 plugin folder also has a &lt;i&gt;plugin.ac&lt;/i&gt; file, but it turned out I didn&#39;t need this file, so I just removed it.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;It was then time to do the actual code moving. To start, I opened &lt;i&gt;drizzled/function/time/unix_timestamp.cc&lt;/i&gt; and &lt;i&gt;drizzled/function/time/unix_timestamp.h&lt;/i&gt; &lt;/div&gt;&lt;div&gt;It was pretty much copy and paste from those two files into &lt;i&gt;plugin/unix_timestamp/unix_timestamp.cc&lt;/i&gt; &lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;And the rest was to replace md5 for unix_timestamp :)&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;Notes:&lt;/b&gt;&lt;/div&gt;&lt;div&gt;When  I first started, I had both, the built-in &lt;b&gt;unix_timestamp()&lt;/b&gt; and the plugin version. To make sure the plugin was returning the correct values, I just temporary named the plugin function &lt;b&gt;unix_timestamp2()&lt;/b&gt;. And you can do that by just changing code in two lines:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;b&gt;Error messages&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-weight: normal;&quot;&gt;Whenever there is an error with your function, the error message will call the plugin function &lt;/span&gt;func_name()&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-weight: normal;&quot;&gt;, the string you return there, will be shown on error messages. One way to force this error is by including either too many, or too few parameters.&lt;/span&gt;&lt;br /&gt;&lt;/b&gt;&lt;pre&gt;&lt;br /&gt;const char *func_name() const&lt;br /&gt;{&lt;br /&gt;return &quot;unix_timestamp2&quot;;&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;To tell Drizzle the name of your plugin function, you use this line:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;Create_function&lt;unix_timestampfunction&gt; unix_timestampudf(string(&quot;unix_timestamp2&quot;));&lt;br /&gt;&lt;/unix_timestampfunction&gt;&lt;/pre&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;unix_timestampfunction&gt;Most (all?) plugins files will start with lib + &lt;&lt;i&gt;name of the plugin&lt;/i&gt;&gt; + _plugin.la. You specify this name using this line:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;drizzle_declare_plugin(unix_timestamp)&lt;br /&gt;&lt;/pre&gt;The rest should be pretty easy to figure out. &lt;/unix_timestampfunction&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:large;&quot;&gt;Tip&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;unix_timestampfunction&gt;Which I wish I knew before. Something that took me way too long to find out, when you add a new plugin folder, you need to run  &lt;b&gt;&lt;i&gt;./config/autorun.sh&lt;/i&gt;&lt;/b&gt;  and ./configure ... &amp;amp;&amp;amp; make &amp;amp;&amp;amp; make install. This would make sure your new plugin gets compiled., if you skip autorun.sh, your new plugin will not be compiled.&lt;/unix_timestampfunction&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot; ;font-size:large;&quot;&gt;Final steps&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;Once I compiled the new plugin, and verified that it all worked well. It was time to delete the built-in function.&lt;/div&gt;&lt;div&gt;1) Went to &lt;i&gt;drizzled/Makefile.am&lt;/i&gt; and removed &lt;i&gt;&lt;b&gt;function/time/unix_timestamp.h&lt;/b&gt;&lt;/i&gt; from there.&lt;/div&gt;&lt;div&gt;2) Removed the files &lt;i&gt;d&lt;b&gt;rizzled/function/time/unix_timestamp.cc&lt;/b&gt;&lt;/i&gt; and &lt;i&gt;&lt;b&gt;drizzled/function/time/unix_timestamp.h&lt;/b&gt;&lt;/i&gt; &lt;/div&gt;&lt;div&gt;3) Edited &lt;i&gt;drizzled/item/create.cc&lt;/i&gt; and removed &lt;i&gt;&lt;b&gt;#include &lt;drizzled/function/time/unix_timestamp.h&gt;&lt;/drizzled/function/time/unix_timestamp.h&gt;&lt;/b&gt;&lt;/i&gt; and some other references to the unix_timestamp function.&lt;/div&gt;&lt;div&gt;4) &lt;i&gt;drizzled/sql_parse.cc&lt;/i&gt; also had to be edited, to remove &lt;b&gt;&lt;i&gt;#include &lt;drizzled/function/time/unix_timestamp.h&gt;&lt;/drizzled/function/time/unix_timestamp.h&gt;&lt;/i&gt;&lt;/b&gt;.&lt;/div&gt;&lt;div&gt;5) Added the new plugin/unix_timestamp/ folder and files to the bzr branch.&lt;/div&gt;&lt;div&gt;6) Run tests (and here I found a &lt;a href=&quot;https://lists.launchpad.net/drizzle-discuss/msg04894.html&quot;&gt;new problem&lt;/a&gt;)&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;I&#39;m still working on a fix for it. I&#39;m going with using one error message, for built-in functions, as well as plugins. I hope to be pushing those changes soon.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Oh, why was I lucky to pick the unix_timestamp() function as the first one to tackle, well, I have been working on timestamp_diff for many hours, and it just does not want to work. It somehow does not see the first parameter. I&#39;m pretty sure I&#39;ll be asking the Drizzle-discuss for help :)&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:large;&quot;&gt;The end.&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;select * from information_schema.plugins where plugin_name like &#39;%time%&#39;;&lt;br /&gt;+-------------------------+----------------+---------------+---------------+--------------------------------+----------------+&lt;br /&gt;| PLUGIN_NAME             | PLUGIN_VERSION | PLUGIN_STATUS | PLUGIN_AUTHOR | PLUGIN_DESCRIPTION             | PLUGIN_LICENSE |&lt;br /&gt;+-------------------------+----------------+---------------+---------------+--------------------------------+----------------+&lt;br /&gt;| unix_timestamp_function | 1.0            | ACTIVE        | Diego Medina  | UDF for getting unix_timestamp | GPL            |&lt;br /&gt;+-------------------------+----------------+---------------+---------------+--------------------------------+----------------+&lt;br /&gt;1 row in set (0 sec)&lt;br /&gt;&lt;br /&gt;drizzle&gt;&lt;br /&gt;&lt;/pre&gt;Well, not really the end, I still have plenty of functions to move into plugins.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Thanks!&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://fmpwizard.blogspot.com/feeds/6536099810616316040/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://fmpwizard.blogspot.com/2009/08/more-drizzle-plug-ins.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6299571792602348259/posts/default/6536099810616316040'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6299571792602348259/posts/default/6536099810616316040'/><link rel='alternate' type='text/html' href='http://fmpwizard.blogspot.com/2009/08/more-drizzle-plug-ins.html' title='More Drizzle plug-ins'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/16354403712237460832</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry></feed>