1 /* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
5 * Copyright (C) 2011 Data Differential, http://datadifferential.com/
6 * Copyright (C) 2006-2009 Brian Aker All rights reserved.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are
12 * * Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
15 * * Redistributions in binary form must reproduce the above
16 * copyright notice, this list of conditions and the following disclaimer
17 * in the documentation and/or other materials provided with the
20 * * The names of its contributors may not be used to endorse or
21 * promote products derived from this software without specific prior
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
27 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
28 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
29 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
30 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
31 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
32 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
33 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
34 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 #include <libmemcached/common.h>
39 #include <libmemcached/options.hpp>
40 #include <libmemcached/virtual_bucket.h>
43 #include <sys/types.h>
45 bool memcached_is_consistent_distribution(const memcached_st
* memc
)
47 switch (memc
->distribution
)
49 case MEMCACHED_DISTRIBUTION_CONSISTENT
:
50 case MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA
:
51 case MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA_SPY
:
52 case MEMCACHED_DISTRIBUTION_CONSISTENT_WEIGHTED
:
55 case MEMCACHED_DISTRIBUTION_MODULA
:
56 case MEMCACHED_DISTRIBUTION_RANDOM
:
57 case MEMCACHED_DISTRIBUTION_VIRTUAL_BUCKET
:
58 case MEMCACHED_DISTRIBUTION_CONSISTENT_MAX
:
66 This function is used to modify the behavior of running client.
68 We quit all connections so we can reset the sockets.
71 memcached_return_t
memcached_behavior_set(memcached_st
*ptr
,
72 const memcached_behavior_t flag
,
77 return MEMCACHED_INVALID_ARGUMENTS
;
82 case MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS
:
83 ptr
->number_of_replicas
= (uint32_t)data
;
86 case MEMCACHED_BEHAVIOR_IO_MSG_WATERMARK
:
87 ptr
->io_msg_watermark
= (uint32_t) data
;
90 case MEMCACHED_BEHAVIOR_IO_BYTES_WATERMARK
:
91 ptr
->io_bytes_watermark
= (uint32_t)data
;
94 case MEMCACHED_BEHAVIOR_IO_KEY_PREFETCH
:
95 ptr
->io_key_prefetch
= (uint32_t)data
;
98 case MEMCACHED_BEHAVIOR_SND_TIMEOUT
:
99 ptr
->snd_timeout
= (int32_t)data
;
102 case MEMCACHED_BEHAVIOR_RCV_TIMEOUT
:
103 ptr
->rcv_timeout
= (int32_t)data
;
106 case MEMCACHED_BEHAVIOR_REMOVE_FAILED_SERVERS
:
107 ptr
->flags
.auto_eject_hosts
= bool(data
);
109 case MEMCACHED_BEHAVIOR_SERVER_FAILURE_LIMIT
:
112 return memcached_set_error(*ptr
, MEMCACHED_INVALID_ARGUMENTS
, MEMCACHED_AT
,
113 memcached_literal_param("MEMCACHED_BEHAVIOR_SERVER_FAILURE_LIMIT requires a value greater then zero."));
115 ptr
->server_failure_limit
= uint32_t(data
);
118 case MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
:
119 send_quit(ptr
); // We need t shutdown all of the connections to make sure we do the correct protocol
122 ptr
->flags
.verify_key
= false;
124 ptr
->flags
.binary_protocol
= bool(data
);
127 case MEMCACHED_BEHAVIOR_SUPPORT_CAS
:
128 ptr
->flags
.support_cas
= bool(data
);
131 case MEMCACHED_BEHAVIOR_NO_BLOCK
:
132 ptr
->flags
.no_block
= bool(data
);
136 case MEMCACHED_BEHAVIOR_BUFFER_REQUESTS
:
137 if (memcached_is_udp(ptr
))
139 return memcached_set_error(*ptr
, MEMCACHED_INVALID_ARGUMENTS
, MEMCACHED_AT
,
140 memcached_literal_param("MEMCACHED_BEHAVIOR_BUFFER_REQUESTS cannot be set while MEMCACHED_BEHAVIOR_USE_UDP is enabled."));
142 ptr
->flags
.buffer_requests
= bool(data
);
146 case MEMCACHED_BEHAVIOR_USE_UDP
:
147 send_quit(ptr
); // We need t shutdown all of the connections to make sure we do the correct protocol
148 ptr
->flags
.use_udp
= bool(data
);
151 ptr
->flags
.reply
= false;
152 ptr
->flags
.buffer_requests
= false;
156 ptr
->flags
.reply
= true;
160 case MEMCACHED_BEHAVIOR_TCP_NODELAY
:
161 ptr
->flags
.tcp_nodelay
= bool(data
);
165 case MEMCACHED_BEHAVIOR_TCP_KEEPALIVE
:
166 ptr
->flags
.tcp_keepalive
= bool(data
);
170 case MEMCACHED_BEHAVIOR_DISTRIBUTION
:
171 return memcached_behavior_set_distribution(ptr
, (memcached_server_distribution_t
)data
);
173 case MEMCACHED_BEHAVIOR_KETAMA
:
177 return memcached_behavior_set_distribution(ptr
, MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA
);
180 return memcached_behavior_set_distribution(ptr
, MEMCACHED_DISTRIBUTION_MODULA
);
183 case MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED
:
185 if (bool(data
) == false)
187 return memcached_behavior_set(ptr
, MEMCACHED_BEHAVIOR_KETAMA
, true);
190 (void)memcached_behavior_set_key_hash(ptr
, MEMCACHED_HASH_MD5
);
191 (void)memcached_behavior_set_distribution_hash(ptr
, MEMCACHED_HASH_MD5
);
193 @note We try to keep the same distribution going. This should be deprecated and rewritten.
195 return memcached_behavior_set_distribution(ptr
, MEMCACHED_DISTRIBUTION_CONSISTENT_WEIGHTED
);
198 case MEMCACHED_BEHAVIOR_HASH
:
199 return memcached_behavior_set_key_hash(ptr
, (memcached_hash_t
)(data
));
201 case MEMCACHED_BEHAVIOR_KETAMA_HASH
:
202 return memcached_behavior_set_distribution_hash(ptr
, (memcached_hash_t
)(data
));
204 case MEMCACHED_BEHAVIOR_CACHE_LOOKUPS
:
205 return memcached_set_error(*ptr
, MEMCACHED_DEPRECATED
, MEMCACHED_AT
,
206 memcached_literal_param("MEMCACHED_BEHAVIOR_CACHE_LOOKUPS has been deprecated."));
208 case MEMCACHED_BEHAVIOR_VERIFY_KEY
:
209 if (ptr
->flags
.binary_protocol
)
211 return memcached_set_error(*ptr
, MEMCACHED_INVALID_ARGUMENTS
, MEMCACHED_AT
,
212 memcached_literal_param("MEMCACHED_BEHAVIOR_VERIFY_KEY if the binary protocol has been enabled."));
214 ptr
->flags
.verify_key
= bool(data
);
217 case MEMCACHED_BEHAVIOR_SORT_HOSTS
:
219 ptr
->flags
.use_sort_hosts
= bool(data
);
220 return run_distribution(ptr
);
223 case MEMCACHED_BEHAVIOR_POLL_TIMEOUT
:
224 ptr
->poll_timeout
= (int32_t)data
;
227 case MEMCACHED_BEHAVIOR_CONNECT_TIMEOUT
:
228 ptr
->connect_timeout
= (int32_t)data
;
231 case MEMCACHED_BEHAVIOR_RETRY_TIMEOUT
:
234 return memcached_set_error(*ptr
, MEMCACHED_INVALID_ARGUMENTS
, MEMCACHED_AT
,
235 memcached_literal_param("MEMCACHED_BEHAVIOR_RETRY_TIMEOUT requires a value greater then zero."));
237 ptr
->retry_timeout
= int32_t(data
);
240 case MEMCACHED_BEHAVIOR_DEAD_TIMEOUT
:
241 ptr
->dead_timeout
= int32_t(data
);
244 case MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE
:
245 ptr
->send_size
= (int32_t)data
;
249 case MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE
:
250 ptr
->recv_size
= (int32_t)data
;
254 case MEMCACHED_BEHAVIOR_TCP_KEEPIDLE
:
255 ptr
->tcp_keepidle
= (uint32_t)data
;
259 case MEMCACHED_BEHAVIOR_USER_DATA
:
260 return memcached_set_error(*ptr
, MEMCACHED_DEPRECATED
, MEMCACHED_AT
,
261 memcached_literal_param("MEMCACHED_BEHAVIOR_USER_DATA deprecated."));
263 case MEMCACHED_BEHAVIOR_HASH_WITH_PREFIX_KEY
:
264 ptr
->flags
.hash_with_namespace
= bool(data
);
267 case MEMCACHED_BEHAVIOR_NOREPLY
:
268 if (memcached_is_udp(ptr
) and bool(data
) == false)
270 return memcached_set_error(*ptr
, MEMCACHED_INVALID_ARGUMENTS
, MEMCACHED_AT
,
271 memcached_literal_param("MEMCACHED_BEHAVIOR_NOREPLY cannot be disabled while MEMCACHED_BEHAVIOR_USE_UDP is enabled."));
273 // We reverse the logic here to make it easier to understand throughout the
275 ptr
->flags
.reply
= bool(data
) ? false : true;
278 case MEMCACHED_BEHAVIOR_AUTO_EJECT_HOSTS
:
279 ptr
->flags
.auto_eject_hosts
= bool(data
);
282 case MEMCACHED_BEHAVIOR_RANDOMIZE_REPLICA_READ
:
283 srandom((uint32_t) time(NULL
));
284 ptr
->flags
.randomize_replica_read
= bool(data
);
287 case MEMCACHED_BEHAVIOR_CORK
:
288 return memcached_set_error(*ptr
, MEMCACHED_DEPRECATED
, MEMCACHED_AT
,
289 memcached_literal_param("MEMCACHED_BEHAVIOR_CORK is now incorporated into the driver by default."));
291 case MEMCACHED_BEHAVIOR_LOAD_FROM_FILE
:
292 return memcached_set_error(*ptr
, MEMCACHED_INVALID_ARGUMENTS
, MEMCACHED_AT
,
293 memcached_literal_param("MEMCACHED_BEHAVIOR_LOAD_FROM_FILE can not be set with memcached_behavior_set()"));
295 case MEMCACHED_BEHAVIOR_MAX
:
297 /* Shouldn't get here */
298 assert_msg(0, "Invalid behavior passed to memcached_behavior_set()");
299 return memcached_set_error(*ptr
, MEMCACHED_INVALID_ARGUMENTS
, MEMCACHED_AT
,
300 memcached_literal_param("Invalid behavior passed to memcached_behavior_set()"));
303 return MEMCACHED_SUCCESS
;
306 bool _is_auto_eject_host(const memcached_st
*ptr
)
308 return ptr
->flags
.auto_eject_hosts
;
311 uint64_t memcached_behavior_get(memcached_st
*ptr
,
312 const memcached_behavior_t flag
)
316 return MEMCACHED_INVALID_ARGUMENTS
;
321 case MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS
:
322 return ptr
->number_of_replicas
;
324 case MEMCACHED_BEHAVIOR_IO_MSG_WATERMARK
:
325 return ptr
->io_msg_watermark
;
327 case MEMCACHED_BEHAVIOR_IO_BYTES_WATERMARK
:
328 return ptr
->io_bytes_watermark
;
330 case MEMCACHED_BEHAVIOR_IO_KEY_PREFETCH
:
331 return ptr
->io_key_prefetch
;
333 case MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
:
334 return ptr
->flags
.binary_protocol
;
336 case MEMCACHED_BEHAVIOR_SUPPORT_CAS
:
337 return ptr
->flags
.support_cas
;
339 case MEMCACHED_BEHAVIOR_CACHE_LOOKUPS
:
342 case MEMCACHED_BEHAVIOR_NO_BLOCK
:
343 return ptr
->flags
.no_block
;
345 case MEMCACHED_BEHAVIOR_BUFFER_REQUESTS
:
346 return ptr
->flags
.buffer_requests
;
348 case MEMCACHED_BEHAVIOR_USE_UDP
:
349 return memcached_is_udp(ptr
);
351 case MEMCACHED_BEHAVIOR_TCP_NODELAY
:
352 return ptr
->flags
.tcp_nodelay
;
354 case MEMCACHED_BEHAVIOR_VERIFY_KEY
:
355 return ptr
->flags
.verify_key
;
357 case MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED
:
358 if (memcached_is_consistent_distribution(ptr
))
360 return memcached_is_weighted_ketama(ptr
);
364 case MEMCACHED_BEHAVIOR_DISTRIBUTION
:
365 return ptr
->distribution
;
367 case MEMCACHED_BEHAVIOR_KETAMA
:
368 return memcached_is_consistent_distribution(ptr
);
370 case MEMCACHED_BEHAVIOR_HASH
:
371 return hashkit_get_function(&ptr
->hashkit
);
373 case MEMCACHED_BEHAVIOR_KETAMA_HASH
:
374 return hashkit_get_function(&ptr
->hashkit
);
376 case MEMCACHED_BEHAVIOR_REMOVE_FAILED_SERVERS
:
377 case MEMCACHED_BEHAVIOR_SERVER_FAILURE_LIMIT
:
378 return ptr
->server_failure_limit
;
380 case MEMCACHED_BEHAVIOR_SORT_HOSTS
:
381 return ptr
->flags
.use_sort_hosts
;
383 case MEMCACHED_BEHAVIOR_POLL_TIMEOUT
:
384 return (uint64_t)ptr
->poll_timeout
;
386 case MEMCACHED_BEHAVIOR_CONNECT_TIMEOUT
:
387 return (uint64_t)ptr
->connect_timeout
;
389 case MEMCACHED_BEHAVIOR_RETRY_TIMEOUT
:
390 return (uint64_t)ptr
->retry_timeout
;
392 case MEMCACHED_BEHAVIOR_DEAD_TIMEOUT
:
393 return uint64_t(ptr
->dead_timeout
);
395 case MEMCACHED_BEHAVIOR_SND_TIMEOUT
:
396 return (uint64_t)ptr
->snd_timeout
;
398 case MEMCACHED_BEHAVIOR_RCV_TIMEOUT
:
399 return (uint64_t)ptr
->rcv_timeout
;
401 case MEMCACHED_BEHAVIOR_TCP_KEEPIDLE
:
402 return (uint64_t)ptr
->tcp_keepidle
;
404 case MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE
:
407 socklen_t sock_length
= sizeof(int);
409 if (ptr
->send_size
!= -1) // If value is -1 then we are using the default
411 return (uint64_t) ptr
->send_size
;
414 org::libmemcached::Instance
* instance
= memcached_instance_fetch(ptr
, 0);
416 if (instance
) // If we have an instance we test, otherwise we just set and pray
419 /* We just try the first host, and if it is down we return zero */
420 if (memcached_failed(memcached_connect(instance
)))
425 if (memcached_failed(memcached_io_wait_for_write(instance
)))
430 if (getsockopt(instance
->fd
, SOL_SOCKET
, SO_SNDBUF
, &sock_size
, &sock_length
) < 0)
432 memcached_set_errno(*ptr
, get_socket_errno(), MEMCACHED_AT
);
433 return 0; /* Zero means error */
437 return (uint64_t) sock_size
;
440 case MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE
:
443 socklen_t sock_length
= sizeof(int);
445 if (ptr
->recv_size
!= -1) // If value is -1 then we are using the default
446 return (uint64_t) ptr
->recv_size
;
448 org::libmemcached::Instance
* instance
= memcached_instance_fetch(ptr
, 0);
455 /* We just try the first host, and if it is down we return zero */
456 if (memcached_failed(memcached_connect(instance
)))
461 if (memcached_failed(memcached_io_wait_for_write(instance
)))
466 if (getsockopt(instance
->fd
, SOL_SOCKET
, SO_RCVBUF
, &sock_size
, &sock_length
) < 0)
468 memcached_set_errno(*ptr
, get_socket_errno(), MEMCACHED_AT
);
469 return 0; /* Zero means error */
473 return (uint64_t) sock_size
;
476 case MEMCACHED_BEHAVIOR_USER_DATA
:
477 memcached_set_error(*ptr
, MEMCACHED_DEPRECATED
, MEMCACHED_AT
,
478 memcached_literal_param("MEMCACHED_BEHAVIOR_USER_DATA deprecated."));
481 case MEMCACHED_BEHAVIOR_HASH_WITH_PREFIX_KEY
:
482 return ptr
->flags
.hash_with_namespace
;
484 case MEMCACHED_BEHAVIOR_NOREPLY
:
485 return ptr
->flags
.reply
? false : true;
487 case MEMCACHED_BEHAVIOR_AUTO_EJECT_HOSTS
:
488 return ptr
->flags
.auto_eject_hosts
;
490 case MEMCACHED_BEHAVIOR_RANDOMIZE_REPLICA_READ
:
491 return ptr
->flags
.randomize_replica_read
;
493 case MEMCACHED_BEHAVIOR_CORK
:
500 case MEMCACHED_BEHAVIOR_TCP_KEEPALIVE
:
501 return ptr
->flags
.tcp_keepalive
;
503 case MEMCACHED_BEHAVIOR_LOAD_FROM_FILE
:
504 return bool(memcached_parse_filename(ptr
));
506 case MEMCACHED_BEHAVIOR_MAX
:
508 assert_msg(0, "Invalid behavior passed to memcached_behavior_set()");
516 memcached_return_t
memcached_behavior_set_distribution(memcached_st
*ptr
, memcached_server_distribution_t type
)
520 case MEMCACHED_DISTRIBUTION_MODULA
:
523 case MEMCACHED_DISTRIBUTION_CONSISTENT
:
524 case MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA
:
525 memcached_set_weighted_ketama(ptr
, false);
528 case MEMCACHED_DISTRIBUTION_RANDOM
:
531 case MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA_SPY
:
534 case MEMCACHED_DISTRIBUTION_CONSISTENT_WEIGHTED
:
535 memcached_set_weighted_ketama(ptr
, true);
538 case MEMCACHED_DISTRIBUTION_VIRTUAL_BUCKET
:
542 case MEMCACHED_DISTRIBUTION_CONSISTENT_MAX
:
543 return memcached_set_error(*ptr
, MEMCACHED_INVALID_ARGUMENTS
, MEMCACHED_AT
,
544 memcached_literal_param("Invalid memcached_server_distribution_t"));
546 ptr
->distribution
= type
;
548 return run_distribution(ptr
);
552 memcached_server_distribution_t
memcached_behavior_get_distribution(memcached_st
*ptr
)
554 return ptr
->distribution
;
557 memcached_return_t
memcached_behavior_set_key_hash(memcached_st
*ptr
, memcached_hash_t type
)
559 if (hashkit_success(hashkit_set_function(&ptr
->hashkit
, (hashkit_hash_algorithm_t
)type
)))
561 return MEMCACHED_SUCCESS
;
564 return memcached_set_error(*ptr
, MEMCACHED_INVALID_ARGUMENTS
, MEMCACHED_AT
,
565 memcached_literal_param("Invalid memcached_hash_t()"));
568 memcached_hash_t
memcached_behavior_get_key_hash(memcached_st
*ptr
)
570 return (memcached_hash_t
)hashkit_get_function(&ptr
->hashkit
);
573 memcached_return_t
memcached_behavior_set_distribution_hash(memcached_st
*ptr
, memcached_hash_t type
)
575 if (hashkit_success(hashkit_set_distribution_function(&ptr
->hashkit
, (hashkit_hash_algorithm_t
)type
)))
577 return MEMCACHED_SUCCESS
;
580 return memcached_set_error(*ptr
, MEMCACHED_INVALID_ARGUMENTS
, MEMCACHED_AT
,
581 memcached_literal_param("Invalid memcached_hash_t()"));
584 memcached_hash_t
memcached_behavior_get_distribution_hash(memcached_st
*ptr
)
586 return (memcached_hash_t
)hashkit_get_function(&ptr
->hashkit
);
589 const char *libmemcached_string_behavior(const memcached_behavior_t flag
)
593 case MEMCACHED_BEHAVIOR_NO_BLOCK
: return "MEMCACHED_BEHAVIOR_NO_BLOCK";
594 case MEMCACHED_BEHAVIOR_TCP_NODELAY
: return "MEMCACHED_BEHAVIOR_TCP_NODELAY";
595 case MEMCACHED_BEHAVIOR_HASH
: return "MEMCACHED_BEHAVIOR_HASH";
596 case MEMCACHED_BEHAVIOR_KETAMA
: return "MEMCACHED_BEHAVIOR_KETAMA";
597 case MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE
: return "MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE";
598 case MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE
: return "MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE";
599 case MEMCACHED_BEHAVIOR_CACHE_LOOKUPS
: return "MEMCACHED_BEHAVIOR_CACHE_LOOKUPS";
600 case MEMCACHED_BEHAVIOR_SUPPORT_CAS
: return "MEMCACHED_BEHAVIOR_SUPPORT_CAS";
601 case MEMCACHED_BEHAVIOR_POLL_TIMEOUT
: return "MEMCACHED_BEHAVIOR_POLL_TIMEOUT";
602 case MEMCACHED_BEHAVIOR_DISTRIBUTION
: return "MEMCACHED_BEHAVIOR_DISTRIBUTION";
603 case MEMCACHED_BEHAVIOR_BUFFER_REQUESTS
: return "MEMCACHED_BEHAVIOR_BUFFER_REQUESTS";
604 case MEMCACHED_BEHAVIOR_USER_DATA
: return "MEMCACHED_BEHAVIOR_USER_DATA";
605 case MEMCACHED_BEHAVIOR_SORT_HOSTS
: return "MEMCACHED_BEHAVIOR_SORT_HOSTS";
606 case MEMCACHED_BEHAVIOR_VERIFY_KEY
: return "MEMCACHED_BEHAVIOR_VERIFY_KEY";
607 case MEMCACHED_BEHAVIOR_CONNECT_TIMEOUT
: return "MEMCACHED_BEHAVIOR_CONNECT_TIMEOUT";
608 case MEMCACHED_BEHAVIOR_RETRY_TIMEOUT
: return "MEMCACHED_BEHAVIOR_RETRY_TIMEOUT";
609 case MEMCACHED_BEHAVIOR_DEAD_TIMEOUT
: return "MEMCACHED_BEHAVIOR_DEAD_TIMEOUT";
610 case MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED
: return "MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED";
611 case MEMCACHED_BEHAVIOR_KETAMA_HASH
: return "MEMCACHED_BEHAVIOR_KETAMA_HASH";
612 case MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
: return "MEMCACHED_BEHAVIOR_BINARY_PROTOCOL";
613 case MEMCACHED_BEHAVIOR_SND_TIMEOUT
: return "MEMCACHED_BEHAVIOR_SND_TIMEOUT";
614 case MEMCACHED_BEHAVIOR_RCV_TIMEOUT
: return "MEMCACHED_BEHAVIOR_RCV_TIMEOUT";
615 case MEMCACHED_BEHAVIOR_SERVER_FAILURE_LIMIT
: return "MEMCACHED_BEHAVIOR_SERVER_FAILURE_LIMIT";
616 case MEMCACHED_BEHAVIOR_IO_MSG_WATERMARK
: return "MEMCACHED_BEHAVIOR_IO_MSG_WATERMARK";
617 case MEMCACHED_BEHAVIOR_IO_BYTES_WATERMARK
: return "MEMCACHED_BEHAVIOR_IO_BYTES_WATERMARK";
618 case MEMCACHED_BEHAVIOR_IO_KEY_PREFETCH
: return "MEMCACHED_BEHAVIOR_IO_KEY_PREFETCH";
619 case MEMCACHED_BEHAVIOR_HASH_WITH_PREFIX_KEY
: return "MEMCACHED_BEHAVIOR_HASH_WITH_PREFIX_KEY";
620 case MEMCACHED_BEHAVIOR_NOREPLY
: return "MEMCACHED_BEHAVIOR_NOREPLY";
621 case MEMCACHED_BEHAVIOR_USE_UDP
: return "MEMCACHED_BEHAVIOR_USE_UDP";
622 case MEMCACHED_BEHAVIOR_AUTO_EJECT_HOSTS
: return "MEMCACHED_BEHAVIOR_AUTO_EJECT_HOSTS";
623 case MEMCACHED_BEHAVIOR_REMOVE_FAILED_SERVERS
: return "MEMCACHED_BEHAVIOR_REMOVE_FAILED_SERVERS";
624 case MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS
: return "MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS";
625 case MEMCACHED_BEHAVIOR_RANDOMIZE_REPLICA_READ
: return "MEMCACHED_BEHAVIOR_RANDOMIZE_REPLICA_READ";
626 case MEMCACHED_BEHAVIOR_CORK
: return "MEMCACHED_BEHAVIOR_CORK";
627 case MEMCACHED_BEHAVIOR_TCP_KEEPALIVE
: return "MEMCACHED_BEHAVIOR_TCP_KEEPALIVE";
628 case MEMCACHED_BEHAVIOR_TCP_KEEPIDLE
: return "MEMCACHED_BEHAVIOR_TCP_KEEPIDLE";
629 case MEMCACHED_BEHAVIOR_LOAD_FROM_FILE
: return "MEMCACHED_BEHAVIOR_LOAD_FROM_FILE";
631 case MEMCACHED_BEHAVIOR_MAX
: return "INVALID memcached_behavior_t";
635 const char *libmemcached_string_distribution(const memcached_server_distribution_t flag
)
639 case MEMCACHED_DISTRIBUTION_MODULA
: return "MEMCACHED_DISTRIBUTION_MODULA";
640 case MEMCACHED_DISTRIBUTION_CONSISTENT
: return "MEMCACHED_DISTRIBUTION_CONSISTENT";
641 case MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA
: return "MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA";
642 case MEMCACHED_DISTRIBUTION_RANDOM
: return "MEMCACHED_DISTRIBUTION_RANDOM";
643 case MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA_SPY
: return "MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA_SPY";
644 case MEMCACHED_DISTRIBUTION_CONSISTENT_WEIGHTED
: return "MEMCACHED_DISTRIBUTION_CONSISTENT_WEIGHTED";
645 case MEMCACHED_DISTRIBUTION_VIRTUAL_BUCKET
: return "MEMCACHED_DISTRIBUTION_VIRTUAL_BUCKET";
647 case MEMCACHED_DISTRIBUTION_CONSISTENT_MAX
: return "INVALID memcached_server_distribution_t";
651 memcached_return_t
memcached_bucket_set(memcached_st
*self
,
652 const uint32_t *host_map
,
653 const uint32_t *forward_map
,
654 const uint32_t buckets
,
655 const uint32_t replicas
)
657 memcached_return_t rc
;
661 return MEMCACHED_INVALID_ARGUMENTS
;
664 if (host_map
== NULL
)
666 return MEMCACHED_INVALID_ARGUMENTS
;
669 memcached_server_distribution_t old
= memcached_behavior_get_distribution(self
);
671 if (memcached_failed(rc
=memcached_behavior_set_distribution(self
, MEMCACHED_DISTRIBUTION_VIRTUAL_BUCKET
)))
676 if (memcached_failed(rc
= memcached_virtual_bucket_create(self
, host_map
, forward_map
, buckets
, replicas
)))
678 memcached_behavior_set_distribution(self
, old
);