drizzle
C++ MySQL-protocol-compatible database server
Loading...
Searching...
No Matches
memc_behavior_set.h
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
41/* implements memc_behavior_set */
42class MemcachedBehaviorSet : public drizzled::Item_str_func
43{
44public:
45 MemcachedBehaviorSet()
46 :
47 Item_str_func(),
48 failure_buff("0", &drizzled::my_charset_bin),
49 success_buff("1", &drizzled::my_charset_bin),
50 behavior_map(),
51 dist_settings_map(),
52 hash_settings_map(),
53 ketama_hash_settings_map()
54 {
55 behavior_map.insert(std::pair<const std::string, memcached_behavior>
56 ("MEMCACHED_BEHAVIOR_SUPPORT_CAS", MEMCACHED_BEHAVIOR_SUPPORT_CAS));
57 behavior_map.insert(std::pair<const std::string, memcached_behavior>
58 ("MEMCACHED_BEHAVIOR_NO_BLOCK", MEMCACHED_BEHAVIOR_NO_BLOCK));
59 behavior_map.insert(std::pair<const std::string, memcached_behavior>
60 ("MEMCACHED_BEHAVIOR_TCP_NODELAY", MEMCACHED_BEHAVIOR_TCP_NODELAY));
61 behavior_map.insert(std::pair<const std::string, memcached_behavior>
62 ("MEMCACHED_BEHAVIOR_HASH", MEMCACHED_BEHAVIOR_HASH));
63 behavior_map.insert(std::pair<const std::string, memcached_behavior>
64 ("MEMCACHED_BEHAVIOR_CACHE_LOOKUPS", MEMCACHED_BEHAVIOR_CACHE_LOOKUPS));
65 behavior_map.insert(std::pair<const std::string, memcached_behavior>
66 ("MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE", MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE));
67 behavior_map.insert(std::pair<const std::string, memcached_behavior>
68 ("MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE", MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE));
69 behavior_map.insert(std::pair<const std::string, memcached_behavior>
70 ("MEMCACHED_BEHAVIOR_BUFFER_REQUESTS", MEMCACHED_BEHAVIOR_BUFFER_REQUESTS));
71 behavior_map.insert(std::pair<const std::string, memcached_behavior>
72 ("MEMCACHED_BEHAVIOR_KETAMA", MEMCACHED_BEHAVIOR_KETAMA));
73 behavior_map.insert(std::pair<const std::string, memcached_behavior>
74 ("MEMCACHED_BEHAVIOR_POLL_TIMEOUT", MEMCACHED_BEHAVIOR_POLL_TIMEOUT));
75 behavior_map.insert(std::pair<const std::string, memcached_behavior>
76 ("MEMCACHED_BEHAVIOR_RETRY_TIMEOUT", MEMCACHED_BEHAVIOR_RETRY_TIMEOUT));
77 behavior_map.insert(std::pair<const std::string, memcached_behavior>
78 ("MEMCACHED_BEHAVIOR_DISTRIBUTION", MEMCACHED_BEHAVIOR_DISTRIBUTION));
79 behavior_map.insert(std::pair<const std::string, memcached_behavior>
80 ("MEMCACHED_BEHAVIOR_USER_DATA", MEMCACHED_BEHAVIOR_USER_DATA));
81 behavior_map.insert(std::pair<const std::string, memcached_behavior>
82 ("MEMCACHED_BEHAVIOR_SORT_HOSTS", MEMCACHED_BEHAVIOR_SORT_HOSTS));
83 behavior_map.insert(std::pair<const std::string, memcached_behavior>
84 ("MEMCACHED_BEHAVIOR_VERIFY_KEY", MEMCACHED_BEHAVIOR_VERIFY_KEY));
85 behavior_map.insert(std::pair<const std::string, memcached_behavior>
86 ("MEMCACHED_BEHAVIOR_CONNECT_TIMEOUT", MEMCACHED_BEHAVIOR_CONNECT_TIMEOUT));
87 behavior_map.insert(std::pair<const std::string, memcached_behavior>
88 ("MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED", MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED));
89 behavior_map.insert(std::pair<const std::string, memcached_behavior>
90 ("MEMCACHED_BEHAVIOR_KETAMA_HASH", MEMCACHED_BEHAVIOR_KETAMA_HASH));
91 behavior_map.insert(std::pair<const std::string, memcached_behavior>
92 ("MEMCACHED_BEHAVIOR_BINARY_PROTOCOL", MEMCACHED_BEHAVIOR_BINARY_PROTOCOL));
93 behavior_map.insert(std::pair<const std::string, memcached_behavior>
94 ("MEMCACHED_BEHAVIOR_SND_TIMEOUT", MEMCACHED_BEHAVIOR_SND_TIMEOUT));
95 behavior_map.insert(std::pair<const std::string, memcached_behavior>
96 ("MEMCACHED_BEHAVIOR_RCV_TIMEOUT", MEMCACHED_BEHAVIOR_RCV_TIMEOUT));
97 behavior_map.insert(std::pair<const std::string, memcached_behavior>
98 ("MEMCACHED_BEHAVIOR_SERVER_FAILURE_LIMIT", MEMCACHED_BEHAVIOR_SERVER_FAILURE_LIMIT));
99 behavior_map.insert(std::pair<const std::string, memcached_behavior>
100 ("MEMCACHED_BEHAVIOR_IO_MSG_WATERMARK", MEMCACHED_BEHAVIOR_IO_MSG_WATERMARK));
101 behavior_map.insert(std::pair<const std::string, memcached_behavior>
102 ("MEMCACHED_BEHAVIOR_IO_BYTES_WATERMARK", MEMCACHED_BEHAVIOR_IO_BYTES_WATERMARK));
103
104 dist_settings_map.insert(std::pair<const std::string, uint64_t>
105 ("MEMCACHED_DISTRIBUTION_MODULA", MEMCACHED_DISTRIBUTION_MODULA));
106 dist_settings_map.insert(std::pair<const std::string, uint64_t>
107 ("MEMCACHED_DISTRIBUTION_CONSISTENT", MEMCACHED_DISTRIBUTION_CONSISTENT));
108 dist_settings_map.insert(std::pair<const std::string, uint64_t>
109 ("MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA", MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA));
110
111 hash_settings_map.insert(std::pair<const std::string, uint64_t>
112 ("MEMCACHED_HASH_DEFAULT", MEMCACHED_HASH_DEFAULT));
113 hash_settings_map.insert(std::pair<const std::string, uint64_t>
114 ("MEMCACHED_HASH_MD5", MEMCACHED_HASH_MD5));
115 hash_settings_map.insert(std::pair<const std::string, uint64_t>
116 ("MEMCACHED_HASH_CRC", MEMCACHED_HASH_CRC));
117 hash_settings_map.insert(std::pair<const std::string, uint64_t>
118 ("MEMCACHED_HASH_FNV1_64", MEMCACHED_HASH_FNV1_64));
119 hash_settings_map.insert(std::pair<const std::string, uint64_t>
120 ("MEMCACHED_HASH_FNV1A_64", MEMCACHED_HASH_FNV1A_64));
121 hash_settings_map.insert(std::pair<const std::string, uint64_t>
122 ("MEMCACHED_HASH_FNV1_32", MEMCACHED_HASH_FNV1_32));
123 hash_settings_map.insert(std::pair<const std::string, uint64_t>
124 ("MEMCACHED_HASH_FNV1A_32", MEMCACHED_HASH_FNV1A_32));
125 hash_settings_map.insert(std::pair<const std::string, uint64_t>
126 ("MEMCACHED_HASH_JENKINS", MEMCACHED_HASH_JENKINS));
127 hash_settings_map.insert(std::pair<const std::string, uint64_t>
128 ("MEMCACHED_HASH_HSIEH", MEMCACHED_HASH_HSIEH));
129 hash_settings_map.insert(std::pair<const std::string, uint64_t>
130 ("MEMCACHED_HASH_MURMUR", MEMCACHED_HASH_MURMUR));
131
132 ketama_hash_settings_map.insert(std::pair<const std::string, uint64_t>
133 ("MEMCACHED_HASH_DEFAULT", MEMCACHED_HASH_DEFAULT));
134 ketama_hash_settings_map.insert(std::pair<const std::string, uint64_t>
135 ("MEMCACHED_HASH_MD5", MEMCACHED_HASH_MD5));
136 ketama_hash_settings_map.insert(std::pair<const std::string, uint64_t>
137 ("MEMCACHED_HASH_CRC", MEMCACHED_HASH_CRC));
138 ketama_hash_settings_map.insert(std::pair<const std::string, uint64_t>
139 ("MEMCACHED_HASH_FNV1_64", MEMCACHED_HASH_FNV1_64));
140 ketama_hash_settings_map.insert(std::pair<const std::string, uint64_t>
141 ("MEMCACHED_HASH_FNV1A_64", MEMCACHED_HASH_FNV1A_64));
142 ketama_hash_settings_map.insert(std::pair<const std::string, uint64_t>
143 ("MEMCACHED_HASH_FNV1_32", MEMCACHED_HASH_FNV1_32));
144 ketama_hash_settings_map.insert(std::pair<const std::string, uint64_t>
145 ("MEMCACHED_HASH_FNV1A_32", MEMCACHED_HASH_FNV1A_32));
146 }
147
148 const char *func_name() const
149 {
150 return "memc_behavior_set";
151 }
152
154
155 void fix_length_and_dec()
156 {
157 max_length= 32;
158 }
159
160private:
161 void setFailureString(const char *error);
162
163 drizzled::String failure_buff;
164 drizzled::String success_buff;
165
166 std::map<const std::string, memcached_behavior> behavior_map;
167 std::map<const std::string, uint64_t> dist_settings_map;
168 std::map<const std::string, uint64_t> hash_settings_map;
169 std::map<const std::string, uint64_t> ketama_hash_settings_map;
170};
171
drizzled::String * val_str(drizzled::String *)