From: Brian Aker Date: Tue, 12 Jun 2012 21:33:31 +0000 (+0100) Subject: Fixed bug where we might not see the right return type for the distribution type. X-Git-Tag: 1.0.9~25 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=728ffce13e3e3b78d0144ea1e304dee1c1055384;p=awesomized%2Flibmemcached Fixed bug where we might not see the right return type for the distribution type. --- diff --git a/libmemcached/behavior.cc b/libmemcached/behavior.cc index c91acc5d..fd096db2 100644 --- a/libmemcached/behavior.cc +++ b/libmemcached/behavior.cc @@ -42,6 +42,26 @@ #include #include +static bool __is_ketama(memcached_st *ptr) +{ + switch (ptr->distribution) + { + case MEMCACHED_DISTRIBUTION_CONSISTENT: + case MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA: + case MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA_SPY: + case MEMCACHED_DISTRIBUTION_CONSISTENT_WEIGHTED: + return true; + + case MEMCACHED_DISTRIBUTION_MODULA: + case MEMCACHED_DISTRIBUTION_RANDOM: + case MEMCACHED_DISTRIBUTION_VIRTUAL_BUCKET: + case MEMCACHED_DISTRIBUTION_CONSISTENT_MAX: + break; + } + + return false; +} + /* This function is used to modify the behavior of running client. @@ -335,13 +355,17 @@ uint64_t memcached_behavior_get(memcached_st *ptr, return ptr->flags.verify_key; case MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED: - return ptr->ketama.weighted; + if (__is_ketama(ptr)) + { + return ptr->ketama.weighted; + } + return false; case MEMCACHED_BEHAVIOR_DISTRIBUTION: return ptr->distribution; case MEMCACHED_BEHAVIOR_KETAMA: - return (ptr->distribution == MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA) ? (uint64_t) 1 : 0; + return __is_ketama(ptr); case MEMCACHED_BEHAVIOR_HASH: return hashkit_get_function(&ptr->hashkit); @@ -519,6 +543,7 @@ memcached_return_t memcached_behavior_set_distribution(memcached_st *ptr, memcac return memcached_set_error(*ptr, MEMCACHED_INVALID_ARGUMENTS, MEMCACHED_AT, memcached_literal_param("Invalid memcached_server_distribution_t")); } + ptr->distribution= type; return run_distribution(ptr); } diff --git a/libmemcached/io.cc b/libmemcached/io.cc index bafa28c8..c848b631 100644 --- a/libmemcached/io.cc +++ b/libmemcached/io.cc @@ -372,7 +372,7 @@ memcached_return_t memcached_io_wait_for_write(memcached_server_write_instance_s return io_wait(ptr, MEM_WRITE); } -static memcached_return_t _io_fill(memcached_server_write_instance_st ptr, ssize_t& nread) +static memcached_return_t _io_fill(memcached_server_write_instance_st ptr) { ssize_t data_read; do @@ -415,12 +415,12 @@ static memcached_return_t _io_fill(memcached_server_write_instance_st ptr, ssize case EFAULT: case ECONNREFUSED: default: - { - memcached_quit_server(ptr, true); - nread= -1; - return memcached_set_errno(*ptr, get_socket_errno(), MEMCACHED_AT); - } + memcached_quit_server(ptr, true); + memcached_set_errno(*ptr, get_socket_errno(), MEMCACHED_AT); + break; } + + return memcached_server_error_return(ptr); } else if (data_read == 0) { @@ -434,7 +434,6 @@ static memcached_return_t _io_fill(memcached_server_write_instance_st ptr, ssize it will return EGAIN if data is not immediatly available. */ memcached_quit_server(ptr, true); - nread= -1; return memcached_set_error(*ptr, MEMCACHED_CONNECTION_FAILURE, MEMCACHED_AT, memcached_literal_param("::rec() returned zero, server has disconnected")); } @@ -469,8 +468,9 @@ memcached_return_t memcached_io_read(memcached_server_write_instance_st ptr, if (ptr->read_buffer_length == 0) { memcached_return_t io_fill_ret; - if (memcached_fatal(io_fill_ret= _io_fill(ptr, nread))) + if (memcached_fatal(io_fill_ret= _io_fill(ptr))) { + nread= -1; return io_fill_ret; } } diff --git a/tests/libmemcached-1.0/mem_functions.cc b/tests/libmemcached-1.0/mem_functions.cc index ce0514d7..2f6d56f3 100644 --- a/tests/libmemcached-1.0/mem_functions.cc +++ b/tests/libmemcached-1.0/mem_functions.cc @@ -650,7 +650,7 @@ test_return_t memcached_mget_mixed_memcached_get_TEST(memcached_st *memc) { } // It is possible that the value has been purged. else { - test_compare_hint(MEMCACHED_SUCCESS, rc, memcached_last_error_message(memc)); + test_compare(MEMCACHED_SUCCESS, rc); } test_null(out_value); test_zero(value_length); @@ -1690,8 +1690,7 @@ test_return_t mget_execute(memcached_st *original_memc) keys.key_at(x), keys.length_at(x), blob, sizeof(blob), 0, 0); - test_true_got(rc == MEMCACHED_SUCCESS or rc == MEMCACHED_BUFFERED, - memcached_last_error_message(memc)); + test_true(rc == MEMCACHED_SUCCESS or rc == MEMCACHED_BUFFERED); test_compare(query_id +1, memcached_query_id(memc)); } @@ -3067,20 +3066,21 @@ test_return_t set_memory_alloc(memcached_st *memc) test_return_t enable_consistent_crc(memcached_st *memc) { + test_compare(MEMCACHED_SUCCESS, memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_DISTRIBUTION, MEMCACHED_DISTRIBUTION_CONSISTENT)); + test_compare(memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_DISTRIBUTION), uint64_t(MEMCACHED_DISTRIBUTION_CONSISTENT)); + test_return_t rc; - memcached_server_distribution_t value= MEMCACHED_DISTRIBUTION_CONSISTENT; - memcached_hash_t hash; - memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_DISTRIBUTION, value); if ((rc= pre_crc(memc)) != TEST_SUCCESS) + { return rc; + } - value= (memcached_server_distribution_t)memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_DISTRIBUTION); - test_true(value == MEMCACHED_DISTRIBUTION_CONSISTENT); - - hash= (memcached_hash_t)memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_HASH); + test_compare(memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_DISTRIBUTION), uint64_t(MEMCACHED_DISTRIBUTION_CONSISTENT)); - if (hash != MEMCACHED_HASH_CRC) + if (memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_HASH) != MEMCACHED_HASH_CRC) + { return TEST_SKIPPED; + } return TEST_SUCCESS; } @@ -3088,22 +3088,18 @@ test_return_t enable_consistent_crc(memcached_st *memc) test_return_t enable_consistent_hsieh(memcached_st *memc) { test_return_t rc; - memcached_server_distribution_t value= MEMCACHED_DISTRIBUTION_CONSISTENT; - memcached_hash_t hash; - memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_DISTRIBUTION, value); + memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_DISTRIBUTION, MEMCACHED_DISTRIBUTION_CONSISTENT); if ((rc= pre_hsieh(memc)) != TEST_SUCCESS) { return rc; } - value= (memcached_server_distribution_t)memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_DISTRIBUTION); - test_true(value == MEMCACHED_DISTRIBUTION_CONSISTENT); - - hash= (memcached_hash_t)memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_HASH); + test_compare(memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_DISTRIBUTION), uint64_t(MEMCACHED_DISTRIBUTION_CONSISTENT)); - if (hash != MEMCACHED_HASH_HSIEH) + if (memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_HASH) != MEMCACHED_HASH_HSIEH) + { return TEST_SKIPPED; - + } return TEST_SUCCESS; } @@ -3236,7 +3232,7 @@ test_return_t noreply_test(memcached_st *memc) { continue; } - test_true_hint(ret == MEMCACHED_SUCCESS and value != NULL, memcached_last_error_message(memc)); + test_true(ret == MEMCACHED_SUCCESS and value != NULL); switch (count) { case 0: /* FALLTHROUGH */ diff --git a/tests/libmemcached-1.0/setup_and_teardowns.cc b/tests/libmemcached-1.0/setup_and_teardowns.cc index 3d6a4a08..4e5c0616 100644 --- a/tests/libmemcached-1.0/setup_and_teardowns.cc +++ b/tests/libmemcached-1.0/setup_and_teardowns.cc @@ -172,11 +172,9 @@ test_return_t pre_hash_fnv1a_32(memcached_st *memc) test_return_t pre_behavior_ketama(memcached_st *memc) { - memcached_return_t rc= memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_KETAMA, 1); - test_compare(MEMCACHED_SUCCESS, rc); + test_compare(MEMCACHED_SUCCESS, memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_KETAMA, 1)); - uint64_t value= memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_KETAMA); - test_compare(value, uint64_t(1)); + test_compare(memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_KETAMA), uint64_t(1)); return TEST_SUCCESS; }