From: Brian Aker Date: Wed, 20 Nov 2013 11:04:05 +0000 (-0500) Subject: Allows zero as a value for retry. X-Git-Tag: 1.0.18~14^2~6 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=45154abf5ce15679bb321c70711d4b3d8be5f855;p=awesomized%2Flibmemcached Allows zero as a value for retry. --- diff --git a/ChangeLog b/ChangeLog index 5fbed160..19a44020 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,5 @@ 1.0.18 +* MEMCACHED_BEHAVIOR_RETRY_TIMEOUT can now be set to zero. 1.0.17 Tue Apr 2 14:02:01 HST 2013 * Remove c++ namespace that was being exposed (the API should be plug compatible).. diff --git a/libmemcached/behavior.cc b/libmemcached/behavior.cc index 2675e236..081f8082 100644 --- a/libmemcached/behavior.cc +++ b/libmemcached/behavior.cc @@ -230,11 +230,6 @@ memcached_return_t memcached_behavior_set(memcached_st *shell, break; case MEMCACHED_BEHAVIOR_RETRY_TIMEOUT: - if (data == 0) - { - return memcached_set_error(*ptr, MEMCACHED_INVALID_ARGUMENTS, MEMCACHED_AT, - memcached_literal_param("MEMCACHED_BEHAVIOR_RETRY_TIMEOUT requires a value greater then zero.")); - } ptr->retry_timeout= int32_t(data); break; diff --git a/libmemcached/server.hpp b/libmemcached/server.hpp index 0c6ac798..708e6460 100644 --- a/libmemcached/server.hpp +++ b/libmemcached/server.hpp @@ -76,17 +76,20 @@ static inline void memcached_mark_server_for_timeout(memcached_instance_st* serv { if (server->state != MEMCACHED_SERVER_STATE_IN_TIMEOUT) { - struct timeval next_time; - if (gettimeofday(&next_time, NULL) == 0) + if (server->root->retry_timeout != 0) { - server->next_retry= next_time.tv_sec +server->root->retry_timeout; - } - else - { - server->next_retry= 1; // Setting the value to 1 causes the timeout to occur immediatly - } + struct timeval next_time; + if (gettimeofday(&next_time, NULL) == 0) + { + server->next_retry= next_time.tv_sec +server->root->retry_timeout; + } + else + { + server->next_retry= 1; // Setting the value to 1 causes the timeout to occur immediatly + } - server->state= MEMCACHED_SERVER_STATE_IN_TIMEOUT; + server->state= MEMCACHED_SERVER_STATE_IN_TIMEOUT; + } if (server->server_failure_counter_query_id != server->root->query_id) { server->server_failure_counter++; diff --git a/tests/libmemcached-1.0/all_tests.h b/tests/libmemcached-1.0/all_tests.h index d748d39e..b4abe9dd 100644 --- a/tests/libmemcached-1.0/all_tests.h +++ b/tests/libmemcached-1.0/all_tests.h @@ -284,6 +284,7 @@ test_st regression_tests[]= { {"lp:1021819", true, (test_callback_fn*)regression_1021819_TEST }, {"lp:1048945", true, (test_callback_fn*)regression_1048945_TEST }, {"lp:1067242", true, (test_callback_fn*)regression_1067242_TEST }, + {"lp:1251482", true, (test_callback_fn*)regression_bug_1251482 }, {0, false, (test_callback_fn*)0} }; diff --git a/tests/libmemcached-1.0/mem_functions.cc b/tests/libmemcached-1.0/mem_functions.cc index e69e0e12..51ce9df6 100644 --- a/tests/libmemcached-1.0/mem_functions.cc +++ b/tests/libmemcached-1.0/mem_functions.cc @@ -4559,7 +4559,7 @@ test_return_t wrong_failure_counter_two_test(memcached_st *memc) /* Put a retry timeout to effectively activate failure_limit effect */ test_compare(MEMCACHED_SUCCESS, - memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_RETRY_TIMEOUT, true)); + memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_RETRY_TIMEOUT, 1)); /* change behavior that triggers memcached_quit()*/ test_compare(MEMCACHED_SUCCESS, @@ -4841,6 +4841,28 @@ test_return_t regression_bug_490520(memcached_st *original_memc) return TEST_SUCCESS; } +test_return_t regression_bug_1251482(memcached_st*) +{ + test::Memc memc("--server=localhost:0"); + + memcached_behavior_set(&memc, MEMCACHED_BEHAVIOR_RETRY_TIMEOUT, 0); + + for (size_t x= 4; x; --x) + { + size_t value_length; + memcached_return_t rc; + char *value= memcached_get(&memc, + test_literal_param(__func__), + &value_length, NULL, &rc); + + test_false(value); + test_compare(0LLU, value_length); + test_compare(MEMCACHED_CONNECTION_FAILURE, rc); + } + + return TEST_SUCCESS; +} + test_return_t regression_1009493_TEST(memcached_st*) { memcached_st* memc= memcached_create(NULL); diff --git a/tests/libmemcached-1.0/mem_functions.h b/tests/libmemcached-1.0/mem_functions.h index 75736931..41aea118 100644 --- a/tests/libmemcached-1.0/mem_functions.h +++ b/tests/libmemcached-1.0/mem_functions.h @@ -187,3 +187,4 @@ test_return_t regression_1009493_TEST(memcached_st*); test_return_t regression_1048945_TEST(memcached_st*); test_return_t regression_1067242_TEST(memcached_st*); test_return_t comparison_operator_memcached_st_and__memcached_return_t_TEST(memcached_st*); +test_return_t regression_bug_1251482(memcached_st*);