From: Brian Aker Date: Thu, 29 Nov 2007 21:34:03 +0000 (-0800) Subject: Added tests for consistent hash. X-Git-Tag: 0.13~63 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=1dd64b216b8a845b2d3399641520833b25a3cb76;p=m6w6%2Flibmemcached Added tests for consistent hash. Fixed memory issue in _stats. Added interface to externally enable consistent hash. --- diff --git a/include/memcached.h b/include/memcached.h index 971b4ab4..8b883534 100644 --- a/include/memcached.h +++ b/include/memcached.h @@ -84,6 +84,7 @@ typedef enum { MEMCACHED_BEHAVIOR_CACHE_LOOKUPS, MEMCACHED_BEHAVIOR_SUPPORT_CAS, MEMCACHED_BEHAVIOR_POLL_TIMEOUT, + MEMCACHED_BEHAVIOR_DISTRIBUTION, } memcached_behavior; typedef enum { diff --git a/lib/memcached_behavior.c b/lib/memcached_behavior.c index 910fb392..853a33b3 100644 --- a/lib/memcached_behavior.c +++ b/lib/memcached_behavior.c @@ -35,6 +35,9 @@ memcached_return memcached_behavior_set(memcached_st *ptr, case MEMCACHED_BEHAVIOR_TCP_NODELAY: set_behavior_flag(ptr, MEM_TCP_NODELAY, data); break; + case MEMCACHED_BEHAVIOR_DISTRIBUTION: + ptr->distribution= *(memcached_server_distribution *)(data); + break; case MEMCACHED_BEHAVIOR_HASH: ptr->hash= *(memcached_hash *)(data); break; @@ -89,6 +92,8 @@ unsigned long long memcached_behavior_get(memcached_st *ptr, case MEMCACHED_BEHAVIOR_TCP_NODELAY: temp_flag= MEM_TCP_NODELAY; break; + case MEMCACHED_BEHAVIOR_DISTRIBUTION: + return ptr->distribution; case MEMCACHED_BEHAVIOR_HASH: return ptr->hash; case MEMCACHED_BEHAVIOR_KETAMA: diff --git a/lib/memcached_stats.c b/lib/memcached_stats.c index 04ef31ba..decf22b6 100644 --- a/lib/memcached_stats.c +++ b/lib/memcached_stats.c @@ -265,7 +265,7 @@ memcached_stat_st *memcached_stat(memcached_st *ptr, char *args, memcached_retur free(stats); return NULL; } - memset(stats, 0, sizeof(memcached_st)*(ptr->number_of_hosts)); + memset(stats, 0, sizeof(memcached_stat_st)*(ptr->number_of_hosts)); rc= MEMCACHED_SUCCESS; for (x= 0; x < ptr->number_of_hosts; x++) diff --git a/tests/function.c b/tests/function.c index c3d764c4..3a0bd648 100644 --- a/tests/function.c +++ b/tests/function.c @@ -1655,6 +1655,14 @@ memcached_return pre_hash_ketama(memcached_st *memc) return MEMCACHED_SUCCESS; } +memcached_return enable_consistent(memcached_st *memc) +{ + memcached_server_distribution value= MEMCACHED_DISTRIBUTION_CONSISTENT; + memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_DISTRIBUTION, &value); + + return MEMCACHED_SUCCESS; +} + memcached_return enable_cas(memcached_st *memc) { unsigned int set= 1; @@ -1836,6 +1844,7 @@ collection_st collection[] ={ {"unix_socket_nodelay", pre_nodelay, 0, tests}, {"poll_timeout", poll_timeout, 0, tests}, {"gets", enable_cas, 0, tests}, + {"consistent", enable_consistent, 0, tests}, // {"udp", pre_udp, 0, tests}, {"version_1_2_3", check_for_1_2_3, 0, version_1_2_3}, {"string", 0, 0, string_tests}, diff --git a/tests/output.res b/tests/output.res index b13a83f0..8d71e670 100644 --- a/tests/output.res +++ b/tests/output.res @@ -1027,3 +1027,76 @@ Found key bytes_read Found key bytes_written Found key limit_maxbytes Found key threads +Error 0 -> SUCCESS +Error 1 -> FAILURE +Error 2 -> HOSTNAME LOOKUP FAILURE +Error 3 -> CONNECTION FAILURE +Error 4 -> CONNECTION BIND FAILURE +Error 5 -> WRITE FAILURE +Error 6 -> READ FAILURE +Error 7 -> UNKNOWN READ FAILURE +Error 8 -> PROTOCOL ERROR +Error 9 -> CLIENT ERROR +Error 10 -> SERVER ERROR +Error 11 -> CONNECTION SOCKET CREATE FAILURE +Error 12 -> CONNECTION DATA EXISTS +Error 13 -> CONNECTION DATA DOES NOT EXIST +Error 14 -> NOT STORED +Error 15 -> STORED +Error 16 -> NOT FOUND +Error 17 -> MEMORY ALLOCATION FAILURE +Error 18 -> PARTIAL READ +Error 19 -> SOME ERRORS WERE REPORTED +Error 20 -> NO SERVERS DEFINED +Error 21 -> SERVER END +Error 22 -> SERVER DELETE +Error 23 -> SERVER VALUE +Error 24 -> STAT VALUE +Error 25 -> SYSTEM ERROR +Error 26 -> COULD NOT OPEN UNIX SOCKET +Error 27 -> ACTION NOT SUPPORTED +Error 28 -> A KEY LENGTH OF ZERO WAS PROVIDED +Found key pid +Found key uptime +Found key time +Found key version +Found key pointer_size +Found key rusage_user +Found key rusage_system +Found key curr_items +Found key total_items +Found key bytes +Found key curr_connections +Found key total_connections +Found key connection_structures +Found key cmd_get +Found key cmd_set +Found key get_hits +Found key get_misses +Found key evictions +Found key bytes_read +Found key bytes_written +Found key limit_maxbytes +Found key threads +Found key pid +Found key uptime +Found key time +Found key version +Found key pointer_size +Found key rusage_user +Found key rusage_system +Found key curr_items +Found key total_items +Found key bytes +Found key curr_connections +Found key total_connections +Found key connection_structures +Found key cmd_get +Found key cmd_set +Found key get_hits +Found key get_misses +Found key evictions +Found key bytes_read +Found key bytes_written +Found key limit_maxbytes +Found key threads