Merge lp:~capttofu/drizzle/memcached-udf-current into lp:~drizzle-trunk/drizzle/development

Proposed by CaptTofu
Status: Superseded
Proposed branch: lp:~capttofu/drizzle/memcached-udf-current
Merge into: lp:~drizzle-trunk/drizzle/development
Diff against target: None lines
To merge this branch: bzr merge lp:~capttofu/drizzle/memcached-udf-current
Reviewer Review Type Date Requested Status
Padraig O'Sullivan (community) Needs Fixing
Monty Taylor Needs Fixing
Stewart Smith (community) Approve
Drizzle Developers Pending
Review via email: mp+8697@code.launchpad.net

This proposal has been superseded by a proposal from 2009-08-14.

To post a comment you must log in.
Revision history for this message
CaptTofu (capttofu) wrote :

I propose a merge please - this merge will give all basic memcached UDFs for get/set operations as well as client behavior. This work includes Padraig's and my latest.

1100. By patg <patg@hanuman>

- Added simple test
- Added docs

Revision history for this message
Jay Pipes (jaypipes) wrote :

  Review: Resubmit

Hi! As discussed on IRC, we'll need a test suite for this plugin...just
marking this on the review.

1101. By patg <patg@hanuman>

-- Merged from Padraig's repo
-- Added Increment and Decrement, and added tests

1102. By patg <patg@hanuman>

* Changed return types for set to true and false, and for get a value or NULL
* Added time value for set

1103. By Patrick <email address hidden>

Many functions implemented, pushing

1104. By Patrick <email address hidden>

Merge

1105. By Padraig O'Sullivan

Updating shell script for memcached UDF test suite.

1106. By Padraig O'Sullivan

Minor modifications needed in order for Patrick's new UDF's to compile.

1107. By Padraig O'Sullivan

Updating the memcached UDF test suite.

1108. By Padraig O'Sullivan

Merge from trunk.

1109. By Patrick Galbraith <email address hidden>

More fixes - OS X is even more persnikity

1110. By Patrick Galbraith <email address hidden>

- Fixes to replace*
- New test and results

1111. By Patrick Galbraith <email address hidden>

* fixed issue of behavior hash result checking
* updated test

Revision history for this message
CaptTofu (capttofu) wrote :

> Review: Resubmit
>
> Hi! As discussed on IRC, we'll need a test suite for this plugin...just
> marking this on the review.

Hi!

I added tests, more UDFs, and tests pass!

So, may this branch please be merged?

Regards,

Patrick

Revision history for this message
Monty Taylor (mordred) wrote :

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

CaptTofu wrote:
>> Review: Resubmit
>>
>> Hi! As discussed on IRC, we'll need a test suite for this plugin...just
>> marking this on the review.
>
> Hi!
>
> I added tests, more UDFs, and tests pass!
>
> So, may this branch please be merged?

Yes... except I'm going to make you wait just a little while longer...
as soon as my most recent changes to plugin stuff hit trunk (should be
today), I want to get you to merge up, and then you can add a new
magical line to your plugin.ini ... testsuite=whatever ... which will
cause the standard make test to run your plugin's test suite as long as
we built the plugin.

woot.

Then I'll merge you. Promise.

Monty
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkpwmpQACgkQ2Jv7/VK1RgHJBQCeJrvsW25ONOkVTKiKJ7MnFp1+
czwAn3oBxlpo6TYMGhH/FrT87xWiV9G2
=ugE6
-----END PGP SIGNATURE-----

Revision history for this message
Stewart Smith (stewart) :
review: Approve
Revision history for this message
Monty Taylor (mordred) wrote :

Hullo.

"%llu" should not be used. That needs be changed to "%"PRIu64 to match your uint64_t variable.

The test suite did not work for me. I started a memcached, no dice. So I started using port 19191 like the script in tests/suite/memcached_udf indicated. Still no luck. (BTW, /etc/sysconfig is redhat specific)

The tests in gearman start and stop memcached as needed ... but I think at some point we should figure that out systemically.

review: Needs Fixing
Revision history for this message
Padraig O'Sullivan (posulliv) wrote :

So for the test suite, I checked it out and the issue is that the result file seems to not have been updated after some UDF's return types were changed? When I run the test suite, I see there are a few diff's (this is just a sampling, there are more diff's):

 memc_delete('mysql:doc1')
-0
+1
 select memc_get('mysql:doc1');
 memc_get('mysql:doc1')
 NULL
 select memc_set('spot:test', ' Spot ');
 memc_set('spot:test', ' Spot ')
-0
+1
 select memc_get('spot:test');
 memc_get('spot:test')
-NULL
+ Spot
 select memc_prepend('spot:test', 'See');
 memc_prepend('spot:test', 'See')
-0
+1
 select memc_get('spot:test');
 memc_get('spot:test')
-NULL
+See Spot

It looks like the result file was recorded on a test run when all these UDF's failed! To record the result file, do the following:

$ ./dtr --record --suite=memcached_udf memc

Since I wrote the test suite, I should comment on some issues I see with the test suite:

 * it requires memcached to be in your path before running
 * it always starts memcached on the same port so if memcached is already running on this port, bad things will happen
 * the test cases are hard-coded to use a memcached instance on this port

I guess the major question I have here is how to have a test case with the ability to take an input parameter that can affect the result output (in this case, the port number to start memcached on)? I'm assuming its not possible right now unless we pass the parameter as an environment variable but I don't know how to access an environment variable from a test case?

Also, Monty's comment on not using %llu also needs to be implemented. Not sure how this branch compiled cleanly with that in there? I had to modify that to compile the branch and run the test suite.

-Padraig

review: Needs Fixing
1112. By Patrick Galbraith <email address hidden>

* Fixed distribution type check to use iterator to check if a distribution is truly defined
* Fixed hash type check to use iterator check
* Re-recorded the test results

Revision history for this message
CaptTofu (capttofu) wrote :

Hi Padraig,

My bad - I was so focused on checking the results for the behavior issue
I didn't double check this! It appears the memcached server didn't start
in this instance when I recorded it.

I've pushed a new version into
lp:~capttofu/drizzle/memcached-udf-current. I also fixed the same issue
that I fixed for behavior types for hash and distribution types. I still
have some issues with some of the behavior settings though that I need
to ask Trond or Brian about (or someone else) as to why when I set some
of the behavior settings, they end up being set to zero. It might be
that the setting I'm trying to assign it is out of bounds and the value
then defaults to zero.

Thanks much!

Other things I need to look at (by tomorrow or tuesday will have done so
this branch can be marged) are the changes that Monty Taylor told me
about that are currently in command_log, pertaining to the loading of
the plugin.

--Patrick

Padraig O'Sullivan wrote:
> Review: Needs Fixing
> So for the test suite, I checked it out and the issue is that the result file seems to not have been updated after some UDF's return types were changed? When I run the test suite, I see there are a few diff's (this is just a sampling, there are more diff's):
>
> memc_delete('mysql:doc1')
> -0
> +1
> select memc_get('mysql:doc1');
> memc_get('mysql:doc1')
> NULL
> select memc_set('spot:test', ' Spot ');
> memc_set('spot:test', ' Spot ')
> -0
> +1
> select memc_get('spot:test');
> memc_get('spot:test')
> -NULL
> + Spot
> select memc_prepend('spot:test', 'See');
> memc_prepend('spot:test', 'See')
> -0
> +1
> select memc_get('spot:test');
> memc_get('spot:test')
> -NULL
> +See Spot
>
> It looks like the result file was recorded on a test run when all these UDF's failed! To record the result file, do the following:
>
> $ ./dtr --record --suite=memcached_udf memc
>
> Since I wrote the test suite, I should comment on some issues I see with the test suite:
>
> * it requires memcached to be in your path before running
> * it always starts memcached on the same port so if memcached is already running on this port, bad things will happen
> * the test cases are hard-coded to use a memcached instance on this port
>
> I guess the major question I have here is how to have a test case with the ability to take an input parameter that can affect the result output (in this case, the port number to start memcached on)? I'm assuming its not possible right now unless we pass the parameter as an environment variable but I don't know how to access an environment variable from a test case?
>
> Also, Monty's comment on not using %llu also needs to be implemented. Not sure how this branch compiled cleanly with that in there? I had to modify that to compile the branch and run the test suite.
>
> -Padraig
>

1113. By Patrick Galbraith <email address hidden>

Merged in Padraig's changes - thanks Padraig!

* He removed the Redhat-specific code in the memcached startup script
* Removed tests that need looking into further and could be system-specific, causing failures
* Added the test suite to plugin.ini

1114. By Patrick Galbraith <email address hidden>

Memcached UDFs working with plugin slot re-org. Also merged with latest.

Ok, Monty, so, you won't change anything for a little while? :) Joking. Sort of.

1115. By Patrick Galbraith <email address hidden>

* Changed true/false functions to return actual int values vs. strings
* Code cleanup

1116. By Patrick Galbraith <email address hidden>

modified all set-type memcached UDFs to return 0 for failure.

1117. By Patrick Galbraith <email address hidden>

A couple more review fixes

1118. By Patrick Galbraith <email address hidden>

Changed License to BSD

1119. By Patrick Galbraith <email address hidden>

Changes per review by Padraig O'Sullivan

1120. By Patrick Galbraith <email address hidden>

* Merge with latest trunk
* Changes per Posulliv

Unmerged revisions

1120. By Patrick Galbraith <email address hidden>

* Merge with latest trunk
* Changes per Posulliv

1119. By Patrick Galbraith <email address hidden>

Changes per review by Padraig O'Sullivan

1118. By Patrick Galbraith <email address hidden>

Changed License to BSD

1117. By Patrick Galbraith <email address hidden>

A couple more review fixes

1116. By Patrick Galbraith <email address hidden>

modified all set-type memcached UDFs to return 0 for failure.

1115. By Patrick Galbraith <email address hidden>

* Changed true/false functions to return actual int values vs. strings
* Code cleanup

1114. By Patrick Galbraith <email address hidden>

Memcached UDFs working with plugin slot re-org. Also merged with latest.

Ok, Monty, so, you won't change anything for a little while? :) Joking. Sort of.

1113. By Patrick Galbraith <email address hidden>

Merged in Padraig's changes - thanks Padraig!

* He removed the Redhat-specific code in the memcached startup script
* Removed tests that need looking into further and could be system-specific, causing failures
* Added the test suite to plugin.ini

1112. By Patrick Galbraith <email address hidden>

* Fixed distribution type check to use iterator to check if a distribution is truly defined
* Fixed hash type check to use iterator check
* Re-recorded the test results

1111. By Patrick Galbraith <email address hidden>

* fixed issue of behavior hash result checking
* updated test

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added directory 'plugin/memcached_udf'
2=== added file 'plugin/memcached_udf/memc_append.cc'
3--- plugin/memcached_udf/memc_append.cc 1970-01-01 00:00:00 +0000
4+++ plugin/memcached_udf/memc_append.cc 2009-07-12 04:13:35 +0000
5@@ -0,0 +1,57 @@
6+/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
7+ * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
8+ *
9+ * Copyright (C) 2009 Sun Microsystems
10+ *
11+ * This program is free software; you can redistribute it and/or modify
12+ * it under the terms of the GNU General Public License as published by
13+ * the Free Software Foundation; either version 2 of the License, or
14+ * (at your option) any later version.
15+ *
16+ * This program is distributed in the hope that it will be useful,
17+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
18+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19+ * GNU General Public License for more details.
20+ *
21+ * You should have received a copy of the GNU General Public License
22+ * along with this program; if not, write to the Free Software
23+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24+ */
25+
26+#include <drizzled/server_includes.h>
27+#include <drizzled/sql_udf.h>
28+#include <drizzled/function/str/strfunc.h>
29+
30+#include "memcached_udf.h"
31+#include "memc_append.h"
32+
33+#include <libmemcached/memcached.h>
34+
35+#include <string>
36+
37+using namespace std;
38+
39+String *MemcachedAppend::val_str(String *str)
40+{
41+ memcached_return rc;
42+ String *key;
43+ String *value;
44+
45+ if (arg_count != 2 ||
46+ ! (key= args[0]->val_str(str)) ||
47+ ! (value= args[1]->val_str(str)) ||
48+ ! memc)
49+ {
50+ return &failure_buff;
51+ }
52+
53+ rc= memcached_append(memc, key->c_ptr(), key->length(),
54+ value->c_ptr(), value->length(), 0, 0);
55+ if (rc != MEMCACHED_SUCCESS)
56+ {
57+ return &failure_buff;
58+ }
59+
60+ return &success_buff;
61+}
62+
63
64=== added file 'plugin/memcached_udf/memc_append.h'
65--- plugin/memcached_udf/memc_append.h 1970-01-01 00:00:00 +0000
66+++ plugin/memcached_udf/memc_append.h 2009-07-12 04:13:35 +0000
67@@ -0,0 +1,56 @@
68+/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
69+ * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
70+ *
71+ * Copyright (C) 2009 Sun Microsystems
72+ *
73+ * This program is free software; you can redistribute it and/or modify
74+ * it under the terms of the GNU General Public License as published by
75+ * the Free Software Foundation; either version 2 of the License, or
76+ * (at your option) any later version.
77+ *
78+ * This program is distributed in the hope that it will be useful,
79+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
80+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
81+ * GNU General Public License for more details.
82+ *
83+ * You should have received a copy of the GNU General Public License
84+ * along with this program; if not, write to the Free Software
85+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
86+ */
87+
88+#ifndef MEMC_APPEND_H
89+#define MEMC_APPEND_H
90+
91+#include <drizzled/server_includes.h>
92+#include <drizzled/sql_udf.h>
93+#include <drizzled/function/str/strfunc.h>
94+
95+/* implements memc_append */
96+class MemcachedAppend : public Item_str_func
97+{
98+public:
99+ MemcachedAppend()
100+ :
101+ Item_str_func(),
102+ failure_buff("FAILURE", &my_charset_bin),
103+ success_buff("SUCCESS", &my_charset_bin)
104+ {}
105+
106+ const char *func_name() const
107+ {
108+ return "memc_append";
109+ }
110+
111+ String *val_str(String *);
112+
113+ void fix_length_and_dec()
114+ {
115+ max_length= 32;
116+ }
117+
118+private:
119+ String failure_buff;
120+ String success_buff;
121+};
122+
123+#endif /* MEMC_APPEND_H */
124
125=== added file 'plugin/memcached_udf/memc_behavior_get.cc'
126--- plugin/memcached_udf/memc_behavior_get.cc 1970-01-01 00:00:00 +0000
127+++ plugin/memcached_udf/memc_behavior_get.cc 2009-07-13 14:55:27 +0000
128@@ -0,0 +1,140 @@
129+/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
130+ * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
131+ *
132+ * Copyright (C) 2009 Sun Microsystems
133+ *
134+ * This program is free software; you can redistribute it and/or modify
135+ * it under the terms of the GNU General Public License as published by
136+ * the Free Software Foundation; either version 2 of the License, or
137+ * (at your option) any later version.
138+ *
139+ * This program is distributed in the hope that it will be useful,
140+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
141+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
142+ * GNU General Public License for more details.
143+ *
144+ * You should have received a copy of the GNU General Public License
145+ * along with this program; if not, write to the Free Software
146+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
147+ */
148+
149+#include <drizzled/server_includes.h>
150+#include <drizzled/sql_udf.h>
151+#include <drizzled/item/func.h>
152+#include <drizzled/function/str/strfunc.h>
153+
154+#include "memcached_udf.h"
155+#include "memc_behavior_get.h"
156+
157+#include <libmemcached/memcached.h>
158+
159+#include <string>
160+#include <algorithm>
161+
162+using namespace std;
163+
164+void MemcachedBehaviorGet::setFailureString(const char *error)
165+{
166+ size_t size= strlen(error);
167+ failure_buff.realloc(size);
168+ failure_buff.length(size);
169+ memcpy(failure_buff.ptr(), error, size);
170+}
171+
172+String *MemcachedBehaviorGet::val_str(String *str)
173+{
174+ memcached_behavior mbehavior;
175+ uint64_t isetting;
176+ String *tmp_behavior;
177+
178+ if (arg_count != 1 ||
179+ ! (tmp_behavior= args[0]->val_str(str)) ||
180+ ! memc)
181+ {
182+ setFailureString("USAGE: memc_behavior_get('<behavior type>')");
183+ return &failure_buff;
184+ }
185+
186+ string behavior(tmp_behavior->c_ptr());
187+
188+ /*
189+ * We don't want the user to have to type in all input in upper
190+ * case so we transform the input strings to upper case here.
191+ */
192+ std::transform(behavior.begin(), behavior.end(),
193+ behavior.begin(), ::toupper);
194+
195+
196+ mbehavior= behavior_map[behavior];
197+
198+ if (! mbehavior)
199+ {
200+ setFailureString("UNKNOWN BEHAVIOR TYPE!");
201+ return &failure_buff;
202+ }
203+
204+ isetting= memcached_behavior_get(memc, mbehavior);
205+
206+ switch (mbehavior)
207+ {
208+ case MEMCACHED_BEHAVIOR_SUPPORT_CAS:
209+ case MEMCACHED_BEHAVIOR_NO_BLOCK:
210+ case MEMCACHED_BEHAVIOR_BUFFER_REQUESTS:
211+ case MEMCACHED_BEHAVIOR_USER_DATA:
212+ case MEMCACHED_BEHAVIOR_SORT_HOSTS:
213+ case MEMCACHED_BEHAVIOR_VERIFY_KEY:
214+ case MEMCACHED_BEHAVIOR_TCP_NODELAY:
215+ case MEMCACHED_BEHAVIOR_KETAMA:
216+ case MEMCACHED_BEHAVIOR_CACHE_LOOKUPS:
217+ if (isetting == 1)
218+ return_buff.append("1");
219+ else if (isetting == 0)
220+ return_buff.append("0");
221+ else
222+ {
223+ setFailureString("INVALID VALUE FOR BEHAVIOR - MUST be 1 OR 0!");
224+ return &failure_buff;
225+ }
226+ break;
227+ case MEMCACHED_BEHAVIOR_DISTRIBUTION:
228+ {
229+ string setting(dist_settings_reverse_map[isetting]);
230+ return_buff.append(setting.c_str());
231+ }
232+ break;
233+ case MEMCACHED_BEHAVIOR_HASH:
234+ {
235+ string setting(hash_settings_reverse_map[isetting]);
236+ return_buff.append(setting.c_str());
237+ }
238+ break;
239+ case MEMCACHED_BEHAVIOR_KETAMA_HASH:
240+ {
241+ string setting(ketama_hash_settings_reverse_map[isetting]);
242+ return_buff.append(setting.c_str());
243+ }
244+ break;
245+ case MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE:
246+ case MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE:
247+ case MEMCACHED_BEHAVIOR_POLL_TIMEOUT:
248+ case MEMCACHED_BEHAVIOR_CONNECT_TIMEOUT:
249+ case MEMCACHED_BEHAVIOR_RETRY_TIMEOUT:
250+ case MEMCACHED_BEHAVIOR_IO_MSG_WATERMARK:
251+ case MEMCACHED_BEHAVIOR_IO_BYTES_WATERMARK:
252+ {
253+ size_t setting_len= 0;
254+ char tmp_buff[10];
255+
256+ sprintf(tmp_buff, "%lu", isetting);
257+ setting_len= strlen(tmp_buff);
258+ return_buff.realloc(setting_len);
259+ return_buff.length(setting_len);
260+ memcpy(return_buff.ptr(),tmp_buff, setting_len);
261+ }
262+ break;
263+ default:
264+ break;
265+ }
266+
267+ return &return_buff;
268+}
269
270=== added file 'plugin/memcached_udf/memc_behavior_get.h'
271--- plugin/memcached_udf/memc_behavior_get.h 1970-01-01 00:00:00 +0000
272+++ plugin/memcached_udf/memc_behavior_get.h 2009-07-13 14:02:39 +0000
273@@ -0,0 +1,215 @@
274+/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
275+ * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
276+ *
277+ * Copyright (C) 2009 Sun Microsystems
278+ *
279+ * This program is free software; you can redistribute it and/or modify
280+ * it under the terms of the GNU General Public License as published by
281+ * the Free Software Foundation; either version 2 of the License, or
282+ * (at your option) any later version.
283+ *
284+ * This program is distributed in the hope that it will be useful,
285+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
286+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
287+ * GNU General Public License for more details.
288+ *
289+ * You should have received a copy of the GNU General Public License
290+ * along with this program; if not, write to the Free Software
291+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
292+ */
293+
294+#ifndef MEMC_BEHAVIOR_GET_H
295+#define MEMC_BEHAVIOR_GET_H
296+
297+#include <drizzled/server_includes.h>
298+#include <drizzled/sql_udf.h>
299+#include <drizzled/item/func.h>
300+
301+#include <libmemcached/memcached.h>
302+
303+#include <map>
304+#include <string>
305+
306+/* implements memc_behavior_get */
307+class MemcachedBehaviorGet : public Item_str_func
308+{
309+public:
310+ MemcachedBehaviorGet()
311+ :
312+ Item_str_func(),
313+ failure_buff("FAILURE", &my_charset_bin),
314+ return_buff("", &my_charset_bin),
315+ behavior_map(),
316+ behavior_reverse_map(),
317+ dist_settings_reverse_map(),
318+ hash_settings_reverse_map(),
319+ ketama_hash_settings_reverse_map()
320+ {
321+ behavior_map.insert(std::pair<const std::string, memcached_behavior>
322+ ("MEMCACHED_BEHAVIOR_SUPPORT_CAS", MEMCACHED_BEHAVIOR_SUPPORT_CAS));
323+ behavior_map.insert(std::pair<const std::string, memcached_behavior>
324+ ("MEMCACHED_BEHAVIOR_NO_BLOCK", MEMCACHED_BEHAVIOR_NO_BLOCK));
325+ behavior_map.insert(std::pair<const std::string, memcached_behavior>
326+ ("MEMCACHED_BEHAVIOR_TCP_NODELAY", MEMCACHED_BEHAVIOR_TCP_NODELAY));
327+ behavior_map.insert(std::pair<const std::string, memcached_behavior>
328+ ("MEMCACHED_BEHAVIOR_HASH", MEMCACHED_BEHAVIOR_HASH));
329+ behavior_map.insert(std::pair<const std::string, memcached_behavior>
330+ ("MEMCACHED_BEHAVIOR_CACHE_LOOKUPS", MEMCACHED_BEHAVIOR_CACHE_LOOKUPS));
331+ behavior_map.insert(std::pair<const std::string, memcached_behavior>
332+ ("MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE", MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE));
333+ behavior_map.insert(std::pair<const std::string, memcached_behavior>
334+ ("MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE", MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE));
335+ behavior_map.insert(std::pair<const std::string, memcached_behavior>
336+ ("MEMCACHED_BEHAVIOR_BUFFER_REQUESTS", MEMCACHED_BEHAVIOR_BUFFER_REQUESTS));
337+ behavior_map.insert(std::pair<const std::string, memcached_behavior>
338+ ("MEMCACHED_BEHAVIOR_KETAMA", MEMCACHED_BEHAVIOR_KETAMA));
339+ behavior_map.insert(std::pair<const std::string, memcached_behavior>
340+ ("MEMCACHED_BEHAVIOR_POLL_TIMEOUT", MEMCACHED_BEHAVIOR_POLL_TIMEOUT));
341+ behavior_map.insert(std::pair<const std::string, memcached_behavior>
342+ ("MEMCACHED_BEHAVIOR_RETRY_TIMEOUT", MEMCACHED_BEHAVIOR_RETRY_TIMEOUT));
343+ behavior_map.insert(std::pair<const std::string, memcached_behavior>
344+ ("MEMCACHED_BEHAVIOR_DISTRIBUTION", MEMCACHED_BEHAVIOR_DISTRIBUTION));
345+ behavior_map.insert(std::pair<const std::string, memcached_behavior>
346+ ("MEMCACHED_BEHAVIOR_USER_DATA", MEMCACHED_BEHAVIOR_USER_DATA));
347+ behavior_map.insert(std::pair<const std::string, memcached_behavior>
348+ ("MEMCACHED_BEHAVIOR_SORT_HOSTS", MEMCACHED_BEHAVIOR_SORT_HOSTS));
349+ behavior_map.insert(std::pair<const std::string, memcached_behavior>
350+ ("MEMCACHED_BEHAVIOR_VERIFY_KEY", MEMCACHED_BEHAVIOR_VERIFY_KEY));
351+ behavior_map.insert(std::pair<const std::string, memcached_behavior>
352+ ("MEMCACHED_BEHAVIOR_CONNECT_TIMEOUT", MEMCACHED_BEHAVIOR_CONNECT_TIMEOUT));
353+ behavior_map.insert(std::pair<const std::string, memcached_behavior>
354+ ("MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED", MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED));
355+ behavior_map.insert(std::pair<const std::string, memcached_behavior>
356+ ("MEMCACHED_BEHAVIOR_KETAMA_HASH", MEMCACHED_BEHAVIOR_KETAMA_HASH));
357+ behavior_map.insert(std::pair<const std::string, memcached_behavior>
358+ ("MEMCACHED_BEHAVIOR_BINARY_PROTOCOL", MEMCACHED_BEHAVIOR_BINARY_PROTOCOL));
359+ behavior_map.insert(std::pair<const std::string, memcached_behavior>
360+ ("MEMCACHED_BEHAVIOR_SND_TIMEOUT", MEMCACHED_BEHAVIOR_SND_TIMEOUT));
361+ behavior_map.insert(std::pair<const std::string, memcached_behavior>
362+ ("MEMCACHED_BEHAVIOR_RCV_TIMEOUT", MEMCACHED_BEHAVIOR_RCV_TIMEOUT));
363+ behavior_map.insert(std::pair<const std::string, memcached_behavior>
364+ ("MEMCACHED_BEHAVIOR_SERVER_FAILURE_LIMIT", MEMCACHED_BEHAVIOR_SERVER_FAILURE_LIMIT));
365+ behavior_map.insert(std::pair<const std::string, memcached_behavior>
366+ ("MEMCACHED_BEHAVIOR_IO_MSG_WATERMARK", MEMCACHED_BEHAVIOR_IO_MSG_WATERMARK));
367+ behavior_map.insert(std::pair<const std::string, memcached_behavior>
368+ ("MEMCACHED_BEHAVIOR_IO_BYTES_WATERMARK", MEMCACHED_BEHAVIOR_IO_BYTES_WATERMARK));
369+
370+ behavior_reverse_map.insert(std::pair<memcached_behavior, const std::string>
371+ (MEMCACHED_BEHAVIOR_SUPPORT_CAS, "MEMCACHED_BEHAVIOR_SUPPORT_CAS"));
372+ behavior_reverse_map.insert(std::pair<memcached_behavior,const std::string>
373+ (MEMCACHED_BEHAVIOR_NO_BLOCK, "MEMCACHED_BEHAVIOR_NO_BLOCK"));
374+ behavior_reverse_map.insert(std::pair<memcached_behavior,const std::string>
375+ (MEMCACHED_BEHAVIOR_TCP_NODELAY, "MEMCACHED_BEHAVIOR_TCP_NODELAY"));
376+ behavior_reverse_map.insert(std::pair<memcached_behavior,const std::string>
377+ (MEMCACHED_BEHAVIOR_HASH, "MEMCACHED_BEHAVIOR_HASH"));
378+ behavior_reverse_map.insert(std::pair<memcached_behavior,const std::string>
379+ (MEMCACHED_BEHAVIOR_CACHE_LOOKUPS, "MEMCACHED_BEHAVIOR_CACHE_LOOKUPS"));
380+ behavior_reverse_map.insert(std::pair<memcached_behavior,const std::string>
381+ (MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE, "MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE"));
382+ behavior_reverse_map.insert(std::pair<memcached_behavior,const std::string>
383+ (MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE, "MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE"));
384+ behavior_reverse_map.insert(std::pair<memcached_behavior,const std::string>
385+ (MEMCACHED_BEHAVIOR_BUFFER_REQUESTS, "MEMCACHED_BEHAVIOR_BUFFER_REQUESTS"));
386+ behavior_reverse_map.insert(std::pair<memcached_behavior,const std::string>
387+ (MEMCACHED_BEHAVIOR_KETAMA, "MEMCACHED_BEHAVIOR_KETAMA"));
388+ behavior_reverse_map.insert(std::pair<memcached_behavior,const std::string>
389+ (MEMCACHED_BEHAVIOR_POLL_TIMEOUT, "MEMCACHED_BEHAVIOR_POLL_TIMEOUT"));
390+ behavior_reverse_map.insert(std::pair<memcached_behavior,const std::string>
391+ (MEMCACHED_BEHAVIOR_RETRY_TIMEOUT, "MEMCACHED_BEHAVIOR_RETRY_TIMEOUT"));
392+ behavior_reverse_map.insert(std::pair<memcached_behavior,const std::string>
393+ (MEMCACHED_BEHAVIOR_DISTRIBUTION, "MEMCACHED_BEHAVIOR_DISTRIBUTION"));
394+ behavior_reverse_map.insert(std::pair<memcached_behavior,const std::string>
395+ (MEMCACHED_BEHAVIOR_USER_DATA, "MEMCACHED_BEHAVIOR_USER_DATA"));
396+ behavior_reverse_map.insert(std::pair<memcached_behavior,const std::string>
397+ (MEMCACHED_BEHAVIOR_SORT_HOSTS, "MEMCACHED_BEHAVIOR_SORT_HOSTS"));
398+ behavior_reverse_map.insert(std::pair<memcached_behavior,const std::string>
399+ (MEMCACHED_BEHAVIOR_VERIFY_KEY, "MEMCACHED_BEHAVIOR_VERIFY_KEY"));
400+ behavior_reverse_map.insert(std::pair<memcached_behavior,const std::string>
401+ (MEMCACHED_BEHAVIOR_CONNECT_TIMEOUT, "MEMCACHED_BEHAVIOR_CONNECT_TIMEOUT"));
402+ behavior_reverse_map.insert(std::pair<memcached_behavior,const std::string>
403+ (MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED, "MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED"));
404+ behavior_reverse_map.insert(std::pair<memcached_behavior,const std::string>
405+ (MEMCACHED_BEHAVIOR_KETAMA_HASH, "MEMCACHED_BEHAVIOR_KETAMA_HASH"));
406+ behavior_reverse_map.insert(std::pair<memcached_behavior,const std::string>
407+ (MEMCACHED_BEHAVIOR_BINARY_PROTOCOL, "MEMCACHED_BEHAVIOR_BINARY_PROTOCOL"));
408+ behavior_reverse_map.insert(std::pair<memcached_behavior,const std::string>
409+ (MEMCACHED_BEHAVIOR_SND_TIMEOUT, "MEMCACHED_BEHAVIOR_SND_TIMEOUT"));
410+ behavior_reverse_map.insert(std::pair<memcached_behavior,const std::string>
411+ (MEMCACHED_BEHAVIOR_RCV_TIMEOUT, "MEMCACHED_BEHAVIOR_RCV_TIMEOUT"));
412+ behavior_reverse_map.insert(std::pair<memcached_behavior,const std::string>
413+ (MEMCACHED_BEHAVIOR_SERVER_FAILURE_LIMIT, "MEMCACHED_BEHAVIOR_SERVER_FAILURE_LIMIT"));
414+ behavior_reverse_map.insert(std::pair<memcached_behavior,const std::string>
415+ (MEMCACHED_BEHAVIOR_IO_MSG_WATERMARK, "MEMCACHED_BEHAVIOR_IO_MSG_WATERMARK"));
416+ behavior_reverse_map.insert(std::pair<memcached_behavior,const std::string>
417+ (MEMCACHED_BEHAVIOR_IO_BYTES_WATERMARK, "MEMCACHED_BEHAVIOR_IO_BYTES_WATERMARK"));
418+
419+ dist_settings_reverse_map.insert(std::pair<uint64_t, const std::string>
420+ (MEMCACHED_DISTRIBUTION_MODULA, "MEMCACHED_DISTRIBUTION_MODULA"));
421+ dist_settings_reverse_map.insert(std::pair<uint64_t, const std::string>
422+ (MEMCACHED_DISTRIBUTION_CONSISTENT, "MEMCACHED_DISTRIBUTION_CONSISTENT"));
423+ dist_settings_reverse_map.insert(std::pair<uint64_t, const std::string>
424+ (MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA, "MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA"));
425+
426+ hash_settings_reverse_map.insert(std::pair<uint64_t, const std::string>
427+ (MEMCACHED_HASH_DEFAULT, "MEMCACHED_HASH_DEFAULT"));
428+ hash_settings_reverse_map.insert(std::pair<uint64_t, const std::string>
429+ (MEMCACHED_HASH_MD5, "MEMCACHED_HASH_MD5"));
430+ hash_settings_reverse_map.insert(std::pair<uint64_t, const std::string>
431+ (MEMCACHED_HASH_CRC, "MEMCACHED_HASH_CRC"));
432+ hash_settings_reverse_map.insert(std::pair<uint64_t, const std::string>
433+ (MEMCACHED_HASH_FNV1_64, "MEMCACHED_HASH_FNV1_64"));
434+ hash_settings_reverse_map.insert(std::pair<uint64_t, const std::string>
435+ (MEMCACHED_HASH_FNV1A_64, "MEMCACHED_HASH_FNV1A_64"));
436+ hash_settings_reverse_map.insert(std::pair<uint64_t, const std::string>
437+ (MEMCACHED_HASH_FNV1_32, "MEMCACHED_HASH_FNV1_32"));
438+ hash_settings_reverse_map.insert(std::pair<uint64_t, const std::string>
439+ (MEMCACHED_HASH_FNV1A_32, "MEMCACHED_HASH_FNV1A_32"));
440+ hash_settings_reverse_map.insert(std::pair<uint64_t, const std::string>
441+ (MEMCACHED_HASH_JENKINS, "MEMCACHED_HASH_JENKINS"));
442+ hash_settings_reverse_map.insert(std::pair<uint64_t, const std::string>
443+ (MEMCACHED_HASH_HSIEH, "MEMCACHED_HASH_HSIEH"));
444+ hash_settings_reverse_map.insert(std::pair<uint64_t, const std::string>
445+ (MEMCACHED_HASH_MURMUR, "MEMCACHED_HASH_MURMUR"));
446+
447+ ketama_hash_settings_reverse_map.insert(std::pair<uint64_t, const std::string>
448+ (MEMCACHED_HASH_DEFAULT, "MEMCACHED_HASH_DEFAULT"));
449+ ketama_hash_settings_reverse_map.insert(std::pair<uint64_t, const std::string>
450+ (MEMCACHED_HASH_MD5, "MEMCACHED_HASH_MD5"));
451+ ketama_hash_settings_reverse_map.insert(std::pair<uint64_t, const std::string>
452+ (MEMCACHED_HASH_CRC, "MEMCACHED_HASH_CRC"));
453+ ketama_hash_settings_reverse_map.insert(std::pair<uint64_t, const std::string>
454+ (MEMCACHED_HASH_FNV1_64, "MEMCACHED_HASH_FNV1_64"));
455+ ketama_hash_settings_reverse_map.insert(std::pair<uint64_t, const std::string>
456+ (MEMCACHED_HASH_FNV1A_64, "MEMCACHED_HASH_FNV1A_64"));
457+ ketama_hash_settings_reverse_map.insert(std::pair<uint64_t, const std::string>
458+ (MEMCACHED_HASH_FNV1_32, "MEMCACHED_HASH_FNV1_32"));
459+ ketama_hash_settings_reverse_map.insert(std::pair<uint64_t, const std::string>
460+ (MEMCACHED_HASH_FNV1A_32, "MEMCACHED_HASH_FNV1A_32"));
461+ }
462+
463+ const char *func_name() const
464+ {
465+ return "memc_behavior_set";
466+ }
467+
468+ String *val_str(String *);
469+
470+ void fix_length_and_dec()
471+ {
472+ max_length= 32;
473+ }
474+
475+private:
476+ void setFailureString(const char *error);
477+
478+ String failure_buff;
479+ String return_buff;
480+
481+ std::map<const std::string, memcached_behavior> behavior_map;
482+ std::map<memcached_behavior, const std::string> behavior_reverse_map;
483+ std::map<uint64_t, const std::string> dist_settings_reverse_map;
484+ std::map<uint64_t, const std::string> hash_settings_reverse_map;
485+ std::map<uint64_t, const std::string> ketama_hash_settings_reverse_map;
486+};
487+
488+#endif /* MEMC_BEHAVIOR_GET_H */
489
490=== added file 'plugin/memcached_udf/memc_behavior_set.cc'
491--- plugin/memcached_udf/memc_behavior_set.cc 1970-01-01 00:00:00 +0000
492+++ plugin/memcached_udf/memc_behavior_set.cc 2009-07-13 14:02:39 +0000
493@@ -0,0 +1,154 @@
494+/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
495+ * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
496+ *
497+ * Copyright (C) 2009 Sun Microsystems
498+ *
499+ * This program is free software; you can redistribute it and/or modify
500+ * it under the terms of the GNU General Public License as published by
501+ * the Free Software Foundation; either version 2 of the License, or
502+ * (at your option) any later version.
503+ *
504+ * This program is distributed in the hope that it will be useful,
505+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
506+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
507+ * GNU General Public License for more details.
508+ *
509+ * You should have received a copy of the GNU General Public License
510+ * along with this program; if not, write to the Free Software
511+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
512+ */
513+
514+#include <drizzled/server_includes.h>
515+#include <drizzled/sql_udf.h>
516+#include <drizzled/item/func.h>
517+#include <drizzled/function/str/strfunc.h>
518+
519+#include "memcached_udf.h"
520+#include "memc_behavior_set.h"
521+
522+#include <libmemcached/memcached.h>
523+
524+#include <string>
525+#include <algorithm>
526+
527+using namespace std;
528+
529+void MemcachedBehaviorSet::setFailureString(const char *error)
530+{
531+ size_t size= strlen(error);
532+ failure_buff.realloc(size);
533+ failure_buff.length(size);
534+ memcpy(failure_buff.ptr(), error, size);
535+}
536+
537+String *MemcachedBehaviorSet::val_str(String *str)
538+{
539+ memcached_return rc;
540+ memcached_behavior mbehavior;
541+ uint64_t isetting= 0;
542+ String *tmp_behavior;
543+ String *tmp_setting;
544+
545+ if (arg_count != 2 ||
546+ ! (tmp_behavior= args[0]->val_str(str)) ||
547+ ! (tmp_setting= args[1]->val_str(str)) ||
548+ ! memc)
549+ {
550+ setFailureString("USAGE: memc_behavior_set('<behavior type>','<value>')");
551+ return &failure_buff;
552+ }
553+
554+ string behavior(tmp_behavior->c_ptr());
555+ string setting(tmp_setting->c_ptr());
556+
557+ /*
558+ * We don't want the user to have to type in all input in upper
559+ * case so we transform the input strings to upper case here.
560+ */
561+ std::transform(behavior.begin(), behavior.end(),
562+ behavior.begin(), ::toupper);
563+ std::transform(setting.begin(), setting.end(),
564+ setting.begin(), ::toupper);
565+
566+ mbehavior= behavior_map[behavior];
567+ if (! mbehavior)
568+ {
569+ setFailureString("UNKNOWN BEHAVIOR TYPE!");
570+ return &failure_buff;
571+ }
572+
573+ switch (mbehavior)
574+ {
575+ case MEMCACHED_BEHAVIOR_SUPPORT_CAS:
576+ case MEMCACHED_BEHAVIOR_NO_BLOCK:
577+ case MEMCACHED_BEHAVIOR_BUFFER_REQUESTS:
578+ case MEMCACHED_BEHAVIOR_USER_DATA:
579+ case MEMCACHED_BEHAVIOR_SORT_HOSTS:
580+ case MEMCACHED_BEHAVIOR_VERIFY_KEY:
581+ case MEMCACHED_BEHAVIOR_TCP_NODELAY:
582+ case MEMCACHED_BEHAVIOR_KETAMA:
583+ case MEMCACHED_BEHAVIOR_CACHE_LOOKUPS:
584+ if (setting.compare("1") == 0)
585+ {
586+ isetting= 1;
587+ }
588+ else if (setting.compare("0") == 0)
589+ {
590+ isetting= 0;
591+ }
592+ else
593+ {
594+ setFailureString("INVALID VALUE FOR BEHAVIOR - MUST be 1 OR 0!");
595+ return &failure_buff;
596+ }
597+ break;
598+ case MEMCACHED_BEHAVIOR_DISTRIBUTION:
599+ isetting= dist_settings_map[setting];
600+ if (! isetting)
601+ {
602+ setFailureString("INVALID VALUE FOR DISTRIBUTION!");
603+ return &failure_buff;
604+ }
605+ break;
606+ case MEMCACHED_BEHAVIOR_HASH:
607+ isetting= hash_settings_map[setting];
608+ if (! isetting)
609+ {
610+ setFailureString("INVALID VALUE FOR MEMCACHED HASH ALGORITHM!");
611+ return &failure_buff;
612+ }
613+ break;
614+ case MEMCACHED_BEHAVIOR_KETAMA_HASH:
615+ isetting= ketama_hash_settings_map[setting];
616+ if (! isetting)
617+ {
618+ setFailureString("INVALID VALUE FOR KETAMA HASH ALGORITHM!");
619+ return &failure_buff;
620+ }
621+ break;
622+ case MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE:
623+ case MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE:
624+ case MEMCACHED_BEHAVIOR_POLL_TIMEOUT:
625+ case MEMCACHED_BEHAVIOR_CONNECT_TIMEOUT:
626+ case MEMCACHED_BEHAVIOR_RETRY_TIMEOUT:
627+ case MEMCACHED_BEHAVIOR_IO_MSG_WATERMARK:
628+ case MEMCACHED_BEHAVIOR_IO_BYTES_WATERMARK:
629+ /*
630+ What type of check the values passed to these behaviors?
631+ Range?
632+ */
633+ break;
634+ default:
635+ break;
636+ }
637+
638+ rc= memcached_behavior_set(memc, mbehavior, isetting);
639+
640+ if (rc != MEMCACHED_SUCCESS)
641+ {
642+ return &failure_buff;
643+ }
644+
645+ return &success_buff;
646+}
647+
648
649=== added file 'plugin/memcached_udf/memc_behavior_set.h'
650--- plugin/memcached_udf/memc_behavior_set.h 1970-01-01 00:00:00 +0000
651+++ plugin/memcached_udf/memc_behavior_set.h 2009-07-13 03:04:57 +0000
652@@ -0,0 +1,164 @@
653+/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
654+ * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
655+ *
656+ * Copyright (C) 2009 Sun Microsystems
657+ *
658+ * This program is free software; you can redistribute it and/or modify
659+ * it under the terms of the GNU General Public License as published by
660+ * the Free Software Foundation; either version 2 of the License, or
661+ * (at your option) any later version.
662+ *
663+ * This program is distributed in the hope that it will be useful,
664+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
665+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
666+ * GNU General Public License for more details.
667+ *
668+ * You should have received a copy of the GNU General Public License
669+ * along with this program; if not, write to the Free Software
670+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
671+ */
672+
673+#ifndef MEMC_BEHAVIOR_SET_H
674+#define MEMC_BEHAVIOR_SET_H
675+
676+#include <drizzled/server_includes.h>
677+#include <drizzled/sql_udf.h>
678+#include <drizzled/item/func.h>
679+
680+#include <libmemcached/memcached.h>
681+
682+#include <map>
683+#include <string>
684+
685+/* implements memc_behavior_set */
686+class MemcachedBehaviorSet : public Item_str_func
687+{
688+public:
689+ MemcachedBehaviorSet()
690+ :
691+ Item_str_func(),
692+ failure_buff("FAILURE", &my_charset_bin),
693+ success_buff("SUCCESS", &my_charset_bin),
694+ behavior_map(),
695+ dist_settings_map(),
696+ hash_settings_map(),
697+ ketama_hash_settings_map()
698+ {
699+ behavior_map.insert(std::pair<const std::string, memcached_behavior>
700+ ("MEMCACHED_BEHAVIOR_SUPPORT_CAS", MEMCACHED_BEHAVIOR_SUPPORT_CAS));
701+ behavior_map.insert(std::pair<const std::string, memcached_behavior>
702+ ("MEMCACHED_BEHAVIOR_NO_BLOCK", MEMCACHED_BEHAVIOR_NO_BLOCK));
703+ behavior_map.insert(std::pair<const std::string, memcached_behavior>
704+ ("MEMCACHED_BEHAVIOR_TCP_NODELAY", MEMCACHED_BEHAVIOR_TCP_NODELAY));
705+ behavior_map.insert(std::pair<const std::string, memcached_behavior>
706+ ("MEMCACHED_BEHAVIOR_HASH", MEMCACHED_BEHAVIOR_HASH));
707+ behavior_map.insert(std::pair<const std::string, memcached_behavior>
708+ ("MEMCACHED_BEHAVIOR_CACHE_LOOKUPS", MEMCACHED_BEHAVIOR_CACHE_LOOKUPS));
709+ behavior_map.insert(std::pair<const std::string, memcached_behavior>
710+ ("MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE", MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE));
711+ behavior_map.insert(std::pair<const std::string, memcached_behavior>
712+ ("MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE", MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE));
713+ behavior_map.insert(std::pair<const std::string, memcached_behavior>
714+ ("MEMCACHED_BEHAVIOR_BUFFER_REQUESTS", MEMCACHED_BEHAVIOR_BUFFER_REQUESTS));
715+ behavior_map.insert(std::pair<const std::string, memcached_behavior>
716+ ("MEMCACHED_BEHAVIOR_KETAMA", MEMCACHED_BEHAVIOR_KETAMA));
717+ behavior_map.insert(std::pair<const std::string, memcached_behavior>
718+ ("MEMCACHED_BEHAVIOR_POLL_TIMEOUT", MEMCACHED_BEHAVIOR_POLL_TIMEOUT));
719+ behavior_map.insert(std::pair<const std::string, memcached_behavior>
720+ ("MEMCACHED_BEHAVIOR_RETRY_TIMEOUT", MEMCACHED_BEHAVIOR_RETRY_TIMEOUT));
721+ behavior_map.insert(std::pair<const std::string, memcached_behavior>
722+ ("MEMCACHED_BEHAVIOR_DISTRIBUTION", MEMCACHED_BEHAVIOR_DISTRIBUTION));
723+ behavior_map.insert(std::pair<const std::string, memcached_behavior>
724+ ("MEMCACHED_BEHAVIOR_USER_DATA", MEMCACHED_BEHAVIOR_USER_DATA));
725+ behavior_map.insert(std::pair<const std::string, memcached_behavior>
726+ ("MEMCACHED_BEHAVIOR_SORT_HOSTS", MEMCACHED_BEHAVIOR_SORT_HOSTS));
727+ behavior_map.insert(std::pair<const std::string, memcached_behavior>
728+ ("MEMCACHED_BEHAVIOR_VERIFY_KEY", MEMCACHED_BEHAVIOR_VERIFY_KEY));
729+ behavior_map.insert(std::pair<const std::string, memcached_behavior>
730+ ("MEMCACHED_BEHAVIOR_CONNECT_TIMEOUT", MEMCACHED_BEHAVIOR_CONNECT_TIMEOUT));
731+ behavior_map.insert(std::pair<const std::string, memcached_behavior>
732+ ("MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED", MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED));
733+ behavior_map.insert(std::pair<const std::string, memcached_behavior>
734+ ("MEMCACHED_BEHAVIOR_KETAMA_HASH", MEMCACHED_BEHAVIOR_KETAMA_HASH));
735+ behavior_map.insert(std::pair<const std::string, memcached_behavior>
736+ ("MEMCACHED_BEHAVIOR_BINARY_PROTOCOL", MEMCACHED_BEHAVIOR_BINARY_PROTOCOL));
737+ behavior_map.insert(std::pair<const std::string, memcached_behavior>
738+ ("MEMCACHED_BEHAVIOR_SND_TIMEOUT", MEMCACHED_BEHAVIOR_SND_TIMEOUT));
739+ behavior_map.insert(std::pair<const std::string, memcached_behavior>
740+ ("MEMCACHED_BEHAVIOR_RCV_TIMEOUT", MEMCACHED_BEHAVIOR_RCV_TIMEOUT));
741+ behavior_map.insert(std::pair<const std::string, memcached_behavior>
742+ ("MEMCACHED_BEHAVIOR_SERVER_FAILURE_LIMIT", MEMCACHED_BEHAVIOR_SERVER_FAILURE_LIMIT));
743+ behavior_map.insert(std::pair<const std::string, memcached_behavior>
744+ ("MEMCACHED_BEHAVIOR_IO_MSG_WATERMARK", MEMCACHED_BEHAVIOR_IO_MSG_WATERMARK));
745+ behavior_map.insert(std::pair<const std::string, memcached_behavior>
746+ ("MEMCACHED_BEHAVIOR_IO_BYTES_WATERMARK", MEMCACHED_BEHAVIOR_IO_BYTES_WATERMARK));
747+
748+ dist_settings_map.insert(std::pair<const std::string, uint64_t>
749+ ("MEMCACHED_DISTRIBUTION_MODULA", MEMCACHED_DISTRIBUTION_MODULA));
750+ dist_settings_map.insert(std::pair<const std::string, uint64_t>
751+ ("MEMCACHED_DISTRIBUTION_CONSISTENT", MEMCACHED_DISTRIBUTION_CONSISTENT));
752+ dist_settings_map.insert(std::pair<const std::string, uint64_t>
753+ ("MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA", MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA));
754+
755+ hash_settings_map.insert(std::pair<const std::string, uint64_t>
756+ ("MEMCACHED_HASH_DEFAULT", MEMCACHED_HASH_DEFAULT));
757+ hash_settings_map.insert(std::pair<const std::string, uint64_t>
758+ ("MEMCACHED_HASH_MD5", MEMCACHED_HASH_MD5));
759+ hash_settings_map.insert(std::pair<const std::string, uint64_t>
760+ ("MEMCACHED_HASH_CRC", MEMCACHED_HASH_CRC));
761+ hash_settings_map.insert(std::pair<const std::string, uint64_t>
762+ ("MEMCACHED_HASH_FNV1_64", MEMCACHED_HASH_FNV1_64));
763+ hash_settings_map.insert(std::pair<const std::string, uint64_t>
764+ ("MEMCACHED_HASH_FNV1A_64", MEMCACHED_HASH_FNV1A_64));
765+ hash_settings_map.insert(std::pair<const std::string, uint64_t>
766+ ("MEMCACHED_HASH_FNV1_32", MEMCACHED_HASH_FNV1_32));
767+ hash_settings_map.insert(std::pair<const std::string, uint64_t>
768+ ("MEMCACHED_HASH_FNV1A_32", MEMCACHED_HASH_FNV1A_32));
769+ hash_settings_map.insert(std::pair<const std::string, uint64_t>
770+ ("MEMCACHED_HASH_JENKINS", MEMCACHED_HASH_JENKINS));
771+ hash_settings_map.insert(std::pair<const std::string, uint64_t>
772+ ("MEMCACHED_HASH_HSIEH", MEMCACHED_HASH_HSIEH));
773+ hash_settings_map.insert(std::pair<const std::string, uint64_t>
774+ ("MEMCACHED_HASH_MURMUR", MEMCACHED_HASH_MURMUR));
775+
776+ ketama_hash_settings_map.insert(std::pair<const std::string, uint64_t>
777+ ("MEMCACHED_HASH_DEFAULT", MEMCACHED_HASH_DEFAULT));
778+ ketama_hash_settings_map.insert(std::pair<const std::string, uint64_t>
779+ ("MEMCACHED_HASH_MD5", MEMCACHED_HASH_MD5));
780+ ketama_hash_settings_map.insert(std::pair<const std::string, uint64_t>
781+ ("MEMCACHED_HASH_CRC", MEMCACHED_HASH_CRC));
782+ ketama_hash_settings_map.insert(std::pair<const std::string, uint64_t>
783+ ("MEMCACHED_HASH_FNV1_64", MEMCACHED_HASH_FNV1_64));
784+ ketama_hash_settings_map.insert(std::pair<const std::string, uint64_t>
785+ ("MEMCACHED_HASH_FNV1A_64", MEMCACHED_HASH_FNV1A_64));
786+ ketama_hash_settings_map.insert(std::pair<const std::string, uint64_t>
787+ ("MEMCACHED_HASH_FNV1_32", MEMCACHED_HASH_FNV1_32));
788+ ketama_hash_settings_map.insert(std::pair<const std::string, uint64_t>
789+ ("MEMCACHED_HASH_FNV1A_32", MEMCACHED_HASH_FNV1A_32));
790+ }
791+
792+ const char *func_name() const
793+ {
794+ return "memc_behavior_set";
795+ }
796+
797+ String *val_str(String *);
798+
799+ void fix_length_and_dec()
800+ {
801+ max_length= 32;
802+ }
803+
804+private:
805+ void setFailureString(const char *error);
806+
807+ String failure_buff;
808+ String success_buff;
809+
810+ std::map<const std::string, memcached_behavior> behavior_map;
811+ std::map<const std::string, uint64_t> dist_settings_map;
812+ std::map<const std::string, uint64_t> hash_settings_map;
813+ std::map<const std::string, uint64_t> ketama_hash_settings_map;
814+};
815+
816+#endif /* MEMC_BEHAVIOR_SET_H */
817
818=== added file 'plugin/memcached_udf/memc_delete.cc'
819--- plugin/memcached_udf/memc_delete.cc 1970-01-01 00:00:00 +0000
820+++ plugin/memcached_udf/memc_delete.cc 2009-07-12 04:13:35 +0000
821@@ -0,0 +1,54 @@
822+/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
823+ * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
824+ *
825+ * Copyright (C) 2009 Sun Microsystems
826+ *
827+ * This program is free software; you can redistribute it and/or modify
828+ * it under the terms of the GNU General Public License as published by
829+ * the Free Software Foundation; either version 2 of the License, or
830+ * (at your option) any later version.
831+ *
832+ * This program is distributed in the hope that it will be useful,
833+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
834+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
835+ * GNU General Public License for more details.
836+ *
837+ * You should have received a copy of the GNU General Public License
838+ * along with this program; if not, write to the Free Software
839+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
840+ */
841+
842+#include <drizzled/server_includes.h>
843+#include <drizzled/sql_udf.h>
844+#include <drizzled/function/str/strfunc.h>
845+
846+#include "memcached_udf.h"
847+#include "memc_delete.h"
848+
849+#include <libmemcached/memcached.h>
850+
851+#include <string>
852+
853+using namespace std;
854+
855+String *MemcachedDelete::val_str(String *str)
856+{
857+ memcached_return rc;
858+ String *key;
859+
860+ if (arg_count != 1 ||
861+ ! (key= args[0]->val_str(str)) ||
862+ ! memc)
863+ {
864+ return &failure_buff;
865+ }
866+
867+ rc= memcached_delete(memc, key->c_ptr(), key->length(), 0);
868+ if (rc != MEMCACHED_SUCCESS)
869+ {
870+ return &failure_buff;
871+ }
872+
873+ return &success_buff;
874+}
875+
876
877=== added file 'plugin/memcached_udf/memc_delete.h'
878--- plugin/memcached_udf/memc_delete.h 1970-01-01 00:00:00 +0000
879+++ plugin/memcached_udf/memc_delete.h 2009-07-12 04:13:35 +0000
880@@ -0,0 +1,56 @@
881+/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
882+ * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
883+ *
884+ * Copyright (C) 2009 Sun Microsystems
885+ *
886+ * This program is free software; you can redistribute it and/or modify
887+ * it under the terms of the GNU General Public License as published by
888+ * the Free Software Foundation; either version 2 of the License, or
889+ * (at your option) any later version.
890+ *
891+ * This program is distributed in the hope that it will be useful,
892+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
893+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
894+ * GNU General Public License for more details.
895+ *
896+ * You should have received a copy of the GNU General Public License
897+ * along with this program; if not, write to the Free Software
898+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
899+ */
900+
901+#ifndef MEMC_DELETE_H
902+#define MEMC_DELETE_H
903+
904+#include <drizzled/server_includes.h>
905+#include <drizzled/sql_udf.h>
906+#include <drizzled/function/str/strfunc.h>
907+
908+/* implements memc_delete */
909+class MemcachedDelete : public Item_str_func
910+{
911+public:
912+ MemcachedDelete()
913+ :
914+ Item_str_func(),
915+ failure_buff("FAILURE", &my_charset_bin),
916+ success_buff("SUCCESS", &my_charset_bin)
917+ {}
918+
919+ const char *func_name() const
920+ {
921+ return "memc_delete";
922+ }
923+
924+ String *val_str(String *);
925+
926+ void fix_length_and_dec()
927+ {
928+ max_length= 32;
929+ }
930+
931+private:
932+ String failure_buff;
933+ String success_buff;
934+};
935+
936+#endif /* MEMC_DELETE_H */
937
938=== added file 'plugin/memcached_udf/memc_get.cc'
939--- plugin/memcached_udf/memc_get.cc 1970-01-01 00:00:00 +0000
940+++ plugin/memcached_udf/memc_get.cc 2009-07-12 04:13:35 +0000
941@@ -0,0 +1,60 @@
942+/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
943+ * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
944+ *
945+ * Copyright (C) 2009 Sun Microsystems
946+ *
947+ * This program is free software; you can redistribute it and/or modify
948+ * it under the terms of the GNU General Public License as published by
949+ * the Free Software Foundation; either version 2 of the License, or
950+ * (at your option) any later version.
951+ *
952+ * This program is distributed in the hope that it will be useful,
953+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
954+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
955+ * GNU General Public License for more details.
956+ *
957+ * You should have received a copy of the GNU General Public License
958+ * along with this program; if not, write to the Free Software
959+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
960+ */
961+
962+#include <drizzled/server_includes.h>
963+#include <drizzled/sql_udf.h>
964+#include <drizzled/function/str/strfunc.h>
965+
966+#include "memcached_udf.h"
967+#include "memc_get.h"
968+
969+#include <libmemcached/memcached.h>
970+
971+#include <string>
972+
973+using namespace std;
974+
975+String *MemcachedGet::val_str(String *str)
976+{
977+ memcached_return rc;
978+ String *key;
979+ uint32_t flags;
980+ size_t val_len;
981+
982+ if (arg_count != 1 ||
983+ ! (key= args[0]->val_str(str)) ||
984+ ! memc)
985+ {
986+ return &failure_buff;
987+ }
988+
989+ char *value= memcached_get(memc, key->c_ptr(), key->length(), &val_len, &flags, &rc);
990+ if (rc != MEMCACHED_SUCCESS)
991+ {
992+ return &failure_buff;
993+ }
994+
995+ buffer.realloc(val_len);
996+ buffer.length(val_len);
997+ memcpy(buffer.ptr(), value, val_len);
998+
999+ return &buffer;
1000+}
1001+
1002
1003=== added file 'plugin/memcached_udf/memc_get.h'
1004--- plugin/memcached_udf/memc_get.h 1970-01-01 00:00:00 +0000
1005+++ plugin/memcached_udf/memc_get.h 2009-07-12 04:13:35 +0000
1006@@ -0,0 +1,55 @@
1007+/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
1008+ * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
1009+ *
1010+ * Copyright (C) 2009 Sun Microsystems
1011+ *
1012+ * This program is free software; you can redistribute it and/or modify
1013+ * it under the terms of the GNU General Public License as published by
1014+ * the Free Software Foundation; either version 2 of the License, or
1015+ * (at your option) any later version.
1016+ *
1017+ * This program is distributed in the hope that it will be useful,
1018+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
1019+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1020+ * GNU General Public License for more details.
1021+ *
1022+ * You should have received a copy of the GNU General Public License
1023+ * along with this program; if not, write to the Free Software
1024+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1025+ */
1026+
1027+#ifndef MEMC_GET_H
1028+#define MEMC_GET_H
1029+
1030+#include <drizzled/server_includes.h>
1031+#include <drizzled/sql_udf.h>
1032+#include <drizzled/function/str/strfunc.h>
1033+
1034+/* implements memc_get */
1035+class MemcachedGet : public Item_str_func
1036+{
1037+public:
1038+ MemcachedGet()
1039+ :
1040+ Item_str_func(),
1041+ failure_buff("FAILURE", &my_charset_bin)
1042+ {}
1043+
1044+ const char *func_name() const
1045+ {
1046+ return "memc_get";
1047+ }
1048+
1049+ String *val_str(String *);
1050+
1051+ void fix_length_and_dec()
1052+ {
1053+ max_length= 32;
1054+ }
1055+
1056+private:
1057+ String failure_buff;
1058+ String buffer;
1059+};
1060+
1061+#endif /* MEMC_GET_H */
1062
1063=== added file 'plugin/memcached_udf/memc_misc.cc'
1064--- plugin/memcached_udf/memc_misc.cc 1970-01-01 00:00:00 +0000
1065+++ plugin/memcached_udf/memc_misc.cc 2009-07-12 04:13:35 +0000
1066@@ -0,0 +1,59 @@
1067+/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
1068+ * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
1069+ *
1070+ * Copyright (C) 2009 Sun Microsystems
1071+ *
1072+ * This program is free software; you can redistribute it and/or modify
1073+ * it under the terms of the GNU General Public License as published by
1074+ * the Free Software Foundation; either version 2 of the License, or
1075+ * (at your option) any later version.
1076+ *
1077+ * This program is distributed in the hope that it will be useful,
1078+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
1079+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1080+ * GNU General Public License for more details.
1081+ *
1082+ * You should have received a copy of the GNU General Public License
1083+ * along with this program; if not, write to the Free Software
1084+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1085+ */
1086+
1087+#include <drizzled/server_includes.h>
1088+#include <drizzled/sql_udf.h>
1089+#include <drizzled/function/str/strfunc.h>
1090+
1091+#include "memcached_udf.h"
1092+#include "memc_misc.h"
1093+
1094+#include <libmemcached/memcached.h>
1095+
1096+#include <string>
1097+
1098+using namespace std;
1099+
1100+String *MemcachedVersion::val_str(String*)
1101+{
1102+ if (! memc)
1103+ {
1104+ return &failure_buff;
1105+ }
1106+
1107+ const char *version= memcached_lib_version();
1108+ size_t ver_len= strlen(version);
1109+
1110+ buffer.realloc(ver_len);
1111+ buffer.length(ver_len);
1112+ memcpy(buffer.ptr(), version, ver_len);
1113+
1114+ return &buffer;
1115+}
1116+
1117+int64_t MemcachedServerCount::val_int()
1118+{
1119+ if (! memc)
1120+ {
1121+ return 0;
1122+ }
1123+
1124+ return (memcached_server_count(memc));
1125+}
1126
1127=== added file 'plugin/memcached_udf/memc_misc.h'
1128--- plugin/memcached_udf/memc_misc.h 1970-01-01 00:00:00 +0000
1129+++ plugin/memcached_udf/memc_misc.h 2009-07-12 04:13:35 +0000
1130@@ -0,0 +1,80 @@
1131+/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
1132+ * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
1133+ *
1134+ * Copyright (C) 2009 Sun Microsystems
1135+ *
1136+ * This program is free software; you can redistribute it and/or modify
1137+ * it under the terms of the GNU General Public License as published by
1138+ * the Free Software Foundation; either version 2 of the License, or
1139+ * (at your option) any later version.
1140+ *
1141+ * This program is distributed in the hope that it will be useful,
1142+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
1143+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1144+ * GNU General Public License for more details.
1145+ *
1146+ * You should have received a copy of the GNU General Public License
1147+ * along with this program; if not, write to the Free Software
1148+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1149+ */
1150+
1151+#ifndef MEMC_MISC_H
1152+#define MEMC_MISC_H
1153+
1154+#include <drizzled/server_includes.h>
1155+#include <drizzled/sql_udf.h>
1156+#include <drizzled/item/func.h>
1157+#include <drizzled/function/str/strfunc.h>
1158+
1159+/* implements memc_libmemcached_version */
1160+class MemcachedVersion : public Item_str_func
1161+{
1162+public:
1163+ MemcachedVersion()
1164+ :
1165+ Item_str_func(),
1166+ failure_buff("FAILURE", &my_charset_bin)
1167+ {}
1168+
1169+ const char *func_name() const
1170+ {
1171+ return "memc_libmemcached_version";
1172+ }
1173+
1174+ String *val_str(String *);
1175+
1176+ void fix_length_and_dec()
1177+ {
1178+ max_length= 32;
1179+ }
1180+
1181+private:
1182+ String buffer;
1183+ String failure_buff;
1184+};
1185+
1186+/* implements memc_server_count */
1187+class MemcachedServerCount : public Item_int_func
1188+{
1189+public:
1190+ MemcachedServerCount()
1191+ :
1192+ Item_int_func()
1193+ {
1194+ unsigned_flag= 1;
1195+ }
1196+
1197+ const char *func_name() const
1198+ {
1199+ return "memc_server_count";
1200+ }
1201+
1202+ void fix_length_and_dec()
1203+ {
1204+ max_length= 10;
1205+ }
1206+
1207+ int64_t val_int();
1208+};
1209+
1210+#endif /* MEMC_MISC_H */
1211
1212=== added file 'plugin/memcached_udf/memc_prepend.cc'
1213--- plugin/memcached_udf/memc_prepend.cc 1970-01-01 00:00:00 +0000
1214+++ plugin/memcached_udf/memc_prepend.cc 2009-07-12 04:13:35 +0000
1215@@ -0,0 +1,57 @@
1216+/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
1217+ * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
1218+ *
1219+ * Copyright (C) 2009 Sun Microsystems
1220+ *
1221+ * This program is free software; you can redistribute it and/or modify
1222+ * it under the terms of the GNU General Public License as published by
1223+ * the Free Software Foundation; either version 2 of the License, or
1224+ * (at your option) any later version.
1225+ *
1226+ * This program is distributed in the hope that it will be useful,
1227+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
1228+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1229+ * GNU General Public License for more details.
1230+ *
1231+ * You should have received a copy of the GNU General Public License
1232+ * along with this program; if not, write to the Free Software
1233+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1234+ */
1235+
1236+#include <drizzled/server_includes.h>
1237+#include <drizzled/sql_udf.h>
1238+#include <drizzled/function/str/strfunc.h>
1239+
1240+#include "memcached_udf.h"
1241+#include "memc_prepend.h"
1242+
1243+#include <libmemcached/memcached.h>
1244+
1245+#include <string>
1246+
1247+using namespace std;
1248+
1249+String *MemcachedPrepend::val_str(String *str)
1250+{
1251+ memcached_return rc;
1252+ String *key;
1253+ String *value;
1254+
1255+ if (arg_count != 2 ||
1256+ ! (key= args[0]->val_str(str)) ||
1257+ ! (value= args[1]->val_str(str)) ||
1258+ ! memc)
1259+ {
1260+ return &failure_buff;
1261+ }
1262+
1263+ rc= memcached_prepend(memc, key->c_ptr(), key->length(),
1264+ value->c_ptr(), value->length(), 0, 0);
1265+ if (rc != MEMCACHED_SUCCESS)
1266+ {
1267+ return &failure_buff;
1268+ }
1269+
1270+ return &success_buff;
1271+}
1272+
1273
1274=== added file 'plugin/memcached_udf/memc_prepend.h'
1275--- plugin/memcached_udf/memc_prepend.h 1970-01-01 00:00:00 +0000
1276+++ plugin/memcached_udf/memc_prepend.h 2009-07-12 04:13:35 +0000
1277@@ -0,0 +1,56 @@
1278+/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
1279+ * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
1280+ *
1281+ * Copyright (C) 2009 Sun Microsystems
1282+ *
1283+ * This program is free software; you can redistribute it and/or modify
1284+ * it under the terms of the GNU General Public License as published by
1285+ * the Free Software Foundation; either version 2 of the License, or
1286+ * (at your option) any later version.
1287+ *
1288+ * This program is distributed in the hope that it will be useful,
1289+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
1290+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1291+ * GNU General Public License for more details.
1292+ *
1293+ * You should have received a copy of the GNU General Public License
1294+ * along with this program; if not, write to the Free Software
1295+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1296+ */
1297+
1298+#ifndef MEMC_PREPEND_H
1299+#define MEMC_PREPEND_H
1300+
1301+#include <drizzled/server_includes.h>
1302+#include <drizzled/sql_udf.h>
1303+#include <drizzled/function/str/strfunc.h>
1304+
1305+/* implements memc_prepend */
1306+class MemcachedPrepend : public Item_str_func
1307+{
1308+public:
1309+ MemcachedPrepend()
1310+ :
1311+ Item_str_func(),
1312+ failure_buff("FAILURE", &my_charset_bin),
1313+ success_buff("SUCCESS", &my_charset_bin)
1314+ {}
1315+
1316+ const char *func_name() const
1317+ {
1318+ return "memc_prepend";
1319+ }
1320+
1321+ String *val_str(String *);
1322+
1323+ void fix_length_and_dec()
1324+ {
1325+ max_length= 32;
1326+ }
1327+
1328+private:
1329+ String failure_buff;
1330+ String success_buff;
1331+};
1332+
1333+#endif /* MEMC_PREPEND_H */
1334
1335=== added file 'plugin/memcached_udf/memc_servers_set.cc'
1336--- plugin/memcached_udf/memc_servers_set.cc 1970-01-01 00:00:00 +0000
1337+++ plugin/memcached_udf/memc_servers_set.cc 2009-07-12 04:13:35 +0000
1338@@ -0,0 +1,62 @@
1339+/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
1340+ * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
1341+ *
1342+ * Copyright (C) 2009 Sun Microsystems
1343+ *
1344+ * This program is free software; you can redistribute it and/or modify
1345+ * it under the terms of the GNU General Public License as published by
1346+ * the Free Software Foundation; either version 2 of the License, or
1347+ * (at your option) any later version.
1348+ *
1349+ * This program is distributed in the hope that it will be useful,
1350+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
1351+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1352+ * GNU General Public License for more details.
1353+ *
1354+ * You should have received a copy of the GNU General Public License
1355+ * along with this program; if not, write to the Free Software
1356+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1357+ */
1358+
1359+#include <drizzled/server_includes.h>
1360+#include <drizzled/sql_udf.h>
1361+#include <drizzled/item/func.h>
1362+#include <drizzled/function/str/strfunc.h>
1363+
1364+#include "memcached_udf.h"
1365+#include "memc_servers_set.h"
1366+
1367+#include <libmemcached/memcached.h>
1368+
1369+#include <string>
1370+
1371+using namespace std;
1372+
1373+String *MemcachedServersSet::val_str(String *str)
1374+{
1375+ memcached_return rc;
1376+ memcached_server_st *servers;
1377+ String *server_names;
1378+
1379+ if (arg_count != 1 ||
1380+ ! (server_names= args[0]->val_str(str)) ||
1381+ ! memc)
1382+ {
1383+ return &failure_buff;
1384+ }
1385+
1386+ servers= memcached_servers_parse(server_names->c_ptr());
1387+ if (servers == NULL)
1388+ {
1389+ return &failure_buff;
1390+ }
1391+
1392+ rc= memcached_server_push(memc, servers);
1393+ if (rc != MEMCACHED_SUCCESS)
1394+ {
1395+ return &failure_buff;
1396+ }
1397+
1398+ return &success_buff;
1399+}
1400+
1401
1402=== added file 'plugin/memcached_udf/memc_servers_set.h'
1403--- plugin/memcached_udf/memc_servers_set.h 1970-01-01 00:00:00 +0000
1404+++ plugin/memcached_udf/memc_servers_set.h 2009-07-12 04:13:35 +0000
1405@@ -0,0 +1,60 @@
1406+/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
1407+ * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
1408+ *
1409+ * Copyright (C) 2009 Sun Microsystems
1410+ *
1411+ * This program is free software; you can redistribute it and/or modify
1412+ * it under the terms of the GNU General Public License as published by
1413+ * the Free Software Foundation; either version 2 of the License, or
1414+ * (at your option) any later version.
1415+ *
1416+ * This program is distributed in the hope that it will be useful,
1417+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
1418+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1419+ * GNU General Public License for more details.
1420+ *
1421+ * You should have received a copy of the GNU General Public License
1422+ * along with this program; if not, write to the Free Software
1423+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1424+ */
1425+
1426+#ifndef MEMC_SERVERS_SET_H
1427+#define MEMC_SERVERS_SET_H
1428+
1429+#include <drizzled/server_includes.h>
1430+#include <drizzled/sql_udf.h>
1431+#include <drizzled/item/func.h>
1432+
1433+/* implements memc_servers_set */
1434+class MemcachedServersSet : public Item_str_func
1435+{
1436+public:
1437+ MemcachedServersSet()
1438+ :
1439+ Item_str_func(),
1440+ failure_buff("FAILURE", &my_charset_bin),
1441+ success_buff("SUCCESS", &my_charset_bin)
1442+ {}
1443+
1444+ const char *func_name() const
1445+ {
1446+ return "memc_servers_set";
1447+ }
1448+
1449+ String *val_str(String *);
1450+
1451+ void fix_length_and_dec()
1452+ {
1453+ max_length= 32;
1454+ args[0]->collation.set(
1455+ get_charset_by_csname(args[0]->collation.collation->csname,
1456+ MY_CS_BINSORT),
1457+ DERIVATION_COERCIBLE);
1458+ }
1459+
1460+private:
1461+ String failure_buff;
1462+ String success_buff;
1463+};
1464+
1465+#endif /* MEMC_SERVERS_SET_H */
1466
1467=== added file 'plugin/memcached_udf/memc_set.cc'
1468--- plugin/memcached_udf/memc_set.cc 1970-01-01 00:00:00 +0000
1469+++ plugin/memcached_udf/memc_set.cc 2009-07-12 04:13:35 +0000
1470@@ -0,0 +1,58 @@
1471+/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
1472+ * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
1473+ *
1474+ * Copyright (C) 2009 Sun Microsystems
1475+ *
1476+ * This program is free software; you can redistribute it and/or modify
1477+ * it under the terms of the GNU General Public License as published by
1478+ * the Free Software Foundation; either version 2 of the License, or
1479+ * (at your option) any later version.
1480+ *
1481+ * This program is distributed in the hope that it will be useful,
1482+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
1483+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1484+ * GNU General Public License for more details.
1485+ *
1486+ * You should have received a copy of the GNU General Public License
1487+ * along with this program; if not, write to the Free Software
1488+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1489+ */
1490+
1491+#include <drizzled/server_includes.h>
1492+#include <drizzled/sql_udf.h>
1493+#include <drizzled/function/str/strfunc.h>
1494+
1495+#include "memcached_udf.h"
1496+#include "memc_set.h"
1497+
1498+#include <libmemcached/memcached.h>
1499+
1500+#include <string>
1501+
1502+using namespace std;
1503+
1504+String *MemcachedSet::val_str(String *str)
1505+{
1506+ memcached_return rc;
1507+ String *key;
1508+ String *value;
1509+
1510+ if (arg_count != 2 ||
1511+ ! (key= args[0]->val_str(str)) ||
1512+ ! (value= args[1]->val_str(str)) ||
1513+ ! memc)
1514+ {
1515+ return &failure_buff;
1516+ }
1517+
1518+ rc= memcached_set(memc, key->c_ptr(), key->length(),
1519+ value->c_ptr(), value->length(),
1520+ 0, 0);
1521+ if (rc != MEMCACHED_SUCCESS)
1522+ {
1523+ return &failure_buff;
1524+ }
1525+
1526+ return &success_buff;
1527+}
1528+
1529
1530=== added file 'plugin/memcached_udf/memc_set.h'
1531--- plugin/memcached_udf/memc_set.h 1970-01-01 00:00:00 +0000
1532+++ plugin/memcached_udf/memc_set.h 2009-07-12 04:13:35 +0000
1533@@ -0,0 +1,56 @@
1534+/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
1535+ * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
1536+ *
1537+ * Copyright (C) 2009 Sun Microsystems
1538+ *
1539+ * This program is free software; you can redistribute it and/or modify
1540+ * it under the terms of the GNU General Public License as published by
1541+ * the Free Software Foundation; either version 2 of the License, or
1542+ * (at your option) any later version.
1543+ *
1544+ * This program is distributed in the hope that it will be useful,
1545+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
1546+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1547+ * GNU General Public License for more details.
1548+ *
1549+ * You should have received a copy of the GNU General Public License
1550+ * along with this program; if not, write to the Free Software
1551+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1552+ */
1553+
1554+#ifndef MEMC_SET_H
1555+#define MEMC_SET_H
1556+
1557+#include <drizzled/server_includes.h>
1558+#include <drizzled/sql_udf.h>
1559+#include <drizzled/function/str/strfunc.h>
1560+
1561+/* implements memc_set */
1562+class MemcachedSet : public Item_str_func
1563+{
1564+public:
1565+ MemcachedSet()
1566+ :
1567+ Item_str_func(),
1568+ failure_buff("FAILURE", &my_charset_bin),
1569+ success_buff("SUCCESS", &my_charset_bin)
1570+ {}
1571+
1572+ const char *func_name() const
1573+ {
1574+ return "memc_set";
1575+ }
1576+
1577+ String *val_str(String *);
1578+
1579+ void fix_length_and_dec()
1580+ {
1581+ max_length= 32;
1582+ }
1583+
1584+private:
1585+ String failure_buff;
1586+ String success_buff;
1587+};
1588+
1589+#endif /* MEMC_SET_H */
1590
1591=== added file 'plugin/memcached_udf/memcached_udf.cc'
1592--- plugin/memcached_udf/memcached_udf.cc 1970-01-01 00:00:00 +0000
1593+++ plugin/memcached_udf/memcached_udf.cc 2009-07-13 14:02:39 +0000
1594@@ -0,0 +1,208 @@
1595+/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
1596+ * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
1597+ *
1598+ * Copyright (C) 2009 Sun Microsystems
1599+ *
1600+ * This program is free software; you can redistribute it and/or modify
1601+ * it under the terms of the GNU General Public License as published by
1602+ * the Free Software Foundation; either version 2 of the License, or
1603+ * (at your option) any later version.
1604+ *
1605+ * This program is distributed in the hope that it will be useful,
1606+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
1607+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1608+ * GNU General Public License for more details.
1609+ *
1610+ * You should have received a copy of the GNU General Public License
1611+ * along with this program; if not, write to the Free Software
1612+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1613+ */
1614+
1615+#include <drizzled/server_includes.h>
1616+#include <drizzled/sql_udf.h>
1617+#include <drizzled/item/func.h>
1618+#include <drizzled/function/str/strfunc.h>
1619+
1620+#include "memcached_udf.h"
1621+#include "memc_servers_set.h"
1622+#include "memc_behavior_set.h"
1623+#include "memc_behavior_get.h"
1624+#include "memc_get.h"
1625+#include "memc_set.h"
1626+#include "memc_delete.h"
1627+#include "memc_append.h"
1628+#include "memc_prepend.h"
1629+#include "memc_misc.h"
1630+
1631+#include <libmemcached/memcached.h>
1632+
1633+#include <string>
1634+
1635+using namespace std;
1636+
1637+/*
1638+ * A global memcached data structure needed by
1639+ * the various libmemcached API functions.
1640+ */
1641+memcached_st *memc= NULL;
1642+
1643+/*
1644+ * The memcached UDF's.
1645+ */
1646+static Create_function<MemcachedServersSet> *memc_servers_set= NULL;
1647+static Create_function<MemcachedBehaviorSet> *memc_behavior_set= NULL;
1648+static Create_function<MemcachedBehaviorGet> *memc_behavior_get= NULL;
1649+static Create_function<MemcachedGet> *memc_get= NULL;
1650+static Create_function<MemcachedSet> *memc_set= NULL;
1651+static Create_function<MemcachedDelete> *memc_delete= NULL;
1652+static Create_function<MemcachedAppend> *memc_append= NULL;
1653+static Create_function<MemcachedPrepend> *memc_prepend= NULL;
1654+static Create_function<MemcachedServerCount> *memc_serv_count= NULL;
1655+static Create_function<MemcachedVersion> *memc_version= NULL;
1656+
1657+bool initMemcUDF()
1658+{
1659+ memc_servers_set= new(std::nothrow)
1660+ Create_function<MemcachedServersSet>(string("memc_servers_set"));
1661+ if (memc_servers_set == NULL)
1662+ {
1663+ return true;
1664+ }
1665+
1666+ memc_behavior_set= new(std::nothrow)
1667+ Create_function<MemcachedBehaviorSet>(string("memc_behavior_set"));
1668+ if (memc_behavior_set == NULL)
1669+ {
1670+ return true;
1671+ }
1672+
1673+ memc_behavior_get= new(std::nothrow)
1674+ Create_function<MemcachedBehaviorGet>(string("memc_behavior_get"));
1675+ if (memc_behavior_get == NULL)
1676+ {
1677+ return true;
1678+ }
1679+
1680+ memc_get= new(std::nothrow)
1681+ Create_function<MemcachedGet>(string("memc_get"));
1682+ if (memc_get == NULL)
1683+ {
1684+ return true;
1685+ }
1686+
1687+ memc_set= new(std::nothrow)
1688+ Create_function<MemcachedSet>(string("memc_set"));
1689+ if (memc_set == NULL)
1690+ {
1691+ return true;
1692+ }
1693+
1694+ memc_delete= new(std::nothrow)
1695+ Create_function<MemcachedDelete>(string("memc_delete"));
1696+ if (memc_delete == NULL)
1697+ {
1698+ return true;
1699+ }
1700+
1701+ memc_append= new(std::nothrow)
1702+ Create_function<MemcachedAppend>(string("memc_append"));
1703+ if (memc_append == NULL)
1704+ {
1705+ return true;
1706+ }
1707+
1708+ memc_prepend= new(std::nothrow)
1709+ Create_function<MemcachedPrepend>(string("memc_prepend"));
1710+ if (memc_prepend == NULL)
1711+ {
1712+ return true;
1713+ }
1714+
1715+ memc_serv_count= new(std::nothrow)
1716+ Create_function<MemcachedServerCount>(string("memc_server_count"));
1717+ if (memc_serv_count == NULL)
1718+ {
1719+ return true;
1720+ }
1721+
1722+ memc_version= new(std::nothrow)
1723+ Create_function<MemcachedVersion>(string("memc_libmemcached_version"));
1724+ if (memc_version == NULL)
1725+ {
1726+ return true;
1727+ }
1728+
1729+ return false;
1730+}
1731+
1732+void cleanupMemcUDF()
1733+{
1734+ delete memc_servers_set;
1735+ delete memc_behavior_set;
1736+ delete memc_behavior_get;
1737+ delete memc_get;
1738+ delete memc_set;
1739+ delete memc_delete;
1740+ delete memc_append;
1741+ delete memc_prepend;
1742+ delete memc_serv_count;
1743+ delete memc_version;
1744+}
1745+
1746+static int memcachedInit(PluginRegistry &registry)
1747+{
1748+ if (initMemcUDF())
1749+ {
1750+ return 1;
1751+ }
1752+
1753+ memc= memcached_create(NULL);
1754+
1755+ registry.add(memc_servers_set);
1756+ registry.add(memc_behavior_set);
1757+ registry.add(memc_behavior_get);
1758+ registry.add(memc_get);
1759+ registry.add(memc_set);
1760+ registry.add(memc_delete);
1761+ registry.add(memc_append);
1762+ registry.add(memc_prepend);
1763+ registry.add(memc_serv_count);
1764+ registry.add(memc_version);
1765+
1766+ return 0;
1767+}
1768+
1769+static int memcachedDone(PluginRegistry &registry)
1770+{
1771+ cleanupMemcUDF();
1772+
1773+ memcached_free(memc);
1774+
1775+ registry.remove(memc_servers_set);
1776+ registry.remove(memc_behavior_set);
1777+ registry.remove(memc_behavior_get);
1778+ registry.remove(memc_get);
1779+ registry.remove(memc_set);
1780+ registry.remove(memc_delete);
1781+ registry.remove(memc_append);
1782+ registry.remove(memc_prepend);
1783+ registry.remove(memc_serv_count);
1784+ registry.remove(memc_version);
1785+
1786+ return 0;
1787+}
1788+
1789+drizzle_declare_plugin(memcached_udf)
1790+{
1791+ "memcached_udf",
1792+ "0.1",
1793+ "Patrick Galbraith, Ronald Bradford, Padraig O'Sullivan",
1794+ "Memcached UDF Plugin",
1795+ PLUGIN_LICENSE_GPL,
1796+ memcachedInit,
1797+ memcachedDone,
1798+ NULL,
1799+ NULL,
1800+ NULL
1801+}
1802+drizzle_declare_plugin_end;
1803
1804=== added file 'plugin/memcached_udf/memcached_udf.h'
1805--- plugin/memcached_udf/memcached_udf.h 1970-01-01 00:00:00 +0000
1806+++ plugin/memcached_udf/memcached_udf.h 2009-07-12 04:13:35 +0000
1807@@ -0,0 +1,41 @@
1808+/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
1809+ * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
1810+ *
1811+ * Copyright (C) 2009 Sun Microsystems
1812+ *
1813+ * This program is free software; you can redistribute it and/or modify
1814+ * it under the terms of the GNU General Public License as published by
1815+ * the Free Software Foundation; either version 2 of the License, or
1816+ * (at your option) any later version.
1817+ *
1818+ * This program is distributed in the hope that it will be useful,
1819+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
1820+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1821+ * GNU General Public License for more details.
1822+ *
1823+ * You should have received a copy of the GNU General Public License
1824+ * along with this program; if not, write to the Free Software
1825+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1826+ */
1827+
1828+#ifndef MEMCACHED_UDF_H
1829+#define MEMCACHED_UDF_H
1830+
1831+#include <libmemcached/memcached.h>
1832+
1833+extern memcached_st *memc;
1834+
1835+/**
1836+ * Initialize all the UDF functions for memcached.
1837+ *
1838+ * @return false on success; true on failure
1839+ */
1840+bool initMemcUDF();
1841+
1842+/**
1843+ * Release all memory allocated for the memcached
1844+ * UDF's.
1845+ */
1846+void cleanupMemcUDF();
1847+
1848+#endif /* MEMCACHED_UDF_H */
1849
1850=== added file 'plugin/memcached_udf/plugin.ac'
1851--- plugin/memcached_udf/plugin.ac 1970-01-01 00:00:00 +0000
1852+++ plugin/memcached_udf/plugin.ac 2009-07-12 04:13:35 +0000
1853@@ -0,0 +1,9 @@
1854+AC_LIB_HAVE_LINKFLAGS(memcached,,
1855+ [#include <libmemcached/memcached.h>],
1856+ [
1857+ memcached_st memc;
1858+ memcached_lib_version();
1859+ ])
1860+AS_IF([test "x$ac_cv_libmemcached" = "xno"],
1861+ AC_MSG_WARN([libmemcached not found: not building memcached_udf plugin.]))
1862+DRIZZLED_PLUGIN_DEP_LIBS="${DRIZZLED_PLUGIN_DEP_LIBS} ${LTLIBMEMCACHED}"
1863
1864=== added file 'plugin/memcached_udf/plugin.ini'
1865--- plugin/memcached_udf/plugin.ini 1970-01-01 00:00:00 +0000
1866+++ plugin/memcached_udf/plugin.ini 2009-07-13 14:02:39 +0000
1867@@ -0,0 +1,13 @@
1868+[plugin]
1869+name=memcached_udf
1870+title=Memcached Client UDFs
1871+description=UDF plugin for libmemcached
1872+load_by_default=yes
1873+headers=memcached_udf.h memc_get.h memc_set.h memc_delete.h memc_append.h
1874+ memc_prepend.h memc_misc.h memc_servers_set.h memc_behavior_set.h
1875+ memc_behavior_get.h
1876+sources=memcached_udf.cc memc_get.cc memc_set.cc memc_delete.cc
1877+ memc_append.cc memc_prepend.cc memc_misc.cc memc_servers_set.cc
1878+ memc_behavior_set.cc memc_behavior_get.cc
1879+build_conditional="${ac_cv_libmemcached}" = "yes"
1880+ldflags=${LTLIBMEMCACHED}