From: Brian Aker Date: Thu, 1 Apr 2010 21:30:52 +0000 (-0700) Subject: Merge in support for prefix keys in the binary protoocol. X-Git-Tag: 0.40~27 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=4aa2f33b41edf38fcab43010e9e57bf0a512d240;p=m6w6%2Flibmemcached Merge in support for prefix keys in the binary protoocol. --- diff --git a/ChangeLog b/ChangeLog index 962299f4..5eaabcc5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,7 @@ 0.39 +* Add support for prefix keys to binary protocol. + * Remove the undocumented call memcached_server_remove(). * The undocumented call memcached_server_by_key() now returns const. diff --git a/libmemcached/auto.c b/libmemcached/auto.c index d94d26f1..b4575f07 100644 --- a/libmemcached/auto.c +++ b/libmemcached/auto.c @@ -108,17 +108,17 @@ static memcached_return_t binary_incr_decr(memcached_st *ptr, uint8_t cmd, request.message.header.request.magic= PROTOCOL_BINARY_REQ; request.message.header.request.opcode= cmd; - request.message.header.request.keylen= htons((uint16_t) key_length); + request.message.header.request.keylen= htons((uint16_t)(key_length + ptr->prefix_key_length)); request.message.header.request.extlen= 20; request.message.header.request.datatype= PROTOCOL_BINARY_RAW_BYTES; - request.message.header.request.bodylen= htonl((uint32_t) (key_length + request.message.header.request.extlen)); + request.message.header.request.bodylen= htonl((uint32_t)(key_length + ptr->prefix_key_length + request.message.header.request.extlen)); request.message.body.delta= htonll(offset); request.message.body.initial= htonll(initial); request.message.body.expiration= htonl((uint32_t) expiration); memcached_return_t rc; - if (((rc= memcached_do(instance, request.bytes, - sizeof(request.bytes), false)) != MEMCACHED_SUCCESS) || + if (((rc= memcached_do(instance, request.bytes, sizeof(request.bytes), false)) != MEMCACHED_SUCCESS) || + (memcached_io_write(instance, ptr->prefix_key, ptr->prefix_key_length, false) == -1) || (memcached_io_write(instance, key, key_length, true) == -1)) { memcached_io_reset(instance); diff --git a/libmemcached/delete.c b/libmemcached/delete.c index da91f703..c83ea5e6 100644 --- a/libmemcached/delete.c +++ b/libmemcached/delete.c @@ -158,9 +158,9 @@ static inline memcached_return_t binary_delete(memcached_st *ptr, request.message.header.request.opcode= PROTOCOL_BINARY_CMD_DELETEQ; else request.message.header.request.opcode= PROTOCOL_BINARY_CMD_DELETE; - request.message.header.request.keylen= htons((uint16_t)key_length); + request.message.header.request.keylen= htons((uint16_t)(key_length + ptr->prefix_key_length)); request.message.header.request.datatype= PROTOCOL_BINARY_RAW_BYTES; - request.message.header.request.bodylen= htonl((uint32_t) key_length); + request.message.header.request.bodylen= htonl((uint32_t)(key_length + ptr->prefix_key_length)); if (ptr->flags.use_udp && ! flush) { @@ -173,10 +173,9 @@ static inline memcached_return_t binary_delete(memcached_st *ptr, memcached_return_t rc= MEMCACHED_SUCCESS; - if (((rc= memcached_do(instance, request.bytes, - sizeof(request.bytes), false)) != MEMCACHED_SUCCESS) || - (memcached_io_write(instance, key, - key_length, flush) == -1)) + if (((rc= memcached_do(instance, request.bytes, sizeof(request.bytes), false)) != MEMCACHED_SUCCESS) || + (memcached_io_write(instance, ptr->prefix_key, ptr->prefix_key_length, false) == -1) || + (memcached_io_write(instance, key, key_length, flush) == -1)) { memcached_io_reset(instance); rc= (rc == MEMCACHED_SUCCESS) ? MEMCACHED_WRITE_FAILURE : rc; diff --git a/libmemcached/fetch.c b/libmemcached/fetch.c index 4359c935..3c819f38 100644 --- a/libmemcached/fetch.c +++ b/libmemcached/fetch.c @@ -91,13 +91,12 @@ memcached_return_t memcached_fetch_execute(memcached_st *ptr, { memcached_result_st *result= &ptr->result; memcached_return_t rc= MEMCACHED_FAILURE; - unsigned int x; while ((result= memcached_fetch_result(ptr, result, &rc)) != NULL) { if (rc == MEMCACHED_SUCCESS) { - for (x= 0; x < number_of_callbacks; x++) + for (uint32_t x= 0; x < number_of_callbacks; x++) { rc= (*callback[x])(ptr, result, context); if (rc != MEMCACHED_SUCCESS) diff --git a/libmemcached/get.c b/libmemcached/get.c index 1df6247c..7d8d6768 100644 --- a/libmemcached/get.c +++ b/libmemcached/get.c @@ -402,14 +402,28 @@ static memcached_return_t simple_binary_mget(memcached_st *ptr, return vk; } - request.message.header.request.keylen= htons((uint16_t)key_length[x]); + request.message.header.request.keylen= htons((uint16_t)(key_length[x] + ptr->prefix_key_length)); request.message.header.request.datatype= PROTOCOL_BINARY_RAW_BYTES; - request.message.header.request.bodylen= htonl((uint32_t) key_length[x]); + request.message.header.request.bodylen= htonl((uint32_t)( key_length[x] + ptr->prefix_key_length)); - if ((memcached_io_write(instance, request.bytes, - sizeof(request.bytes), false) == -1) || - (memcached_io_write(instance, keys[x], - key_length[x], flush) == -1)) + if (memcached_io_write(instance, request.bytes, sizeof(request.bytes), false) == -1) + { + memcached_server_response_reset(instance); + rc= MEMCACHED_SOME_ERRORS; + continue; + } + + if (ptr->prefix_key_length) + { + if (memcached_io_write(instance, ptr->prefix_key, ptr->prefix_key_length, false) == -1) + { + memcached_server_response_reset(instance); + rc= MEMCACHED_SOME_ERRORS; + continue; + } + } + + if (memcached_io_write(instance, keys[x], key_length[x], flush) == -1) { memcached_server_response_reset(instance); rc= MEMCACHED_SOME_ERRORS; @@ -419,9 +433,10 @@ static memcached_return_t simple_binary_mget(memcached_st *ptr, /* We just want one pending response per server */ memcached_server_response_reset(instance); memcached_server_response_increment(instance); - if ((x > 0 && x == ptr->io_key_prefetch) && - memcached_flush_buffers(ptr) != MEMCACHED_SUCCESS) + if ((x > 0 && x == ptr->io_key_prefetch) && memcached_flush_buffers(ptr) != MEMCACHED_SUCCESS) + { rc= MEMCACHED_SOME_ERRORS; + } } if (mget_mode) @@ -519,9 +534,9 @@ static memcached_return_t replication_binary_mget(memcached_st *ptr, .message.header.request= { .magic= PROTOCOL_BINARY_REQ, .opcode= PROTOCOL_BINARY_CMD_GETK, - .keylen= htons((uint16_t)key_length[x]), + .keylen= htons((uint16_t)(key_length[x] + ptr->prefix_key_length)), .datatype= PROTOCOL_BINARY_RAW_BYTES, - .bodylen= htonl((uint32_t)key_length[x]) + .bodylen= htonl((uint32_t)(key_length[x] + ptr->prefix_key_length)) } }; @@ -535,10 +550,9 @@ static memcached_return_t replication_binary_mget(memcached_st *ptr, * that we might have processed some of the responses etc. For now, * just make sure we work _correctly_ */ - if ((memcached_io_write(instance, request.bytes, - sizeof(request.bytes), false) == -1) || - (memcached_io_write(instance, keys[x], - key_length[x], true) == -1)) + if ((memcached_io_write(instance, request.bytes, sizeof(request.bytes), false) == -1) || + (memcached_io_write(instance, ptr->prefix_key, ptr->prefix_key_length, false) == -1) || + (memcached_io_write(instance, keys[x], key_length[x], true) == -1)) { memcached_io_reset(instance); dead_servers[server]= true; diff --git a/libmemcached/storage.c b/libmemcached/storage.c index abc5b7ca..88794596 100644 --- a/libmemcached/storage.c +++ b/libmemcached/storage.c @@ -454,7 +454,7 @@ static memcached_return_t memcached_send_binary(memcached_st *ptr, request.message.header.request.magic= PROTOCOL_BINARY_REQ; request.message.header.request.opcode= get_com_code(verb, noreply); - request.message.header.request.keylen= htons((uint16_t)key_length); + request.message.header.request.keylen= htons((uint16_t)(key_length + ptr->prefix_key_length)); request.message.header.request.datatype= PROTOCOL_BINARY_RAW_BYTES; if (verb == APPEND_OP || verb == PREPEND_OP) send_length -= 8; /* append & prepend does not contain extras! */ @@ -465,7 +465,7 @@ static memcached_return_t memcached_send_binary(memcached_st *ptr, request.message.body.expiration= htonl((uint32_t)expiration); } - request.message.header.request.bodylen= htonl((uint32_t) (key_length + value_length + + request.message.header.request.bodylen= htonl((uint32_t) (key_length + ptr->prefix_key_length + value_length + request.message.header.request.extlen)); if (cas) @@ -491,6 +491,7 @@ static memcached_return_t memcached_send_binary(memcached_st *ptr, memcached_return_t rc; if (((rc= memcached_do(server, (const char*)request.bytes, send_length, false)) != MEMCACHED_SUCCESS) || + (memcached_io_write(server, ptr->prefix_key, ptr->prefix_key_length, false) == -1) || (memcached_io_write(server, key, key_length, false) == -1) || (memcached_io_write(server, value, value_length, flush) == -1)) {