From: Date: Wed, 13 Feb 2008 09:51:13 +0000 (+0530) Subject: Added MEMCACHED_BEHAVIOR_SORT_HOSTS behavior to enable and disable sorted host X-Git-Tag: 0.20~18 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=8c6442357f4685e75c8b6a851404d9b8f7079ef1;p=awesomized%2Flibmemcached Added MEMCACHED_BEHAVIOR_SORT_HOSTS behavior to enable and disable sorted host behavior. --- diff --git a/ChangeLog b/ChangeLog index 59a6f932..d57737ac 100644 --- a/ChangeLog +++ b/ChangeLog @@ -5,7 +5,8 @@ * Added Atom Smasher test (scale baby, scale!) * Servers are now sorted, meaning that servers are now ordered so that clients with the same lists, will have same distribution. (Idea from - Ross McFarland). + Ross McFarland). MEMCACHED_BEHAVIOR_SORT_HOSTS was added to enable + this support. * Added MEMCACHED_BAD_KEY_PROVIDED error for auto, set, and get operations when the library is compiled with --enable-debug. This additional code will test for bad keys. diff --git a/docs/memcached_behavior.pod b/docs/memcached_behavior.pod index 25986cdf..e71f1438 100755 --- a/docs/memcached_behavior.pod +++ b/docs/memcached_behavior.pod @@ -88,6 +88,11 @@ action that gets data causes this buffer to be be sent to the remote connection. Quiting the connection or closing down the connection will also cause the buffered data to be pushed to the remote connection. +=item MEMCACHED_BEHAVIOR_SORT_HOSTS + +Enabling this will cause hosts that are added to be placed in the host list in +sorted order. This will defeat consisten hashing. + =back =head1 RETURN diff --git a/include/memcached.h b/include/memcached.h index fa2d305c..0939a7ae 100644 --- a/include/memcached.h +++ b/include/memcached.h @@ -100,6 +100,7 @@ typedef enum { MEMCACHED_BEHAVIOR_DISTRIBUTION, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS, MEMCACHED_BEHAVIOR_USER_DATA, + MEMCACHED_BEHAVIOR_SORT_HOSTS, } memcached_behavior; typedef enum { diff --git a/lib/common.h b/lib/common.h index 610d4320..ff54fe57 100644 --- a/lib/common.h +++ b/lib/common.h @@ -65,6 +65,7 @@ typedef enum { MEM_USE_CACHE_LOOKUPS= (1 << 6), MEM_SUPPORT_CAS= (1 << 7), MEM_BUFFER_REQUESTS= (1 << 8), + MEM_USE_SORT_HOSTS= (1 << 9), } memcached_flags; /* Hashing algo */ diff --git a/lib/memcached_behavior.c b/lib/memcached_behavior.c index 62b767f7..1458c1a9 100644 --- a/lib/memcached_behavior.c +++ b/lib/memcached_behavior.c @@ -49,6 +49,9 @@ memcached_return memcached_behavior_set(memcached_st *ptr, case MEMCACHED_BEHAVIOR_KETAMA: set_behavior_flag(ptr, MEM_USE_KETAMA, data); break; + case MEMCACHED_BEHAVIOR_SORT_HOSTS: + set_behavior_flag(ptr, MEM_USE_SORT_HOSTS, data); + break; case MEMCACHED_BEHAVIOR_USER_DATA: ptr->user_data= data; break; @@ -107,6 +110,9 @@ unsigned long long memcached_behavior_get(memcached_st *ptr, case MEMCACHED_BEHAVIOR_KETAMA: temp_flag= MEM_USE_KETAMA; break; + case MEMCACHED_BEHAVIOR_SORT_HOSTS: + temp_flag= MEM_USE_SORT_HOSTS; + break; case MEMCACHED_BEHAVIOR_USER_DATA: return 0; //return (unsigned long long)ptr->user_data; diff --git a/tests/function.c b/tests/function.c index 1534019c..b971134e 100644 --- a/tests/function.c +++ b/tests/function.c @@ -63,9 +63,13 @@ uint8_t server_list_null_test(memcached_st *ptr) uint8_t server_sort_test(memcached_st *ptr) { + unsigned int setting; memcached_server_st *server_list; memcached_return rc; + setting= 1; + memcached_behavior_set(ptr, MEMCACHED_BEHAVIOR_SORT_HOSTS, &setting); + server_list= memcached_server_list_append(NULL, "arg", 0, &rc); assert(server_list);