*
*/
-#include "common.h"
+#include <libmemcached/common.h>
+#include <libmemcached/virtual_bucket.h>
+
#include <time.h>
#include <sys/types.h>
{
(void)memcached_behavior_set_key_hash(ptr, MEMCACHED_HASH_MD5);
(void)memcached_behavior_set_distribution_hash(ptr, MEMCACHED_HASH_MD5);
- ptr->flags.ketama_weighted= set_flag(data);
+ ptr->ketama.weighted= set_flag(data);
/**
@note We try to keep the same distribution going. This should be deprecated and rewritten.
*/
break;
case MEMCACHED_BEHAVIOR_CORK:
{
- memcached_server_write_instance_st instance;
- bool action= set_flag(data);
-
- if (action == false)
- {
- ptr->flags.cork= set_flag(false);
- return MEMCACHED_SUCCESS;
- }
-
- instance= memcached_server_instance_fetch(ptr, 0);
- if (! instance)
- return MEMCACHED_NO_SERVERS;
-
-
- /* We just try the first host, and if it is down we return zero */
- memcached_return_t rc;
- rc= memcached_connect(instance);
- if (rc != MEMCACHED_SUCCESS)
- {
- return rc;
- }
-
- /* Now we test! */
- memcached_ternary_t enabled;
- enabled= test_cork(instance, true);
-
- switch (enabled)
- {
- case MEM_FALSE:
- return memcached_last_error_errno(ptr) ? MEMCACHED_ERRNO : MEMCACHED_FAILURE ;
- case MEM_TRUE:
- {
- enabled= test_cork(instance, false);
-
- if (enabled == false) // Possible bug in OS?
- {
- memcached_quit_server(instance, false); // We should reset everything on this error.
- return MEMCACHED_ERRNO; // Errno will be true because we will have already set it.
- }
- ptr->flags.cork= true;
- ptr->flags.tcp_nodelay= true;
- memcached_quit(ptr); // We go on and reset the connections.
- }
- break;
- case MEM_NOT:
- default:
- return memcached_set_error_string(ptr, MEMCACHED_NOT_SUPPORTED,
- memcached_string_with_size("MEMCACHED_BEHAVIOR_CORK is not supported on this platform."));
- }
+#ifdef HAVE_MSG_MORE
+ break;
+#else
+ return memcached_set_error_string(ptr, MEMCACHED_NOT_SUPPORTED,
+ memcached_string_with_size("MEMCACHED_BEHAVIOR_CORK is not supported on this platform."));
+#endif
}
break;
case MEMCACHED_BEHAVIOR_LOAD_FROM_FILE:
case MEMCACHED_BEHAVIOR_VERIFY_KEY:
return ptr->flags.verify_key;
case MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED:
- return ptr->flags.ketama_weighted;
+ return ptr->ketama.weighted;
case MEMCACHED_BEHAVIOR_DISTRIBUTION:
return ptr->distribution;
case MEMCACHED_BEHAVIOR_KETAMA:
case MEMCACHED_BEHAVIOR_RANDOMIZE_REPLICA_READ:
return ptr->flags.randomize_replica_read;
case MEMCACHED_BEHAVIOR_CORK:
- return ptr->flags.cork;
+#ifdef HAVE_MSG_MORE
+ return true;
+#else
+ return false;
+#endif
case MEMCACHED_BEHAVIOR_TCP_KEEPALIVE:
return ptr->flags.tcp_keepalive;
case MEMCACHED_BEHAVIOR_LOAD_FROM_FILE:
{
if (type < MEMCACHED_DISTRIBUTION_CONSISTENT_MAX)
{
+ if (MEMCACHED_DISTRIBUTION_CONSISTENT_WEIGHTED)
+ {
+ ptr->ketama.weighted= true;
+ }
+ else
+ {
+ ptr->ketama.weighted= false;
+ }
ptr->distribution= type;
run_distribution(ptr);
return MEMCACHED_SUCCESS;
case MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA: return "MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA";
case MEMCACHED_DISTRIBUTION_RANDOM: return "MEMCACHED_DISTRIBUTION_RANDOM";
case MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA_SPY: return "MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA_SPY";
+ case MEMCACHED_DISTRIBUTION_CONSISTENT_WEIGHTED: return "MEMCACHED_DISTRIBUTION_CONSISTENT_WEIGHTED";
+ case MEMCACHED_DISTRIBUTION_VIRTUAL_BUCKET: return "MEMCACHED_DISTRIBUTION_VIRTUAL_BUCKET";
default:
case MEMCACHED_DISTRIBUTION_CONSISTENT_MAX: return "INVALID memcached_server_distribution_t";
}
}
+
+memcached_return_t memcached_bucket_set(memcached_st *self,
+ const uint32_t *host_map,
+ const uint32_t *forward_map,
+ const uint32_t buckets,
+ const uint32_t replicas)
+{
+ memcached_return_t rc;
+
+ if (! self)
+ return MEMCACHED_INVALID_ARGUMENTS;
+
+ if (! host_map)
+ return MEMCACHED_INVALID_ARGUMENTS;
+
+ memcached_server_distribution_t old;
+ old= memcached_behavior_get_distribution(self);
+
+ rc =memcached_behavior_set_distribution(self, MEMCACHED_DISTRIBUTION_VIRTUAL_BUCKET);
+ if (rc != MEMCACHED_SUCCESS)
+ {
+ return rc;
+ }
+
+ rc= memcached_virtual_bucket_create(self, host_map, forward_map, buckets, replicas);
+ if (rc != MEMCACHED_SUCCESS)
+ {
+ memcached_behavior_set_distribution(self, old);
+ }
+
+ return rc;
+}