Permalink
Browse files

Added new memcached_dump() command.

  • Loading branch information...
Unknown committed May 19, 2009
1 parent 4aac578 commit c41e93402bbafd6a9393c0589b8b01650049749f
View
@@ -12,6 +12,15 @@
^lib/libmemcachedPlus.la$
^tests/testplus$
+# Don't bother with TAGS files
+TAGS
+clients/TAGS
+clients/memdump
+libmemcached/TAGS
+libmemcachedutil/TAGS
+tests/TAGS
+
+
# Build artifacts
^libmemcached/libmemcached.la$
View
@@ -1,3 +1,6 @@
+0.30
+ * Added memcachd_dump command (and framework for memdump tool)
+
0.29 Tue May 19 08:26:48 PDT 2009
* Fixed malloc usage to calloc for spots where we need zero filled memory.
* All code warnings now treated as errors.
View
@@ -1,6 +1,6 @@
LDADDS = $(top_builddir)/libmemcached/libmemcached.la
-bin_PROGRAMS = memcat memcp memstat memrm memflush memslap memerror
+bin_PROGRAMS = memcat memdump memcp memstat memrm memflush memslap memerror
noinst_HEADERS = client_options.h \
utilities.h \
@@ -15,6 +15,10 @@ memcp_SOURCES = memcp.c utilities.c
memcp_LDADD = $(LDADDS)
memcp_LDFLAGS = -rpath $(pkglibdir)
+memdump_SOURCES = memdump.c utilities.c
+memdump_LDADD = $(LDADDS)
+memdump_LDFLAGS = -rpath $(pkglibdir)
+
memstat_SOURCES = memstat.c utilities.c
memstat_LDADD = $(LDADDS)
memstat_LDFLAGS = -rpath $(pkglibdir)
View
@@ -0,0 +1,152 @@
+#include "libmemcached/common.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include <inttypes.h>
+#include <unistd.h>
+#include <getopt.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <strings.h>
+#include <string.h>
+
+#include <libmemcached/memcached.h>
+
+#include "client_options.h"
+#include "utilities.h"
+
+#define PROGRAM_NAME "memdump"
+#define PROGRAM_DESCRIPTION "Dump all values from one or many servers."
+
+/* Prototypes */
+void options_parse(int argc, char *argv[]);
+
+static int opt_binary=0;
+static int opt_verbose= 0;
+static char *opt_servers= NULL;
+static char *opt_hash= NULL;
+
+/* Print the keys and counter how many were found */
+static memcached_return key_printer(memcached_st *ptr __attribute__((unused)),
+ const char *key, size_t key_length,
+ void *context __attribute__((unused)))
+{
+ printf("%.*s\n", (uint32_t)key_length, key);
+
+ return MEMCACHED_SUCCESS;
+}
+
+int main(int argc, char *argv[])
+{
+ memcached_st *memc;
+ memcached_return rc;
+ memcached_server_st *servers;
+ memcached_dump_func callbacks[1];
+
+ callbacks[0]= &key_printer;
+
+ options_parse(argc, argv);
+
+ memc= memcached_create(NULL);
+ process_hash_option(memc, opt_hash);
+
+ if (!opt_servers)
+ {
+ char *temp;
+
+ if ((temp= getenv("MEMCACHED_SERVERS")))
+ opt_servers= strdup(temp);
+ else
+ {
+ fprintf(stderr, "No Servers provided\n");
+ exit(1);
+ }
+ }
+
+ if (opt_servers)
+ servers= memcached_servers_parse(opt_servers);
+ else
+ servers= memcached_servers_parse(argv[--argc]);
+
+ memcached_server_push(memc, servers);
+ memcached_server_list_free(servers);
+ memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL, opt_binary);
+
+ rc= memcached_dump(memc, callbacks, NULL, 1);
+
+ if (rc != MEMCACHED_SUCCESS)
+ {
+ fprintf(stderr, "memdump: memcache error %s", memcached_strerror(memc, rc));
+ if (memc->cached_errno)
+ fprintf(stderr, " system error %s", strerror(memc->cached_errno));
+ fprintf(stderr, "\n");
+ }
+
+ memcached_free(memc);
+
+ if (opt_servers)
+ free(opt_servers);
+ if (opt_hash)
+ free(opt_hash);
+
+ return 0;
+}
+
+void options_parse(int argc, char *argv[])
+{
+ int option_index= 0;
+ int option_rv;
+
+ static struct option long_options[]=
+ {
+ {"version", no_argument, NULL, OPT_VERSION},
+ {"help", no_argument, NULL, OPT_HELP},
+ {"verbose", no_argument, &opt_verbose, OPT_VERBOSE},
+ {"debug", no_argument, &opt_verbose, OPT_DEBUG},
+ {"servers", required_argument, NULL, OPT_SERVERS},
+ {"hash", required_argument, NULL, OPT_HASH},
+ {"binary", no_argument, NULL, OPT_BINARY},
+ {0, 0, 0, 0}
+ };
+
+ while (1)
+ {
+ option_rv= getopt_long(argc, argv, "Vhvds:", long_options, &option_index);
+
+ if (option_rv == -1) break;
+
+ switch (option_rv)
+ {
+ case 0:
+ break;
+ case OPT_BINARY:
+ opt_binary = 1;
+ break;
+ case OPT_VERBOSE: /* --verbose or -v */
+ opt_verbose = OPT_VERBOSE;
+ break;
+ case OPT_DEBUG: /* --debug or -d */
+ opt_verbose = OPT_DEBUG;
+ break;
+ case OPT_VERSION: /* --version or -V */
+ version_command(PROGRAM_NAME);
+ break;
+ case OPT_HELP: /* --help or -h */
+ help_command(PROGRAM_NAME, PROGRAM_DESCRIPTION, long_options, NULL);
+ break;
+ case OPT_SERVERS: /* --servers or -s */
+ opt_servers= strdup(optarg);
+ break;
+ case OPT_HASH:
+ opt_hash= strdup(optarg);
+ break;
+ case '?':
+ /* getopt_long already printed an error message. */
+ exit(1);
+ default:
+ abort();
+ }
+ }
+}
View
@@ -4,6 +4,7 @@ CLEANFILES= *.1 *.3
EXTRA_DIST = libmemcached.pod\
libmemcachedutil.pod\
memcached_flush.pod\
+ memcached_dump.pod\
memcached_stats.pod\
memrm.pod\
memerror.pod\
@@ -27,6 +28,7 @@ EXTRA_DIST = libmemcached.pod\
memcached_set.pod\
memcached_version.pod\
memflush.pod\
+ memdump.pod\
memcached_flush_buffers.pod\
memcached_analyze.pod\
memcached_generate_hash_value.pod
@@ -37,6 +39,7 @@ man_MANS = libmemcached.3\
memcp.1\
memerror.1\
memflush.1\
+ memdump.1\
memrm.1\
memslap.1\
memstat.1\
@@ -91,6 +94,7 @@ man_MANS = libmemcached.3\
memcached_lib_version.3\
memcached_version.3\
memcached_flush_buffers.3\
+ memcached_dump.3\
memcached_generate_hash_value.3
if BUILD_LIBMEMCACHEDUTIL
@@ -174,6 +178,9 @@ memcached_decrement.3:
memcached_decrement_with_initial.3:
@POD2MAN@ -c "libmemcached" -r "" -s 3 ${top_srcdir}/docs/memcached_auto.pod > memcached_decrement_with_initial.3
+memcached_dump.3: memcached_dump.pod
+ @POD2MAN@ -c "libmemcached" -r "" -s 3 ${top_srcdir}/docs/memcached_dump.pod > memcached_dump.3
+
memcached_flush.3: memcached_flush.pod
@POD2MAN@ -c "libmemcached" -r "" -s 3 ${top_srcdir}/docs/memcached_flush.pod > memcached_flush.3
@@ -330,6 +337,9 @@ memrm.1: memrm.pod
memerror.1: memerror.pod
@POD2MAN@ -c "libmemcached" -r "" -s 1 ${top_srcdir}/docs/memerror.pod > memerror.1
+memdump.1: memdump.pod
+ @POD2MAN@ -c "libmemcached" -r "" -s 1 ${top_srcdir}/docs/memdump.pod > memdump.1
+
memflush.1: memflush.pod
@POD2MAN@ -c "libmemcached" -r "" -s 1 ${top_srcdir}/docs/memflush.pod > memflush.1
View
@@ -121,7 +121,7 @@ Brian Aker, E<lt>brian@tangent.orgE<gt>
=head1 SEE ALSO
-memcached(1) libmemcached_examples(3) libmemcached(1) memcat(1) memcp(1) memflush(1) memrm(1) memslap(1) memstat(1) memcached_fetch(3) memcached_replace(3) memcached_server_list_free(3) libmemcached_examples(3) memcached_clone(3) memcached_free(3) memcached_server_add(3) memcached_server_push(3) memcached_add(3) memcached_get(3) memcached_server_count(3) memcached_servers_parse(3) memcached_create(3) memcached_increment(3) memcached_server_list(3) memcached_set(3) memcached_decrement(3) memcached_mget(3) memcached_server_list_append(3) memcached_strerror(3) memcached_delete(3) memcached_quit(3) memcached_server_list_count(3) memcached_verbosity(3) memcached_server_add_unix_socket(3) memcached_result_create(3) memcached_result_free(3) memcached_result_key_value(3) memcached_result_key_length(3) memcached_result_value(3) memcached_result_length(3) memcached_result_flags(3) memcached_result_cas(3) memcached_result_st(3) memcached_append(3) memcached_prepend(3) memcached_fetch_result(3) memerror(1) memcached_get_by_key(3) memcached_mget_by_key(3) memcached_delete_by_key(3) memcached_fetch_execute(3) memcached_callback_get(3) memcached_callback_set(3) memcached_version(3) memcached_lib_version(3) memcached_result_set_value(3)
+memcached(1) libmemcached_examples(3) libmemcached(1) memcat(1) memcp(1) memflush(1) memrm(1) memslap(1) memstat(1) memcached_fetch(3) memcached_replace(3) memcached_server_list_free(3) libmemcached_examples(3) memcached_clone(3) memcached_free(3) memcached_server_add(3) memcached_server_push(3) memcached_add(3) memcached_get(3) memcached_server_count(3) memcached_servers_parse(3) memcached_create(3) memcached_increment(3) memcached_server_list(3) memcached_set(3) memcached_decrement(3) memcached_mget(3) memcached_server_list_append(3) memcached_strerror(3) memcached_delete(3) memcached_quit(3) memcached_server_list_count(3) memcached_verbosity(3) memcached_server_add_unix_socket(3) memcached_result_create(3) memcached_result_free(3) memcached_result_key_value(3) memcached_result_key_length(3) memcached_result_value(3) memcached_result_length(3) memcached_result_flags(3) memcached_result_cas(3) memcached_result_st(3) memcached_append(3) memcached_prepend(3) memcached_fetch_result(3) memerror(1) memcached_get_by_key(3) memcached_mget_by_key(3) memcached_delete_by_key(3) memcached_fetch_execute(3) memcached_callback_get(3) memcached_callback_set(3) memcached_version(3) memcached_lib_version(3) memcached_result_set_value(3) memcached_dump(3) memdump(1)
=cut
View
@@ -0,0 +1,53 @@
+=head1 NAME
+
+memcached_dump
+
+=head1 LIBRARY
+
+C Client Library for memcached (libmemcached, -lmemcached)
+
+=head1 SYNOPSIS
+
+ #include <memcached.h>
+
+ memcached_return
+ memcached_dump (memcached_st *ptr,
+ memcached_dump_func *function,
+ void *context,
+ uint32_t number_of_callbacks);
+
+ typedef memcached_return (*memcached_dump_func)(memcached_st *ptr,
+ const char *key,
+ size_t key_length,
+ void *context);
+
+=head1 DESCRIPTION
+
+memcached_dump() is used to get a list of keys found memcached(1) servers.
+Because memcached(1) does not guarentee to dump all keys you can not assume
+you have fetched all keys from the server. The function takes an array
+of callbacks that it will use to execute on keys as they are found.
+
+Currently the binar protocol is not supported.
+
+=head1 RETURN
+
+A value of type C<memcached_return> is returned
+On success that value will be C<MEMCACHED_SUCCESS>.
+Use memcached_strerror() to translate this value to a printable string.
+
+=head1 HOME
+
+To find out more information please check:
+L<http://tangent.org/552/libmemcached.html>
+
+=head1 AUTHOR
+
+Brian Aker, E<lt>brian@tangent.orgE<gt>
+
+=head1 SEE ALSO
+
+memcached(1) libmemcached(3) memcached_strerror(3)
+
+=cut
+
View
@@ -0,0 +1,31 @@
+=head1 NAME
+
+memdump - Dump a list of keys from a server.
+
+=head1 SYNOPSIS
+
+ memdump [options]
+
+=head1 DESCRIPTION
+
+B<memdump> currently dumps a list of "keys" from all servers that
+it is told to fetch from. Because memcached does not guarentee to
+provide all keys it is not possible to get a complete "dump".
+
+For a full list of operations run the tool with the B<--help> option.
+
+=head1 HOME
+
+To find out more information please check:
+L<http://tangent.org/552/libmemcached.html>
+
+=head1 AUTHOR
+
+Brian Aker, E<lt>brian@tangent.orgE<gt>
+
+=head1 SEE ALSO
+
+memcached(1) libmemcached(3)
+
+=cut
+
View
@@ -38,6 +38,7 @@ libmemcached_la_SOURCES = crc.c \
memcached_connect.c \
memcached_delete.c \
memcached_do.c \
+ memcached_dump.c \
memcached_fetch.c \
memcached_flush.c \
memcached_get.c \
View
@@ -223,6 +223,8 @@ void *memcached_callback_get(memcached_st *ptr,
memcached_callback flag,
memcached_return *error);
+memcached_return memcached_dump(memcached_st *ptr, memcached_dump_func *function, void *context, uint32_t number_of_callbacks);
+
#ifdef __cplusplus
}
@@ -306,6 +306,7 @@ memcached_return memcached_connect(memcached_server_st *ptr)
LIBMEMCACHED_MEMCACHED_CONNECT_START();
/* both retry_timeout and server_failure_limit must be set in order to delay retrying a server on error. */
+ WATCHPOINT_ASSERT(ptr->root);
if (ptr->root->retry_timeout && ptr->root->server_failure_limit)
{
struct timeval next_time;
@@ -54,6 +54,7 @@ typedef enum {
MEMCACHED_DELETED,
MEMCACHED_VALUE,
MEMCACHED_STAT,
+ MEMCACHED_ITEM,
MEMCACHED_ERRNO,
MEMCACHED_FAIL_UNIX_SOCKET,
MEMCACHED_NOT_SUPPORTED,
Oops, something went wrong.

0 comments on commit c41e934

Please sign in to comment.