~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/memcached_functions/memc_behavior_get.h

  • Committer: Patrick Galbraith
  • Date: 2009-10-08 22:42:05 UTC
  • mto: (1166.5.3 memcached_functions)
  • mto: This revision was merged to the branch mainline in revision 1189.
  • Revision ID: patg@patrick-galbraiths-macbook-pro.local-20091008224205-gq1pehjsivvx0qo9
Starting over with a fresh tree, moved in memcached functions.

Memcached Functions for Drizzle. 

All tests pass.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
#ifndef DRIZZLE_PLUGIN_MEMCACHED_FUNCTIONS_MEMC_BEHAVIOR_GET_H
 
33
#define DRIZZLE_PLUGIN_MEMCACHED_FUNCTIONS_MEMC_BEHAVIOR_GET_H
 
34
 
 
35
#include <drizzled/server_includes.h>
 
36
#include <drizzled/item/func.h>
 
37
 
 
38
#include <libmemcached/memcached.h>
 
39
 
 
40
#include <map>
 
41
#include <string>
 
42
 
 
43
/**
 
44
 * @file
 
45
 *   The memc_behavior_get UDF
 
46
 */
 
47
class MemcachedBehaviorGet : public Item_str_func
 
48
{
 
49
public:
 
50
  MemcachedBehaviorGet()
 
51
    : 
 
52
      Item_str_func(),
 
53
      failure_buff("FAILURE", &my_charset_bin),
 
54
      return_buff("", &my_charset_bin),
 
55
      behavior_map(),
 
56
      behavior_reverse_map(),
 
57
      dist_settings_reverse_map(),
 
58
      hash_settings_reverse_map(),
 
59
      ketama_hash_settings_reverse_map()
 
60
  {
 
61
    /*
 
62
     * std::map for mapping string behaviors to int behavior values
 
63
     * This is used to take user input behaviors from the UDF and 
 
64
     * be able to set the correct int behavior
 
65
     */
 
66
    behavior_map.insert(std::pair<const std::string, memcached_behavior>
 
67
      ("MEMCACHED_BEHAVIOR_SUPPORT_CAS", MEMCACHED_BEHAVIOR_SUPPORT_CAS));
 
68
    behavior_map.insert(std::pair<const std::string, memcached_behavior>
 
69
      ("MEMCACHED_BEHAVIOR_NO_BLOCK", MEMCACHED_BEHAVIOR_NO_BLOCK));
 
70
    behavior_map.insert(std::pair<const std::string, memcached_behavior>
 
71
      ("MEMCACHED_BEHAVIOR_TCP_NODELAY", MEMCACHED_BEHAVIOR_TCP_NODELAY));
 
72
    behavior_map.insert(std::pair<const std::string, memcached_behavior>
 
73
      ("MEMCACHED_BEHAVIOR_HASH", MEMCACHED_BEHAVIOR_HASH));
 
74
    behavior_map.insert(std::pair<const std::string, memcached_behavior>
 
75
      ("MEMCACHED_BEHAVIOR_CACHE_LOOKUPS", MEMCACHED_BEHAVIOR_CACHE_LOOKUPS));
 
76
    behavior_map.insert(std::pair<const std::string, memcached_behavior>
 
77
      ("MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE", MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE));
 
78
    behavior_map.insert(std::pair<const std::string, memcached_behavior>
 
79
      ("MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE", MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE));
 
80
    behavior_map.insert(std::pair<const std::string, memcached_behavior>
 
81
      ("MEMCACHED_BEHAVIOR_BUFFER_REQUESTS", MEMCACHED_BEHAVIOR_BUFFER_REQUESTS));
 
82
    behavior_map.insert(std::pair<const std::string, memcached_behavior>
 
83
      ("MEMCACHED_BEHAVIOR_KETAMA", MEMCACHED_BEHAVIOR_KETAMA));
 
84
    behavior_map.insert(std::pair<const std::string, memcached_behavior>
 
85
      ("MEMCACHED_BEHAVIOR_POLL_TIMEOUT", MEMCACHED_BEHAVIOR_POLL_TIMEOUT));
 
86
    behavior_map.insert(std::pair<const std::string, memcached_behavior>
 
87
      ("MEMCACHED_BEHAVIOR_RETRY_TIMEOUT", MEMCACHED_BEHAVIOR_RETRY_TIMEOUT));
 
88
    behavior_map.insert(std::pair<const std::string, memcached_behavior>
 
89
      ("MEMCACHED_BEHAVIOR_DISTRIBUTION", MEMCACHED_BEHAVIOR_DISTRIBUTION));
 
90
    behavior_map.insert(std::pair<const std::string, memcached_behavior>
 
91
      ("MEMCACHED_BEHAVIOR_USER_DATA", MEMCACHED_BEHAVIOR_USER_DATA));
 
92
    behavior_map.insert(std::pair<const std::string, memcached_behavior>
 
93
      ("MEMCACHED_BEHAVIOR_SORT_HOSTS", MEMCACHED_BEHAVIOR_SORT_HOSTS));
 
94
    behavior_map.insert(std::pair<const std::string, memcached_behavior>
 
95
      ("MEMCACHED_BEHAVIOR_VERIFY_KEY", MEMCACHED_BEHAVIOR_VERIFY_KEY));
 
96
    behavior_map.insert(std::pair<const std::string, memcached_behavior>
 
97
      ("MEMCACHED_BEHAVIOR_CONNECT_TIMEOUT", MEMCACHED_BEHAVIOR_CONNECT_TIMEOUT));
 
98
    behavior_map.insert(std::pair<const std::string, memcached_behavior>
 
99
      ("MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED", MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED));
 
100
    behavior_map.insert(std::pair<const std::string, memcached_behavior>
 
101
      ("MEMCACHED_BEHAVIOR_KETAMA_HASH", MEMCACHED_BEHAVIOR_KETAMA_HASH));
 
102
    behavior_map.insert(std::pair<const std::string, memcached_behavior>
 
103
      ("MEMCACHED_BEHAVIOR_BINARY_PROTOCOL", MEMCACHED_BEHAVIOR_BINARY_PROTOCOL));
 
104
    behavior_map.insert(std::pair<const std::string, memcached_behavior>
 
105
      ("MEMCACHED_BEHAVIOR_SND_TIMEOUT", MEMCACHED_BEHAVIOR_SND_TIMEOUT));
 
106
    behavior_map.insert(std::pair<const std::string, memcached_behavior>
 
107
      ("MEMCACHED_BEHAVIOR_RCV_TIMEOUT", MEMCACHED_BEHAVIOR_RCV_TIMEOUT));
 
108
    behavior_map.insert(std::pair<const std::string, memcached_behavior>
 
109
      ("MEMCACHED_BEHAVIOR_SERVER_FAILURE_LIMIT", MEMCACHED_BEHAVIOR_SERVER_FAILURE_LIMIT));
 
110
    behavior_map.insert(std::pair<const std::string, memcached_behavior>
 
111
      ("MEMCACHED_BEHAVIOR_IO_MSG_WATERMARK", MEMCACHED_BEHAVIOR_IO_MSG_WATERMARK));
 
112
    behavior_map.insert(std::pair<const std::string, memcached_behavior>
 
113
      ("MEMCACHED_BEHAVIOR_IO_BYTES_WATERMARK", MEMCACHED_BEHAVIOR_IO_BYTES_WATERMARK));
 
114
 
 
115
    /*
 
116
     * std::map for mapping int behavior values to behavior strings
 
117
     * This is used to take int behaviors from the the clien and be
 
118
     * able to print the string value of the behavior in memc_behavior_get 
 
119
     * UDF 
 
120
     */
 
121
    behavior_reverse_map.insert(std::pair<memcached_behavior, const std::string>
 
122
      (MEMCACHED_BEHAVIOR_SUPPORT_CAS, "MEMCACHED_BEHAVIOR_SUPPORT_CAS"));
 
123
    behavior_reverse_map.insert(std::pair<memcached_behavior,const std::string>
 
124
      (MEMCACHED_BEHAVIOR_NO_BLOCK, "MEMCACHED_BEHAVIOR_NO_BLOCK"));
 
125
    behavior_reverse_map.insert(std::pair<memcached_behavior,const std::string>
 
126
      (MEMCACHED_BEHAVIOR_TCP_NODELAY, "MEMCACHED_BEHAVIOR_TCP_NODELAY"));
 
127
    behavior_reverse_map.insert(std::pair<memcached_behavior,const std::string>
 
128
      (MEMCACHED_BEHAVIOR_HASH, "MEMCACHED_BEHAVIOR_HASH"));
 
129
    behavior_reverse_map.insert(std::pair<memcached_behavior,const std::string>
 
130
      (MEMCACHED_BEHAVIOR_CACHE_LOOKUPS, "MEMCACHED_BEHAVIOR_CACHE_LOOKUPS"));
 
131
    behavior_reverse_map.insert(std::pair<memcached_behavior,const std::string>
 
132
      (MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE, "MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE"));
 
133
    behavior_reverse_map.insert(std::pair<memcached_behavior,const std::string>
 
134
      (MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE, "MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE"));
 
135
    behavior_reverse_map.insert(std::pair<memcached_behavior,const std::string>
 
136
      (MEMCACHED_BEHAVIOR_BUFFER_REQUESTS, "MEMCACHED_BEHAVIOR_BUFFER_REQUESTS"));
 
137
    behavior_reverse_map.insert(std::pair<memcached_behavior,const std::string>
 
138
      (MEMCACHED_BEHAVIOR_KETAMA, "MEMCACHED_BEHAVIOR_KETAMA"));
 
139
    behavior_reverse_map.insert(std::pair<memcached_behavior,const std::string>
 
140
      (MEMCACHED_BEHAVIOR_POLL_TIMEOUT, "MEMCACHED_BEHAVIOR_POLL_TIMEOUT"));
 
141
    behavior_reverse_map.insert(std::pair<memcached_behavior,const std::string>
 
142
      (MEMCACHED_BEHAVIOR_RETRY_TIMEOUT, "MEMCACHED_BEHAVIOR_RETRY_TIMEOUT"));
 
143
    behavior_reverse_map.insert(std::pair<memcached_behavior,const std::string>
 
144
      (MEMCACHED_BEHAVIOR_DISTRIBUTION, "MEMCACHED_BEHAVIOR_DISTRIBUTION"));
 
145
    behavior_reverse_map.insert(std::pair<memcached_behavior,const std::string>
 
146
      (MEMCACHED_BEHAVIOR_USER_DATA, "MEMCACHED_BEHAVIOR_USER_DATA"));
 
147
    behavior_reverse_map.insert(std::pair<memcached_behavior,const std::string>
 
148
      (MEMCACHED_BEHAVIOR_SORT_HOSTS, "MEMCACHED_BEHAVIOR_SORT_HOSTS"));
 
149
    behavior_reverse_map.insert(std::pair<memcached_behavior,const std::string>
 
150
      (MEMCACHED_BEHAVIOR_VERIFY_KEY, "MEMCACHED_BEHAVIOR_VERIFY_KEY"));
 
151
    behavior_reverse_map.insert(std::pair<memcached_behavior,const std::string>
 
152
      (MEMCACHED_BEHAVIOR_CONNECT_TIMEOUT, "MEMCACHED_BEHAVIOR_CONNECT_TIMEOUT"));
 
153
    behavior_reverse_map.insert(std::pair<memcached_behavior,const std::string>
 
154
      (MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED, "MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED"));
 
155
    behavior_reverse_map.insert(std::pair<memcached_behavior,const std::string>
 
156
      (MEMCACHED_BEHAVIOR_KETAMA_HASH, "MEMCACHED_BEHAVIOR_KETAMA_HASH"));
 
157
    behavior_reverse_map.insert(std::pair<memcached_behavior,const std::string>
 
158
      (MEMCACHED_BEHAVIOR_BINARY_PROTOCOL, "MEMCACHED_BEHAVIOR_BINARY_PROTOCOL"));
 
159
    behavior_reverse_map.insert(std::pair<memcached_behavior,const std::string>
 
160
      (MEMCACHED_BEHAVIOR_SND_TIMEOUT, "MEMCACHED_BEHAVIOR_SND_TIMEOUT"));
 
161
    behavior_reverse_map.insert(std::pair<memcached_behavior,const std::string>
 
162
      (MEMCACHED_BEHAVIOR_RCV_TIMEOUT, "MEMCACHED_BEHAVIOR_RCV_TIMEOUT"));
 
163
    behavior_reverse_map.insert(std::pair<memcached_behavior,const std::string>
 
164
      (MEMCACHED_BEHAVIOR_SERVER_FAILURE_LIMIT, "MEMCACHED_BEHAVIOR_SERVER_FAILURE_LIMIT"));
 
165
    behavior_reverse_map.insert(std::pair<memcached_behavior,const std::string>
 
166
      (MEMCACHED_BEHAVIOR_IO_MSG_WATERMARK, "MEMCACHED_BEHAVIOR_IO_MSG_WATERMARK"));
 
167
    behavior_reverse_map.insert(std::pair<memcached_behavior,const std::string>
 
168
      (MEMCACHED_BEHAVIOR_IO_BYTES_WATERMARK, "MEMCACHED_BEHAVIOR_IO_BYTES_WATERMARK"));
 
169
 
 
170
    /*
 
171
     * std::map for mapping distribution string values to int distribution values
 
172
     * For being able to map int distribution values to string distribution values
 
173
     * Used by memc_behavior_get() for distribution types
 
174
     */
 
175
    dist_settings_reverse_map.insert(std::pair<uint64_t, const std::string>
 
176
      (MEMCACHED_DISTRIBUTION_MODULA, "MEMCACHED_DISTRIBUTION_MODULA"));
 
177
    dist_settings_reverse_map.insert(std::pair<uint64_t, const std::string>
 
178
      (MEMCACHED_DISTRIBUTION_CONSISTENT, "MEMCACHED_DISTRIBUTION_CONSISTENT"));
 
179
    dist_settings_reverse_map.insert(std::pair<uint64_t, const std::string>
 
180
      (MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA, "MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA"));
 
181
 
 
182
    /*
 
183
     * std::map for mapping distribution string values to int distribution values
 
184
     * For being able to map int distribution values to string distribution values
 
185
     * Used by memc_behavior_get() for hash types
 
186
     */
 
187
    hash_settings_reverse_map.insert(std::pair<uint64_t, const std::string>
 
188
      (MEMCACHED_HASH_DEFAULT, "MEMCACHED_HASH_DEFAULT"));
 
189
    hash_settings_reverse_map.insert(std::pair<uint64_t, const std::string>
 
190
      (MEMCACHED_HASH_MD5, "MEMCACHED_HASH_MD5"));
 
191
    hash_settings_reverse_map.insert(std::pair<uint64_t, const std::string>
 
192
      (MEMCACHED_HASH_CRC, "MEMCACHED_HASH_CRC"));
 
193
    hash_settings_reverse_map.insert(std::pair<uint64_t, const std::string>
 
194
      (MEMCACHED_HASH_FNV1_64, "MEMCACHED_HASH_FNV1_64"));
 
195
    hash_settings_reverse_map.insert(std::pair<uint64_t, const std::string>
 
196
      (MEMCACHED_HASH_FNV1A_64, "MEMCACHED_HASH_FNV1A_64"));
 
197
    hash_settings_reverse_map.insert(std::pair<uint64_t, const std::string>
 
198
      (MEMCACHED_HASH_FNV1_32, "MEMCACHED_HASH_FNV1_32"));
 
199
    hash_settings_reverse_map.insert(std::pair<uint64_t, const std::string>
 
200
      (MEMCACHED_HASH_FNV1A_32, "MEMCACHED_HASH_FNV1A_32"));
 
201
    hash_settings_reverse_map.insert(std::pair<uint64_t, const std::string>
 
202
      (MEMCACHED_HASH_JENKINS, "MEMCACHED_HASH_JENKINS"));
 
203
    hash_settings_reverse_map.insert(std::pair<uint64_t, const std::string>
 
204
      (MEMCACHED_HASH_HSIEH, "MEMCACHED_HASH_HSIEH"));
 
205
    hash_settings_reverse_map.insert(std::pair<uint64_t, const std::string>
 
206
      (MEMCACHED_HASH_MURMUR, "MEMCACHED_HASH_MURMUR"));
 
207
 
 
208
    /*
 
209
     * std::map for mapping distribution string values to int distribution values
 
210
     * For being able to map int distribution values to string distribution values
 
211
     * Used by memc_behavior_get() for ketama hash types
 
212
     */
 
213
    ketama_hash_settings_reverse_map.insert(std::pair<uint64_t, const std::string>
 
214
      (MEMCACHED_HASH_DEFAULT, "MEMCACHED_HASH_DEFAULT"));
 
215
    ketama_hash_settings_reverse_map.insert(std::pair<uint64_t, const std::string>
 
216
      (MEMCACHED_HASH_MD5, "MEMCACHED_HASH_MD5"));
 
217
    ketama_hash_settings_reverse_map.insert(std::pair<uint64_t, const std::string>
 
218
      (MEMCACHED_HASH_CRC, "MEMCACHED_HASH_CRC"));
 
219
    ketama_hash_settings_reverse_map.insert(std::pair<uint64_t, const std::string>
 
220
      (MEMCACHED_HASH_FNV1_64, "MEMCACHED_HASH_FNV1_64"));
 
221
    ketama_hash_settings_reverse_map.insert(std::pair<uint64_t, const std::string>
 
222
      (MEMCACHED_HASH_FNV1A_64, "MEMCACHED_HASH_FNV1A_64"));
 
223
    ketama_hash_settings_reverse_map.insert(std::pair<uint64_t, const std::string>
 
224
      (MEMCACHED_HASH_FNV1_32, "MEMCACHED_HASH_FNV1_32"));
 
225
    ketama_hash_settings_reverse_map.insert(std::pair<uint64_t, const std::string>
 
226
      (MEMCACHED_HASH_FNV1A_32, "MEMCACHED_HASH_FNV1A_32"));
 
227
  }
 
228
 
 
229
  const char *func_name() const
 
230
  {
 
231
    return "memc_behavior_set";
 
232
  }
 
233
 
 
234
  String *val_str(String *);
 
235
 
 
236
  void fix_length_and_dec()
 
237
  {
 
238
    max_length= 32;
 
239
  }
 
240
 
 
241
private:
 
242
  void setFailureString(const char *error);
 
243
 
 
244
  String failure_buff;
 
245
  String return_buff;
 
246
 
 
247
  /*
 
248
   * std::map for behavioral get/set UDFs
 
249
   */
 
250
  std::map<const std::string, memcached_behavior> behavior_map;
 
251
  std::map<memcached_behavior, const std::string> behavior_reverse_map;
 
252
  std::map<uint64_t, const std::string> dist_settings_reverse_map;
 
253
  std::map<uint64_t, const std::string> hash_settings_reverse_map;
 
254
  std::map<uint64_t, const std::string> ketama_hash_settings_reverse_map;
 
255
};
 
256
 
 
257
#endif /* DRIZZLE_PLUGIN_MEMCACHED_FUNCTIONS_MEMC_BEHAVIOR_GET_H */