From: Brian Aker Date: Sat, 12 Feb 2011 08:45:44 +0000 (-0800) Subject: Better reporting on errors from mget. X-Git-Tag: 0.51~43^2~4 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=05d5ad2cd0a4ae9e8c70ae031d4639691083765c;p=m6w6%2Flibmemcached Better reporting on errors from mget. --- diff --git a/libmemcached/get.c b/libmemcached/get.c index a6cb549f..876389bf 100644 --- a/libmemcached/get.c +++ b/libmemcached/get.c @@ -144,7 +144,7 @@ static memcached_return_t memcached_mget_by_key_real(memcached_st *ptr, size_t number_of_keys, bool mget_mode) { - memcached_return_t rc= MEMCACHED_NOTFOUND; + bool failures_occured_in_sending= false; const char *get_command= "get "; uint8_t get_command_length= 4; unsigned int master_server_key= (unsigned int)-1; /* 0 is a valid server id! */ @@ -211,6 +211,8 @@ static memcached_return_t memcached_mget_by_key_real(memcached_st *ptr, If a server fails we warn about errors and start all over with sending keys to the server. */ + memcached_return_t rc= MEMCACHED_SUCCESS; + size_t hosts_connected= 0; for (uint32_t x= 0; x < number_of_keys; x++) { memcached_server_write_instance_st instance; @@ -241,12 +243,15 @@ static memcached_return_t memcached_mget_by_key_real(memcached_st *ptr, rc= memcached_connect(instance); if (rc != MEMCACHED_SUCCESS) + { continue; + } + hosts_connected++; if ((memcached_io_writev(instance, vector, 4, false)) == -1) { fprintf(stderr, "%s:%d (%s)\n", __FILE__, __LINE__,__func__);fflush(stdout); - rc= MEMCACHED_SOME_ERRORS; + failures_occured_in_sending= true; continue; } WATCHPOINT_ASSERT(instance->cursor_active == 0); @@ -259,15 +264,27 @@ static memcached_return_t memcached_mget_by_key_real(memcached_st *ptr, { memcached_server_response_reset(instance); fprintf(stderr, "%s:%d (%s)\n", __FILE__, __LINE__,__func__);fflush(stdout); - rc= MEMCACHED_SOME_ERRORS; + failures_occured_in_sending= true; continue; } } } + if (hosts_connected == 0) + { + LIBMEMCACHED_MEMCACHED_MGET_END(); + + if (rc != MEMCACHED_SUCCESS) + return rc; + + return MEMCACHED_NO_SERVERS; + } + + /* Should we muddle on if some servers are dead? */ + bool success_happened= false; for (uint32_t x= 0; x < memcached_server_count(ptr); x++) { memcached_server_write_instance_st instance= @@ -279,13 +296,24 @@ static memcached_return_t memcached_mget_by_key_real(memcached_st *ptr, if ((memcached_io_write(instance, "\r\n", 2, true)) == -1) { fprintf(stderr, "%s:%d (%s)\n", __FILE__, __LINE__,__func__);fflush(stdout); - rc= MEMCACHED_SOME_ERRORS; + failures_occured_in_sending= true; + } + else + { + success_happened= true; } } } LIBMEMCACHED_MEMCACHED_MGET_END(); - return rc; + + if (failures_occured_in_sending && success_happened) + return MEMCACHED_SOME_ERRORS; + + if (success_happened) + return MEMCACHED_SUCCESS; + + return MEMCACHED_FAILURE; } memcached_return_t memcached_mget_by_key(memcached_st *ptr, diff --git a/libmemcached/quit.c b/libmemcached/quit.c index 85eb3015..251f578c 100644 --- a/libmemcached/quit.c +++ b/libmemcached/quit.c @@ -65,6 +65,7 @@ void memcached_quit_server(memcached_server_st *ptr, bool io_death) } ptr->fd= -1; + ptr->io_bytes_sent= 0; ptr->write_buffer_offset= (size_t) ((ptr->type == MEMCACHED_CONNECTION_UDP) ? UDP_DATAGRAM_HEADER_LENGTH : 0); ptr->read_buffer_length= 0; ptr->read_ptr= ptr->read_buffer; diff --git a/tests/mem_functions.c b/tests/mem_functions.c index fa4c36c6..a38c49c4 100644 --- a/tests/mem_functions.c +++ b/tests/mem_functions.c @@ -3361,7 +3361,9 @@ static test_return_t generate_large_pairs(memcached_st *memc __attribute__((unus static test_return_t generate_data(memcached_st *memc) { - execute_set(memc, global_pairs, global_count); + unsigned int check_execute= execute_set(memc, global_pairs, global_count); + + test_true(check_execute == global_count); return TEST_SUCCESS; } @@ -3371,7 +3373,9 @@ static test_return_t generate_data_with_stats(memcached_st *memc) memcached_stat_st *stat_p; memcached_return_t rc; uint32_t host_index= 0; - execute_set(memc, global_pairs, global_count); + unsigned int check_execute= execute_set(memc, global_pairs, global_count); + + test_true(check_execute == global_count); //TODO: hosts used size stats stat_p= memcached_stat(memc, NULL, &rc); @@ -5983,7 +5987,7 @@ static test_return_t regression_bug_583031(memcached_st *unused) (void)memcached_get(memc, "dsf", 3, &length, &flags, &rc); - test_true(rc == MEMCACHED_TIMEOUT); + test_true_got(rc == MEMCACHED_TIMEOUT, memcached_strerror(NULL, rc)); memcached_free(memc);