From 765cbda088d67af78051836b13f4faf0bc164679 Mon Sep 17 00:00:00 2001 From: Date: Sun, 20 Apr 2008 09:08:32 -0700 Subject: [PATCH] Work on adding ketama style distribution. --- libmemcached/memcached_constants.h | 2 +- libmemcached/memcached_hosts.c | 19 +++++++++++-------- libmemcached/memcached_storage.c | 1 - libmemcached/memcached_watchpoint.h | 2 ++ 4 files changed, 14 insertions(+), 10 deletions(-) diff --git a/libmemcached/memcached_constants.h b/libmemcached/memcached_constants.h index b2b819f2..237ff54d 100644 --- a/libmemcached/memcached_constants.h +++ b/libmemcached/memcached_constants.h @@ -20,8 +20,8 @@ extern "C" { #define MEMCACHED_MAX_HOST_LENGTH 64 #define MEMCACHED_MAX_HOST_SORT_LENGTH 86 /* Used for Ketama */ #define MEMCACHED_WHEEL_SIZE 1024 -#define MEMCACHED_CONTINUUM_SIZE 2048 #define MEMCACHED_POINTS_PER_SERVER 100 +#define MEMCACHED_CONTINUUM_SIZE MEMCACHED_POINTS_PER_SERVER*100 /* This would then set max hosts to 100 */ #define MEMCACHED_STRIDE 4 #define MEMCACHED_DEFAULT_TIMEOUT INT32_MAX diff --git a/libmemcached/memcached_hosts.c b/libmemcached/memcached_hosts.c index 65dcc546..3809feed 100644 --- a/libmemcached/memcached_hosts.c +++ b/libmemcached/memcached_hosts.c @@ -95,9 +95,11 @@ static int continuum_item_cmp(const void *t1, const void *t2) { struct continuum_item *ct1 = (struct continuum_item *)t1; struct continuum_item *ct2 = (struct continuum_item *)t2; - if(ct1->value == ct2->value) + + WATCHPOINT_ASSERT(ct1->value != 153); + if (ct1->value == ct2->value) return 0; - else if(ct1->value > ct2->value) + else if (ct1->value > ct2->value) return 1; else return -1; @@ -117,10 +119,10 @@ static uint32_t internal_generate_ketama_md5(char *key, size_t key_length) void update_continuum(memcached_st *ptr) { - int index; - int host_index; - int continuum_index= 0; - int value; + uint32_t index; + uint32_t host_index; + uint32_t continuum_index= 0; + uint32_t value; memcached_server_st *list = ptr->hosts; for (host_index = 0; host_index < ptr->number_of_hosts; ++host_index) @@ -139,11 +141,12 @@ void update_continuum(memcached_st *ptr) } } + WATCHPOINT_ASSERT(ptr->number_of_hosts * MEMCACHED_POINTS_PER_SERVER <= MEMCACHED_CONTINUUM_SIZE); qsort(ptr->continuum, ptr->number_of_hosts * MEMCACHED_POINTS_PER_SERVER, sizeof(struct continuum_item), continuum_item_cmp); #ifdef HAVE_DEBUG - for(index= 0; index < ptr->number_of_hosts * MEMCACHED_POINTS_PER_SERVER - 1; ++index) + for (index= 0; index < ((ptr->number_of_hosts * MEMCACHED_POINTS_PER_SERVER) - 1); index++) { - WATCHPOINT_ASSERT(ptr->continuum[index].value < ptr->continuum[index + 1].value); + WATCHPOINT_ASSERT(ptr->continuum[index].value <= ptr->continuum[index + 1].value); } #endif } diff --git a/libmemcached/memcached_storage.c b/libmemcached/memcached_storage.c index 0f6daa4e..30afd263 100644 --- a/libmemcached/memcached_storage.c +++ b/libmemcached/memcached_storage.c @@ -58,7 +58,6 @@ static inline memcached_return memcached_send(memcached_st *ptr, unsigned int server_key; WATCHPOINT_ASSERT(!(value == NULL && value_length > 0)); - WATCHPOINT_ASSERT(!(value && value_length == 0)); unlikely (key_length == 0) return MEMCACHED_NO_KEY_PROVIDED; diff --git a/libmemcached/memcached_watchpoint.h b/libmemcached/memcached_watchpoint.h index b0270b61..03c2b160 100644 --- a/libmemcached/memcached_watchpoint.h +++ b/libmemcached/memcached_watchpoint.h @@ -23,6 +23,7 @@ extern "C" { #define WATCHPOINT_STRING_LENGTH(A,B) fprintf(stderr, "\nWATCHPOINT %s:%d (%s) %.*s\n", __FILE__, __LINE__,__func__,(int)B,A);fflush(stdout); #define WATCHPOINT_NUMBER(A) fprintf(stderr, "\nWATCHPOINT %s:%d (%s) %zu\n", __FILE__, __LINE__,__func__,(size_t)(A));fflush(stdout); #define WATCHPOINT_ERRNO(A) fprintf(stderr, "\nWATCHPOINT %s:%d (%s) %s\n", __FILE__, __LINE__,__func__, strerror(A));fflush(stdout); +#define WATCHPOINT_ASSERT_PRINT(A,B,C) if(!(A)){fprintf(stderr, "\nWATCHPOINT ASSERT %s:%d (%s) ", __FILE__, __LINE__,__func__);fprintf(stderr, (B),(C));fprintf(stderr,"\n");fflush(stdout);}assert((A)); #define WATCHPOINT_ASSERT(A) assert((A)); #else #define WATCHPOINT @@ -31,6 +32,7 @@ extern "C" { #define WATCHPOINT_STRING(A) #define WATCHPOINT_NUMBER(A) #define WATCHPOINT_ERRNO(A) +#define WATCHPOINT_ASSERT_PRINT(A,B,C) #define WATCHPOINT_ASSERT(A) #endif #endif /* MEMCACHED_INTERNAL */ -- 2.30.2