1 /* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
5 * Copyright (C) 2012 Data Differential, http://datadifferential.com/
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
14 * * Redistributions in binary form must reproduce the above
15 * copyright notice, this list of conditions and the following disclaimer
16 * in the documentation and/or other materials provided with the
19 * * The names of its contributors may not be used to endorse or
20 * promote products derived from this software without specific prior
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39 #include <libmemcached/csl/common.h>
45 %define parse.error verbose
47 %define api.prefix {config_}
48 %define api.value.type {union CONFIG_STYPE}
52 %lex-param { yyscan_t *scanner }
53 %parse-param { class Context *context }
54 %parse-param { yyscan_t *scanner }
61 #include <libmemcached/options.hpp>
63 #include <libmemcached/csl/context.h>
64 #include <libmemcached/csl/symbol.h>
65 #include <libmemcached/csl/scanner.h>
67 #ifndef __INTEL_COMPILER
68 # pragma GCC diagnostic ignored "-Wold-style-cast"
71 #ifndef __INTEL_COMPILER
73 # pragma GCC diagnostic ignored "-Wlogical-op"
74 # pragma GCC diagnostic ignored "-Wunsafe-loop-optimizations"
78 int config_lex(YYSTYPE* lvalp, void* scanner);
80 #define select_yychar(__context) yychar == UNKNOWN ? ( (__context)->previous_token == END ? UNKNOWN : (__context)->previous_token ) : yychar
82 #define stryytname(__yytokentype) ((__yytokentype) < YYNTOKENS ) ? yytname[(__yytokentype)] : ""
84 #define parser_abort(__context, __error_message) do { (__context)->abort((__error_message), config_tokentype(select_yychar(__context)), stryytname(YYTRANSLATE(select_yychar(__context)))); YYABORT; } while (0)
86 // This is bison calling error.
87 inline void __config_error(Context *context, yyscan_t *scanner, const char *error, int last_token, const char *last_token_str)
89 if (not context->end())
91 context->error(error, config_tokentype(last_token), last_token_str);
95 context->error(error, config_tokentype(last_token), last_token_str);
99 #define config_error(__context, __scanner, __error_msg) do { __config_error((__context), (__scanner), (__error_msg), select_yychar(__context), stryytname(YYTRANSLATE(select_yychar(__context)))); } while (0)
110 %token CONFIGURE_FILE
115 %token SERVERS_OPTION
116 %token UNKNOWN_OPTION
119 /* All behavior options */
120 %token BINARY_PROTOCOL
121 %token BUFFER_REQUESTS
122 %token CONNECT_TIMEOUT
125 %token HASH_WITH_NAMESPACE
126 %token IO_BYTES_WATERMARK
127 %token IO_KEY_PREFETCH
128 %token IO_MSG_WATERMARK
130 %token KETAMA_WEIGHTED
132 %token NUMBER_OF_REPLICAS
134 %token RANDOMIZE_REPLICA_READ
136 %token REMOVE_FAILED_SERVERS
139 %token SOCKET_RECV_SIZE
140 %token SOCKET_SEND_SIZE
146 %token _TCP_KEEPALIVE
175 %token <boolean> CSL_TRUE
176 %token <boolean> CSL_FALSE
181 %token <number> CSL_FLOAT
182 %token <number> NUMBER
184 %token <number> WEIGHT_START
185 %token <server> IPADDRESS
186 %token <server> HOSTNAME
187 %token <string> STRING
188 %token <string> QUOTED_STRING
189 %token <string> FILE_PATH
191 %type <behavior> behavior_boolean
192 %type <behavior> behavior_number
193 %type <distribution> distribution
195 %type <number> optional_port
196 %type <number> optional_weight
197 %type <string> string
203 | begin ' ' statement
220 context->rc= MEMCACHED_PARSE_USER_ERROR;
221 parser_abort(context, "ERROR called directly");
225 memcached_reset(context->memc);
233 if ((context->rc= memcached_parse_configure_file(*context->memc, $3.c_str, $3.size)) != MEMCACHED_SUCCESS)
235 parser_abort(context, "Failed to parse configuration file");
242 SERVER HOSTNAME optional_port optional_weight
244 if (memcached_failed(context->rc= memcached_server_add_with_weight(context->memc, $2.c_str, $3, uint32_t($4))))
247 snprintf(buffer, sizeof(buffer), "Failed to add server: %s:%u", $2.c_str, uint32_t($3));
248 parser_abort(context, buffer);
250 context->unset_server();
252 | SERVER IPADDRESS optional_port optional_weight
254 if (memcached_failed(context->rc= memcached_server_add_with_weight(context->memc, $2.c_str, $3, uint32_t($4))))
257 snprintf(buffer, sizeof(buffer), "Failed to add server: %s:%u", $2.c_str, uint32_t($3));
258 parser_abort(context, buffer);
260 context->unset_server();
262 | CSL_SOCKET string optional_weight
264 if (memcached_failed(context->rc= memcached_server_add_unix_socket_with_weight(context->memc, $2.c_str, uint32_t($3))))
267 snprintf(buffer, sizeof(buffer), "Failed to add socket: %s", $2.c_str);
268 parser_abort(context, buffer);
271 | CONFIGURE_FILE string
273 memcached_set_configuration_file(context->memc, $2.c_str, $2.size);
277 context->memc->configure.initial_pool_size= uint32_t($2);
281 context->memc->configure.max_pool_size= uint32_t($2);
289 if (memcached_callback_get(context->memc, MEMCACHED_CALLBACK_PREFIX_KEY, NULL))
291 parser_abort(context, "--NAMESPACE can only be called once");
294 if ((context->rc= memcached_set_namespace(*context->memc, $2.c_str, $2.size)) != MEMCACHED_SUCCESS)
296 parser_abort(context, memcached_last_error_message(context->memc));
301 memcached_flag(*context->memc, MEMCACHED_FLAG_IS_FETCHING_VERSION, true);
303 | DISTRIBUTION distribution
305 // Check to see if DISTRIBUTION has already been set
306 if ((context->rc= memcached_behavior_set(context->memc, MEMCACHED_BEHAVIOR_DISTRIBUTION, $2)) != MEMCACHED_SUCCESS)
308 parser_abort(context, "--DISTRIBUTION can only be called once");
311 if ((context->rc= memcached_behavior_set(context->memc, MEMCACHED_BEHAVIOR_DISTRIBUTION, $2)) != MEMCACHED_SUCCESS)
313 parser_abort(context, memcached_last_error_message(context->memc));;
316 | DISTRIBUTION distribution ',' hash
318 // Check to see if DISTRIBUTION has already been set
319 if ((context->rc= memcached_behavior_set(context->memc, MEMCACHED_BEHAVIOR_DISTRIBUTION, $2)) != MEMCACHED_SUCCESS)
321 parser_abort(context, "--DISTRIBUTION can only be called once");
324 if ((context->rc= memcached_behavior_set_distribution_hash(context->memc, $4)) != MEMCACHED_SUCCESS)
326 parser_abort(context, "Unable to set the hash for the DISTRIBUTION requested");
331 if (context->set_hash($2) == false)
333 parser_abort(context, "--HASH can only be set once");
336 | behavior_number NUMBER
338 if ((context->rc= memcached_behavior_set(context->memc, $1, $2)) != MEMCACHED_SUCCESS)
340 parser_abort(context, "Unable to set behavior");
345 if ((context->rc= memcached_behavior_set(context->memc, $1, true)) != MEMCACHED_SUCCESS)
348 snprintf(buffer, sizeof(buffer), "Could not set: %s", libmemcached_string_behavior($1));
349 parser_abort(context, buffer);
358 REMOVE_FAILED_SERVERS
360 $$= MEMCACHED_BEHAVIOR_REMOVE_FAILED_SERVERS;
364 $$= MEMCACHED_BEHAVIOR_CONNECT_TIMEOUT;
368 $$= MEMCACHED_BEHAVIOR_IO_MSG_WATERMARK;
372 $$= MEMCACHED_BEHAVIOR_IO_BYTES_WATERMARK;
376 $$= MEMCACHED_BEHAVIOR_IO_KEY_PREFETCH;
380 $$= MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS;
384 $$= MEMCACHED_BEHAVIOR_POLL_TIMEOUT;
388 $$= MEMCACHED_BEHAVIOR_RCV_TIMEOUT;
392 $$= MEMCACHED_BEHAVIOR_RETRY_TIMEOUT;
396 $$= MEMCACHED_BEHAVIOR_SND_TIMEOUT;
400 $$= MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE;
404 $$= MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE;
411 $$= MEMCACHED_BEHAVIOR_BINARY_PROTOCOL;
415 $$= MEMCACHED_BEHAVIOR_BUFFER_REQUESTS;
417 | HASH_WITH_NAMESPACE
419 $$= MEMCACHED_BEHAVIOR_HASH_WITH_PREFIX_KEY;
423 $$= MEMCACHED_BEHAVIOR_NOREPLY;
425 | RANDOMIZE_REPLICA_READ
427 $$= MEMCACHED_BEHAVIOR_RANDOMIZE_REPLICA_READ;
431 $$= MEMCACHED_BEHAVIOR_SORT_HOSTS;
435 $$= MEMCACHED_BEHAVIOR_SUPPORT_CAS;
439 $$= MEMCACHED_BEHAVIOR_TCP_NODELAY;
443 $$= MEMCACHED_BEHAVIOR_TCP_KEEPALIVE;
447 $$= MEMCACHED_BEHAVIOR_TCP_KEEPIDLE;
451 $$= MEMCACHED_BEHAVIOR_USE_UDP;
455 $$= MEMCACHED_BEHAVIOR_VERIFY_KEY;
460 { $$= MEMCACHED_DEFAULT_PORT;}
474 $$= MEMCACHED_HASH_MD5;
478 $$= MEMCACHED_HASH_CRC;
482 $$= MEMCACHED_HASH_FNV1_64;
486 $$= MEMCACHED_HASH_FNV1A_64;
490 $$= MEMCACHED_HASH_FNV1_32;
494 $$= MEMCACHED_HASH_FNV1A_32;
498 $$= MEMCACHED_HASH_HSIEH;
502 $$= MEMCACHED_HASH_MURMUR;
506 $$= MEMCACHED_HASH_JENKINS;
524 $$= MEMCACHED_DISTRIBUTION_CONSISTENT;
528 $$= MEMCACHED_DISTRIBUTION_MODULA;
532 $$= MEMCACHED_DISTRIBUTION_RANDOM;
538 void Context::start()
540 config_parse(this, (void **)scanner);