From: Date: Fri, 21 Mar 2008 16:57:19 +0000 (-0700) Subject: Fix for wrong count on memcache_server_st structure (aka the old hack for X-Git-Tag: _20~1^2~42 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=d1cd53476c4f30f762c8ca18d335e205086dc95f;p=m6w6%2Flibmemcached Fix for wrong count on memcache_server_st structure (aka the old hack for server lists). --- diff --git a/ChangeLog b/ChangeLog index 70377ed5..7c7828f6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,7 @@ 0.19 * Read through cached support. * Fixed for cas by key operation. + * Fix for memcached_server_st list structures to have correct count. 0.18 Sun Mar 16 21:57:55 PDT 2008 diff --git a/libmemcached/memcached_hosts.c b/libmemcached/memcached_hosts.c index c62c3b41..b97476a5 100644 --- a/libmemcached/memcached_hosts.c +++ b/libmemcached/memcached_hosts.c @@ -179,11 +179,12 @@ static memcached_return server_add(memcached_st *ptr, char *hostname, host_reset(ptr, &ptr->hosts[ptr->number_of_hosts], hostname, port, type); ptr->number_of_hosts++; - ptr->hosts[0].count++; if (ptr->number_of_hosts > 1) qsort(ptr->hosts, ptr->number_of_hosts, sizeof(memcached_server_st), compare_servers); + ptr->hosts[0].count= ptr->number_of_hosts; + rebalance_wheel(ptr); LIBMEMCACHED_MEMCACHED_SERVER_ADD_END(); @@ -220,14 +221,11 @@ memcached_server_st *memcached_server_list_append(memcached_server_st *ptr, host_reset(NULL, &new_host_list[count-1], hostname, port, MEMCACHED_CONNECTION_TCP); - /* Backwards compatibility hack */ - new_host_list[0].count++; - - count= new_host_list[0].count; - + /* We alway sort lists by default */ if (new_host_list[0].count > 1) qsort(new_host_list, count, sizeof(memcached_server_st), compare_servers); + /* Backwards compatibility hack */ new_host_list[0].count= count; diff --git a/tests/function.c b/tests/function.c index 19c104df..9e10552c 100644 --- a/tests/function.c +++ b/tests/function.c @@ -87,6 +87,8 @@ uint8_t server_sort_test(memcached_st *ptr) { test_ports[x]= random() % 64000; rc= memcached_server_add(local_memc, "localhost", test_ports[x]); + assert(local_memc->number_of_hosts == x+1); + assert(local_memc->hosts[0].count == x+1); assert(rc == MEMCACHED_SUCCESS); }