X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=libmemcached%2Fmemcached_hosts.c;h=3082f693836c37eda7a86c17f971461ebe2dbb28;hb=7fe9d9a3c8e127ab12c4830e44fd931adb262e25;hp=dd137dda0f088e08b192ad6b2d993ae271c187af;hpb=335064cd46d8c7bb73b50c6bf690c595c15b7742;p=m6w6%2Flibmemcached diff --git a/libmemcached/memcached_hosts.c b/libmemcached/memcached_hosts.c index dd137dda..3082f693 100644 --- a/libmemcached/memcached_hosts.c +++ b/libmemcached/memcached_hosts.c @@ -23,7 +23,7 @@ static int compare_servers(const void *p1, const void *p2) return return_value; } -void sort_hosts(memcached_st *ptr) +static void sort_hosts(memcached_st *ptr) { if (ptr->number_of_hosts) { @@ -51,9 +51,9 @@ memcached_return run_distribution(memcached_st *ptr) return MEMCACHED_SUCCESS; } -static void host_reset(memcached_st *ptr, memcached_server_st *host, - char *hostname, unsigned int port, - memcached_connection type) +void host_reset(memcached_st *ptr, memcached_server_st *host, + char *hostname, unsigned int port, + memcached_connection type) { memset(host, 0, sizeof(memcached_server_st)); strncpy(host->hostname, hostname, MEMCACHED_MAX_HOST_LENGTH - 1); @@ -89,9 +89,10 @@ void server_list_free(memcached_st *ptr, memcached_server_st *servers) static int continuum_item_cmp(const void *t1, const void *t2) { - memcached_continuum_item_st *ct1 = (memcached_continuum_item_st *)t1; - memcached_continuum_item_st *ct2 = (memcached_continuum_item_st *)t2; + memcached_continuum_item_st *ct1= (memcached_continuum_item_st *)t1; + memcached_continuum_item_st *ct2= (memcached_continuum_item_st *)t2; + /* Why 153? Hmmm... */ WATCHPOINT_ASSERT(ct1->value != 153); if (ct1->value == ct2->value) return 0; @@ -151,7 +152,11 @@ memcached_return update_continuum(memcached_st *ptr) float pct = (float)list[host_index].limit_maxbytes/ (float)total_mem_bytes; pointer_per_server= floorf( pct * MEMCACHED_POINTS_PER_SERVER * (float)(ptr->number_of_hosts)); #ifdef HAVE_DEBUG - printf("ketama_weighted:%s|%d|%llu|%u\n", list[host_index].hostname, list[host_index].port, list[host_index].limit_maxbytes, pointer_per_server); + printf("ketama_weighted:%s|%d|%llu|%u\n", + list[host_index].hostname, + list[host_index].port, + (unsigned long long)list[host_index].limit_maxbytes, + pointer_per_server); #endif } for(index= 1; index <= pointer_per_server; ++index) @@ -169,10 +174,13 @@ memcached_return update_continuum(memcached_st *ptr) pointer_counter+= pointer_per_server; } + WATCHPOINT_ASSERT(ptr); + WATCHPOINT_ASSERT(ptr->continuum); + WATCHPOINT_ASSERT(ptr->number_of_hosts); 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(memcached_continuum_item_st), continuum_item_cmp); - ptr->continuum_points_counter= pointer_counter; + qsort(ptr->continuum, ptr->continuum_points_counter, sizeof(memcached_continuum_item_st), continuum_item_cmp); + if (stat_p) memcached_stat_free(NULL, stat_p); @@ -295,15 +303,14 @@ memcached_return memcached_server_remove(memcached_server_st *st_ptr) memcpy(list+index, list+x, sizeof(memcached_server_st)); index++; } - else - { - ptr->number_of_hosts--; - } } - + ptr->number_of_hosts= index; if (st_ptr->address_info) + { freeaddrinfo(st_ptr->address_info); + st_ptr->address_info= NULL; + } run_distribution(ptr); return MEMCACHED_SUCCESS;