From 46eb35cbfdbfd7f8ea544c712678ceab9a9205f9 Mon Sep 17 00:00:00 2001 From: uhm0311 Date: Wed, 29 Dec 2021 13:39:11 +0900 Subject: [PATCH] ENHANCE: Enhance error handling where uses memcached_vdo() #167 --- libmemcached/collection.cc | 680 ++++++++++++++++++------------------- libmemcached/delete.cc | 53 +-- libmemcached/exist.cc | 25 +- libmemcached/storage.cc | 57 ++-- 4 files changed, 397 insertions(+), 418 deletions(-) diff --git a/libmemcached/collection.cc b/libmemcached/collection.cc index e8bd370c..8dcd6c13 100644 --- a/libmemcached/collection.cc +++ b/libmemcached/collection.cc @@ -734,38 +734,38 @@ memcached_return_t memcached_set_attrs(memcached_st *ptr, WATCHPOINT_IFERROR(rc); - if (rc == MEMCACHED_SUCCESS) + if (rc != MEMCACHED_SUCCESS) { - if (to_write == false) - { - rc= MEMCACHED_BUFFERED; - } - else if (ptr->flags.no_reply) - { - rc= MEMCACHED_SUCCESS; - } - else - { - // expecting OK (MEMCACHED_SUCCESS) - char result[MEMCACHED_DEFAULT_COMMAND_SIZE]; - rc= memcached_coll_response(instance, result, MEMCACHED_DEFAULT_COMMAND_SIZE, NULL); + if (rc == MEMCACHED_WRITE_FAILURE) + memcached_io_reset(instance); + + return rc; + } + + if (to_write == false) + { + rc= MEMCACHED_BUFFERED; + return rc; + } + + if (ptr->flags.no_reply == false) + { + // expecting OK (MEMCACHED_SUCCESS) + char result[MEMCACHED_DEFAULT_COMMAND_SIZE]; + rc= memcached_coll_response(instance, result, MEMCACHED_DEFAULT_COMMAND_SIZE, NULL); #ifdef ENABLE_REPLICATION - if (rc == MEMCACHED_SWITCHOVER or rc == MEMCACHED_REPL_SLAVE) - { - ZOO_LOG_INFO(("Switchover: hostname=%s port=%d error=%s", - instance->hostname, instance->port, memcached_strerror(ptr, rc))); - if (memcached_rgroup_switchover(ptr, instance) == true) { - instance= memcached_server_instance_fetch(ptr, server_key); - goto do_action; - } + if (rc == MEMCACHED_SWITCHOVER or rc == MEMCACHED_REPL_SLAVE) + { + ZOO_LOG_INFO(("Switchover: hostname=%s port=%d error=%s", + instance->hostname, instance->port, memcached_strerror(ptr, rc))); + if (memcached_rgroup_switchover(ptr, instance) == true) { + instance= memcached_server_instance_fetch(ptr, server_key); + goto do_action; } -#endif } +#endif } - if (rc == MEMCACHED_WRITE_FAILURE) - memcached_io_reset(instance); - return rc; } @@ -1009,45 +1009,44 @@ static memcached_return_t do_coll_create(memcached_st *ptr, #endif rc= memcached_vdo(instance, vector, 4, to_write); - if (rc == MEMCACHED_SUCCESS) + if (rc != MEMCACHED_SUCCESS) { - if (to_write == false) - { - rc= MEMCACHED_BUFFERED; - } - else if (ptr->flags.no_reply || ptr->flags.piped) - { - rc= MEMCACHED_SUCCESS; - } - else - { - char result[MEMCACHED_DEFAULT_COMMAND_SIZE]; - rc= memcached_coll_response(instance, result, MEMCACHED_DEFAULT_COMMAND_SIZE, NULL); + if (rc == MEMCACHED_WRITE_FAILURE) + memcached_io_reset(instance); + + return rc; + } + + if (to_write == false) + { + rc= MEMCACHED_BUFFERED; + return rc; + } + + if (ptr->flags.no_reply == false and ptr->flags.piped == false) + { + char result[MEMCACHED_DEFAULT_COMMAND_SIZE]; + rc= memcached_coll_response(instance, result, MEMCACHED_DEFAULT_COMMAND_SIZE, NULL); #ifdef ENABLE_REPLICATION - if (rc == MEMCACHED_SWITCHOVER or rc == MEMCACHED_REPL_SLAVE) - { - ZOO_LOG_INFO(("Switchover: hostname=%s port=%d error=%s", - instance->hostname, instance->port, memcached_strerror(ptr, rc))); - if (memcached_rgroup_switchover(ptr, instance) == true) { - instance= memcached_server_instance_fetch(ptr, server_key); - goto do_action; - } + if (rc == MEMCACHED_SWITCHOVER or rc == MEMCACHED_REPL_SLAVE) + { + ZOO_LOG_INFO(("Switchover: hostname=%s port=%d error=%s", + instance->hostname, instance->port, memcached_strerror(ptr, rc))); + if (memcached_rgroup_switchover(ptr, instance) == true) { + instance= memcached_server_instance_fetch(ptr, server_key); + goto do_action; } + } #endif - memcached_set_last_response_code(ptr, rc); + memcached_set_last_response_code(ptr, rc); - if (rc == MEMCACHED_CREATED) - { - rc= MEMCACHED_SUCCESS; - } + if (rc == MEMCACHED_CREATED) + { + rc= MEMCACHED_SUCCESS; + return rc; } } - if (rc == MEMCACHED_WRITE_FAILURE) - { - memcached_io_reset(instance); - } - return rc; } @@ -1188,6 +1187,7 @@ static memcached_return_t internal_coll_piped_insert(memcached_st *ptr, { if (rc == MEMCACHED_WRITE_FAILURE) memcached_io_reset(instance); + return rc; } @@ -1263,6 +1263,7 @@ static memcached_return_t internal_coll_piped_exist(memcached_st *ptr, { if (rc == MEMCACHED_WRITE_FAILURE) memcached_io_reset(instance); + return rc; } @@ -1387,48 +1388,48 @@ static memcached_return_t do_coll_insert(memcached_st *ptr, /* Send command header */ rc= memcached_vdo(instance, vector, 6, to_write); - if (rc == MEMCACHED_SUCCESS) + if (rc != MEMCACHED_SUCCESS) { - if (to_write == false) + if (rc == MEMCACHED_WRITE_FAILURE) + memcached_io_reset(instance); + + return rc; + } + + if (to_write == false) + { + rc= MEMCACHED_BUFFERED; + return rc; + } + + if (ptr->flags.no_reply == false and ptr->flags.piped == false) + { + char result[MEMCACHED_DEFAULT_COMMAND_SIZE]; + rc= memcached_coll_response(instance, result, MEMCACHED_DEFAULT_COMMAND_SIZE, NULL); +#ifdef ENABLE_REPLICATION + if (rc == MEMCACHED_SWITCHOVER or rc == MEMCACHED_REPL_SLAVE) { - rc= MEMCACHED_BUFFERED; + ZOO_LOG_INFO(("Switchover: hostname=%s port=%d error=%s", + instance->hostname, instance->port, memcached_strerror(ptr, rc))); + if (memcached_rgroup_switchover(ptr, instance) == true) { + instance= memcached_server_instance_fetch(ptr, server_key); + goto do_action; + } } - else if (ptr->flags.no_reply or ptr->flags.piped) +#endif + memcached_set_last_response_code(ptr, rc); + + if (rc == MEMCACHED_STORED || rc == MEMCACHED_CREATED_STORED) { rc= MEMCACHED_SUCCESS; } - else + else if (rc == MEMCACHED_REPLACED && verb == BOP_UPSERT_OP) { - char result[MEMCACHED_DEFAULT_COMMAND_SIZE]; - rc= memcached_coll_response(instance, result, MEMCACHED_DEFAULT_COMMAND_SIZE, NULL); -#ifdef ENABLE_REPLICATION - if (rc == MEMCACHED_SWITCHOVER or rc == MEMCACHED_REPL_SLAVE) - { - ZOO_LOG_INFO(("Switchover: hostname=%s port=%d error=%s", - instance->hostname, instance->port, memcached_strerror(ptr, rc))); - if (memcached_rgroup_switchover(ptr, instance) == true) { - instance= memcached_server_instance_fetch(ptr, server_key); - goto do_action; - } - } -#endif - memcached_set_last_response_code(ptr, rc); - - if (rc == MEMCACHED_STORED || rc == MEMCACHED_CREATED_STORED) - { - rc= MEMCACHED_SUCCESS; - } - else if (rc == MEMCACHED_REPLACED && verb == BOP_UPSERT_OP) - { - /* bop upsert returns REPLACED if the same bkey element is replaced. */ - rc= MEMCACHED_SUCCESS; - } + /* bop upsert returns REPLACED if the same bkey element is replaced. */ + rc= MEMCACHED_SUCCESS; } } - if (rc == MEMCACHED_WRITE_FAILURE) - memcached_io_reset(instance); - return rc; } @@ -1621,44 +1622,39 @@ static memcached_return_t do_coll_delete(memcached_st *ptr, #endif rc= memcached_vdo(instance, vector, veclen, to_write); - if (rc == MEMCACHED_SUCCESS) + if (rc != MEMCACHED_SUCCESS) { - if (to_write == false) - { - rc= MEMCACHED_BUFFERED; - } - else if (ptr->flags.no_reply) - { - rc= MEMCACHED_SUCCESS; - } - else - { - char result[MEMCACHED_DEFAULT_COMMAND_SIZE]; - rc= memcached_coll_response(instance, result, MEMCACHED_DEFAULT_COMMAND_SIZE, NULL); -#ifdef ENABLE_REPLICATION - if (rc == MEMCACHED_SWITCHOVER or rc == MEMCACHED_REPL_SLAVE) - { - ZOO_LOG_INFO(("Switchover: hostname=%s port=%d error=%s", - instance->hostname, instance->port, memcached_strerror(ptr, rc))); - if (memcached_rgroup_switchover(ptr, instance) == true) { - instance= memcached_server_instance_fetch(ptr, server_key); - goto do_action; - } - } -#endif - memcached_set_last_response_code(ptr, rc); + if (rc == MEMCACHED_WRITE_FAILURE) + memcached_io_reset(instance); + + return rc; + } - if (rc == MEMCACHED_DELETED or - rc == MEMCACHED_DELETED_DROPPED) - { - rc= MEMCACHED_SUCCESS; + if (to_write == false) + { + rc= MEMCACHED_BUFFERED; + return rc; + } + + if (ptr->flags.no_reply == false) + { + char result[MEMCACHED_DEFAULT_COMMAND_SIZE]; + rc= memcached_coll_response(instance, result, MEMCACHED_DEFAULT_COMMAND_SIZE, NULL); +#ifdef ENABLE_REPLICATION + if (rc == MEMCACHED_SWITCHOVER or rc == MEMCACHED_REPL_SLAVE) + { + ZOO_LOG_INFO(("Switchover: hostname=%s port=%d error=%s", + instance->hostname, instance->port, memcached_strerror(ptr, rc))); + if (memcached_rgroup_switchover(ptr, instance) == true) { + instance= memcached_server_instance_fetch(ptr, server_key); + goto do_action; } } - } +#endif + memcached_set_last_response_code(ptr, rc); - if (rc == MEMCACHED_WRITE_FAILURE) - { - memcached_io_reset(instance); + if (rc == MEMCACHED_DELETED or rc == MEMCACHED_DELETED_DROPPED) + rc= MEMCACHED_SUCCESS; } return rc; @@ -1917,58 +1913,56 @@ static memcached_return_t do_coll_get(memcached_st *ptr, #endif rc= memcached_vdo(instance, vector, veclen, to_write); - if (rc == MEMCACHED_SUCCESS) + if (rc != MEMCACHED_SUCCESS) { - if (to_write == false) + if (mkey_buffer) { - rc= MEMCACHED_BUFFERED; + libmemcached_free(ptr, mkey_buffer); + mkey_buffer= NULL; } - else if (ptr->flags.no_reply || ptr->flags.piped) - { - rc= MEMCACHED_SUCCESS; - } - else - { - /* Fetch results */ - result = memcached_coll_fetch_result(ptr, result, &rc); -#ifdef ENABLE_REPLICATION - if (rc == MEMCACHED_SWITCHOVER or rc == MEMCACHED_REPL_SLAVE) - { - ZOO_LOG_INFO(("Switchover: hostname=%s port=%d error=%s", - instance->hostname, instance->port, memcached_strerror(ptr, rc))); - if (memcached_rgroup_switchover(ptr, instance) == true) { - instance= memcached_server_instance_fetch(ptr, server_key); - goto do_action; - } - } -#endif - /* Search for END or something */ - if (result) - { - memcached_coll_result_reset(&ptr->collection_result); - memcached_coll_fetch_result(ptr, &ptr->collection_result, &rc); - } - memcached_set_last_response_code(ptr, rc); - if (rc == MEMCACHED_END or - rc == MEMCACHED_TRIMMED or - rc == MEMCACHED_DELETED or - rc == MEMCACHED_DELETED_DROPPED ) - { - rc= MEMCACHED_SUCCESS; - } - } + if (rc == MEMCACHED_WRITE_FAILURE) + memcached_io_reset(instance); + + return rc; } - if (mkey_buffer) + if (to_write == false) { - libmemcached_free(ptr, mkey_buffer); - mkey_buffer= NULL; + rc= MEMCACHED_BUFFERED; + return rc; } - - if (rc == MEMCACHED_WRITE_FAILURE) + + if (ptr->flags.no_reply == false and ptr->flags.piped == false) { - memcached_io_reset(instance); + /* Fetch results */ + result = memcached_coll_fetch_result(ptr, result, &rc); +#ifdef ENABLE_REPLICATION + if (rc == MEMCACHED_SWITCHOVER or rc == MEMCACHED_REPL_SLAVE) + { + ZOO_LOG_INFO(("Switchover: hostname=%s port=%d error=%s", + instance->hostname, instance->port, memcached_strerror(ptr, rc))); + if (memcached_rgroup_switchover(ptr, instance) == true) { + instance= memcached_server_instance_fetch(ptr, server_key); + goto do_action; + } + } +#endif + /* Search for END or something */ + if (result) + { + memcached_coll_result_reset(&ptr->collection_result); + memcached_coll_fetch_result(ptr, &ptr->collection_result, &rc); + } + memcached_set_last_response_code(ptr, rc); + + if (rc == MEMCACHED_END or + rc == MEMCACHED_TRIMMED or + rc == MEMCACHED_DELETED or + rc == MEMCACHED_DELETED_DROPPED ) + { + rc= MEMCACHED_SUCCESS; + } } return rc; @@ -2314,34 +2308,32 @@ static memcached_return_t do_bop_find_position(memcached_st *ptr, rc = memcached_vdo(instance, vector, 4, to_write); - if (rc == MEMCACHED_SUCCESS) + if (rc != MEMCACHED_SUCCESS) { - if (to_write == false) - { - rc = MEMCACHED_BUFFERED; - } - else if (ptr->flags.no_reply || ptr->flags.piped) - { - rc = MEMCACHED_SUCCESS; - } - else - { - char response[MEMCACHED_DEFAULT_COMMAND_SIZE]; - rc= memcached_coll_response(instance, response, MEMCACHED_DEFAULT_COMMAND_SIZE, &ptr->collection_result); - - if (rc == MEMCACHED_POSITION) - { - *position= ptr->collection_result.btree_position; - /* reset btree_position because it is intended for use in bop pwg */ - ptr->collection_result.btree_position= 0; - rc= MEMCACHED_SUCCESS; - } - } + if (rc == MEMCACHED_WRITE_FAILURE) + memcached_io_reset(instance); + + return rc; } - if (rc == MEMCACHED_WRITE_FAILURE) + if (to_write == false) { - memcached_io_reset(instance); + rc = MEMCACHED_BUFFERED; + return rc; + } + + if (ptr->flags.no_reply == false and ptr->flags.piped == false) + { + char response[MEMCACHED_DEFAULT_COMMAND_SIZE]; + rc= memcached_coll_response(instance, response, MEMCACHED_DEFAULT_COMMAND_SIZE, &ptr->collection_result); + + if (rc == MEMCACHED_POSITION) + { + *position= ptr->collection_result.btree_position; + /* reset btree_position because it is intended for use in bop pwg */ + ptr->collection_result.btree_position= 0; + rc= MEMCACHED_SUCCESS; + } } return rc; @@ -2413,38 +2405,34 @@ static memcached_return_t do_bop_get_by_position(memcached_st *ptr, rc = memcached_vdo(instance, vector, 4, to_write); - if (rc == MEMCACHED_SUCCESS) + if (rc != MEMCACHED_SUCCESS) { - if (to_write == false) - { - rc = MEMCACHED_BUFFERED; - } - else if (ptr->flags.no_reply || ptr->flags.piped) - { - rc = MEMCACHED_SUCCESS; - } - else - { - /* Fetch results */ - result = memcached_coll_fetch_result(ptr, result, &rc); + if (rc == MEMCACHED_WRITE_FAILURE) + memcached_io_reset(instance); + + return rc; + } - /* Search for END or something */ - if (result) - { - memcached_coll_result_reset(&ptr->collection_result); - memcached_coll_fetch_result(ptr, &ptr->collection_result, &rc); - } + if (to_write == false) + { + rc = MEMCACHED_BUFFERED; + return rc; + } + + if (ptr->flags.no_reply == false and ptr->flags.piped == false) + { + /* Fetch results */ + result = memcached_coll_fetch_result(ptr, result, &rc); - if (rc == MEMCACHED_END) - { - rc= MEMCACHED_SUCCESS; - } + /* Search for END or something */ + if (result) + { + memcached_coll_result_reset(&ptr->collection_result); + memcached_coll_fetch_result(ptr, &ptr->collection_result, &rc); } - } - if (rc == MEMCACHED_WRITE_FAILURE) - { - memcached_io_reset(instance); + if (rc == MEMCACHED_END) + rc= MEMCACHED_SUCCESS; } return rc; @@ -2526,38 +2514,36 @@ static memcached_return_t do_bop_find_position_with_get(memcached_st *ptr, rc = memcached_vdo(instance, vector, 4, to_write); - if (rc == MEMCACHED_SUCCESS) + if (rc != MEMCACHED_SUCCESS) { - if (to_write == false) - { - rc = MEMCACHED_BUFFERED; - } - else if (ptr->flags.no_reply || ptr->flags.piped) - { - rc = MEMCACHED_SUCCESS; - } - else - { - /* Fetch results */ - result = memcached_coll_fetch_result(ptr, result, &rc); + if (rc == MEMCACHED_WRITE_FAILURE) + memcached_io_reset(instance); + + return rc; + } - /* Search for END or something */ - if (result) - { - memcached_coll_result_reset(&ptr->collection_result); - memcached_coll_fetch_result(ptr, &ptr->collection_result, &rc); - } + if (to_write == false) + { + rc = MEMCACHED_BUFFERED; + return rc; + } + + if (ptr->flags.no_reply == false and ptr->flags.piped == false) + { + /* Fetch results */ + result = memcached_coll_fetch_result(ptr, result, &rc); - if (rc == MEMCACHED_END) - { - rc= MEMCACHED_SUCCESS; - } + /* Search for END or something */ + if (result) + { + memcached_coll_result_reset(&ptr->collection_result); + memcached_coll_fetch_result(ptr, &ptr->collection_result, &rc); } - } - if (rc == MEMCACHED_WRITE_FAILURE) - { - memcached_io_reset(instance); + if (rc == MEMCACHED_END) + { + rc= MEMCACHED_SUCCESS; + } } return rc; @@ -2904,32 +2890,28 @@ static memcached_return_t do_coll_exist(memcached_st *ptr, rc= memcached_vdo(instance, vector, 5, to_write); - if (rc == MEMCACHED_SUCCESS) + if (rc != MEMCACHED_SUCCESS) { - if (to_write == false) - { - rc= MEMCACHED_BUFFERED; - } - else if (ptr->flags.no_reply) - { - rc= MEMCACHED_SUCCESS; - } - else - { - char result[MEMCACHED_DEFAULT_COMMAND_SIZE]; - rc= memcached_coll_response(instance, result, MEMCACHED_DEFAULT_COMMAND_SIZE, NULL); - memcached_set_last_response_code(ptr, rc); - - if (rc == MEMCACHED_EXIST) - { - rc= MEMCACHED_SUCCESS; - } - } + if (rc == MEMCACHED_WRITE_FAILURE) + memcached_io_reset(instance); + + return rc; } - if (rc == MEMCACHED_WRITE_FAILURE) + if (to_write == false) { - memcached_io_reset(instance); + rc= MEMCACHED_BUFFERED; + return rc; + } + + if (ptr->flags.no_reply == false) + { + char result[MEMCACHED_DEFAULT_COMMAND_SIZE]; + rc= memcached_coll_response(instance, result, MEMCACHED_DEFAULT_COMMAND_SIZE, NULL); + memcached_set_last_response_code(ptr, rc); + + if (rc == MEMCACHED_EXIST) + rc= MEMCACHED_SUCCESS; } return rc; @@ -3472,43 +3454,39 @@ static memcached_return_t do_coll_update(memcached_st *ptr, #endif rc= memcached_vdo(instance, vector, veclen, to_write); - if (rc == MEMCACHED_SUCCESS) + if (rc != MEMCACHED_SUCCESS) { - if (to_write == false) - { - rc= MEMCACHED_BUFFERED; - } - else if (ptr->flags.no_reply || ptr->flags.piped) - { - rc= MEMCACHED_SUCCESS; - } - else - { - char result[MEMCACHED_DEFAULT_COMMAND_SIZE]; - rc= memcached_coll_response(instance, result, MEMCACHED_DEFAULT_COMMAND_SIZE, NULL); -#ifdef ENABLE_REPLICATION - if (rc == MEMCACHED_SWITCHOVER or rc == MEMCACHED_REPL_SLAVE) - { - ZOO_LOG_INFO(("Switchover: hostname=%s port=%d error=%s", - instance->hostname, instance->port, memcached_strerror(ptr, rc))); - if (memcached_rgroup_switchover(ptr, instance) == true) { - instance= memcached_server_instance_fetch(ptr, server_key); - goto do_action; - } - } -#endif - memcached_set_last_response_code(ptr, rc); + if (rc == MEMCACHED_WRITE_FAILURE) + memcached_io_reset(instance); + + return rc; + } - if (rc == MEMCACHED_UPDATED) - { - rc= MEMCACHED_SUCCESS; - } - } + if (to_write == false) + { + rc= MEMCACHED_BUFFERED; + return rc; } - if (rc == MEMCACHED_WRITE_FAILURE) + if (ptr->flags.no_reply == false and ptr->flags.piped == false) { - memcached_io_reset(instance); + char result[MEMCACHED_DEFAULT_COMMAND_SIZE]; + rc= memcached_coll_response(instance, result, MEMCACHED_DEFAULT_COMMAND_SIZE, NULL); +#ifdef ENABLE_REPLICATION + if (rc == MEMCACHED_SWITCHOVER or rc == MEMCACHED_REPL_SLAVE) + { + ZOO_LOG_INFO(("Switchover: hostname=%s port=%d error=%s", + instance->hostname, instance->port, memcached_strerror(ptr, rc))); + if (memcached_rgroup_switchover(ptr, instance) == true) { + instance= memcached_server_instance_fetch(ptr, server_key); + goto do_action; + } + } +#endif + memcached_set_last_response_code(ptr, rc); + + if (rc == MEMCACHED_UPDATED) + rc= MEMCACHED_SUCCESS; } return rc; @@ -3618,45 +3596,43 @@ static memcached_return_t do_coll_arithmetic(memcached_st *ptr, #endif rc= memcached_vdo(instance, vector, 4, to_write); - if (rc == MEMCACHED_SUCCESS) + if (rc != MEMCACHED_SUCCESS) + return rc; + + if (to_write == false) + { + rc= MEMCACHED_BUFFERED; + return rc; + } + + if (ptr->flags.no_reply == false and ptr->flags.piped == false) { - if (to_write == false) + char result[MEMCACHED_DEFAULT_COMMAND_SIZE]; + rc= memcached_coll_response(instance, result, MEMCACHED_DEFAULT_COMMAND_SIZE, NULL); + #ifdef ENABLE_REPLICATION + if (rc == MEMCACHED_SWITCHOVER or rc == MEMCACHED_REPL_SLAVE) { - rc= MEMCACHED_BUFFERED; + ZOO_LOG_INFO(("Switchover: hostname=%s port=%d error=%s", + instance->hostname, instance->port, memcached_strerror(ptr, rc))); + if (memcached_rgroup_switchover(ptr, instance) == true) { + instance= memcached_server_instance_fetch(ptr, server_key); + goto do_action; + } } - else if (ptr->flags.no_reply || ptr->flags.piped) + #endif + if (rc == MEMCACHED_NOTFOUND + || rc == MEMCACHED_NOTFOUND_ELEMENT + || rc == MEMCACHED_CLIENT_ERROR + || rc == MEMCACHED_TYPE_MISMATCH + || rc == MEMCACHED_BKEY_MISMATCH + || rc == MEMCACHED_SERVER_ERROR) { - rc= MEMCACHED_SUCCESS; + *value= 0; + return rc; } else { - char result[MEMCACHED_DEFAULT_COMMAND_SIZE]; - rc= memcached_coll_response(instance, result, MEMCACHED_DEFAULT_COMMAND_SIZE, NULL); -#ifdef ENABLE_REPLICATION - if (rc == MEMCACHED_SWITCHOVER or rc == MEMCACHED_REPL_SLAVE) - { - ZOO_LOG_INFO(("Switchover: hostname=%s port=%d error=%s", - instance->hostname, instance->port, memcached_strerror(ptr, rc))); - if (memcached_rgroup_switchover(ptr, instance) == true) { - instance= memcached_server_instance_fetch(ptr, server_key); - goto do_action; - } - } -#endif - if (rc == MEMCACHED_NOTFOUND - || rc == MEMCACHED_NOTFOUND_ELEMENT - || rc == MEMCACHED_CLIENT_ERROR - || rc == MEMCACHED_TYPE_MISMATCH - || rc == MEMCACHED_BKEY_MISMATCH - || rc == MEMCACHED_SERVER_ERROR) - { - *value= 0; - return rc; - } - else - { - *value= strtoull(result, (char **)NULL, 10); - } + *value= strtoull(result, (char **)NULL, 10); } } @@ -3766,34 +3742,32 @@ static memcached_return_t do_coll_count(memcached_st *ptr, rc= memcached_vdo(instance, vector, 4, to_write); - if (rc == MEMCACHED_SUCCESS) + if (rc != MEMCACHED_SUCCESS) { - if (to_write == false) - { - rc= MEMCACHED_BUFFERED; - } - else if (ptr->flags.no_reply || ptr->flags.piped) - { - rc= MEMCACHED_SUCCESS; - } - else - { - char response[MEMCACHED_DEFAULT_COMMAND_SIZE]; - rc= memcached_coll_response(instance, response, MEMCACHED_DEFAULT_COMMAND_SIZE, &ptr->collection_result); - - if (rc == MEMCACHED_COUNT) - { - *count= ptr->collection_result.collection_count; - /* reset collection because it is used in memcached_coll_result_reset(collection_result.cc)*/ - ptr->collection_result.collection_count= 0; - rc= MEMCACHED_SUCCESS; - } - } + if (rc == MEMCACHED_WRITE_FAILURE) + memcached_io_reset(instance); + + return rc; } - if (rc == MEMCACHED_WRITE_FAILURE) + if (to_write == false) + { + rc= MEMCACHED_BUFFERED; + return rc; + } + + if (ptr->flags.no_reply == false and ptr->flags.piped == false) { - memcached_io_reset(instance); + char response[MEMCACHED_DEFAULT_COMMAND_SIZE]; + rc= memcached_coll_response(instance, response, MEMCACHED_DEFAULT_COMMAND_SIZE, &ptr->collection_result); + + if (rc == MEMCACHED_COUNT) + { + *count= ptr->collection_result.collection_count; + /* reset collection because it is used in memcached_coll_result_reset(collection_result.cc)*/ + ptr->collection_result.collection_count= 0; + rc= MEMCACHED_SUCCESS; + } } return rc; diff --git a/libmemcached/delete.cc b/libmemcached/delete.cc index 8f1de223..5e17f004 100644 --- a/libmemcached/delete.cc +++ b/libmemcached/delete.cc @@ -101,38 +101,39 @@ static inline memcached_return_t ascii_delete(memcached_st *ptr, /* Send command header */ memcached_return_t rc= memcached_vdo(instance, vector, 5, to_write); - if (rc == MEMCACHED_SUCCESS) + if (rc != MEMCACHED_SUCCESS) { - if (to_write == false) + memcached_io_reset(instance); + return rc; + } + + if (to_write == false) + { + rc= MEMCACHED_BUFFERED; + return rc; + } + + if (no_reply == false) + { + char result[MEMCACHED_DEFAULT_COMMAND_SIZE]; + rc= memcached_response(instance, result, MEMCACHED_DEFAULT_COMMAND_SIZE, NULL); + + if (rc == MEMCACHED_DELETED) { - rc= MEMCACHED_BUFFERED; + rc= MEMCACHED_SUCCESS; + return rc; } - else if (no_reply == false) - { - char result[MEMCACHED_DEFAULT_COMMAND_SIZE]; - rc= memcached_response(instance, result, MEMCACHED_DEFAULT_COMMAND_SIZE, NULL); - - if (rc == MEMCACHED_DELETED) - { - rc= MEMCACHED_SUCCESS; - } #ifdef ENABLE_REPLICATION - else if (rc == MEMCACHED_SWITCHOVER or rc == MEMCACHED_REPL_SLAVE) - { - ZOO_LOG_INFO(("Switchover: hostname=%s port=%d error=%s", - instance->hostname, instance->port, memcached_strerror(ptr, rc))); - if (memcached_rgroup_switchover(ptr, instance) == true) { - instance= memcached_server_instance_fetch(ptr, server_key); - goto do_action; - } + if (rc == MEMCACHED_SWITCHOVER or rc == MEMCACHED_REPL_SLAVE) + { + ZOO_LOG_INFO(("Switchover: hostname=%s port=%d error=%s", + instance->hostname, instance->port, memcached_strerror(ptr, rc))); + if (memcached_rgroup_switchover(ptr, instance) == true) { + instance= memcached_server_instance_fetch(ptr, server_key); + goto do_action; } -#endif } - } - else - { - memcached_io_reset(instance); - return rc; +#endif } return rc; diff --git a/libmemcached/exist.cc b/libmemcached/exist.cc index 5cdeb6ed..8cfc02c5 100644 --- a/libmemcached/exist.cc +++ b/libmemcached/exist.cc @@ -74,21 +74,24 @@ static memcached_return_t ascii_exist(memcached_st *memc, memcached_server_write_instance_st instance= memcached_server_instance_fetch(memc, server_key); /* Send command header */ - memcached_return_t rc= memcached_vdo(instance, vector, 8, true); - if (rc == MEMCACHED_SUCCESS) + memcached_return_t rc= memcached_vdo(instance, vector, 8, true); + + if (rc != MEMCACHED_SUCCESS) { - char buffer[MEMCACHED_DEFAULT_COMMAND_SIZE]; - rc= memcached_response(instance, buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, NULL); + if (rc == MEMCACHED_WRITE_FAILURE) + memcached_io_reset(instance); + + return rc; + } - if (rc == MEMCACHED_NOTSTORED) - rc= MEMCACHED_SUCCESS; + char buffer[MEMCACHED_DEFAULT_COMMAND_SIZE]; + rc= memcached_response(instance, buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, NULL); - if (rc == MEMCACHED_STORED) - rc= MEMCACHED_NOTFOUND; - } + if (rc == MEMCACHED_NOTSTORED) + rc= MEMCACHED_SUCCESS; - if (rc == MEMCACHED_WRITE_FAILURE) - memcached_io_reset(instance); + if (rc == MEMCACHED_STORED) + rc= MEMCACHED_NOTFOUND; return rc; } diff --git a/libmemcached/storage.cc b/libmemcached/storage.cc index aae5fd39..1f0a2254 100644 --- a/libmemcached/storage.cc +++ b/libmemcached/storage.cc @@ -354,42 +354,43 @@ static memcached_return_t memcached_send_ascii(memcached_st *ptr, /* Send command header */ memcached_return_t rc= memcached_vdo(instance, vector, 11, to_write); - if (rc == MEMCACHED_SUCCESS) + if (rc != MEMCACHED_SUCCESS) { - if (ptr->flags.no_reply) - { - rc= (to_write == false) ? MEMCACHED_BUFFERED : MEMCACHED_SUCCESS; - } - else if (to_write == false) + if (rc == MEMCACHED_WRITE_FAILURE) + memcached_io_reset(instance); + + return rc; + } + + if (to_write == false) + { + rc= MEMCACHED_BUFFERED; + return rc; + } + + if (ptr->flags.no_reply == false) + { + char result[MEMCACHED_DEFAULT_COMMAND_SIZE]; + rc= memcached_response(instance, result, MEMCACHED_DEFAULT_COMMAND_SIZE, NULL); + + if (rc == MEMCACHED_STORED) { - rc= MEMCACHED_BUFFERED; + rc= MEMCACHED_SUCCESS; + return rc; } - else - { - char result[MEMCACHED_DEFAULT_COMMAND_SIZE]; - rc= memcached_response(instance, result, MEMCACHED_DEFAULT_COMMAND_SIZE, NULL); - - if (rc == MEMCACHED_STORED) - { - rc= MEMCACHED_SUCCESS; - } #ifdef ENABLE_REPLICATION - else if (rc == MEMCACHED_SWITCHOVER or rc == MEMCACHED_REPL_SLAVE) - { - ZOO_LOG_INFO(("Switchover: hostname=%s port=%d error=%s", - instance->hostname, instance->port, memcached_strerror(ptr, rc))); - if (memcached_rgroup_switchover(ptr, instance) == true) { - instance= memcached_server_instance_fetch(ptr, server_key); - goto do_action; - } + if (rc == MEMCACHED_SWITCHOVER or rc == MEMCACHED_REPL_SLAVE) + { + ZOO_LOG_INFO(("Switchover: hostname=%s port=%d error=%s", + instance->hostname, instance->port, memcached_strerror(ptr, rc))); + if (memcached_rgroup_switchover(ptr, instance) == true) { + instance= memcached_server_instance_fetch(ptr, server_key); + goto do_action; } -#endif } +#endif } - if (rc == MEMCACHED_WRITE_FAILURE) - memcached_io_reset(instance); - return rc; }