From: Brian Aker Date: Sun, 3 Apr 2011 04:02:40 +0000 (-0700) Subject: Set weight correctly. X-Git-Tag: 0.51~15^2~51 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=8dbf5dfc11d59551dbe433dc45e8c1283cbd939a;p=m6w6%2Flibmemcached Set weight correctly. --- diff --git a/libmemcached/hosts.c b/libmemcached/hosts.c index 67ba6d19..d95dbcff 100644 --- a/libmemcached/hosts.c +++ b/libmemcached/hosts.c @@ -109,7 +109,6 @@ static memcached_return_t update_continuum(memcached_st *ptr) uint32_t pointer_counter= 0; uint32_t pointer_per_server= MEMCACHED_POINTS_PER_SERVER; uint32_t pointer_per_hash= 1; - uint64_t total_weight= 0; uint32_t live_servers= 0; struct timeval now; @@ -163,16 +162,15 @@ static memcached_return_t update_continuum(memcached_st *ptr) ptr->ketama.continuum_count= live_servers + MEMCACHED_CONTINUUM_ADDITION; } + uint64_t total_weight= 0; if (is_ketama_weighted) { for (uint32_t host_index = 0; host_index < memcached_server_count(ptr); ++host_index) { - if (list[host_index].weight == 0) - { - list[host_index].weight = 1; - } if (! is_auto_ejecting || list[host_index].next_retry <= now.tv_sec) + { total_weight += list[host_index].weight; + } } } diff --git a/libmemcached/parse.c b/libmemcached/parse.c index 917c5e30..85860ef3 100644 --- a/libmemcached/parse.c +++ b/libmemcached/parse.c @@ -10,8 +10,6 @@ memcached_server_list_st memcached_servers_parse(const char *server_strings) { char *string; - in_port_t port; - uint32_t weight; const char *begin_ptr; const char *end_ptr; memcached_server_st *servers= NULL; @@ -27,8 +25,7 @@ memcached_server_list_st memcached_servers_parse(const char *server_strings) { char buffer[HUGE_STRING_LEN]; char *ptr, *ptr2; - port= 0; - weight= 0; + uint32_t weight= 0; if (string) { @@ -46,6 +43,7 @@ memcached_server_list_st memcached_servers_parse(const char *server_strings) ptr= index(buffer, ':'); + in_port_t port= 0; if (ptr) { ptr[0]= 0; @@ -57,6 +55,7 @@ memcached_server_list_st memcached_servers_parse(const char *server_strings) ptr2= index(ptr, ' '); if (! ptr2) ptr2= index(ptr, ':'); + if (ptr2) { ptr2++; diff --git a/libmemcached/server.c b/libmemcached/server.c index 7b9b2eef..fa750c25 100644 --- a/libmemcached/server.c +++ b/libmemcached/server.c @@ -26,7 +26,7 @@ static inline void _server_init(memcached_server_st *self, const memcached_st *r self->fd= -1; self->io_bytes_sent= 0; self->server_failure_counter= 0; - self->weight= weight; + self->weight= weight ? weight : 1; // 1 is the default weight value self->state.is_corked= false; self->state.is_dead= false; WATCHPOINT_SET(self->io_wait_count.read= 0);