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>
46 This function is used to modify the behavior of running client.
48 We quit all connections so we can reset the sockets.
51 memcached_return_t
memcached_behavior_set(memcached_st
*ptr
,
52 const memcached_behavior_t flag
,
57 return MEMCACHED_INVALID_ARGUMENTS
;
62 case MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS
:
63 ptr
->number_of_replicas
= (uint32_t)data
;
66 case MEMCACHED_BEHAVIOR_IO_MSG_WATERMARK
:
67 ptr
->io_msg_watermark
= (uint32_t) data
;
70 case MEMCACHED_BEHAVIOR_IO_BYTES_WATERMARK
:
71 ptr
->io_bytes_watermark
= (uint32_t)data
;
74 case MEMCACHED_BEHAVIOR_IO_KEY_PREFETCH
:
75 ptr
->io_key_prefetch
= (uint32_t)data
;
78 case MEMCACHED_BEHAVIOR_SND_TIMEOUT
:
79 ptr
->snd_timeout
= (int32_t)data
;
82 case MEMCACHED_BEHAVIOR_RCV_TIMEOUT
:
83 ptr
->rcv_timeout
= (int32_t)data
;
86 case MEMCACHED_BEHAVIOR_REMOVE_FAILED_SERVERS
:
87 ptr
->flags
.auto_eject_hosts
= bool(data
);
89 case MEMCACHED_BEHAVIOR_SERVER_FAILURE_LIMIT
:
92 return memcached_set_error(*ptr
, MEMCACHED_INVALID_ARGUMENTS
, MEMCACHED_AT
,
93 memcached_literal_param("MEMCACHED_BEHAVIOR_SERVER_FAILURE_LIMIT requires a value greater then zero."));
95 ptr
->server_failure_limit
= uint32_t(data
);
98 case MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
:
99 send_quit(ptr
); // We need t shutdown all of the connections to make sure we do the correct protocol
102 ptr
->flags
.verify_key
= false;
104 ptr
->flags
.binary_protocol
= bool(data
);
107 case MEMCACHED_BEHAVIOR_SUPPORT_CAS
:
108 ptr
->flags
.support_cas
= bool(data
);
111 case MEMCACHED_BEHAVIOR_NO_BLOCK
:
112 ptr
->flags
.no_block
= bool(data
);
116 case MEMCACHED_BEHAVIOR_BUFFER_REQUESTS
:
117 if (ptr
->flags
.use_udp
)
119 return memcached_set_error(*ptr
, MEMCACHED_INVALID_ARGUMENTS
, MEMCACHED_AT
,
120 memcached_literal_param("MEMCACHED_BEHAVIOR_BUFFER_REQUESTS cannot be set while MEMCACHED_BEHAVIOR_USE_UDP is enabled."));
122 ptr
->flags
.buffer_requests
= bool(data
);
126 case MEMCACHED_BEHAVIOR_USE_UDP
:
127 send_quit(ptr
); // We need t shutdown all of the connections to make sure we do the correct protocol
128 ptr
->flags
.use_udp
= bool(data
);
131 ptr
->flags
.no_reply
= true;
132 ptr
->flags
.buffer_requests
= false;
136 case MEMCACHED_BEHAVIOR_TCP_NODELAY
:
137 ptr
->flags
.tcp_nodelay
= bool(data
);
141 case MEMCACHED_BEHAVIOR_TCP_KEEPALIVE
:
142 ptr
->flags
.tcp_keepalive
= bool(data
);
146 case MEMCACHED_BEHAVIOR_DISTRIBUTION
:
147 return memcached_behavior_set_distribution(ptr
, (memcached_server_distribution_t
)data
);
149 case MEMCACHED_BEHAVIOR_KETAMA
:
152 return memcached_behavior_set_distribution(ptr
, MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA
);
154 return memcached_behavior_set_distribution(ptr
, MEMCACHED_DISTRIBUTION_MODULA
);
157 case MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED
:
159 (void)memcached_behavior_set_key_hash(ptr
, MEMCACHED_HASH_MD5
);
160 (void)memcached_behavior_set_distribution_hash(ptr
, MEMCACHED_HASH_MD5
);
161 ptr
->ketama
.weighted
= bool(data
);
163 @note We try to keep the same distribution going. This should be deprecated and rewritten.
165 return memcached_behavior_set_distribution(ptr
, MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA
);
168 case MEMCACHED_BEHAVIOR_HASH
:
169 return memcached_behavior_set_key_hash(ptr
, (memcached_hash_t
)(data
));
171 case MEMCACHED_BEHAVIOR_KETAMA_HASH
:
172 return memcached_behavior_set_distribution_hash(ptr
, (memcached_hash_t
)(data
));
174 case MEMCACHED_BEHAVIOR_CACHE_LOOKUPS
:
175 return memcached_set_error(*ptr
, MEMCACHED_DEPRECATED
, MEMCACHED_AT
,
176 memcached_literal_param("MEMCACHED_BEHAVIOR_CACHE_LOOKUPS has been deprecated."));
178 case MEMCACHED_BEHAVIOR_VERIFY_KEY
:
179 if (ptr
->flags
.binary_protocol
)
180 return memcached_set_error(*ptr
, MEMCACHED_INVALID_ARGUMENTS
, MEMCACHED_AT
,
181 memcached_literal_param("MEMCACHED_BEHAVIOR_VERIFY_KEY if the binary protocol has been enabled."));
182 ptr
->flags
.verify_key
= bool(data
);
185 case MEMCACHED_BEHAVIOR_SORT_HOSTS
:
187 ptr
->flags
.use_sort_hosts
= bool(data
);
188 run_distribution(ptr
);
193 case MEMCACHED_BEHAVIOR_POLL_TIMEOUT
:
194 ptr
->poll_timeout
= (int32_t)data
;
197 case MEMCACHED_BEHAVIOR_CONNECT_TIMEOUT
:
198 ptr
->connect_timeout
= (int32_t)data
;
201 case MEMCACHED_BEHAVIOR_RETRY_TIMEOUT
:
204 return memcached_set_error(*ptr
, MEMCACHED_INVALID_ARGUMENTS
, MEMCACHED_AT
,
205 memcached_literal_param("MEMCACHED_BEHAVIOR_RETRY_TIMEOUT requires a value greater then zero."));
207 ptr
->retry_timeout
= int32_t(data
);
210 case MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE
:
211 ptr
->send_size
= (int32_t)data
;
215 case MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE
:
216 ptr
->recv_size
= (int32_t)data
;
220 case MEMCACHED_BEHAVIOR_TCP_KEEPIDLE
:
221 ptr
->tcp_keepidle
= (uint32_t)data
;
225 case MEMCACHED_BEHAVIOR_USER_DATA
:
226 return memcached_set_error(*ptr
, MEMCACHED_DEPRECATED
, MEMCACHED_AT
,
227 memcached_literal_param("MEMCACHED_BEHAVIOR_USER_DATA deprecated."));
229 case MEMCACHED_BEHAVIOR_HASH_WITH_PREFIX_KEY
:
230 ptr
->flags
.hash_with_namespace
= bool(data
);
233 case MEMCACHED_BEHAVIOR_NOREPLY
:
234 if (ptr
->flags
.use_udp
and bool(data
) == false)
236 return memcached_set_error(*ptr
, MEMCACHED_INVALID_ARGUMENTS
, MEMCACHED_AT
,
237 memcached_literal_param("MEMCACHED_BEHAVIOR_NOREPLY cannot be disabled while MEMCACHED_BEHAVIOR_USE_UDP is enabled."));
239 ptr
->flags
.no_reply
= bool(data
);
242 case MEMCACHED_BEHAVIOR_AUTO_EJECT_HOSTS
:
243 ptr
->flags
.auto_eject_hosts
= bool(data
);
246 case MEMCACHED_BEHAVIOR_RANDOMIZE_REPLICA_READ
:
247 srandom((uint32_t) time(NULL
));
248 ptr
->flags
.randomize_replica_read
= bool(data
);
251 case MEMCACHED_BEHAVIOR_CORK
:
252 return memcached_set_error(*ptr
, MEMCACHED_DEPRECATED
, MEMCACHED_AT
,
253 memcached_literal_param("MEMCACHED_BEHAVIOR_CORK is now incorporated into the driver by default."));
255 case MEMCACHED_BEHAVIOR_LOAD_FROM_FILE
:
256 return memcached_set_error(*ptr
, MEMCACHED_INVALID_ARGUMENTS
, MEMCACHED_AT
,
257 memcached_literal_param("MEMCACHED_BEHAVIOR_LOAD_FROM_FILE can not be set with memcached_behavior_set()"));
259 case MEMCACHED_BEHAVIOR_MAX
:
261 /* Shouldn't get here */
262 assert_msg(0, "Invalid behavior passed to memcached_behavior_set()");
263 return memcached_set_error(*ptr
, MEMCACHED_INVALID_ARGUMENTS
, MEMCACHED_AT
,
264 memcached_literal_param("Invalid behavior passed to memcached_behavior_set()"));
267 return MEMCACHED_SUCCESS
;
270 bool _is_auto_eject_host(const memcached_st
*ptr
)
272 return ptr
->flags
.auto_eject_hosts
;
275 uint64_t memcached_behavior_get(memcached_st
*ptr
,
276 const memcached_behavior_t flag
)
280 return MEMCACHED_INVALID_ARGUMENTS
;
285 case MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS
:
286 return ptr
->number_of_replicas
;
288 case MEMCACHED_BEHAVIOR_IO_MSG_WATERMARK
:
289 return ptr
->io_msg_watermark
;
291 case MEMCACHED_BEHAVIOR_IO_BYTES_WATERMARK
:
292 return ptr
->io_bytes_watermark
;
294 case MEMCACHED_BEHAVIOR_IO_KEY_PREFETCH
:
295 return ptr
->io_key_prefetch
;
297 case MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
:
298 return ptr
->flags
.binary_protocol
;
300 case MEMCACHED_BEHAVIOR_SUPPORT_CAS
:
301 return ptr
->flags
.support_cas
;
303 case MEMCACHED_BEHAVIOR_CACHE_LOOKUPS
:
306 case MEMCACHED_BEHAVIOR_NO_BLOCK
:
307 return ptr
->flags
.no_block
;
309 case MEMCACHED_BEHAVIOR_BUFFER_REQUESTS
:
310 return ptr
->flags
.buffer_requests
;
312 case MEMCACHED_BEHAVIOR_USE_UDP
:
313 return ptr
->flags
.use_udp
;
315 case MEMCACHED_BEHAVIOR_TCP_NODELAY
:
316 return ptr
->flags
.tcp_nodelay
;
318 case MEMCACHED_BEHAVIOR_VERIFY_KEY
:
319 return ptr
->flags
.verify_key
;
321 case MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED
:
322 return ptr
->ketama
.weighted
;
324 case MEMCACHED_BEHAVIOR_DISTRIBUTION
:
325 return ptr
->distribution
;
327 case MEMCACHED_BEHAVIOR_KETAMA
:
328 return (ptr
->distribution
== MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA
) ? (uint64_t) 1 : 0;
330 case MEMCACHED_BEHAVIOR_HASH
:
331 return hashkit_get_function(&ptr
->hashkit
);
333 case MEMCACHED_BEHAVIOR_KETAMA_HASH
:
334 return hashkit_get_function(&ptr
->hashkit
);
336 case MEMCACHED_BEHAVIOR_REMOVE_FAILED_SERVERS
:
337 case MEMCACHED_BEHAVIOR_SERVER_FAILURE_LIMIT
:
338 return ptr
->server_failure_limit
;
340 case MEMCACHED_BEHAVIOR_SORT_HOSTS
:
341 return ptr
->flags
.use_sort_hosts
;
343 case MEMCACHED_BEHAVIOR_POLL_TIMEOUT
:
344 return (uint64_t)ptr
->poll_timeout
;
346 case MEMCACHED_BEHAVIOR_CONNECT_TIMEOUT
:
347 return (uint64_t)ptr
->connect_timeout
;
349 case MEMCACHED_BEHAVIOR_RETRY_TIMEOUT
:
350 return (uint64_t)ptr
->retry_timeout
;
352 case MEMCACHED_BEHAVIOR_SND_TIMEOUT
:
353 return (uint64_t)ptr
->snd_timeout
;
355 case MEMCACHED_BEHAVIOR_RCV_TIMEOUT
:
356 return (uint64_t)ptr
->rcv_timeout
;
358 case MEMCACHED_BEHAVIOR_TCP_KEEPIDLE
:
359 return (uint64_t)ptr
->tcp_keepidle
;
361 case MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE
:
364 socklen_t sock_length
= sizeof(int);
366 if (ptr
->send_size
!= -1) // If value is -1 then we are using the default
367 return (uint64_t) ptr
->send_size
;
369 memcached_server_write_instance_st instance
= memcached_server_instance_fetch(ptr
, 0);
371 if (instance
) // If we have an instance we test, otherwise we just set and pray
374 /* We just try the first host, and if it is down we return zero */
375 if (memcached_failed(memcached_connect(instance
)))
380 if (memcached_failed(memcached_io_wait_for_write(instance
)))
385 if (getsockopt(instance
->fd
, SOL_SOCKET
, SO_SNDBUF
, &sock_size
, &sock_length
) < 0)
387 memcached_set_errno(*ptr
, errno
, MEMCACHED_AT
);
388 return 0; /* Zero means error */
392 return (uint64_t) sock_size
;
395 case MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE
:
398 socklen_t sock_length
= sizeof(int);
400 if (ptr
->recv_size
!= -1) // If value is -1 then we are using the default
401 return (uint64_t) ptr
->recv_size
;
403 memcached_server_write_instance_st instance
= memcached_server_instance_fetch(ptr
, 0);
410 /* We just try the first host, and if it is down we return zero */
411 if (memcached_failed(memcached_connect(instance
)))
416 if (memcached_failed(memcached_io_wait_for_write(instance
)))
421 if (getsockopt(instance
->fd
, SOL_SOCKET
, SO_RCVBUF
, &sock_size
, &sock_length
) < 0)
423 memcached_set_errno(*ptr
, errno
, MEMCACHED_AT
);
424 return 0; /* Zero means error */
429 return (uint64_t) sock_size
;
432 case MEMCACHED_BEHAVIOR_USER_DATA
:
433 memcached_set_error(*ptr
, MEMCACHED_DEPRECATED
, MEMCACHED_AT
,
434 memcached_literal_param("MEMCACHED_BEHAVIOR_USER_DATA deprecated."));
437 case MEMCACHED_BEHAVIOR_HASH_WITH_PREFIX_KEY
:
438 return ptr
->flags
.hash_with_namespace
;
440 case MEMCACHED_BEHAVIOR_NOREPLY
:
441 return ptr
->flags
.no_reply
;
443 case MEMCACHED_BEHAVIOR_AUTO_EJECT_HOSTS
:
444 return ptr
->flags
.auto_eject_hosts
;
446 case MEMCACHED_BEHAVIOR_RANDOMIZE_REPLICA_READ
:
447 return ptr
->flags
.randomize_replica_read
;
449 case MEMCACHED_BEHAVIOR_CORK
:
456 case MEMCACHED_BEHAVIOR_TCP_KEEPALIVE
:
457 return ptr
->flags
.tcp_keepalive
;
459 case MEMCACHED_BEHAVIOR_LOAD_FROM_FILE
:
460 return bool(memcached_parse_filename(ptr
));
462 case MEMCACHED_BEHAVIOR_MAX
:
464 assert_msg(0, "Invalid behavior passed to memcached_behavior_set()");
472 memcached_return_t
memcached_behavior_set_distribution(memcached_st
*ptr
, memcached_server_distribution_t type
)
474 if (type
< MEMCACHED_DISTRIBUTION_CONSISTENT_MAX
)
476 if (MEMCACHED_DISTRIBUTION_CONSISTENT_WEIGHTED
)
478 ptr
->ketama
.weighted
= true;
482 ptr
->ketama
.weighted
= false;
485 ptr
->distribution
= type
;
486 run_distribution(ptr
);
488 return MEMCACHED_SUCCESS
;
491 return memcached_set_error(*ptr
, MEMCACHED_INVALID_ARGUMENTS
, MEMCACHED_AT
,
492 memcached_literal_param("Invalid memcached_server_distribution_t"));
496 memcached_server_distribution_t
memcached_behavior_get_distribution(memcached_st
*ptr
)
498 return ptr
->distribution
;
501 memcached_return_t
memcached_behavior_set_key_hash(memcached_st
*ptr
, memcached_hash_t type
)
503 if (hashkit_success(hashkit_set_function(&ptr
->hashkit
, (hashkit_hash_algorithm_t
)type
)))
505 return MEMCACHED_SUCCESS
;
508 return memcached_set_error(*ptr
, MEMCACHED_INVALID_ARGUMENTS
, MEMCACHED_AT
,
509 memcached_literal_param("Invalid memcached_hash_t()"));
512 memcached_hash_t
memcached_behavior_get_key_hash(memcached_st
*ptr
)
514 return (memcached_hash_t
)hashkit_get_function(&ptr
->hashkit
);
517 memcached_return_t
memcached_behavior_set_distribution_hash(memcached_st
*ptr
, memcached_hash_t type
)
519 if (hashkit_success(hashkit_set_distribution_function(&ptr
->hashkit
, (hashkit_hash_algorithm_t
)type
)))
520 return MEMCACHED_SUCCESS
;
522 return memcached_set_error(*ptr
, MEMCACHED_INVALID_ARGUMENTS
, MEMCACHED_AT
,
523 memcached_literal_param("Invalid memcached_hash_t()"));
526 memcached_hash_t
memcached_behavior_get_distribution_hash(memcached_st
*ptr
)
528 return (memcached_hash_t
)hashkit_get_function(&ptr
->hashkit
);
531 const char *libmemcached_string_behavior(const memcached_behavior_t flag
)
535 case MEMCACHED_BEHAVIOR_NO_BLOCK
: return "MEMCACHED_BEHAVIOR_NO_BLOCK";
536 case MEMCACHED_BEHAVIOR_TCP_NODELAY
: return "MEMCACHED_BEHAVIOR_TCP_NODELAY";
537 case MEMCACHED_BEHAVIOR_HASH
: return "MEMCACHED_BEHAVIOR_HASH";
538 case MEMCACHED_BEHAVIOR_KETAMA
: return "MEMCACHED_BEHAVIOR_KETAMA";
539 case MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE
: return "MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE";
540 case MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE
: return "MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE";
541 case MEMCACHED_BEHAVIOR_CACHE_LOOKUPS
: return "MEMCACHED_BEHAVIOR_CACHE_LOOKUPS";
542 case MEMCACHED_BEHAVIOR_SUPPORT_CAS
: return "MEMCACHED_BEHAVIOR_SUPPORT_CAS";
543 case MEMCACHED_BEHAVIOR_POLL_TIMEOUT
: return "MEMCACHED_BEHAVIOR_POLL_TIMEOUT";
544 case MEMCACHED_BEHAVIOR_DISTRIBUTION
: return "MEMCACHED_BEHAVIOR_DISTRIBUTION";
545 case MEMCACHED_BEHAVIOR_BUFFER_REQUESTS
: return "MEMCACHED_BEHAVIOR_BUFFER_REQUESTS";
546 case MEMCACHED_BEHAVIOR_USER_DATA
: return "MEMCACHED_BEHAVIOR_USER_DATA";
547 case MEMCACHED_BEHAVIOR_SORT_HOSTS
: return "MEMCACHED_BEHAVIOR_SORT_HOSTS";
548 case MEMCACHED_BEHAVIOR_VERIFY_KEY
: return "MEMCACHED_BEHAVIOR_VERIFY_KEY";
549 case MEMCACHED_BEHAVIOR_CONNECT_TIMEOUT
: return "MEMCACHED_BEHAVIOR_CONNECT_TIMEOUT";
550 case MEMCACHED_BEHAVIOR_RETRY_TIMEOUT
: return "MEMCACHED_BEHAVIOR_RETRY_TIMEOUT";
551 case MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED
: return "MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED";
552 case MEMCACHED_BEHAVIOR_KETAMA_HASH
: return "MEMCACHED_BEHAVIOR_KETAMA_HASH";
553 case MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
: return "MEMCACHED_BEHAVIOR_BINARY_PROTOCOL";
554 case MEMCACHED_BEHAVIOR_SND_TIMEOUT
: return "MEMCACHED_BEHAVIOR_SND_TIMEOUT";
555 case MEMCACHED_BEHAVIOR_RCV_TIMEOUT
: return "MEMCACHED_BEHAVIOR_RCV_TIMEOUT";
556 case MEMCACHED_BEHAVIOR_SERVER_FAILURE_LIMIT
: return "MEMCACHED_BEHAVIOR_SERVER_FAILURE_LIMIT";
557 case MEMCACHED_BEHAVIOR_IO_MSG_WATERMARK
: return "MEMCACHED_BEHAVIOR_IO_MSG_WATERMARK";
558 case MEMCACHED_BEHAVIOR_IO_BYTES_WATERMARK
: return "MEMCACHED_BEHAVIOR_IO_BYTES_WATERMARK";
559 case MEMCACHED_BEHAVIOR_IO_KEY_PREFETCH
: return "MEMCACHED_BEHAVIOR_IO_KEY_PREFETCH";
560 case MEMCACHED_BEHAVIOR_HASH_WITH_PREFIX_KEY
: return "MEMCACHED_BEHAVIOR_HASH_WITH_PREFIX_KEY";
561 case MEMCACHED_BEHAVIOR_NOREPLY
: return "MEMCACHED_BEHAVIOR_NOREPLY";
562 case MEMCACHED_BEHAVIOR_USE_UDP
: return "MEMCACHED_BEHAVIOR_USE_UDP";
563 case MEMCACHED_BEHAVIOR_AUTO_EJECT_HOSTS
: return "MEMCACHED_BEHAVIOR_AUTO_EJECT_HOSTS";
564 case MEMCACHED_BEHAVIOR_REMOVE_FAILED_SERVERS
: return "MEMCACHED_BEHAVIOR_REMOVE_FAILED_SERVERS";
565 case MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS
: return "MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS";
566 case MEMCACHED_BEHAVIOR_RANDOMIZE_REPLICA_READ
: return "MEMCACHED_BEHAVIOR_RANDOMIZE_REPLICA_READ";
567 case MEMCACHED_BEHAVIOR_CORK
: return "MEMCACHED_BEHAVIOR_CORK";
568 case MEMCACHED_BEHAVIOR_TCP_KEEPALIVE
: return "MEMCACHED_BEHAVIOR_TCP_KEEPALIVE";
569 case MEMCACHED_BEHAVIOR_TCP_KEEPIDLE
: return "MEMCACHED_BEHAVIOR_TCP_KEEPIDLE";
570 case MEMCACHED_BEHAVIOR_LOAD_FROM_FILE
: return "MEMCACHED_BEHAVIOR_LOAD_FROM_FILE";
572 case MEMCACHED_BEHAVIOR_MAX
: return "INVALID memcached_behavior_t";
576 const char *libmemcached_string_distribution(const memcached_server_distribution_t flag
)
580 case MEMCACHED_DISTRIBUTION_MODULA
: return "MEMCACHED_DISTRIBUTION_MODULA";
581 case MEMCACHED_DISTRIBUTION_CONSISTENT
: return "MEMCACHED_DISTRIBUTION_CONSISTENT";
582 case MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA
: return "MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA";
583 case MEMCACHED_DISTRIBUTION_RANDOM
: return "MEMCACHED_DISTRIBUTION_RANDOM";
584 case MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA_SPY
: return "MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA_SPY";
585 case MEMCACHED_DISTRIBUTION_CONSISTENT_WEIGHTED
: return "MEMCACHED_DISTRIBUTION_CONSISTENT_WEIGHTED";
586 case MEMCACHED_DISTRIBUTION_VIRTUAL_BUCKET
: return "MEMCACHED_DISTRIBUTION_VIRTUAL_BUCKET";
588 case MEMCACHED_DISTRIBUTION_CONSISTENT_MAX
: return "INVALID memcached_server_distribution_t";
592 memcached_return_t
memcached_bucket_set(memcached_st
*self
,
593 const uint32_t *host_map
,
594 const uint32_t *forward_map
,
595 const uint32_t buckets
,
596 const uint32_t replicas
)
598 memcached_return_t rc
;
601 return MEMCACHED_INVALID_ARGUMENTS
;
604 return MEMCACHED_INVALID_ARGUMENTS
;
606 memcached_server_distribution_t old
= memcached_behavior_get_distribution(self
);
608 if (memcached_failed(rc
=memcached_behavior_set_distribution(self
, MEMCACHED_DISTRIBUTION_VIRTUAL_BUCKET
)))
613 if (memcached_failed(rc
= memcached_virtual_bucket_create(self
, host_map
, forward_map
, buckets
, replicas
)))
615 memcached_behavior_set_distribution(self
, old
);