Skip to content

Commit

Permalink
Add binary GATK/GATKQ
Browse files Browse the repository at this point in the history
Apparently nothing tests GETK/GETKQ, so tests still have to be added.

1.6 doesn't have GATK/GATKQ because the membase folks didn't need it. I'm
adding them for completeness and because I don't want to argue about why
people can't have it. If you're reading this, please use opaques :)
  • Loading branch information
dormando committed Sep 27, 2011
1 parent d87f568 commit 0d16e8c
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 4 deletions.
26 changes: 24 additions & 2 deletions memcached.c
Expand Up @@ -1215,6 +1215,9 @@ static void process_bin_touch(conn *c) {


if (c->cmd == PROTOCOL_BINARY_CMD_TOUCH) { if (c->cmd == PROTOCOL_BINARY_CMD_TOUCH) {
bodylen -= it->nbytes - 2; bodylen -= it->nbytes - 2;
} else if (c->cmd == PROTOCOL_BINARY_CMD_GATK) {
bodylen += nkey;
keylen = nkey;
} }


add_bin_header(c, 0, sizeof(rsp->message.body), keylen, bodylen); add_bin_header(c, 0, sizeof(rsp->message.body), keylen, bodylen);
Expand All @@ -1224,10 +1227,15 @@ static void process_bin_touch(conn *c) {
rsp->message.body.flags = htonl(strtoul(ITEM_suffix(it), NULL, 10)); rsp->message.body.flags = htonl(strtoul(ITEM_suffix(it), NULL, 10));
add_iov(c, &rsp->message.body, sizeof(rsp->message.body)); add_iov(c, &rsp->message.body, sizeof(rsp->message.body));


if (c->cmd == PROTOCOL_BINARY_CMD_GATK) {
add_iov(c, ITEM_key(it), nkey);
}

/* Add the data minus the CRLF */ /* Add the data minus the CRLF */
if (c->cmd != PROTOCOL_BINARY_CMD_TOUCH) { if (c->cmd != PROTOCOL_BINARY_CMD_TOUCH) {
add_iov(c, ITEM_data(it), it->nbytes - 2); add_iov(c, ITEM_data(it), it->nbytes - 2);
} }

conn_set_state(c, conn_mwrite); conn_set_state(c, conn_mwrite);
/* Remember this command so we can garbage collect it later */ /* Remember this command so we can garbage collect it later */
c->item = it; c->item = it;
Expand All @@ -1242,7 +1250,16 @@ static void process_bin_touch(conn *c) {
if (c->noreply) { if (c->noreply) {
conn_set_state(c, conn_new_cmd); conn_set_state(c, conn_new_cmd);
} else { } else {
write_bin_error(c, PROTOCOL_BINARY_RESPONSE_KEY_ENOENT, 0); if (c->cmd == PROTOCOL_BINARY_CMD_GATK) {
char *ofs = c->wbuf + sizeof(protocol_binary_response_header);
add_bin_header(c, PROTOCOL_BINARY_RESPONSE_KEY_ENOENT,
0, nkey, nkey);
memcpy(ofs, key, nkey);
add_iov(c, ofs, nkey);
conn_set_state(c, conn_mwrite);
} else {
write_bin_error(c, PROTOCOL_BINARY_RESPONSE_KEY_ENOENT, 0);
}
} }
} }


Expand Down Expand Up @@ -1810,7 +1827,10 @@ static void dispatch_bin_command(conn *c) {
c->cmd = PROTOCOL_BINARY_CMD_GETK; c->cmd = PROTOCOL_BINARY_CMD_GETK;
break; break;
case PROTOCOL_BINARY_CMD_GATQ: case PROTOCOL_BINARY_CMD_GATQ:
c->cmd = PROTOCOL_BINARY_CMD_GATQ; c->cmd = PROTOCOL_BINARY_CMD_GAT;
break;
case PROTOCOL_BINARY_CMD_GATKQ:
c->cmd = PROTOCOL_BINARY_CMD_GAT;
break; break;
default: default:
c->noreply = false; c->noreply = false;
Expand Down Expand Up @@ -1916,6 +1936,8 @@ static void dispatch_bin_command(conn *c) {
case PROTOCOL_BINARY_CMD_TOUCH: case PROTOCOL_BINARY_CMD_TOUCH:
case PROTOCOL_BINARY_CMD_GAT: case PROTOCOL_BINARY_CMD_GAT:
case PROTOCOL_BINARY_CMD_GATQ: case PROTOCOL_BINARY_CMD_GATQ:
case PROTOCOL_BINARY_CMD_GATK:
case PROTOCOL_BINARY_CMD_GATKQ:
if (extlen == 4 && keylen != 0) { if (extlen == 4 && keylen != 0) {
bin_read_key(c, bin_reading_touch_key, 4); bin_read_key(c, bin_reading_touch_key, 4);
} else { } else {
Expand Down
6 changes: 6 additions & 0 deletions protocol_binary.h
Expand Up @@ -108,6 +108,8 @@ extern "C"
PROTOCOL_BINARY_CMD_TOUCH = 0x1c, PROTOCOL_BINARY_CMD_TOUCH = 0x1c,
PROTOCOL_BINARY_CMD_GAT = 0x1d, PROTOCOL_BINARY_CMD_GAT = 0x1d,
PROTOCOL_BINARY_CMD_GATQ = 0x1e, PROTOCOL_BINARY_CMD_GATQ = 0x1e,
PROTOCOL_BINARY_CMD_GATK = 0x23,
PROTOCOL_BINARY_CMD_GATKQ = 0x24,


PROTOCOL_BINARY_CMD_SASL_LIST_MECHS = 0x20, PROTOCOL_BINARY_CMD_SASL_LIST_MECHS = 0x20,
PROTOCOL_BINARY_CMD_SASL_AUTH = 0x21, PROTOCOL_BINARY_CMD_SASL_AUTH = 0x21,
Expand Down Expand Up @@ -416,12 +418,16 @@ extern "C"
} protocol_binary_request_gat; } protocol_binary_request_gat;


typedef protocol_binary_request_gat protocol_binary_request_gatq; typedef protocol_binary_request_gat protocol_binary_request_gatq;
typedef protocol_binary_request_gat protocol_binary_request_gatk;
typedef protocol_binary_request_gat protocol_binary_request_gatkq;


/** /**
* Definition of the packet returned from the GAT(Q) * Definition of the packet returned from the GAT(Q)
*/ */
typedef protocol_binary_response_get protocol_binary_response_gat; typedef protocol_binary_response_get protocol_binary_response_gat;
typedef protocol_binary_response_get protocol_binary_response_gatq; typedef protocol_binary_response_get protocol_binary_response_gatq;
typedef protocol_binary_response_get protocol_binary_response_gatk;
typedef protocol_binary_response_get protocol_binary_response_gatkq;


/** /**
* Definition of a request for a range operation. * Definition of a request for a range operation.
Expand Down
2 changes: 2 additions & 0 deletions t/binary.t
Expand Up @@ -44,6 +44,8 @@ use constant CMD_PREPENDQ => 0x1A;
use constant CMD_TOUCH => 0x1C; use constant CMD_TOUCH => 0x1C;
use constant CMD_GAT => 0x1D; use constant CMD_GAT => 0x1D;
use constant CMD_GATQ => 0x1E; use constant CMD_GATQ => 0x1E;
use constant CMD_GATK => 0x23;
use constant CMD_GATKQ => 0x24;


# REQ and RES formats are divided even though they currently share # REQ and RES formats are divided even though they currently share
# the same format, since they _could_ differ in the future. # the same format, since they _could_ differ in the future.
Expand Down
7 changes: 5 additions & 2 deletions testapp.c
Expand Up @@ -967,7 +967,8 @@ static void validate_response_header(protocol_binary_response_no_extras *respons
} else { } else {
assert(response->message.header.response.cas == 0); assert(response->message.header.response.cas == 0);
assert(response->message.header.response.extlen == 0); assert(response->message.header.response.extlen == 0);
if (cmd != PROTOCOL_BINARY_CMD_GETK) { if (cmd != PROTOCOL_BINARY_CMD_GETK &&
cmd != PROTOCOL_BINARY_CMD_GATK) {
assert(response->message.header.response.keylen == 0); assert(response->message.header.response.keylen == 0);
} }
} }
Expand Down Expand Up @@ -1597,7 +1598,7 @@ static enum test_return test_binary_stat(void) {
} }


static enum test_return test_binary_illegal(void) { static enum test_return test_binary_illegal(void) {
uint8_t cmd = 0x23; uint8_t cmd = 0x25;
while (cmd != 0x00) { while (cmd != 0x00) {
union { union {
protocol_binary_request_no_extras request; protocol_binary_request_no_extras request;
Expand Down Expand Up @@ -1704,6 +1705,8 @@ static enum test_return test_binary_pipeline_hickup_chunk(void *buffer, size_t b
case PROTOCOL_BINARY_CMD_TOUCH: case PROTOCOL_BINARY_CMD_TOUCH:
case PROTOCOL_BINARY_CMD_GAT: case PROTOCOL_BINARY_CMD_GAT:
case PROTOCOL_BINARY_CMD_GATQ: case PROTOCOL_BINARY_CMD_GATQ:
case PROTOCOL_BINARY_CMD_GATK:
case PROTOCOL_BINARY_CMD_GATKQ:
len = touch_command(command.bytes, sizeof(command.bytes), cmd, len = touch_command(command.bytes, sizeof(command.bytes), cmd,
key, keylen, 10); key, keylen, 10);
break; break;
Expand Down

0 comments on commit 0d16e8c

Please sign in to comment.