From 0f2ad14d692b5bb7d0340681391862df8948f0f0 Mon Sep 17 00:00:00 2001 From: Brian Aker Date: Sat, 29 Sep 2007 09:05:28 -0700 Subject: [PATCH] More udpates to memslap. Fixed protocol error in single get call. --- configure.in | 3 +-- lib/memcached_get.c | 9 ++++++++ src/memslap.c | 19 ++++++++++++++++ tests/test.c | 54 ++++++++++++++++++++++++++++++++++++++++++--- 4 files changed, 80 insertions(+), 5 deletions(-) diff --git a/configure.in b/configure.in index cb15a7b1..84b756ed 100644 --- a/configure.in +++ b/configure.in @@ -13,8 +13,7 @@ sinclude(config/dtrace.m4) # We only support GCC and Sun's forte at the moment if test "$GCC" = "yes" then - CFLAGS="-Wall" - CXXFLAGS="$CXXFLAGS -fno-implicit-templates -fno-exceptions -fno-rtti" + CFLAGS="-Wall -ggdb" else CFLAGS="-Xa -xstrconst -mt -D_FORTEC_ -fast -m64" LDFLAGS="-lsocket -lnsl" diff --git a/lib/memcached_get.c b/lib/memcached_get.c index 5bef0c04..aedfd001 100644 --- a/lib/memcached_get.c +++ b/lib/memcached_get.c @@ -129,6 +129,7 @@ char *memcached_get(memcached_st *ptr, char *key, size_t key_length, char buffer[MEMCACHED_DEFAULT_COMMAND_SIZE]; unsigned int server_key; char *value; + memcached_return rc; LIBMEMCACHED_MEMCACHED_GET_START(); *value_length= 0; @@ -152,6 +153,14 @@ char *memcached_get(memcached_st *ptr, char *key, size_t key_length, value= memcached_value_fetch(ptr, key, &key_length, value_length, flags, error, 0, server_key); + /* We need to read END */ + rc= memcached_response(ptr, buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, server_key); + if (rc != MEMCACHED_NOTFOUND) + { + free(value); + *value_length= 0; + *error= MEMCACHED_PROTOCOL_ERROR; + } LIBMEMCACHED_MEMCACHED_GET_END(); return value; diff --git a/src/memslap.c b/src/memslap.c index ade9e11e..3551536b 100644 --- a/src/memslap.c +++ b/src/memslap.c @@ -70,6 +70,25 @@ int main(int argc, char *argv[]) (unsigned int)pairs[x].key_length, pairs[x].key); } + for (x= 0; x < opt_default_pairs; x++) + { + printf("Key(%u) %.10s \n", x, pairs[x].key); + char *value; + size_t value_length; + uint16_t flags; + + value= memcached_get(memc, pairs[x].key, pairs[x].key_length, + &value_length, + &flags, &rc); + + WATCHPOINT_ERROR(rc); + if (rc != MEMCACHED_SUCCESS) + fprintf(stderr, "Failured on read of %.*s\n", + (unsigned int)pairs[x].key_length, pairs[x].key); + printf("\t%.10s\n", value); + free(value); + } + pairs_free(pairs); free(opt_servers); diff --git a/tests/test.c b/tests/test.c index d457cf50..4ce1fb91 100644 --- a/tests/test.c +++ b/tests/test.c @@ -243,6 +243,51 @@ void get_test3(void) memcached_deinit(memc); } +void get_test4(void) +{ + memcached_st *memc; + memcached_return rc; + char *key= "foo"; + char *value; + size_t value_length= 8191; + char *string; + size_t string_length; + uint16_t flags; + int x; + + value = (char*)malloc(value_length); + assert(value); + + for (x= 0; x < value_length; x++) + value[x] = (char) (x % 127); + + memc= memcached_init(NULL); + assert(memc); + rc= memcached_server_add(memc, "localhost", 0); + assert(rc == MEMCACHED_SUCCESS); + + rc= memcached_set(memc, key, strlen(key), + value, value_length, + (time_t)0, (uint16_t)0); + assert(rc == MEMCACHED_SUCCESS); + + for (x= 0; x < 10; x++) + { + string= memcached_get(memc, key, strlen(key), + &string_length, &flags, &rc); + + assert(rc == MEMCACHED_SUCCESS); + assert(string); + assert(string_length == value_length); + assert(!memcmp(string, value, string_length)); + free(string); + } + + free(value); + + memcached_deinit(memc); +} + void stats_servername_test(void) { memcached_return rc; @@ -387,8 +432,8 @@ void mget_test(void) assert(rc == MEMCACHED_SUCCESS); x= 0; - while (return_value= memcached_fetch(memc, return_key, &return_key_length, - &return_value_length, &flags, &rc)) + while ((return_value= memcached_fetch(memc, return_key, &return_key_length, + &return_value_length, &flags, &rc))) { assert(return_value); assert(rc == MEMCACHED_SUCCESS); @@ -492,10 +537,11 @@ void get_stats_multiple(void) } -int main(int argc, char argvp[]) +int main(int argc, char *argv[]) { /* Clean the server before beginning testing */ flush_test(); +#ifdef CRAP init_test(); allocation_test(); connection_test(); @@ -509,6 +555,8 @@ int main(int argc, char argvp[]) get_test(); get_test2(); get_test3(); +#endif + get_test4(); stats_servername_test(); increment_test(); -- 2.30.2