drizzle
C++ MySQL-protocol-compatible database server
Loading...
Searching...
No Matches
memc_behavior_get.h
Go to the documentation of this file.
1/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3 *
4 * Copyright (C) 2009, Patrick "CaptTofu" Galbraith, Padraig O'Sullivan
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are met:
9 *
10 * * Redistributions of source code must retain the above copyright notice,
11 * this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above copyright notice,
13 * this list of conditions and the following disclaimer in the documentation
14 * and/or other materials provided with the distribution.
15 * * Neither the name of Patrick Galbraith nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
29 * THE POSSIBILITY OF SUCH DAMAGE.
30 */
31
32#pragma once
33
34#include <drizzled/item/func.h>
35
36#include <libmemcached/memcached.h>
37
38#include <map>
39#include <string>
40
45class MemcachedBehaviorGet : public drizzled::Item_str_func
46{
47public:
48 MemcachedBehaviorGet()
49 :
50 Item_str_func(),
51 failure_buff("FAILURE", &drizzled::my_charset_bin),
52 return_buff("", &drizzled::my_charset_bin),
53 behavior_map(),
54 behavior_reverse_map(),
55 dist_settings_reverse_map(),
56 hash_settings_reverse_map(),
57 ketama_hash_settings_reverse_map()
58 {
59 /*
60 * std::map for mapping string behaviors to int behavior values
61 * This is used to take user input behaviors from the UDF and
62 * be able to set the correct int behavior
63 */
64 behavior_map.insert(std::pair<const std::string, memcached_behavior>
65 ("MEMCACHED_BEHAVIOR_SUPPORT_CAS", MEMCACHED_BEHAVIOR_SUPPORT_CAS));
66 behavior_map.insert(std::pair<const std::string, memcached_behavior>
67 ("MEMCACHED_BEHAVIOR_NO_BLOCK", MEMCACHED_BEHAVIOR_NO_BLOCK));
68 behavior_map.insert(std::pair<const std::string, memcached_behavior>
69 ("MEMCACHED_BEHAVIOR_TCP_NODELAY", MEMCACHED_BEHAVIOR_TCP_NODELAY));
70 behavior_map.insert(std::pair<const std::string, memcached_behavior>
71 ("MEMCACHED_BEHAVIOR_HASH", MEMCACHED_BEHAVIOR_HASH));
72 behavior_map.insert(std::pair<const std::string, memcached_behavior>
73 ("MEMCACHED_BEHAVIOR_CACHE_LOOKUPS", MEMCACHED_BEHAVIOR_CACHE_LOOKUPS));
74 behavior_map.insert(std::pair<const std::string, memcached_behavior>
75 ("MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE", MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE));
76 behavior_map.insert(std::pair<const std::string, memcached_behavior>
77 ("MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE", MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE));
78 behavior_map.insert(std::pair<const std::string, memcached_behavior>
79 ("MEMCACHED_BEHAVIOR_BUFFER_REQUESTS", MEMCACHED_BEHAVIOR_BUFFER_REQUESTS));
80 behavior_map.insert(std::pair<const std::string, memcached_behavior>
81 ("MEMCACHED_BEHAVIOR_KETAMA", MEMCACHED_BEHAVIOR_KETAMA));
82 behavior_map.insert(std::pair<const std::string, memcached_behavior>
83 ("MEMCACHED_BEHAVIOR_POLL_TIMEOUT", MEMCACHED_BEHAVIOR_POLL_TIMEOUT));
84 behavior_map.insert(std::pair<const std::string, memcached_behavior>
85 ("MEMCACHED_BEHAVIOR_RETRY_TIMEOUT", MEMCACHED_BEHAVIOR_RETRY_TIMEOUT));
86 behavior_map.insert(std::pair<const std::string, memcached_behavior>
87 ("MEMCACHED_BEHAVIOR_DISTRIBUTION", MEMCACHED_BEHAVIOR_DISTRIBUTION));
88 behavior_map.insert(std::pair<const std::string, memcached_behavior>
89 ("MEMCACHED_BEHAVIOR_USER_DATA", MEMCACHED_BEHAVIOR_USER_DATA));
90 behavior_map.insert(std::pair<const std::string, memcached_behavior>
91 ("MEMCACHED_BEHAVIOR_SORT_HOSTS", MEMCACHED_BEHAVIOR_SORT_HOSTS));
92 behavior_map.insert(std::pair<const std::string, memcached_behavior>
93 ("MEMCACHED_BEHAVIOR_VERIFY_KEY", MEMCACHED_BEHAVIOR_VERIFY_KEY));
94 behavior_map.insert(std::pair<const std::string, memcached_behavior>
95 ("MEMCACHED_BEHAVIOR_CONNECT_TIMEOUT", MEMCACHED_BEHAVIOR_CONNECT_TIMEOUT));
96 behavior_map.insert(std::pair<const std::string, memcached_behavior>
97 ("MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED", MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED));
98 behavior_map.insert(std::pair<const std::string, memcached_behavior>
99 ("MEMCACHED_BEHAVIOR_KETAMA_HASH", MEMCACHED_BEHAVIOR_KETAMA_HASH));
100 behavior_map.insert(std::pair<const std::string, memcached_behavior>
101 ("MEMCACHED_BEHAVIOR_BINARY_PROTOCOL", MEMCACHED_BEHAVIOR_BINARY_PROTOCOL));
102 behavior_map.insert(std::pair<const std::string, memcached_behavior>
103 ("MEMCACHED_BEHAVIOR_SND_TIMEOUT", MEMCACHED_BEHAVIOR_SND_TIMEOUT));
104 behavior_map.insert(std::pair<const std::string, memcached_behavior>
105 ("MEMCACHED_BEHAVIOR_RCV_TIMEOUT", MEMCACHED_BEHAVIOR_RCV_TIMEOUT));
106 behavior_map.insert(std::pair<const std::string, memcached_behavior>
107 ("MEMCACHED_BEHAVIOR_SERVER_FAILURE_LIMIT", MEMCACHED_BEHAVIOR_SERVER_FAILURE_LIMIT));
108 behavior_map.insert(std::pair<const std::string, memcached_behavior>
109 ("MEMCACHED_BEHAVIOR_IO_MSG_WATERMARK", MEMCACHED_BEHAVIOR_IO_MSG_WATERMARK));
110 behavior_map.insert(std::pair<const std::string, memcached_behavior>
111 ("MEMCACHED_BEHAVIOR_IO_BYTES_WATERMARK", MEMCACHED_BEHAVIOR_IO_BYTES_WATERMARK));
112
113 /*
114 * std::map for mapping int behavior values to behavior strings
115 * This is used to take int behaviors from the the clien and be
116 * able to print the string value of the behavior in memc_behavior_get
117 * UDF
118 */
119 behavior_reverse_map.insert(std::pair<memcached_behavior, const std::string>
120 (MEMCACHED_BEHAVIOR_SUPPORT_CAS, "MEMCACHED_BEHAVIOR_SUPPORT_CAS"));
121 behavior_reverse_map.insert(std::pair<memcached_behavior,const std::string>
122 (MEMCACHED_BEHAVIOR_NO_BLOCK, "MEMCACHED_BEHAVIOR_NO_BLOCK"));
123 behavior_reverse_map.insert(std::pair<memcached_behavior,const std::string>
124 (MEMCACHED_BEHAVIOR_TCP_NODELAY, "MEMCACHED_BEHAVIOR_TCP_NODELAY"));
125 behavior_reverse_map.insert(std::pair<memcached_behavior,const std::string>
126 (MEMCACHED_BEHAVIOR_HASH, "MEMCACHED_BEHAVIOR_HASH"));
127 behavior_reverse_map.insert(std::pair<memcached_behavior,const std::string>
128 (MEMCACHED_BEHAVIOR_CACHE_LOOKUPS, "MEMCACHED_BEHAVIOR_CACHE_LOOKUPS"));
129 behavior_reverse_map.insert(std::pair<memcached_behavior,const std::string>
130 (MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE, "MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE"));
131 behavior_reverse_map.insert(std::pair<memcached_behavior,const std::string>
132 (MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE, "MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE"));
133 behavior_reverse_map.insert(std::pair<memcached_behavior,const std::string>
134 (MEMCACHED_BEHAVIOR_BUFFER_REQUESTS, "MEMCACHED_BEHAVIOR_BUFFER_REQUESTS"));
135 behavior_reverse_map.insert(std::pair<memcached_behavior,const std::string>
136 (MEMCACHED_BEHAVIOR_KETAMA, "MEMCACHED_BEHAVIOR_KETAMA"));
137 behavior_reverse_map.insert(std::pair<memcached_behavior,const std::string>
138 (MEMCACHED_BEHAVIOR_POLL_TIMEOUT, "MEMCACHED_BEHAVIOR_POLL_TIMEOUT"));
139 behavior_reverse_map.insert(std::pair<memcached_behavior,const std::string>
140 (MEMCACHED_BEHAVIOR_RETRY_TIMEOUT, "MEMCACHED_BEHAVIOR_RETRY_TIMEOUT"));
141 behavior_reverse_map.insert(std::pair<memcached_behavior,const std::string>
142 (MEMCACHED_BEHAVIOR_DISTRIBUTION, "MEMCACHED_BEHAVIOR_DISTRIBUTION"));
143 behavior_reverse_map.insert(std::pair<memcached_behavior,const std::string>
144 (MEMCACHED_BEHAVIOR_USER_DATA, "MEMCACHED_BEHAVIOR_USER_DATA"));
145 behavior_reverse_map.insert(std::pair<memcached_behavior,const std::string>
146 (MEMCACHED_BEHAVIOR_SORT_HOSTS, "MEMCACHED_BEHAVIOR_SORT_HOSTS"));
147 behavior_reverse_map.insert(std::pair<memcached_behavior,const std::string>
148 (MEMCACHED_BEHAVIOR_VERIFY_KEY, "MEMCACHED_BEHAVIOR_VERIFY_KEY"));
149 behavior_reverse_map.insert(std::pair<memcached_behavior,const std::string>
150 (MEMCACHED_BEHAVIOR_CONNECT_TIMEOUT, "MEMCACHED_BEHAVIOR_CONNECT_TIMEOUT"));
151 behavior_reverse_map.insert(std::pair<memcached_behavior,const std::string>
152 (MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED, "MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED"));
153 behavior_reverse_map.insert(std::pair<memcached_behavior,const std::string>
154 (MEMCACHED_BEHAVIOR_KETAMA_HASH, "MEMCACHED_BEHAVIOR_KETAMA_HASH"));
155 behavior_reverse_map.insert(std::pair<memcached_behavior,const std::string>
156 (MEMCACHED_BEHAVIOR_BINARY_PROTOCOL, "MEMCACHED_BEHAVIOR_BINARY_PROTOCOL"));
157 behavior_reverse_map.insert(std::pair<memcached_behavior,const std::string>
158 (MEMCACHED_BEHAVIOR_SND_TIMEOUT, "MEMCACHED_BEHAVIOR_SND_TIMEOUT"));
159 behavior_reverse_map.insert(std::pair<memcached_behavior,const std::string>
160 (MEMCACHED_BEHAVIOR_RCV_TIMEOUT, "MEMCACHED_BEHAVIOR_RCV_TIMEOUT"));
161 behavior_reverse_map.insert(std::pair<memcached_behavior,const std::string>
162 (MEMCACHED_BEHAVIOR_SERVER_FAILURE_LIMIT, "MEMCACHED_BEHAVIOR_SERVER_FAILURE_LIMIT"));
163 behavior_reverse_map.insert(std::pair<memcached_behavior,const std::string>
164 (MEMCACHED_BEHAVIOR_IO_MSG_WATERMARK, "MEMCACHED_BEHAVIOR_IO_MSG_WATERMARK"));
165 behavior_reverse_map.insert(std::pair<memcached_behavior,const std::string>
166 (MEMCACHED_BEHAVIOR_IO_BYTES_WATERMARK, "MEMCACHED_BEHAVIOR_IO_BYTES_WATERMARK"));
167
168 /*
169 * std::map for mapping distribution string values to int distribution values
170 * For being able to map int distribution values to string distribution values
171 * Used by memc_behavior_get() for distribution types
172 */
173 dist_settings_reverse_map.insert(std::pair<uint64_t, const std::string>
174 (MEMCACHED_DISTRIBUTION_MODULA, "MEMCACHED_DISTRIBUTION_MODULA"));
175 dist_settings_reverse_map.insert(std::pair<uint64_t, const std::string>
176 (MEMCACHED_DISTRIBUTION_CONSISTENT, "MEMCACHED_DISTRIBUTION_CONSISTENT"));
177 dist_settings_reverse_map.insert(std::pair<uint64_t, const std::string>
178 (MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA, "MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA"));
179
180 /*
181 * std::map for mapping distribution string values to int distribution values
182 * For being able to map int distribution values to string distribution values
183 * Used by memc_behavior_get() for hash types
184 */
185 hash_settings_reverse_map.insert(std::pair<uint64_t, const std::string>
186 (MEMCACHED_HASH_DEFAULT, "MEMCACHED_HASH_DEFAULT"));
187 hash_settings_reverse_map.insert(std::pair<uint64_t, const std::string>
188 (MEMCACHED_HASH_MD5, "MEMCACHED_HASH_MD5"));
189 hash_settings_reverse_map.insert(std::pair<uint64_t, const std::string>
190 (MEMCACHED_HASH_CRC, "MEMCACHED_HASH_CRC"));
191 hash_settings_reverse_map.insert(std::pair<uint64_t, const std::string>
192 (MEMCACHED_HASH_FNV1_64, "MEMCACHED_HASH_FNV1_64"));
193 hash_settings_reverse_map.insert(std::pair<uint64_t, const std::string>
194 (MEMCACHED_HASH_FNV1A_64, "MEMCACHED_HASH_FNV1A_64"));
195 hash_settings_reverse_map.insert(std::pair<uint64_t, const std::string>
196 (MEMCACHED_HASH_FNV1_32, "MEMCACHED_HASH_FNV1_32"));
197 hash_settings_reverse_map.insert(std::pair<uint64_t, const std::string>
198 (MEMCACHED_HASH_FNV1A_32, "MEMCACHED_HASH_FNV1A_32"));
199 hash_settings_reverse_map.insert(std::pair<uint64_t, const std::string>
200 (MEMCACHED_HASH_JENKINS, "MEMCACHED_HASH_JENKINS"));
201 hash_settings_reverse_map.insert(std::pair<uint64_t, const std::string>
202 (MEMCACHED_HASH_HSIEH, "MEMCACHED_HASH_HSIEH"));
203 hash_settings_reverse_map.insert(std::pair<uint64_t, const std::string>
204 (MEMCACHED_HASH_MURMUR, "MEMCACHED_HASH_MURMUR"));
205
206 /*
207 * std::map for mapping distribution string values to int distribution values
208 * For being able to map int distribution values to string distribution values
209 * Used by memc_behavior_get() for ketama hash types
210 */
211 ketama_hash_settings_reverse_map.insert(std::pair<uint64_t, const std::string>
212 (MEMCACHED_HASH_DEFAULT, "MEMCACHED_HASH_DEFAULT"));
213 ketama_hash_settings_reverse_map.insert(std::pair<uint64_t, const std::string>
214 (MEMCACHED_HASH_MD5, "MEMCACHED_HASH_MD5"));
215 ketama_hash_settings_reverse_map.insert(std::pair<uint64_t, const std::string>
216 (MEMCACHED_HASH_CRC, "MEMCACHED_HASH_CRC"));
217 ketama_hash_settings_reverse_map.insert(std::pair<uint64_t, const std::string>
218 (MEMCACHED_HASH_FNV1_64, "MEMCACHED_HASH_FNV1_64"));
219 ketama_hash_settings_reverse_map.insert(std::pair<uint64_t, const std::string>
220 (MEMCACHED_HASH_FNV1A_64, "MEMCACHED_HASH_FNV1A_64"));
221 ketama_hash_settings_reverse_map.insert(std::pair<uint64_t, const std::string>
222 (MEMCACHED_HASH_FNV1_32, "MEMCACHED_HASH_FNV1_32"));
223 ketama_hash_settings_reverse_map.insert(std::pair<uint64_t, const std::string>
224 (MEMCACHED_HASH_FNV1A_32, "MEMCACHED_HASH_FNV1A_32"));
225 }
226
227 const char *func_name() const
228 {
229 return "memc_behavior_set";
230 }
231
233
234 void fix_length_and_dec()
235 {
236 max_length= 32;
237 }
238
239private:
240 void setFailureString(const char *error);
241
242 drizzled::String failure_buff;
243 drizzled::String return_buff;
244
245 /*
246 * std::map for behavioral get/set UDFs
247 */
248 std::map<const std::string, memcached_behavior> behavior_map;
249 std::map<memcached_behavior, const std::string> behavior_reverse_map;
250 std::map<uint64_t, const std::string> dist_settings_reverse_map;
251 std::map<uint64_t, const std::string> hash_settings_reverse_map;
252 std::map<uint64_t, const std::string> ketama_hash_settings_reverse_map;
253};
254
drizzled::String * val_str(drizzled::String *)