#include <ctime>
#include <sys/types.h>
+bool memcached_is_consistent_distribution(const memcached_st* memc)
+{
+ switch (memc->distribution)
+ {
+ case MEMCACHED_DISTRIBUTION_CONSISTENT:
+ case MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA:
+ case MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA_SPY:
+ case MEMCACHED_DISTRIBUTION_CONSISTENT_WEIGHTED:
+ return true;
+
+ case MEMCACHED_DISTRIBUTION_MODULA:
+ case MEMCACHED_DISTRIBUTION_RANDOM:
+ case MEMCACHED_DISTRIBUTION_VIRTUAL_BUCKET:
+ case MEMCACHED_DISTRIBUTION_CONSISTENT_MAX:
+ break;
+ }
+
+ return false;
+}
+
/*
This function is used to modify the behavior of running client.
return ptr->flags.verify_key;
case MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED:
- return ptr->ketama.weighted;
+ if (memcached_is_consistent_distribution(ptr))
+ {
+ return memcached_is_weighted_ketama(ptr);
+ }
+ return false;
case MEMCACHED_BEHAVIOR_DISTRIBUTION:
return ptr->distribution;
case MEMCACHED_BEHAVIOR_KETAMA:
- return (ptr->distribution == MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA) ? (uint64_t) 1 : 0;
+ return memcached_is_consistent_distribution(ptr);
case MEMCACHED_BEHAVIOR_HASH:
return hashkit_get_function(&ptr->hashkit);
return (uint64_t) ptr->send_size;
}
- memcached_server_write_instance_st instance= memcached_server_instance_fetch(ptr, 0);
+ org::libmemcached::Instance* instance= memcached_instance_fetch(ptr, 0);
if (instance) // If we have an instance we test, otherwise we just set and pray
{
if (ptr->recv_size != -1) // If value is -1 then we are using the default
return (uint64_t) ptr->recv_size;
- memcached_server_write_instance_st instance= memcached_server_instance_fetch(ptr, 0);
+ org::libmemcached::Instance* instance= memcached_instance_fetch(ptr, 0);
/**
@note REFACTOR
case MEMCACHED_DISTRIBUTION_CONSISTENT:
case MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA:
- ptr->ketama.weighted= false;
+ memcached_set_weighted_ketama(ptr, false);
break;
case MEMCACHED_DISTRIBUTION_RANDOM:
break;
case MEMCACHED_DISTRIBUTION_CONSISTENT_WEIGHTED:
- ptr->ketama.weighted= true;
+ memcached_set_weighted_ketama(ptr, true);
break;
case MEMCACHED_DISTRIBUTION_VIRTUAL_BUCKET:
return memcached_set_error(*ptr, MEMCACHED_INVALID_ARGUMENTS, MEMCACHED_AT,
memcached_literal_param("Invalid memcached_server_distribution_t"));
}
+ ptr->distribution= type;
return run_distribution(ptr);
}