Add a request id for each request that hits the wire.
authorBrian Aker <brian@tangent.org>
Mon, 18 Jun 2012 01:21:55 +0000 (18:21 -0700)
committerBrian Aker <brian@tangent.org>
Mon, 18 Jun 2012 01:21:55 +0000 (18:21 -0700)
16 files changed:
libmemcached-1.0/struct/server.h
libmemcached/auto.cc
libmemcached/common.h
libmemcached/delete.cc
libmemcached/exist.cc
libmemcached/flush.cc
libmemcached/get.cc
libmemcached/io.cc
libmemcached/io.hpp
libmemcached/quit.cc
libmemcached/sasl.cc
libmemcached/server.cc
libmemcached/stats.cc
libmemcached/storage.cc
libmemcached/touch.cc
libmemcached/version.cc

index b5bd1ca73718a0236ae839c55db57f7bc9e8e12b..d20b54a29a0bf95cf89fdbe52b05ebd74165e83b 100644 (file)
@@ -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;
index df4ceb2fd2f1025f5415e05e3a05675a821570ee..3054368bc965d7f1fb80205a5a16adb07742f66f 100644 (file)
@@ -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;
index 2fe6b0f8cf6988ccbbd38bdfc8ac0c731b34d37f..2d031509c072f0e8e7b664a469f29f6b5c1b3747 100644 (file)
@@ -106,6 +106,7 @@ memcached_return_t memcached_server_execute(memcached_st *ptr,
 #include <libmemcached/io.h>
 #ifdef __cplusplus
 #include <libmemcached/string.hpp>
+#include <libmemcached/memcached/protocol_binary.h>
 #include <libmemcached/io.hpp>
 #include <libmemcached/udp.hpp>
 #include <libmemcached/do.hpp>
@@ -122,7 +123,6 @@ memcached_return_t memcached_server_execute(memcached_st *ptr,
 #include <libmemcached/internal.h>
 #include <libmemcached/array.h>
 #include <libmemcached/libmemcached_probes.h>
-#include <libmemcached/memcached/protocol_binary.h>
 #include <libmemcached/byteorder.h>
 #include <libmemcached/initialize_query.h>
 #ifdef __cplusplus
index e2a73450950b45e0e41cc5f834c8d9dd4de00e22..a96ecbace8627b5f66e978ae63ab783febad826b 100644 (file)
@@ -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;
index 67c6902eca9bb5eddc51ef265284bef0ed582b15..58408fd747d2e0795257e468c6c1982fbfeb5bee 100644 (file)
@@ -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;
index 6b8ea4b0815a7b6ae4daf7bfd4832a1aff934f94..0c6141d8c121920a60ed4f32ca5a5880ab64ba81 100644 (file)
@@ -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)
     {
index be7d9e5f66b226912f86ced59e7d9bf9e277e953..9aa884f443687d63f9c2390179179019c483030e 100644 (file)
@@ -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;
index defe234316adf3f8308f74c608253b6c4f885f8b..48e5ecffbe789846e832f297fa6bdb79388920d1 100644 (file)
 
 #include <libmemcached/common.h>
 
+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
index ce9cef5122267c755fbdff75d1f3485bce46453b..bff6b83db205ae8edc6b638e48eb9ff0c035c1f6 100644 (file)
@@ -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,
index 2cfc44b56dab85abc371502d818ddca1f1caa317..929d0ca0cc3809f48884e637e3cecf1ae96ed55a 100644 (file)
@@ -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;
 
index 7e0e50d625b2c4c1cbd5047fe3cd9c852db20492..603c5864091a27b143f1d3c1e03b8c214ecc8129 100644 (file)
@@ -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,
index 8aba7576e60e4fa661b9ff1aaba75eede009984b..9345da0b3a28eb1957e7bc19d33473ea95d94e4b 100644 (file)
@@ -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
index 49dfab018e4ac37cddf3891ece763670902a15de..cfe870b9985c7f7d817638f6fb698dc113713183 100644 (file)
@@ -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;
 
index 40c8d34d389560b3d66793866a82e1c616142675..97470048e5d081e78b71e355d5343188d2db2080 100644 (file)
@@ -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;
index b7fa247532e41f32d46e4fe210c23a69688f4f49..c78352479c8e0ba9644c864f997d49d6d4534a94 100644 (file)
@@ -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)));
index 9ba09b0d5409f53cede05f658b59aecf09a437b9..9f41c97ae6ac10e7224cb576d81027dc21615fd7 100644 (file)
@@ -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;