From: Brian Aker Date: Mon, 5 Apr 2010 22:27:54 +0000 (-0700) Subject: Update for last disconnect to stick around even if ejected. X-Git-Tag: 0.40~15 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=c52c930e6cb28a0c48c63992135691111fd9f779;p=awesomized%2Flibmemcached Update for last disconnect to stick around even if ejected. --- diff --git a/libmemcached/connect.c b/libmemcached/connect.c index 38fc2ca1..f0ad282b 100644 --- a/libmemcached/connect.c +++ b/libmemcached/connect.c @@ -382,7 +382,9 @@ memcached_return_t memcached_connect(memcached_server_write_instance_st ptr) run_distribution(root); } - root->last_disconnected_server = ptr; + if (ptr->root->last_disconnected_server) + memcached_server_free(ptr->root->last_disconnected_server); + root->last_disconnected_server= memcached_server_clone(NULL, ptr); return MEMCACHED_SERVER_MARKED_DEAD; } @@ -407,14 +409,17 @@ memcached_return_t memcached_connect(memcached_server_write_instance_st ptr) WATCHPOINT_ASSERT(0); } + LIBMEMCACHED_MEMCACHED_CONNECT_END(); + unlikely ( rc != MEMCACHED_SUCCESS) { - //@todo create interface around last_discontected_server memcached_st *root= (memcached_st *)ptr->root; - root->last_disconnected_server = ptr; - } - LIBMEMCACHED_MEMCACHED_CONNECT_END(); + //@todo create interface around last_discontected_server + if (ptr->root->last_disconnected_server) + memcached_server_free(ptr->root->last_disconnected_server); + root->last_disconnected_server= memcached_server_clone(NULL, ptr); + } return rc; } diff --git a/libmemcached/hosts.c b/libmemcached/hosts.c index 0836c97e..4018a258 100644 --- a/libmemcached/hosts.c +++ b/libmemcached/hosts.c @@ -69,8 +69,6 @@ memcached_return_t run_distribution(memcached_st *ptr) WATCHPOINT_ASSERT(0); /* We have added a distribution without extending the logic */ } - ptr->last_disconnected_server = NULL; - return MEMCACHED_SUCCESS; } diff --git a/libmemcached/memcached.c b/libmemcached/memcached.c index 0c38cc69..5ffaee9e 100644 --- a/libmemcached/memcached.c +++ b/libmemcached/memcached.c @@ -15,6 +15,7 @@ static const memcached_st global_copy= { .state= { .is_purging= false, .is_processing_input= false, + .is_time_for_rebuild= false, }, .flags= { .auto_eject_hosts= false, @@ -145,6 +146,10 @@ void memcached_servers_reset(memcached_st *ptr) memcached_server_list_set(ptr, NULL); ptr->number_of_hosts= 0; + if (ptr->last_disconnected_server) + { + memcached_server_free(ptr->last_disconnected_server); + } ptr->last_disconnected_server= NULL; ptr->server_failure_limit= 0; } @@ -156,6 +161,9 @@ void memcached_free(memcached_st *ptr) memcached_server_list_free(memcached_server_list(ptr)); memcached_result_free(&ptr->result); + if (ptr->last_disconnected_server) + memcached_server_free(ptr->last_disconnected_server); + if (ptr->on_cleanup) ptr->on_cleanup(ptr); diff --git a/libmemcached/memcached.h b/libmemcached/memcached.h index 2244c62d..668e9a12 100644 --- a/libmemcached/memcached.h +++ b/libmemcached/memcached.h @@ -62,6 +62,7 @@ struct memcached_st { struct { bool is_purging:1; bool is_processing_input:1; + bool is_time_for_rebuild:1; } state; struct { // Everything below here is pretty static. diff --git a/libmemcached/server.c b/libmemcached/server.c index e7082af9..aac5a50e 100644 --- a/libmemcached/server.c +++ b/libmemcached/server.c @@ -29,6 +29,7 @@ static inline void _server_init(memcached_server_st *self, const memcached_st *r self->server_failure_counter= 0; self->weight= weight; self->state.is_corked= false; + self->state.is_dead= false; self->major_version= 0; self->micro_version= 0; self->minor_version= 0; diff --git a/libmemcached/server.h b/libmemcached/server.h index 92e6d888..6a2ae5ee 100644 --- a/libmemcached/server.h +++ b/libmemcached/server.h @@ -29,7 +29,8 @@ struct memcached_server_st { uint32_t server_failure_counter; uint32_t weight; struct { // Place any "state" sort variables in here. - bool is_corked; + bool is_corked:1; + bool is_dead:1; } state; uint8_t major_version; uint8_t micro_version; diff --git a/tests/mem_functions.c b/tests/mem_functions.c index 75d00932..ea716a34 100644 --- a/tests/mem_functions.c +++ b/tests/mem_functions.c @@ -5462,6 +5462,24 @@ static test_return_t test_verbosity(memcached_st *memc) return TEST_SUCCESS; } +static test_return_t test_cull_servers(memcached_st *memc) +{ + uint32_t count = memcached_server_count(memc); + + // Do not do this in your code, it is not supported. + memc->servers[1].state.is_dead= true; + memc->state.is_time_for_rebuild= true; + + uint32_t new_count= memcached_server_count(memc); + test_true(count == new_count); + +#if 0 + test_true(count == new_count + 1 ); +#endif + + return TEST_SUCCESS; +} + /* * This test ensures that the failure counter isn't incremented during * normal termination of the memcached instance. @@ -5688,6 +5706,7 @@ test_st tests[] ={ #endif {"test_get_last_disconnect", 1, (test_callback_fn)test_get_last_disconnect}, {"verbosity", 1, (test_callback_fn)test_verbosity}, + {"cull_servers", 1, (test_callback_fn)test_cull_servers}, {0, 0, 0} };