From ea65554ea537786c7bc27018264f9e0d2ebd02ce Mon Sep 17 00:00:00 2001 From: Yin Chen Date: Thu, 7 Aug 2008 16:43:15 +0800 Subject: [PATCH] Fix some flaw and bugs in server failure rehash --- configure.ac | 7 ++++++- libmemcached/common.h | 2 +- libmemcached/memcached.h | 2 +- libmemcached/memcached_behavior.c | 2 +- libmemcached/memcached_connect.c | 2 +- libmemcached/memcached_hosts.c | 18 +++++++++++------- 6 files changed, 21 insertions(+), 12 deletions(-) diff --git a/configure.ac b/configure.ac index f6dd9b63..3118870a 100644 --- a/configure.ac +++ b/configure.ac @@ -1,6 +1,11 @@ AC_INIT(clients/memcat.c) AC_CONFIG_AUX_DIR(config) -AM_CONFIG_HEADER(libmemcached/libmemcached_config.h) AC_CANONICAL_SYSTEM MEMCACHED_LIBRARY_NAME=libmemcached #release versioning +AM_CONFIG_HEADER(libmemcached/libmemcached_config.h) +AC_CANONICAL_SYSTEM + +MEMCACHED_LIBRARY_NAME=libmemcached + +#release versioning MEMCACHED_MAJOR_VERSION=0 MEMCACHED_MINOR_VERSION=22 MEMCACHED_MICRO_VERSION=0 diff --git a/libmemcached/common.h b/libmemcached/common.h index 9b8a1040..5993e57c 100644 --- a/libmemcached/common.h +++ b/libmemcached/common.h @@ -118,7 +118,7 @@ memcached_return run_distribution(memcached_st *ptr); uint32_t generate_hash_value(const char *key, size_t key_length, memcached_hash hash_algorithm); uint32_t generate_hash(memcached_st *ptr, const char *key, size_t key_length); -memcached_return server_remove(memcached_server_st *st_ptr); +memcached_return memcached_server_remove(memcached_server_st *st_ptr); extern uint64_t ntohll(uint64_t); extern uint64_t htonll(uint64_t); diff --git a/libmemcached/memcached.h b/libmemcached/memcached.h index 8ce333ca..aab451cc 100644 --- a/libmemcached/memcached.h +++ b/libmemcached/memcached.h @@ -97,7 +97,7 @@ struct memcached_st { uint32_t continuum_points_counter; int32_t snd_timeout; int32_t rcv_timeout; - int32_t server_failure_limit; + uint32_t server_failure_limit; }; diff --git a/libmemcached/memcached_behavior.c b/libmemcached/memcached_behavior.c index a4b77d66..97ad3781 100644 --- a/libmemcached/memcached_behavior.c +++ b/libmemcached/memcached_behavior.c @@ -30,7 +30,7 @@ memcached_return memcached_behavior_set(memcached_st *ptr, ptr->rcv_timeout= (int32_t)data; break; case MEMCACHED_BEHAVIOR_SERVER_FAILURE_LIMIT: - ptr->server_failure_limit= (int32_t)data; + ptr->server_failure_limit= (uint32_t)data; break; case MEMCACHED_BEHAVIOR_BINARY_PROTOCOL: set_behavior_flag(ptr, MEM_BINARY_PROTOCOL, data); diff --git a/libmemcached/memcached_connect.c b/libmemcached/memcached_connect.c index f2549dc7..8c7ef332 100644 --- a/libmemcached/memcached_connect.c +++ b/libmemcached/memcached_connect.c @@ -174,7 +174,7 @@ static memcached_return network_connect(memcached_server_st *ptr) if(ptr->root->server_failure_limit != 0) { if(ptr->server_failure_counter >= ptr->root->server_failure_limit) { - server_remove(ptr); + memcached_server_remove(ptr); } } /* Old connection junk still is in the structure */ diff --git a/libmemcached/memcached_hosts.c b/libmemcached/memcached_hosts.c index 69375038..5f51d546 100644 --- a/libmemcached/memcached_hosts.c +++ b/libmemcached/memcached_hosts.c @@ -282,21 +282,25 @@ static memcached_return server_add(memcached_st *ptr, char *hostname, return run_distribution(ptr); } -memcached_return server_remove(memcached_server_st *st_ptr) +memcached_return memcached_server_remove(memcached_server_st *st_ptr) { - int i,index; + int x,index; memcached_st *ptr= st_ptr->root; memcached_server_st *list=ptr->hosts; index= 0; - for(i= 0; i< ptr->number_of_hosts; ++i) { - if(strncmp(list[i].hostname, st_ptr->hostname, MEMCACHED_MAX_HOST_LENGTH)!=0 || list[i].port != st_ptr->port) { - memcpy(list+index, list+i, sizeof(memcached_server_st)); + for (x= 0; x< ptr->number_of_hosts; ++x) + { + if (strncmp(list[x].hostname, st_ptr->hostname, MEMCACHED_MAX_HOST_LENGTH)!=0 || list[x].port != st_ptr->port) + { + memcpy(list+index, list+x, sizeof(memcached_server_st)); index++; - } else { + } else + { ptr->number_of_hosts-=1; } } - if(st_ptr->address_info) { + if(st_ptr->address_info) + { freeaddrinfo(st_ptr->address_info); } run_distribution(ptr); -- 2.30.2