memcached_result_st result;
struct {
- bool weighted;
+ bool weighted_;
uint32_t continuum_count; // Ketama
uint32_t continuum_points_counter; // Ketama
time_t next_distribution_rebuild; // Ketama
- memcached_continuum_item_st *continuum; // Ketama
+ struct memcached_continuum_item_st *continuum; // Ketama
} ketama;
struct memcached_virtual_bucket_t *virtual_bucket;
// The following two structures are internal, and never exposed to users.
typedef struct memcached_string_st memcached_string_st;
typedef struct memcached_string_t memcached_string_t;
-typedef struct memcached_continuum_item_st memcached_continuum_item_st;
#endif
#include <ctime>
#include <sys/types.h>
-static bool __is_ketama(memcached_st *ptr)
+bool memcached_is_consistent_distribution(const memcached_st* memc)
{
- switch (ptr->distribution)
+ switch (memc->distribution)
{
case MEMCACHED_DISTRIBUTION_CONSISTENT:
case MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA:
return ptr->flags.verify_key;
case MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED:
- if (__is_ketama(ptr))
+ if (memcached_is_consistent_distribution(ptr))
{
- return ptr->ketama.weighted;
+ return memcached_is_weighted_ketama(ptr);
}
return false;
return ptr->distribution;
case MEMCACHED_BEHAVIOR_KETAMA:
- return __is_ketama(ptr);
+ return memcached_is_consistent_distribution(ptr);
case MEMCACHED_BEHAVIOR_HASH:
return hashkit_get_function(&ptr->hashkit);
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:
#pragma once
+bool memcached_is_consistent_distribution(const memcached_st*);
bool _is_auto_eject_host(const memcached_st *ptr);
/* Why 153? Hmmm... */
WATCHPOINT_ASSERT(ct1->value != 153);
if (ct1->value == ct2->value)
+ {
return 0;
+ }
else if (ct1->value > ct2->value)
+ {
return 1;
+ }
else
+ {
return -1;
+ }
}
static memcached_return_t update_continuum(memcached_st *ptr)
live_servers= memcached_server_count(ptr);
}
- uint64_t is_ketama_weighted= memcached_behavior_get(ptr, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED);
- uint32_t points_per_server= (uint32_t) (is_ketama_weighted ? MEMCACHED_POINTS_PER_SERVER_KETAMA : MEMCACHED_POINTS_PER_SERVER);
+ uint32_t points_per_server= (uint32_t) (memcached_is_weighted_ketama(ptr) ? MEMCACHED_POINTS_PER_SERVER_KETAMA : MEMCACHED_POINTS_PER_SERVER);
if (live_servers == 0)
{
}
uint64_t total_weight= 0;
- if (is_ketama_weighted)
+ if (memcached_is_weighted_ketama(ptr))
{
for (uint32_t host_index = 0; host_index < memcached_server_count(ptr); ++host_index)
{
continue;
}
- if (is_ketama_weighted)
+ if (memcached_is_weighted_ketama(ptr))
{
float pct= (float)list[host_index].weight / (float)total_weight;
pointer_per_server= (uint32_t) ((::floor((float) (pct * MEMCACHED_POINTS_PER_SERVER_KETAMA / 4 * (float)live_servers + 0.0000000001))) * 4);
fprintf(stdout, "update_continuum: key is %s\n", sort_host);
}
- if (is_ketama_weighted)
+ if (memcached_is_weighted_ketama(ptr))
{
for (uint32_t x= 0; x < pointer_per_hash; x++)
{
memcached_literal_param("snprintf(sizeof(sort_host)))"));
}
- if (is_ketama_weighted)
+ if (memcached_is_weighted_ketama(ptr))
{
for (uint32_t x = 0; x < pointer_per_hash; x++)
{
if (weight > 1)
{
- ptr->ketama.weighted= true;
+ if (memcached_is_consistent_distribution(ptr))
+ {
+ memcached_set_weighted_ketama(ptr, true);
+ }
}
ptr->number_of_hosts++;
if (list[x].weight > 1)
{
- ptr->ketama.weighted= true;
+ memcached_set_weighted_ketama(ptr, true);
}
ptr->number_of_hosts++;
if (list[x].weight > 1)
{
- ptr->ketama.weighted= true;
+ memcached_set_weighted_ketama(ptr, true);
}
ptr->number_of_hosts++;
noinst_HEADERS+= libmemcached/array.h
noinst_HEADERS+= libmemcached/assert.hpp
noinst_HEADERS+= libmemcached/backtrace.hpp
+noinst_HEADERS+= libmemcached/behavior.hpp
noinst_HEADERS+= libmemcached/byteorder.h
noinst_HEADERS+= libmemcached/common.h
noinst_HEADERS+= libmemcached/connect.hpp
libmemcached_libmemcached_la_SOURCES+= libmemcached/auto.cc
libmemcached_libmemcached_la_SOURCES+= libmemcached/backtrace.cc
libmemcached_libmemcached_la_SOURCES+= libmemcached/behavior.cc
-libmemcached_libmemcached_la_SOURCES+= libmemcached/behavior.hpp
libmemcached_libmemcached_la_SOURCES+= libmemcached/byteorder.cc
libmemcached_libmemcached_la_SOURCES+= libmemcached/callback.cc
libmemcached_libmemcached_la_SOURCES+= libmemcached/connect.cc
#define memcached_is_auto_eject_hosts(__object) ((__object)->flags.auto_eject_hosts)
#define memcached_is_use_sort_hosts(__object) ((__object)->flags.use_sort_hosts)
+#define memcached_is_weighted_ketama(__object) ((__object)->ketama.weighted_)
+
#define memcached_set_aes(__object, __flag) ((__object).flags.is_aes= __flag)
#define memcached_set_udp(__object, __flag) ((__object).flags.use_udp= __flag)
#define memcached_set_verify_key(__object, __flag) ((__object).flags.verify_key= __flag)
#define memcached_set_processing_input(__object, __value) ((__object)->state.is_processing_input= (__value))
#define memcached_set_initialized(__object, __value) ((__object)->options.is_initialized(= (__value))
#define memcached_set_allocated(__object, __value) ((__object)->options.is_allocated= (__value))
+
+#define memcached_set_weighted_ketama(__object, __value) ((__object)->ketama.weighted_= (__value))
self->ketama.continuum_count= 0;
self->ketama.continuum_points_counter= 0;
self->ketama.next_distribution_rebuild= 0;
- self->ketama.weighted= false;
+ self->ketama.weighted_= false;
self->number_of_hosts= 0;
self->servers= NULL;
test_true(memc_clone->flags.buffer_requests == memc->flags.buffer_requests);
test_true(memc_clone->flags.use_sort_hosts == memc->flags.use_sort_hosts);
test_true(memc_clone->flags.verify_key == memc->flags.verify_key);
- test_true(memc_clone->ketama.weighted == memc->ketama.weighted);
+ test_true(memc_clone->ketama.weighted_ == memc->ketama.weighted_);
test_true(memc_clone->flags.binary_protocol == memc->flags.binary_protocol);
test_true(memc_clone->flags.hash_with_namespace == memc->flags.hash_with_namespace);
test_true(memc_clone->flags.reply == memc->flags.reply);