From: Brian Aker Date: Mon, 18 Jun 2012 01:21:55 +0000 (-0700) Subject: Add a request id for each request that hits the wire. X-Git-Tag: 1.0.9~18 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=b5495838fb245aa1068a1198ed549b98a9c3e666;p=awesomized%2Flibmemcached Add a request id for each request that hits the wire. --- diff --git a/libmemcached-1.0/struct/server.h b/libmemcached-1.0/struct/server.h index b5bd1ca7..d20b54a2 100644 --- a/libmemcached-1.0/struct/server.h +++ b/libmemcached-1.0/struct/server.h @@ -74,6 +74,7 @@ struct memcached_server_st { in_port_t port; memcached_socket_t fd; uint32_t io_bytes_sent; /* # bytes sent since last read */ + uint32_t request_id; uint32_t server_failure_counter; uint64_t server_failure_counter_query_id; uint32_t weight; diff --git a/libmemcached/auto.cc b/libmemcached/auto.cc index df4ceb2f..3054368b 100644 --- a/libmemcached/auto.cc +++ b/libmemcached/auto.cc @@ -118,7 +118,8 @@ static memcached_return_t binary_incr_decr(memcached_server_write_instance_st in } protocol_binary_request_incr request= {}; // = {.bytes= {0}}; - request.message.header.request.magic= PROTOCOL_BINARY_REQ; + initialize_binary_request(instance, request.message.header); + request.message.header.request.opcode= cmd; request.message.header.request.keylen= htons((uint16_t)(key_length + memcached_array_size(instance->root->_namespace))); request.message.header.request.extlen= 20; diff --git a/libmemcached/common.h b/libmemcached/common.h index 2fe6b0f8..2d031509 100644 --- a/libmemcached/common.h +++ b/libmemcached/common.h @@ -106,6 +106,7 @@ memcached_return_t memcached_server_execute(memcached_st *ptr, #include #ifdef __cplusplus #include +#include #include #include #include @@ -122,7 +123,6 @@ memcached_return_t memcached_server_execute(memcached_st *ptr, #include #include #include -#include #include #include #ifdef __cplusplus diff --git a/libmemcached/delete.cc b/libmemcached/delete.cc index e2a73450..a96ecbac 100644 --- a/libmemcached/delete.cc +++ b/libmemcached/delete.cc @@ -76,7 +76,8 @@ static inline memcached_return_t binary_delete(memcached_server_write_instance_s bool should_flush= is_buffering ? false : true; - request.message.header.request.magic= PROTOCOL_BINARY_REQ; + initialize_binary_request(instance, request.message.header); + if (reply) { request.message.header.request.opcode= PROTOCOL_BINARY_CMD_DELETE; diff --git a/libmemcached/exist.cc b/libmemcached/exist.cc index 67c6902e..58408fd7 100644 --- a/libmemcached/exist.cc +++ b/libmemcached/exist.cc @@ -79,7 +79,8 @@ static memcached_return_t binary_exist(memcached_st *memc, memcached_server_writ protocol_binary_request_set request= {}; size_t send_length= sizeof(request.bytes); - request.message.header.request.magic= PROTOCOL_BINARY_REQ; + initialize_binary_request(instance, request.message.header); + request.message.header.request.opcode= PROTOCOL_BINARY_CMD_ADD; request.message.header.request.keylen= htons((uint16_t)(key_length + memcached_array_size(memc->_namespace))); request.message.header.request.datatype= PROTOCOL_BINARY_RAW_BYTES; diff --git a/libmemcached/flush.cc b/libmemcached/flush.cc index 6b8ea4b0..0c6141d8 100644 --- a/libmemcached/flush.cc +++ b/libmemcached/flush.cc @@ -42,7 +42,6 @@ static memcached_return_t memcached_flush_binary(memcached_st *ptr, { protocol_binary_request_flush request= {}; - request.message.header.request.magic= (uint8_t)PROTOCOL_BINARY_REQ; request.message.header.request.opcode= PROTOCOL_BINARY_CMD_FLUSH; request.message.header.request.extlen= 4; request.message.header.request.datatype= PROTOCOL_BINARY_RAW_BYTES; @@ -54,6 +53,7 @@ static memcached_return_t memcached_flush_binary(memcached_st *ptr, for (uint32_t x= 0; x < memcached_server_count(ptr); x++) { memcached_server_write_instance_st instance= memcached_server_instance_fetch(ptr, x); + initialize_binary_request(instance, request.message.header); if (reply) { diff --git a/libmemcached/get.cc b/libmemcached/get.cc index be7d9e5f..9aa884f4 100644 --- a/libmemcached/get.cc +++ b/libmemcached/get.cc @@ -492,7 +492,7 @@ static memcached_return_t simple_binary_mget(memcached_st *ptr, } protocol_binary_request_getk request= { }; //= {.bytes= {0}}; - request.message.header.request.magic= PROTOCOL_BINARY_REQ; + initialize_binary_request(instance, request.message.header); if (mget_mode) { request.message.header.request.opcode= PROTOCOL_BINARY_CMD_GETKQ; @@ -548,13 +548,13 @@ static memcached_return_t simple_binary_mget(memcached_st *ptr, Send a noop command to flush the buffers */ protocol_binary_request_noop request= {}; //= {.bytes= {0}}; - request.message.header.request.magic= PROTOCOL_BINARY_REQ; request.message.header.request.opcode= PROTOCOL_BINARY_CMD_NOOP; request.message.header.request.datatype= PROTOCOL_BINARY_RAW_BYTES; for (uint32_t x= 0; x < memcached_server_count(ptr); ++x) { memcached_server_write_instance_st instance= memcached_server_instance_fetch(ptr, x); + initialize_binary_request(instance, request.message.header); if (memcached_server_response_count(instance)) { @@ -640,7 +640,7 @@ static memcached_return_t replication_binary_mget(memcached_st *ptr, } protocol_binary_request_getk request= {}; - request.message.header.request.magic= PROTOCOL_BINARY_REQ; + initialize_binary_request(instance, request.message.header); request.message.header.request.opcode= PROTOCOL_BINARY_CMD_GETK; request.message.header.request.keylen= htons((uint16_t)(key_length[x] + memcached_array_size(ptr->_namespace))); request.message.header.request.datatype= PROTOCOL_BINARY_RAW_BYTES; diff --git a/libmemcached/io.cc b/libmemcached/io.cc index defe2343..48e5ecff 100644 --- a/libmemcached/io.cc +++ b/libmemcached/io.cc @@ -39,6 +39,13 @@ #include +void initialize_binary_request(memcached_server_write_instance_st server, protocol_binary_request_header& header) +{ + server->request_id++; + header.request.magic= PROTOCOL_BINARY_REQ; + header.request.opaque= htons(server->request_id); +} + enum memc_read_or_write { MEM_READ, MEM_WRITE diff --git a/libmemcached/io.hpp b/libmemcached/io.hpp index ce9cef51..bff6b83d 100644 --- a/libmemcached/io.hpp +++ b/libmemcached/io.hpp @@ -38,6 +38,8 @@ #pragma once +void initialize_binary_request(memcached_server_write_instance_st server, protocol_binary_request_header&); + bool memcached_io_write(memcached_server_write_instance_st ptr); ssize_t memcached_io_write(memcached_server_write_instance_st ptr, diff --git a/libmemcached/quit.cc b/libmemcached/quit.cc index 2cfc44b5..929d0ca0 100644 --- a/libmemcached/quit.cc +++ b/libmemcached/quit.cc @@ -58,7 +58,9 @@ void memcached_quit_server(memcached_server_st *ptr, bool io_death) if (ptr->root->flags.binary_protocol) { protocol_binary_request_quit request= {}; // = {.bytes= {0}}; - request.message.header.request.magic = PROTOCOL_BINARY_REQ; + + initialize_binary_request(ptr, request.message.header); + request.message.header.request.opcode = PROTOCOL_BINARY_CMD_QUIT; request.message.header.request.datatype = PROTOCOL_BINARY_RAW_BYTES; diff --git a/libmemcached/sasl.cc b/libmemcached/sasl.cc index 7e0e50d6..603c5864 100644 --- a/libmemcached/sasl.cc +++ b/libmemcached/sasl.cc @@ -147,7 +147,9 @@ memcached_return_t memcached_sasl_authenticate_connection(memcached_server_st *s * as authenticated */ protocol_binary_request_no_extras request= { }; - request.message.header.request.magic= PROTOCOL_BINARY_REQ; + + initialize_binary_request(ptr, request.message.header); + request.message.header.request.opcode= PROTOCOL_BINARY_CMD_SASL_LIST_MECHS; if (memcached_io_write(server, request.bytes, diff --git a/libmemcached/server.cc b/libmemcached/server.cc index 8aba7576..9345da0b 100644 --- a/libmemcached/server.cc +++ b/libmemcached/server.cc @@ -52,6 +52,7 @@ static inline void _server_init(memcached_server_st *self, memcached_st *root, self->port= port; self->fd= INVALID_SOCKET; self->io_bytes_sent= 0; + self->request_id= 0; self->server_failure_counter= 0; self->server_failure_counter_query_id= 0; self->weight= weight ? weight : 1; // 1 is the default weight value diff --git a/libmemcached/stats.cc b/libmemcached/stats.cc index 49dfab01..cfe870b9 100644 --- a/libmemcached/stats.cc +++ b/libmemcached/stats.cc @@ -351,7 +351,9 @@ static memcached_return_t binary_stats_fetch(memcached_stat_st *memc_stat, { char buffer[MEMCACHED_DEFAULT_COMMAND_SIZE]; protocol_binary_request_stats request= {}; // = {.bytes= {0}}; - request.message.header.request.magic= PROTOCOL_BINARY_REQ; + + initialize_binary_request(instance, request.message.header); + request.message.header.request.opcode= PROTOCOL_BINARY_CMD_STAT; request.message.header.request.datatype= PROTOCOL_BINARY_RAW_BYTES; diff --git a/libmemcached/storage.cc b/libmemcached/storage.cc index 40c8d34d..97470048 100644 --- a/libmemcached/storage.cc +++ b/libmemcached/storage.cc @@ -155,7 +155,8 @@ static memcached_return_t memcached_send_binary(memcached_st *ptr, protocol_binary_request_set request= {}; size_t send_length= sizeof(request.bytes); - request.message.header.request.magic= PROTOCOL_BINARY_REQ; + initialize_binary_request(server, request.message.header); + request.message.header.request.opcode= get_com_code(verb, reply); request.message.header.request.keylen= htons((uint16_t)(key_length + memcached_array_size(ptr->_namespace))); request.message.header.request.datatype= PROTOCOL_BINARY_RAW_BYTES; diff --git a/libmemcached/touch.cc b/libmemcached/touch.cc index b7fa2475..c7835247 100644 --- a/libmemcached/touch.cc +++ b/libmemcached/touch.cc @@ -75,7 +75,9 @@ static memcached_return_t binary_touch(memcached_server_write_instance_st instan time_t expiration) { protocol_binary_request_touch request= {}; //{.bytes= {0}}; - request.message.header.request.magic= PROTOCOL_BINARY_REQ; + + initialize_binary_request(instance, request.message.header); + request.message.header.request.opcode= PROTOCOL_BINARY_CMD_TOUCH; request.message.header.request.extlen= 4; request.message.header.request.keylen= htons((uint16_t)(key_length +memcached_array_size(instance->root->_namespace))); diff --git a/libmemcached/version.cc b/libmemcached/version.cc index 9ba09b0d..9f41c97a 100644 --- a/libmemcached/version.cc +++ b/libmemcached/version.cc @@ -91,7 +91,7 @@ static inline memcached_return_t memcached_version_textual(memcached_st *ptr) static inline memcached_return_t memcached_version_binary(memcached_st *ptr) { protocol_binary_request_version request= {}; - request.message.header.request.magic= PROTOCOL_BINARY_REQ; + request.message.header.request.opcode= PROTOCOL_BINARY_CMD_VERSION; request.message.header.request.datatype= PROTOCOL_BINARY_RAW_BYTES; @@ -106,6 +106,8 @@ static inline memcached_return_t memcached_version_binary(memcached_st *ptr) { memcached_server_write_instance_st instance= memcached_server_instance_fetch(ptr, x); + initialize_binary_request(instance, request.message.header); + if (instance->major_version != UINT8_MAX) { continue;