From d360b4e7edb133db3dc9750538e4de6b1c5cdcf7 Mon Sep 17 00:00:00 2001 From: Brian Aker Date: Tue, 10 Jan 2012 22:24:22 -0800 Subject: [PATCH] More memcached_dump() --- libmemcached/auto.cc | 5 -- libmemcached/delete.cc | 5 +- libmemcached/dump.cc | 8 +-- libmemcached/get.cc | 9 +++- libmemcached/server.cc | 10 +--- libmemcached/storage.cc | 7 +-- libmemcached/touch.cc | 2 +- tests/libmemcached-1.0/dump.cc | 70 +++++++++++++++++++++++++ tests/libmemcached-1.0/dump.h | 39 ++++++++++++++ tests/libmemcached-1.0/include.am | 2 + tests/libmemcached-1.0/mem_functions.cc | 2 + 11 files changed, 130 insertions(+), 29 deletions(-) create mode 100644 tests/libmemcached-1.0/dump.cc create mode 100644 tests/libmemcached-1.0/dump.h diff --git a/libmemcached/auto.cc b/libmemcached/auto.cc index 28550a18..e5054a0a 100644 --- a/libmemcached/auto.cc +++ b/libmemcached/auto.cc @@ -177,11 +177,6 @@ memcached_return_t memcached_increment_by_key(memcached_st *ptr, return rc; } - if (memcached_failed(rc= memcached_validate_key_length(key_length, ptr->flags.binary_protocol))) - { - return rc; - } - if (memcached_failed(rc= memcached_key_test(*ptr, (const char **)&key, &key_length, 1))) { return memcached_set_error(*ptr, rc, MEMCACHED_AT); diff --git a/libmemcached/delete.cc b/libmemcached/delete.cc index 121ec91b..660a903c 100644 --- a/libmemcached/delete.cc +++ b/libmemcached/delete.cc @@ -144,10 +144,9 @@ memcached_return_t memcached_delete_by_key(memcached_st *ptr, return rc; } - rc= memcached_validate_key_length(key_length, ptr->flags.binary_protocol); - if (memcached_failed(rc)) + if (memcached_failed(rc= memcached_key_test(*ptr, (const char **)&key, &key_length, 1))) { - return rc; + return memcached_set_error(*ptr, rc, MEMCACHED_AT); } if (expiration) diff --git a/libmemcached/dump.cc b/libmemcached/dump.cc index 830c3ff4..b46ca179 100644 --- a/libmemcached/dump.cc +++ b/libmemcached/dump.cc @@ -53,8 +53,8 @@ static memcached_return_t ascii_dump(memcached_st *ptr, memcached_dump_fn *callb memcached_server_write_instance_st instance; instance= memcached_server_instance_fetch(ptr, server_key); - /* 256 I BELIEVE is the upper limit of slabs */ - for (uint32_t x= 0; x < 256; x++) + /* MAX_NUMBER_OF_SLAB_CLASSESdefined to 200 in Memcached 1.4.10 */ + for (uint32_t x= 0; x < 200; x++) { char buffer[MEMCACHED_DEFAULT_COMMAND_SIZE]; int buffer_length= snprintf(buffer, sizeof(buffer), "%u", x); @@ -151,9 +151,9 @@ memcached_return_t memcached_dump(memcached_st *ptr, memcached_dump_fn *callback No support for Binary protocol yet @todo Fix this so that we just flush, switch to ascii, and then go back to binary. */ - if (ptr->flags.binary_protocol) + if (memcached_is_binary(ptr)) { - return MEMCACHED_FAILURE; + return memcached_set_error(*ptr, MEMCACHED_NOT_SUPPORTED, MEMCACHED_AT, memcached_literal_param("Binary protocol is not supported for memcached_dump()")); } return ascii_dump(ptr, callback, context, number_of_callbacks); diff --git a/libmemcached/get.cc b/libmemcached/get.cc index b2428386..fa76adae 100644 --- a/libmemcached/get.cc +++ b/libmemcached/get.cc @@ -439,7 +439,8 @@ memcached_return_t memcached_mget_execute_by_key(memcached_st *ptr, if (memcached_is_binary(ptr) == false) { - return MEMCACHED_NOT_SUPPORTED; + return memcached_set_error(*ptr, MEMCACHED_NOT_SUPPORTED, MEMCACHED_AT, + memcached_literal_param("ASCII protocol is not supported for memcached_mget_execute_by_key()")); } memcached_callback_st *original_callbacks= ptr->callbacks; @@ -498,14 +499,18 @@ 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; if (mget_mode) + { request.message.header.request.opcode= PROTOCOL_BINARY_CMD_GETKQ; + } else + { request.message.header.request.opcode= PROTOCOL_BINARY_CMD_GETK; + } memcached_return_t vk; vk= memcached_validate_key_length(key_length[x], ptr->flags.binary_protocol); - unlikely (vk != MEMCACHED_SUCCESS) + if (vk != MEMCACHED_SUCCESS) { if (x > 0) { diff --git a/libmemcached/server.cc b/libmemcached/server.cc index f08f8bf0..85ce8381 100644 --- a/libmemcached/server.cc +++ b/libmemcached/server.cc @@ -275,18 +275,12 @@ memcached_server_instance_st memcached_server_by_key(memcached_st *ptr, return NULL; } - if (memcached_failed(rc= memcached_validate_key_length(key_length, ptr->flags.binary_protocol))) + if (memcached_failed(rc= (memcached_key_test(*ptr, (const char **)&key, &key_length, 1)))) { *error= rc; return NULL; } - if (memcached_failed((memcached_key_test(*ptr, (const char **)&key, &key_length, 1)))) - { - *error= MEMCACHED_BAD_KEY_PROVIDED; - return NULL; - } - uint32_t server_key= memcached_generate_hash(ptr, key, key_length); return memcached_server_instance_by_position(ptr, server_key); @@ -295,7 +289,7 @@ memcached_server_instance_st memcached_server_by_key(memcached_st *ptr, void memcached_server_error_reset(memcached_server_st *self) { WATCHPOINT_ASSERT(self); - if (not self) + if (self == NULL) { return; } diff --git a/libmemcached/storage.cc b/libmemcached/storage.cc index 2d0ae8fc..e5f67dbc 100644 --- a/libmemcached/storage.cc +++ b/libmemcached/storage.cc @@ -342,16 +342,11 @@ static inline memcached_return_t memcached_send(memcached_st *ptr, return rc; } - if (memcached_failed(rc= memcached_validate_key_length(key_length, memcached_is_binary(ptr)))) + if (memcached_failed(rc= memcached_key_test(*ptr, (const char **)&key, &key_length, 1))) { return rc; } - if (memcached_failed(memcached_key_test(*ptr, (const char **)&key, &key_length, 1))) - { - return MEMCACHED_BAD_KEY_PROVIDED; - } - uint32_t server_key= memcached_generate_hash_with_redistribution(ptr, group_key, group_key_length); memcached_server_write_instance_st instance= memcached_server_instance_fetch(ptr, server_key); diff --git a/libmemcached/touch.cc b/libmemcached/touch.cc index 8505d7e6..b7fa2475 100644 --- a/libmemcached/touch.cc +++ b/libmemcached/touch.cc @@ -123,7 +123,7 @@ memcached_return_t memcached_touch_by_key(memcached_st *ptr, if (memcached_failed(rc= memcached_validate_key_length(key_length, ptr->flags.binary_protocol))) { - return memcached_set_error(*ptr, rc, MEMCACHED_AT); + return rc; } uint32_t server_key= memcached_generate_hash_with_redistribution(ptr, group_key, group_key_length); diff --git a/tests/libmemcached-1.0/dump.cc b/tests/libmemcached-1.0/dump.cc new file mode 100644 index 00000000..44391eff --- /dev/null +++ b/tests/libmemcached-1.0/dump.cc @@ -0,0 +1,70 @@ +/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: + * + * Libmemcached library + * + * Copyright (C) 2012 Data Differential, http://datadifferential.com/ + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * + * * The names of its contributors may not be used to endorse or + * promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#include +#include + +#include +#include + +using namespace libtest; + +#include "tests/libmemcached-1.0/dump.h" + +static memcached_return_t callback_dump_counter(const memcached_st *, + const char *, + size_t , + void *context) +{ + size_t *counter= (size_t *)context; + + *counter= *counter +1; + + return MEMCACHED_SUCCESS; +} + +test_return_t memcached_dump_TEST(memcached_st *memc) +{ + test_skip(false, memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL)); + + size_t count= 0; + memcached_dump_fn callbacks[1]; + callbacks[0]= &callback_dump_counter; + + test_compare_hint(MEMCACHED_SUCCESS, memcached_dump(memc, callbacks, &count, 1), memcached_last_error_message(memc)); + + return TEST_SUCCESS; +} diff --git a/tests/libmemcached-1.0/dump.h b/tests/libmemcached-1.0/dump.h new file mode 100644 index 00000000..37c4d5a2 --- /dev/null +++ b/tests/libmemcached-1.0/dump.h @@ -0,0 +1,39 @@ +/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: + * + * Libmemcached library + * + * Copyright (C) 2012 Data Differential, http://datadifferential.com/ + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * + * * The names of its contributors may not be used to endorse or + * promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#pragma once + +test_return_t memcached_dump_TEST(memcached_st *); diff --git a/tests/libmemcached-1.0/include.am b/tests/libmemcached-1.0/include.am index 81653a1c..88bdeb1d 100644 --- a/tests/libmemcached-1.0/include.am +++ b/tests/libmemcached-1.0/include.am @@ -17,6 +17,7 @@ noinst_HEADERS+= \ tests/ketama.h \ tests/ketama_test_cases.h \ tests/ketama_test_cases_spy.h \ + tests/libmemcached-1.0/dump.h \ tests/namespace.h \ tests/parser.h \ tests/touch.h \ @@ -48,6 +49,7 @@ tests_libmemcached_1_0_testapp_SOURCES= \ tests/libmemcached-1.0/callbacks.cc \ tests/libmemcached-1.0/debug.cc \ tests/libmemcached-1.0/deprecated.cc \ + tests/libmemcached-1.0/dump.cc \ tests/libmemcached-1.0/error_conditions.cc \ tests/libmemcached-1.0/exist.cc \ tests/libmemcached-1.0/ketama.cc \ diff --git a/tests/libmemcached-1.0/mem_functions.cc b/tests/libmemcached-1.0/mem_functions.cc index 62b32473..ac88ee50 100644 --- a/tests/libmemcached-1.0/mem_functions.cc +++ b/tests/libmemcached-1.0/mem_functions.cc @@ -78,6 +78,7 @@ #include "tests/ketama.h" #include "tests/namespace.h" #include "tests/parser.h" +#include "tests/libmemcached-1.0/dump.h" #include "tests/touch.h" #include "tests/callbacks.h" #include "tests/pool.h" @@ -5664,6 +5665,7 @@ test_st tests[] ={ {"memcached_exist_by_key(MEMCACHED_SUCCESS)", true, (test_callback_fn*)memcached_exist_by_key_SUCCESS }, {"memcached_touch", 0, (test_callback_fn*)test_memcached_touch}, {"memcached_touch_with_prefix", 0, (test_callback_fn*)test_memcached_touch_by_key}, + {"memcached_dump()", 0, (test_callback_fn*)memcached_dump_TEST }, {0, 0, 0} }; -- 2.30.2