From 0cf38dabee76051696d28d430416a7a0a4c75362 Mon Sep 17 00:00:00 2001 From: uhm0311 Date: Tue, 19 Apr 2022 16:32:58 +0900 Subject: [PATCH] INTERNAL: Move io reset from where calls memcached_vdo() to where fails inside of memcached_vdo() #167 --- libmemcached/auto.cc | 11 +++++++++++ libmemcached/collection.cc | 39 ++++++++++++++++++++++++++++++++++++++ libmemcached/constants.h | 1 + libmemcached/delete.cc | 14 ++++++++++++++ libmemcached/do.cc | 6 ++++++ libmemcached/exist.cc | 10 ++++++++++ libmemcached/flush.cc | 7 +++++++ libmemcached/get.cc | 4 ++++ libmemcached/stats.cc | 18 ++++++++++++++++++ libmemcached/storage.cc | 16 ++++++++++++++++ libmemcached/version.cc | 28 +++++++++++++++++++++++++++ 11 files changed, 154 insertions(+) diff --git a/libmemcached/auto.cc b/libmemcached/auto.cc index e8ceca19..312dbddc 100644 --- a/libmemcached/auto.cc +++ b/libmemcached/auto.cc @@ -113,7 +113,11 @@ static memcached_return_t text_incr_decr(memcached_st *ptr, #endif /* Send command header */ memcached_return_t rc= memcached_vdo(instance, vector, 7, true); +#ifdef MEMCACHED_VDO_ERROR_HANDLING + if (ptr->flags.no_reply or rc != MEMCACHED_SUCCESS) +#else if (ptr->flags.no_reply or memcached_failed(rc)) +#endif { return rc; } @@ -214,6 +218,12 @@ static memcached_return_t binary_incr_decr(memcached_st *ptr, uint8_t cmd, #ifdef ENABLE_REPLICATION do_action: #endif +#ifdef MEMCACHED_VDO_ERROR_HANDLING + memcached_return_t rc= memcached_vdo(instance, vector, 3, true); + if (no_reply or rc != MEMCACHED_SUCCESS) { + return rc; + } +#else memcached_return_t rc; if (memcached_failed(rc= memcached_vdo(instance, vector, 3, true))) { @@ -223,6 +233,7 @@ static memcached_return_t binary_incr_decr(memcached_st *ptr, uint8_t cmd, if (no_reply) return MEMCACHED_SUCCESS; +#endif rc= memcached_response(instance, (char*)value, sizeof(*value), NULL); #ifdef ENABLE_REPLICATION diff --git a/libmemcached/collection.cc b/libmemcached/collection.cc index e9f05024..2c6087d0 100644 --- a/libmemcached/collection.cc +++ b/libmemcached/collection.cc @@ -763,8 +763,11 @@ memcached_return_t memcached_set_attrs(memcached_st *ptr, } } +#ifdef MEMCACHED_VDO_ERROR_HANDLING +#else if (rc == MEMCACHED_WRITE_FAILURE) memcached_io_reset(instance); +#endif return rc; } @@ -1043,10 +1046,13 @@ static memcached_return_t do_coll_create(memcached_st *ptr, } } +#ifdef MEMCACHED_VDO_ERROR_HANDLING +#else if (rc == MEMCACHED_WRITE_FAILURE) { memcached_io_reset(instance); } +#endif return rc; } @@ -1186,8 +1192,11 @@ static memcached_return_t internal_coll_piped_insert(memcached_st *ptr, rc= memcached_vdo(instance, vector, 7, to_write); if (rc != MEMCACHED_SUCCESS) { +#ifdef MEMCACHED_VDO_ERROR_HANDLING +#else if (rc == MEMCACHED_WRITE_FAILURE) memcached_io_reset(instance); +#endif return rc; } @@ -1261,8 +1270,11 @@ static memcached_return_t internal_coll_piped_exist(memcached_st *ptr, rc= memcached_vdo(instance, vector, 6, to_write); if (rc != MEMCACHED_SUCCESS) { +#ifdef MEMCACHED_VDO_ERROR_HANDLING +#else if (rc == MEMCACHED_WRITE_FAILURE) memcached_io_reset(instance); +#endif return rc; } @@ -1426,8 +1438,11 @@ static memcached_return_t do_coll_insert(memcached_st *ptr, } } +#ifdef MEMCACHED_VDO_ERROR_HANDLING +#else if (rc == MEMCACHED_WRITE_FAILURE) memcached_io_reset(instance); +#endif return rc; } @@ -1656,10 +1671,13 @@ static memcached_return_t do_coll_delete(memcached_st *ptr, } } +#ifdef MEMCACHED_VDO_ERROR_HANDLING +#else if (rc == MEMCACHED_WRITE_FAILURE) { memcached_io_reset(instance); } +#endif return rc; } @@ -1966,10 +1984,13 @@ static memcached_return_t do_coll_get(memcached_st *ptr, mkey_buffer= NULL; } +#ifdef MEMCACHED_VDO_ERROR_HANDLING +#else if (rc == MEMCACHED_WRITE_FAILURE) { memcached_io_reset(instance); } +#endif return rc; } @@ -2339,10 +2360,13 @@ static memcached_return_t do_bop_find_position(memcached_st *ptr, } } +#ifdef MEMCACHED_VDO_ERROR_HANDLING +#else if (rc == MEMCACHED_WRITE_FAILURE) { memcached_io_reset(instance); } +#endif return rc; } @@ -2442,10 +2466,13 @@ static memcached_return_t do_bop_get_by_position(memcached_st *ptr, } } +#ifdef MEMCACHED_VDO_ERROR_HANDLING +#else if (rc == MEMCACHED_WRITE_FAILURE) { memcached_io_reset(instance); } +#endif return rc; } @@ -2555,10 +2582,13 @@ static memcached_return_t do_bop_find_position_with_get(memcached_st *ptr, } } +#ifdef MEMCACHED_VDO_ERROR_HANDLING +#else if (rc == MEMCACHED_WRITE_FAILURE) { memcached_io_reset(instance); } +#endif return rc; } @@ -2927,10 +2957,13 @@ static memcached_return_t do_coll_exist(memcached_st *ptr, } } +#ifdef MEMCACHED_VDO_ERROR_HANDLING +#else if (rc == MEMCACHED_WRITE_FAILURE) { memcached_io_reset(instance); } +#endif return rc; } @@ -3506,10 +3539,13 @@ static memcached_return_t do_coll_update(memcached_st *ptr, } } +#ifdef MEMCACHED_VDO_ERROR_HANDLING +#else if (rc == MEMCACHED_WRITE_FAILURE) { memcached_io_reset(instance); } +#endif return rc; } @@ -3791,10 +3827,13 @@ static memcached_return_t do_coll_count(memcached_st *ptr, } } +#ifdef MEMCACHED_VDO_ERROR_HANDLING +#else if (rc == MEMCACHED_WRITE_FAILURE) { memcached_io_reset(instance); } +#endif return rc; } diff --git a/libmemcached/constants.h b/libmemcached/constants.h index 18686c64..74751b5d 100644 --- a/libmemcached/constants.h +++ b/libmemcached/constants.h @@ -66,6 +66,7 @@ #define POOL_UPDATE_SERVERLIST 1 #define POOL_MORE_CONCURRENCY 1 #define KETAMA_HASH_COLLSION 1 +#define MEMCACHED_VDO_ERROR_HANDLING 1 /* Public defines */ #define MEMCACHED_DEFAULT_PORT 11211 diff --git a/libmemcached/delete.cc b/libmemcached/delete.cc index 8f1de223..12eb2089 100644 --- a/libmemcached/delete.cc +++ b/libmemcached/delete.cc @@ -129,11 +129,14 @@ static inline memcached_return_t ascii_delete(memcached_st *ptr, #endif } } +#ifdef MEMCACHED_VDO_ERROR_HANDLING +#else else { memcached_io_reset(instance); return rc; } +#endif return rc; } @@ -184,10 +187,15 @@ static inline memcached_return_t binary_delete(memcached_st *ptr, memcached_io_write(instance, NULL, 0, true); } +#ifdef MEMCACHED_VDO_ERROR_HANDLING + memcached_return_t rc= memcached_vdo(instance, vector, 3, to_write); + if (rc != MEMCACHED_SUCCESS) { +#else memcached_return_t rc= MEMCACHED_SUCCESS; if ((rc= memcached_vdo(instance, vector, 3, to_write)) != MEMCACHED_SUCCESS) { memcached_io_reset(instance); +#endif return rc; } @@ -205,6 +213,11 @@ static inline memcached_return_t binary_delete(memcached_st *ptr, replica= memcached_server_instance_fetch(ptr, server_key); +#ifdef MEMCACHED_VDO_ERROR_HANDLING + if (memcached_vdo(replica, vector, 3, to_write) == MEMCACHED_SUCCESS) { + memcached_server_response_decrement(replica); + } +#else if (memcached_vdo(replica, vector, 3, to_write) != MEMCACHED_SUCCESS) { memcached_io_reset(replica); @@ -213,6 +226,7 @@ static inline memcached_return_t binary_delete(memcached_st *ptr, { memcached_server_response_decrement(replica); } +#endif } } diff --git a/libmemcached/do.cc b/libmemcached/do.cc index 14b65a8d..64dd9328 100644 --- a/libmemcached/do.cc +++ b/libmemcached/do.cc @@ -61,6 +61,9 @@ memcached_return_t memcached_do(memcached_server_write_instance_st ptr, if (sent_length == -1 || (size_t)sent_length != command_length) { rc= MEMCACHED_WRITE_FAILURE; +#ifdef MEMCACHED_VDO_ERROR_HANDLING + memcached_io_reset(ptr); +#endif return rc; } if ((ptr->root->flags.no_reply) == 0) @@ -114,6 +117,9 @@ memcached_return_t memcached_vdo(memcached_server_write_instance_st ptr, rc= MEMCACHED_WRITE_FAILURE; WATCHPOINT_ERROR(rc); WATCHPOINT_ERRNO(errno); +#ifdef MEMCACHED_VDO_ERROR_HANDLING + memcached_io_reset(ptr); +#endif return rc; } if ((ptr->root->flags.no_reply) == 0 and (ptr->root->flags.piped == false)) diff --git a/libmemcached/exist.cc b/libmemcached/exist.cc index e8db2e46..f97b75ba 100644 --- a/libmemcached/exist.cc +++ b/libmemcached/exist.cc @@ -110,8 +110,11 @@ static memcached_return_t ascii_exist(memcached_st *memc, #endif } +#ifdef MEMCACHED_VDO_ERROR_HANDLING +#else if (rc == MEMCACHED_WRITE_FAILURE) memcached_io_reset(instance); +#endif return rc; } @@ -148,12 +151,19 @@ static memcached_return_t binary_exist(memcached_st *memc, memcached_server_write_instance_st instance= memcached_server_instance_fetch(memc, server_key); /* write the header */ +#ifdef MEMCACHED_VDO_ERROR_HANDLING + memcached_return_t rc= memcached_vdo(instance, vector, 3, true); + if (rc != MEMCACHED_SUCCESS) { + return rc; + } +#else memcached_return_t rc; if ((rc= memcached_vdo(instance, vector, 3, true)) != MEMCACHED_SUCCESS) { memcached_io_reset(instance); return (rc == MEMCACHED_SUCCESS) ? MEMCACHED_WRITE_FAILURE : rc; } +#endif rc= memcached_response(instance, NULL, 0, NULL); diff --git a/libmemcached/flush.cc b/libmemcached/flush.cc index 20061317..e4729cc9 100644 --- a/libmemcached/flush.cc +++ b/libmemcached/flush.cc @@ -219,11 +219,18 @@ static memcached_return_t memcached_flush_binary(memcached_st *ptr, request.message.header.request.opcode= PROTOCOL_BINARY_CMD_FLUSH; } +#ifdef MEMCACHED_VDO_ERROR_HANDLING + memcached_return_t rc = memcached_do(instance, request.bytes, sizeof(request.bytes), true); + if (rc != MEMCACHED_SUCCESS) { + return rc; + } +#else if (memcached_do(instance, request.bytes, sizeof(request.bytes), true) != MEMCACHED_SUCCESS) { memcached_io_reset(instance); return MEMCACHED_WRITE_FAILURE; } +#endif } for (uint32_t x= 0; x < memcached_server_count(ptr); x++) diff --git a/libmemcached/get.cc b/libmemcached/get.cc index 8edbedf8..33d3d361 100644 --- a/libmemcached/get.cc +++ b/libmemcached/get.cc @@ -199,9 +199,13 @@ static memcached_return_t ascii_get_by_key(memcached_st *ptr, }; rc= memcached_vdo(instance, vector, 4, true); +#ifdef MEMCACHED_VDO_ERROR_HANDLING + if (rc != MEMCACHED_SUCCESS) { +#else if (memcached_failed(rc)) { memcached_io_reset(instance); +#endif memcached_set_error(*ptr, rc, MEMCACHED_AT); } return rc; diff --git a/libmemcached/stats.cc b/libmemcached/stats.cc index fbc3b95f..b3d72142 100644 --- a/libmemcached/stats.cc +++ b/libmemcached/stats.cc @@ -352,20 +352,34 @@ static memcached_return_t binary_stats_fetch(memcached_stat_st *memc_stat, { len, args } }; +#ifdef MEMCACHED_VDO_ERROR_HANDLING + rc = memcached_vdo(instance, vector, 2, true); + if (rc != MEMCACHED_SUCCESS) { + return rc; + } +#else if (memcached_vdo(instance, vector, 2, true) != MEMCACHED_SUCCESS) { memcached_io_reset(instance); return MEMCACHED_WRITE_FAILURE; } +#endif } else { +#ifdef MEMCACHED_VDO_ERROR_HANDLING + memcached_return_t rc = memcached_do(instance, request.bytes, sizeof(request.bytes), true); + if (rc != MEMCACHED_SUCCESS) { + return rc; + } +#else if (memcached_do(instance, request.bytes, sizeof(request.bytes), true) != MEMCACHED_SUCCESS) { memcached_io_reset(instance); return MEMCACHED_WRITE_FAILURE; } +#endif } memcached_server_response_decrement(instance); @@ -434,7 +448,11 @@ static memcached_return_t ascii_stats_fetch(memcached_stat_st *memc_stat, } memcached_return_t rc= memcached_do(instance, buffer, (size_t)write_length, true); +#ifdef MEMCACHED_VDO_ERROR_HANDLING + if (rc == MEMCACHED_SUCCESS) +#else if (memcached_success(rc)) +#endif { char result[MEMCACHED_DEFAULT_COMMAND_SIZE]; while ((rc= memcached_response(instance, result, MEMCACHED_DEFAULT_COMMAND_SIZE, NULL)) == MEMCACHED_STAT) diff --git a/libmemcached/storage.cc b/libmemcached/storage.cc index aae5fd39..1223bc1b 100644 --- a/libmemcached/storage.cc +++ b/libmemcached/storage.cc @@ -196,12 +196,19 @@ static memcached_return_t memcached_send_binary(memcached_st *ptr, } /* write the header */ +#ifdef MEMCACHED_VDO_ERROR_HANDLING + memcached_return_t rc= memcached_vdo(server, vector, 4, flush); + if (rc != MEMCACHED_SUCCESS) { + return rc; + } +#else memcached_return_t rc; if ((rc= memcached_vdo(server, vector, 4, flush)) != MEMCACHED_SUCCESS) { memcached_io_reset(server); return (rc == MEMCACHED_SUCCESS) ? MEMCACHED_WRITE_FAILURE : rc; } +#endif if (verb == SET_OP && ptr->number_of_replicas > 0) { @@ -218,6 +225,11 @@ static memcached_return_t memcached_send_binary(memcached_st *ptr, instance= memcached_server_instance_fetch(ptr, server_key); +#ifdef MEMCACHED_VDO_ERROR_HANDLING + if (memcached_vdo(instance, vector, 4, false) == MEMCACHED_SUCCESS) { + memcached_server_response_decrement(instance); + } +#else if (memcached_vdo(instance, vector, 4, false) != MEMCACHED_SUCCESS) { memcached_io_reset(instance); @@ -226,6 +238,7 @@ static memcached_return_t memcached_send_binary(memcached_st *ptr, { memcached_server_response_decrement(instance); } +#endif } } @@ -387,8 +400,11 @@ static memcached_return_t memcached_send_ascii(memcached_st *ptr, } } +#ifdef MEMCACHED_VDO_ERROR_HANDLING +#else if (rc == MEMCACHED_WRITE_FAILURE) memcached_io_reset(instance); +#endif return rc; } diff --git a/libmemcached/version.cc b/libmemcached/version.cc index d632be41..3b2165d9 100644 --- a/libmemcached/version.cc +++ b/libmemcached/version.cc @@ -79,11 +79,18 @@ static inline memcached_return_t memcached_version_textual(memcached_st *ptr) } memcached_return_t rrc= memcached_vdo(instance, vector, 1, true); +#ifdef MEMCACHED_VDO_ERROR_HANDLING + if (rrc != MEMCACHED_SUCCESS) +#else if (memcached_failed(rrc)) +#endif { errors_happened= true; (void)memcached_set_error(*instance, rrc, MEMCACHED_AT); +#ifdef MEMCACHED_VDO_ERROR_HANDLING +#else memcached_io_reset(instance); +#endif continue; } success++; @@ -133,11 +140,18 @@ static inline memcached_return_t memcached_version_binary(memcached_st *ptr) } memcached_return_t rrc= memcached_vdo(instance, vector, 1, true); +#ifdef MEMCACHED_VDO_ERROR_HANDLING + if (rrc != MEMCACHED_SUCCESS) +#else if (memcached_failed(rrc)) +#endif { errors_happened= true; (void)memcached_set_error(*instance, rrc, MEMCACHED_AT); +#ifdef MEMCACHED_VDO_ERROR_HANDLING +#else memcached_io_reset(instance); +#endif continue; } success++; @@ -174,10 +188,17 @@ static inline memcached_return_t version_ascii_instance(memcached_server_st *ins uint32_t before_active= instance->cursor_active; rc= memcached_vdo(instance, vector, 1, true); +#ifdef MEMCACHED_VDO_ERROR_HANDLING + if (rc != MEMCACHED_SUCCESS) +#else if (rc == MEMCACHED_WRITE_FAILURE) +#endif { (void)memcached_set_error(*instance, rc, MEMCACHED_AT); +#ifdef MEMCACHED_VDO_ERROR_HANDLING +#else memcached_io_reset(instance); +#endif return rc; } /* If no_reply or piped is set, cursor_active is not increased in memcached_vdo(). @@ -212,10 +233,17 @@ static inline memcached_return_t version_binary_instance(memcached_server_st *in uint32_t before_active= instance->cursor_active; rc= memcached_vdo(instance, vector, 1, true); +#ifdef MEMCACHED_VDO_ERROR_HANDLING + if (rc != MEMCACHED_SUCCESS) +#else if (rc == MEMCACHED_WRITE_FAILURE) +#endif { (void)memcached_set_error(*instance, rc, MEMCACHED_AT); +#ifdef MEMCACHED_VDO_ERROR_HANDLING +#else memcached_io_reset(instance); +#endif return rc; } /* If no_reply or piped is set, cursor_active is not increased in memcached_vdo().