summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doc/protocol-binary.txt158
-rw-r--r--doc/protocol-binary.xml16
-rw-r--r--memcached.c113
-rw-r--r--protocol_binary.h12
4 files changed, 214 insertions, 85 deletions
diff --git a/doc/protocol-binary.txt b/doc/protocol-binary.txt
index bd1862a..7767e68 100644
--- a/doc/protocol-binary.txt
+++ b/doc/protocol-binary.txt
@@ -68,32 +68,32 @@ Table of Contents
3.3. Command Opcodes . . . . . . . . . . . . . . . . . . . . . 6
3.4. Data Types . . . . . . . . . . . . . . . . . . . . . . . . 6
4. Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
- 4.1. Introduction . . . . . . . . . . . . . . . . . . . . . . . 6
- 4.1.1. Example . . . . . . . . . . . . . . . . . . . . . . . 6
- 4.2. Get, Get Quietly, Get Key, Get Key Quietly . . . . . . . . 7
- 4.2.1. Example . . . . . . . . . . . . . . . . . . . . . . . 8
- 4.3. Set, Add, Replace . . . . . . . . . . . . . . . . . . . . 12
- 4.3.1. Example . . . . . . . . . . . . . . . . . . . . . . . 12
- 4.4. Delete . . . . . . . . . . . . . . . . . . . . . . . . . . 14
- 4.4.1. Example . . . . . . . . . . . . . . . . . . . . . . . 15
- 4.5. Increment, Decrement . . . . . . . . . . . . . . . . . . . 16
- 4.5.1. Example . . . . . . . . . . . . . . . . . . . . . . . 17
- 4.6. quit . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
- 4.6.1. Example . . . . . . . . . . . . . . . . . . . . . . . 20
- 4.7. Flush . . . . . . . . . . . . . . . . . . . . . . . . . . 20
- 4.7.1. Example . . . . . . . . . . . . . . . . . . . . . . . 21
- 4.8. noop . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
- 4.8.1. Example . . . . . . . . . . . . . . . . . . . . . . . 23
- 4.9. version . . . . . . . . . . . . . . . . . . . . . . . . . 23
- 4.9.1. Example . . . . . . . . . . . . . . . . . . . . . . . 24
- 4.10. Append, Prepend . . . . . . . . . . . . . . . . . . . . . 25
- 4.10.1. Example . . . . . . . . . . . . . . . . . . . . . . . 26
- 4.11. Stat . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
- 4.11.1. Example . . . . . . . . . . . . . . . . . . . . . . . 27
- 5. Security Considerations . . . . . . . . . . . . . . . . . . . 29
- 6. Normative References . . . . . . . . . . . . . . . . . . . . . 30
- Appendix A. Acknowledgments . . . . . . . . . . . . . . . . . . . 30
- Authors' Addresses . . . . . . . . . . . . . . . . . . . . . . . . 30
+ 4.1. Introduction . . . . . . . . . . . . . . . . . . . . . . . 7
+ 4.1.1. Example . . . . . . . . . . . . . . . . . . . . . . . 7
+ 4.2. Get, Get Quietly, Get Key, Get Key Quietly . . . . . . . . 8
+ 4.2.1. Example . . . . . . . . . . . . . . . . . . . . . . . 9
+ 4.3. Set, Add, Replace . . . . . . . . . . . . . . . . . . . . 13
+ 4.3.1. Example . . . . . . . . . . . . . . . . . . . . . . . 13
+ 4.4. Delete . . . . . . . . . . . . . . . . . . . . . . . . . . 15
+ 4.4.1. Example . . . . . . . . . . . . . . . . . . . . . . . 16
+ 4.5. Increment, Decrement . . . . . . . . . . . . . . . . . . . 17
+ 4.5.1. Example . . . . . . . . . . . . . . . . . . . . . . . 18
+ 4.6. quit . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
+ 4.6.1. Example . . . . . . . . . . . . . . . . . . . . . . . 21
+ 4.7. Flush . . . . . . . . . . . . . . . . . . . . . . . . . . 21
+ 4.7.1. Example . . . . . . . . . . . . . . . . . . . . . . . 22
+ 4.8. noop . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
+ 4.8.1. Example . . . . . . . . . . . . . . . . . . . . . . . 24
+ 4.9. version . . . . . . . . . . . . . . . . . . . . . . . . . 24
+ 4.9.1. Example . . . . . . . . . . . . . . . . . . . . . . . 25
+ 4.10. Append, Prepend . . . . . . . . . . . . . . . . . . . . . 26
+ 4.10.1. Example . . . . . . . . . . . . . . . . . . . . . . . 27
+ 4.11. Stat . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
+ 4.11.1. Example . . . . . . . . . . . . . . . . . . . . . . . 28
+ 5. Security Considerations . . . . . . . . . . . . . . . . . . . 30
+ 6. Normative References . . . . . . . . . . . . . . . . . . . . . 31
+ Appendix A. Acknowledgments . . . . . . . . . . . . . . . . . . . 31
+ Authors' Addresses . . . . . . . . . . . . . . . . . . . . . . . . 31
@@ -303,6 +303,21 @@ Internet-Draft Memcache Binary Protocol August 2008
0x0E Append
0x0F Prepend
0x10 Stat
+ 0x11 SetQ
+ 0x12 AddQ
+ 0x13 ReplaceQ
+ 0x14 DeleteQ
+ 0x15 IncrementQ
+ 0x16 DecrementQ
+ 0x17 QuitQ
+ 0x18 FlushQ
+ 0x19 AppendQ
+ 0x1A PrependQ
+
+ As a convention all of the commands ending with "Q" for Quiet. A
+ quiet version of a command will not send back a response, except for
+ GetQ and GetKQ. See the description of the Get commands
+ (Section 4.2) for a full description.
3.4. Data Types
@@ -312,6 +327,16 @@ Internet-Draft Memcache Binary Protocol August 2008
4. Commands
+
+
+
+
+
+Stone & Norbye Expires March 1, 2009 [Page 6]
+
+Internet-Draft Memcache Binary Protocol August 2008
+
+
4.1. Introduction
All communication is initiated by a request from the client, and the
@@ -332,7 +357,38 @@ Internet-Draft Memcache Binary Protocol August 2008
-Stone & Norbye Expires March 1, 2009 [Page 6]
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+Stone & Norbye Expires March 1, 2009 [Page 7]
Internet-Draft Memcache Binary Protocol August 2008
@@ -388,7 +444,7 @@ Internet-Draft Memcache Binary Protocol August 2008
-Stone & Norbye Expires March 1, 2009 [Page 7]
+Stone & Norbye Expires March 1, 2009 [Page 8]
Internet-Draft Memcache Binary Protocol August 2008
@@ -444,7 +500,7 @@ Internet-Draft Memcache Binary Protocol August 2008
-Stone & Norbye Expires March 1, 2009 [Page 8]
+Stone & Norbye Expires March 1, 2009 [Page 9]
Internet-Draft Memcache Binary Protocol August 2008
@@ -500,7 +556,7 @@ Internet-Draft Memcache Binary Protocol August 2008
-Stone & Norbye Expires March 1, 2009 [Page 9]
+Stone & Norbye Expires March 1, 2009 [Page 10]
Internet-Draft Memcache Binary Protocol August 2008
@@ -556,7 +612,7 @@ Internet-Draft Memcache Binary Protocol August 2008
-Stone & Norbye Expires March 1, 2009 [Page 10]
+Stone & Norbye Expires March 1, 2009 [Page 11]
Internet-Draft Memcache Binary Protocol August 2008
@@ -612,7 +668,7 @@ Internet-Draft Memcache Binary Protocol August 2008
-Stone & Norbye Expires March 1, 2009 [Page 11]
+Stone & Norbye Expires March 1, 2009 [Page 12]
Internet-Draft Memcache Binary Protocol August 2008
@@ -668,7 +724,7 @@ Internet-Draft Memcache Binary Protocol August 2008
-Stone & Norbye Expires March 1, 2009 [Page 12]
+Stone & Norbye Expires March 1, 2009 [Page 13]
Internet-Draft Memcache Binary Protocol August 2008
@@ -724,7 +780,7 @@ Internet-Draft Memcache Binary Protocol August 2008
-Stone & Norbye Expires March 1, 2009 [Page 13]
+Stone & Norbye Expires March 1, 2009 [Page 14]
Internet-Draft Memcache Binary Protocol August 2008
@@ -780,7 +836,7 @@ Internet-Draft Memcache Binary Protocol August 2008
-Stone & Norbye Expires March 1, 2009 [Page 14]
+Stone & Norbye Expires March 1, 2009 [Page 15]
Internet-Draft Memcache Binary Protocol August 2008
@@ -836,7 +892,7 @@ Internet-Draft Memcache Binary Protocol August 2008
-Stone & Norbye Expires March 1, 2009 [Page 15]
+Stone & Norbye Expires March 1, 2009 [Page 16]
Internet-Draft Memcache Binary Protocol August 2008
@@ -892,7 +948,7 @@ Internet-Draft Memcache Binary Protocol August 2008
-Stone & Norbye Expires March 1, 2009 [Page 16]
+Stone & Norbye Expires March 1, 2009 [Page 17]
Internet-Draft Memcache Binary Protocol August 2008
@@ -948,7 +1004,7 @@ Internet-Draft Memcache Binary Protocol August 2008
-Stone & Norbye Expires March 1, 2009 [Page 17]
+Stone & Norbye Expires March 1, 2009 [Page 18]
Internet-Draft Memcache Binary Protocol August 2008
@@ -1004,7 +1060,7 @@ Internet-Draft Memcache Binary Protocol August 2008
-Stone & Norbye Expires March 1, 2009 [Page 18]
+Stone & Norbye Expires March 1, 2009 [Page 19]
Internet-Draft Memcache Binary Protocol August 2008
@@ -1060,7 +1116,7 @@ Internet-Draft Memcache Binary Protocol August 2008
-Stone & Norbye Expires March 1, 2009 [Page 19]
+Stone & Norbye Expires March 1, 2009 [Page 20]
Internet-Draft Memcache Binary Protocol August 2008
@@ -1116,7 +1172,7 @@ Internet-Draft Memcache Binary Protocol August 2008
-Stone & Norbye Expires March 1, 2009 [Page 20]
+Stone & Norbye Expires March 1, 2009 [Page 21]
Internet-Draft Memcache Binary Protocol August 2008
@@ -1172,7 +1228,7 @@ Internet-Draft Memcache Binary Protocol August 2008
-Stone & Norbye Expires March 1, 2009 [Page 21]
+Stone & Norbye Expires March 1, 2009 [Page 22]
Internet-Draft Memcache Binary Protocol August 2008
@@ -1228,7 +1284,7 @@ Internet-Draft Memcache Binary Protocol August 2008
-Stone & Norbye Expires March 1, 2009 [Page 22]
+Stone & Norbye Expires March 1, 2009 [Page 23]
Internet-Draft Memcache Binary Protocol August 2008
@@ -1284,7 +1340,7 @@ Internet-Draft Memcache Binary Protocol August 2008
-Stone & Norbye Expires March 1, 2009 [Page 23]
+Stone & Norbye Expires March 1, 2009 [Page 24]
Internet-Draft Memcache Binary Protocol August 2008
@@ -1340,7 +1396,7 @@ Internet-Draft Memcache Binary Protocol August 2008
-Stone & Norbye Expires March 1, 2009 [Page 24]
+Stone & Norbye Expires March 1, 2009 [Page 25]
Internet-Draft Memcache Binary Protocol August 2008
@@ -1396,7 +1452,7 @@ Internet-Draft Memcache Binary Protocol August 2008
-Stone & Norbye Expires March 1, 2009 [Page 25]
+Stone & Norbye Expires March 1, 2009 [Page 26]
Internet-Draft Memcache Binary Protocol August 2008
@@ -1452,7 +1508,7 @@ Internet-Draft Memcache Binary Protocol August 2008
-Stone & Norbye Expires March 1, 2009 [Page 26]
+Stone & Norbye Expires March 1, 2009 [Page 27]
Internet-Draft Memcache Binary Protocol August 2008
@@ -1508,7 +1564,7 @@ Internet-Draft Memcache Binary Protocol August 2008
-Stone & Norbye Expires March 1, 2009 [Page 27]
+Stone & Norbye Expires March 1, 2009 [Page 28]
Internet-Draft Memcache Binary Protocol August 2008
@@ -1564,7 +1620,7 @@ Internet-Draft Memcache Binary Protocol August 2008
-Stone & Norbye Expires March 1, 2009 [Page 28]
+Stone & Norbye Expires March 1, 2009 [Page 29]
Internet-Draft Memcache Binary Protocol August 2008
@@ -1620,7 +1676,7 @@ Internet-Draft Memcache Binary Protocol August 2008
-Stone & Norbye Expires March 1, 2009 [Page 29]
+Stone & Norbye Expires March 1, 2009 [Page 30]
Internet-Draft Memcache Binary Protocol August 2008
@@ -1676,5 +1732,5 @@ Authors' Addresses
-Stone & Norbye Expires March 1, 2009 [Page 30]
+Stone & Norbye Expires March 1, 2009 [Page 31]
diff --git a/doc/protocol-binary.xml b/doc/protocol-binary.xml
index 89f5ce4..94862b2 100644
--- a/doc/protocol-binary.xml
+++ b/doc/protocol-binary.xml
@@ -237,8 +237,24 @@
<t hangText="0x0E">Append</t>
<t hangText="0x0F">Prepend</t>
<t hangText="0x10">Stat</t>
+ <t hangText="0x11">SetQ</t>
+ <t hangText="0x12">AddQ</t>
+ <t hangText="0x13">ReplaceQ</t>
+ <t hangText="0x14">DeleteQ</t>
+ <t hangText="0x15">IncrementQ</t>
+ <t hangText="0x16">DecrementQ</t>
+ <t hangText="0x17">QuitQ</t>
+ <t hangText="0x18">FlushQ</t>
+ <t hangText="0x19">AppendQ</t>
+ <t hangText="0x1A">PrependQ</t>
</list>
</t>
+ <t>
+ As a convention all of the commands ending with "Q" for Quiet.
+ A quiet version of a command will not send back a response, except
+ for GetQ and GetKQ. See the description of the
+ <xref target="command-get">Get commands</xref> for a full description.
+ </t>
</section>
<section anchor="value-types" title="Data Types">
diff --git a/memcached.c b/memcached.c
index 0baeb5e..703203a 100644
--- a/memcached.c
+++ b/memcached.c
@@ -911,7 +911,7 @@ static void add_bin_header(conn *c, uint16_t err, uint8_t hdr_len, uint16_t key_
header = (protocol_binary_response_header *)c->wbuf;
header->response.magic = (uint8_t)PROTOCOL_BINARY_RES;
- header->response.opcode = c->cmd;
+ header->response.opcode = c->binary_header.request.opcode;
header->response.keylen = (uint16_t)htons(key_len);
header->response.extlen = (uint8_t)hdr_len;
@@ -938,10 +938,13 @@ static void add_bin_header(conn *c, uint16_t err, uint8_t hdr_len, uint16_t key_
}
static void write_bin_error(conn *c, protocol_binary_response_status err, int swallow) {
- const char *errstr = "Unknown error";
- size_t len;
+ if (c->noreply) {
+ conn_set_state(c, conn_new_cmd);
+ } else {
+ const char *errstr = "Unknown error";
+ size_t len;
- switch (err) {
+ switch (err) {
case PROTOCOL_BINARY_RESPONSE_ENOMEM:
errstr = "Out of memory";
break;
@@ -967,34 +970,40 @@ static void write_bin_error(conn *c, protocol_binary_response_status err, int sw
assert(false);
errstr = "UNHANDLED ERROR";
fprintf(stderr, ">%d UNHANDLED ERROR: %d\n", c->sfd, err);
- }
-
- if (settings.verbose > 0) {
- fprintf(stderr, ">%d Writing an error: %s\n", c->sfd, errstr);
- }
-
- len = strlen(errstr);
- add_bin_header(c, err, 0, 0, len);
- if (len > 0) {
- add_iov(c, errstr, len);
- }
- conn_set_state(c, conn_mwrite);
- if(swallow > 0) {
- c->sbytes = swallow;
- c->write_and_go = conn_swallow;
- } else {
- c->write_and_go = conn_new_cmd;
+ }
+
+ if (settings.verbose > 0) {
+ fprintf(stderr, ">%d Writing an error: %s\n", c->sfd, errstr);
+ }
+
+ len = strlen(errstr);
+ add_bin_header(c, err, 0, 0, len);
+ if (len > 0) {
+ add_iov(c, errstr, len);
+ }
+ conn_set_state(c, conn_mwrite);
+ if(swallow > 0) {
+ c->sbytes = swallow;
+ c->write_and_go = conn_swallow;
+ } else {
+ c->write_and_go = conn_new_cmd;
+ }
}
}
/* Form and send a response to a command over the binary protocol */
static void write_bin_response(conn *c, void *d, int hlen, int keylen, int dlen) {
- add_bin_header(c, 0, hlen, keylen, dlen);
- if(dlen > 0) {
- add_iov(c, d, dlen);
+ if (!c->noreply || c->cmd == PROTOCOL_BINARY_CMD_GET ||
+ c->cmd == PROTOCOL_BINARY_CMD_GETK) {
+ add_bin_header(c, 0, hlen, keylen, dlen);
+ if(dlen > 0) {
+ add_iov(c, d, dlen);
+ }
+ conn_set_state(c, conn_mwrite);
+ c->write_and_go = conn_new_cmd;
+ } else {
+ conn_set_state(c, conn_new_cmd);
}
- conn_set_state(c, conn_mwrite);
- c->write_and_go = conn_new_cmd;
}
/* Byte swap a 64-bit number */
@@ -1187,8 +1196,7 @@ static void process_bin_get(conn *c) {
MEMCACHED_COMMAND_GET(c->sfd, ITEM_key(it), it->nkey,
it->nbytes, ITEM_get_cas(it));
- if (c->cmd == PROTOCOL_BINARY_CMD_GETK ||
- c->cmd == PROTOCOL_BINARY_CMD_GETKQ) {
+ if (c->cmd == PROTOCOL_BINARY_CMD_GETK) {
bodylen += nkey;
keylen = nkey;
}
@@ -1199,8 +1207,7 @@ static void process_bin_get(conn *c) {
rsp->message.body.flags = htonl(strtoul(ITEM_suffix(it), NULL, 10));
add_iov(c, &rsp->message.body, sizeof(rsp->message.body));
- if (c->cmd == PROTOCOL_BINARY_CMD_GETK ||
- c->cmd == PROTOCOL_BINARY_CMD_GETKQ) {
+ if (c->cmd == PROTOCOL_BINARY_CMD_GETK) {
add_iov(c, ITEM_key(it), nkey);
}
@@ -1214,8 +1221,7 @@ static void process_bin_get(conn *c) {
STATS_UNLOCK();
MEMCACHED_COMMAND_GET(c->sfd, key, nkey, -1, 0);
- if (c->cmd == PROTOCOL_BINARY_CMD_GETQ ||
- c->cmd == PROTOCOL_BINARY_CMD_GETKQ) {
+ if (c->noreply) {
conn_set_state(c, conn_new_cmd);
} else {
if (c->cmd == PROTOCOL_BINARY_CMD_GETK) {
@@ -1421,8 +1427,49 @@ static void dispatch_bin_command(conn *c) {
uint32_t bodylen = c->binary_header.request.bodylen;
MEMCACHED_PROCESS_COMMAND_START(c->sfd, c->rcurr, c->rbytes);
+ c->noreply = true;
+ switch (c->cmd) {
+ case PROTOCOL_BINARY_CMD_SETQ:
+ c->cmd = PROTOCOL_BINARY_CMD_SET;
+ break;
+ case PROTOCOL_BINARY_CMD_ADDQ:
+ c->cmd = PROTOCOL_BINARY_CMD_ADD;
+ break;
+ case PROTOCOL_BINARY_CMD_REPLACEQ:
+ c->cmd = PROTOCOL_BINARY_CMD_REPLACE;
+ break;
+ case PROTOCOL_BINARY_CMD_DELETEQ:
+ c->cmd = PROTOCOL_BINARY_CMD_DELETE;
+ break;
+ case PROTOCOL_BINARY_CMD_INCREMENTQ:
+ c->cmd = PROTOCOL_BINARY_CMD_INCREMENT;
+ break;
+ case PROTOCOL_BINARY_CMD_DECREMENTQ:
+ c->cmd = PROTOCOL_BINARY_CMD_DECREMENT;
+ break;
+ case PROTOCOL_BINARY_CMD_QUITQ:
+ c->cmd = PROTOCOL_BINARY_CMD_QUIT;
+ break;
+ case PROTOCOL_BINARY_CMD_FLUSHQ:
+ c->cmd = PROTOCOL_BINARY_CMD_FLUSH;
+ break;
+ case PROTOCOL_BINARY_CMD_APPENDQ:
+ c->cmd = PROTOCOL_BINARY_CMD_APPEND;
+ break;
+ case PROTOCOL_BINARY_CMD_PREPENDQ:
+ c->cmd = PROTOCOL_BINARY_CMD_PREPEND;
+ break;
+ case PROTOCOL_BINARY_CMD_GETQ:
+ c->cmd = PROTOCOL_BINARY_CMD_GET;
+ break;
+ case PROTOCOL_BINARY_CMD_GETKQ:
+ c->cmd = PROTOCOL_BINARY_CMD_GETK;
+ break;
+ default:
+ c->noreply = false;
+ }
- switch(c->cmd) {
+ switch (c->cmd) {
case PROTOCOL_BINARY_CMD_VERSION:
if (extlen == 0 && keylen == 0 && bodylen == 0) {
write_bin_response(c, VERSION, 0, 0, strlen(VERSION));
diff --git a/protocol_binary.h b/protocol_binary.h
index ee5dd0b..08df72e 100644
--- a/protocol_binary.h
+++ b/protocol_binary.h
@@ -93,7 +93,17 @@ extern "C"
PROTOCOL_BINARY_CMD_GETKQ = 0x0d,
PROTOCOL_BINARY_CMD_APPEND = 0x0e,
PROTOCOL_BINARY_CMD_PREPEND = 0x0f,
- PROTOCOL_BINARY_CMD_STAT = 0x10
+ PROTOCOL_BINARY_CMD_STAT = 0x10,
+ PROTOCOL_BINARY_CMD_SETQ = 0x11,
+ PROTOCOL_BINARY_CMD_ADDQ = 0x12,
+ PROTOCOL_BINARY_CMD_REPLACEQ = 0x13,
+ PROTOCOL_BINARY_CMD_DELETEQ = 0x14,
+ PROTOCOL_BINARY_CMD_INCREMENTQ = 0x15,
+ PROTOCOL_BINARY_CMD_DECREMENTQ = 0x16,
+ PROTOCOL_BINARY_CMD_QUITQ = 0x17,
+ PROTOCOL_BINARY_CMD_FLUSHQ = 0x18,
+ PROTOCOL_BINARY_CMD_APPENDQ = 0x19,
+ PROTOCOL_BINARY_CMD_PREPENDQ = 0x1a
} protocol_binary_command;
/**