Browse files

avoid libmemcached dependency

Temporarily removing libmemcached dependency.  It will return, but will
need to refresh the version.
  • Loading branch information...
1 parent 6751069 commit 0577ccb0b673e6ffc418f02a4b2d955bcc27bcb6 @steveyen steveyen committed Jun 8, 2010
Showing with 166 additions and 51 deletions.
  1. +8 −7 Makefile.am
  2. +1 −0 agent_config.c
  3. +1 −0 agent_ping.c
  4. +8 −5 agent_stats.c
  5. +1 −13 configure.ac
  6. +1 −0 cproxy.c
  7. +1 −0 cproxy_config.c
  8. +1 −0 cproxy_front.c
  9. +1 −0 cproxy_multiget.c
  10. +1 −5 cproxy_protocol_a2b.c
  11. +1 −0 cproxy_stats.c
  12. +25 −21 mcs.h
  13. +81 −0 murmur_hash.c
  14. +32 −0 util.c
  15. +3 −0 util.h
View
15 Makefile.am
@@ -34,6 +34,7 @@ moxi_SOURCES = memcached.c memcached.h \
cproxy_stats.c \
cproxy_front.c \
matcher.c matcher.h \
+ murmur_hash.c \
mcs.c mcs.h
timedrun_SOURCES = timedrun.c
@@ -73,15 +74,15 @@ moxi_SOURCES += solaris_priv.c
endif
moxi_debug_SOURCES = $(moxi_SOURCES)
-moxi_debug_CPPFLAGS = -I$(top_srcdir)/libmemcached-0.30 -DCONFLATE_DB_PATH=\"$(CONFLATE_DB_PATH)\"
+moxi_debug_CPPFLAGS = -DCONFLATE_DB_PATH=\"$(CONFLATE_DB_PATH)\"
moxi_CPPFLAGS = -DNDEBUG $(moxi_debug_CPPFLAGS)
-moxi_debug_LDADD = @PROFILER_LDFLAGS@ \
- libmemcached-0.30/libmemcached/libmemcached.la
+moxi_debug_LDADD = @PROFILER_LDFLAGS@
moxi_debug_CFLAGS = @PROFILER_FLAGS@
-moxi_LDADD = libmemcached-0.30/libmemcached/libmemcached.la
+moxi_LDADD =
moxi_DEPENDENCIES =
moxi_debug_DEPENDENCIES =
+
CLEANFILES=
if BUILD_DTRACE
@@ -109,10 +110,10 @@ memcached_dtrace.o: $(moxi_OBJECTS)
memcached_debug_dtrace.o: $(moxi_debug_OBJECTS)
$(DTRACE) $(DTRACEFLAGS) -G -o memcached_debug_dtrace.o -s ${srcdir}/memcached_dtrace.d $(moxi_debug_OBJECTS)
-SUBDIRS = doc libmemcached-0.30/libmemcached $(MAYBE_LIBCONFLATE)
-DIST_SUBDIRS = doc libmemcached-0.30/libmemcached $(MAYBE_LIBCONFLATE)
+SUBDIRS = doc $(MAYBE_LIBCONFLATE)
+DIST_SUBDIRS = doc $(MAYBE_LIBCONFLATE)
DIST_DIRS = scripts
-EXTRA_DIST = doc scripts TODO t memcached.spec memcached_dtrace.d version.m4 libmemcached-0.30 protocol_binary.h patches debian
+EXTRA_DIST = doc scripts TODO t memcached.spec memcached_dtrace.d version.m4 protocol_binary.h patches debian
MOSTLYCLEANFILES = *.gcov *.gcno *.gcda *.tcov
View
1 agent_config.c
@@ -1,6 +1,7 @@
/* -*- Mode: C; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
#include <stdio.h>
+#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <sysexits.h>
View
1 agent_ping.c
@@ -1,6 +1,7 @@
/* -*- Mode: C; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
#include <stdio.h>
+#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <sysexits.h>
View
13 agent_stats.c
@@ -1,6 +1,7 @@
/* -*- Mode: C; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
#include <stdio.h>
+#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
@@ -127,6 +128,7 @@ static
#undef collect_memcached_stats_for_proxy
#endif
void collect_memcached_stats_for_proxy(struct main_stats_collect_info *msci, const char *proxy_name, int proxy_port) {
+#ifndef MOXI_USE_VBUCKET
memcached_st mst;
memcached_create(&mst);
@@ -141,10 +143,10 @@ void collect_memcached_stats_for_proxy(struct main_stats_collect_info *msci, con
char bufk[500];
-#define emit_s(key, val) \
- snprintf(bufk, sizeof(bufk), "%u:%s:stats:%s", \
- proxy_port, \
- proxy_name != NULL ? proxy_name : "", key); \
+#define emit_s(key, val) \
+ snprintf(bufk, sizeof(bufk), "%u:%s:stats:%s", \
+ proxy_port, \
+ proxy_name != NULL ? proxy_name : "", key); \
conflate_add_field(msci->result, bufk, val);
char **keys = memcached_stat_get_keys(&mst, st, &error);
@@ -163,12 +165,13 @@ void collect_memcached_stats_for_proxy(struct main_stats_collect_info *msci, con
out_free:
memcached_free(&mst);
+#endif // !MOXI_USE_VBUCKET
}
+
#ifdef REDIRECTS_FOR_MOCKS
#define collect_memcached_stats_for_proxy redirected_collect_memcached_stats_for_proxy
#endif
-
/* This callback is invoked by conflate on a conflate thread
* when it wants proxy stats.
*
View
14 configure.ac
@@ -5,7 +5,6 @@ AC_CANONICAL_SYSTEM
AC_CONFIG_SRCDIR(memcached.c)
AM_INIT_AUTOMAKE(AC_PACKAGE_NAME, AC_PACKAGE_VERSION)
AM_CONFIG_HEADER(config.h)
-AM_CONFIG_HEADER(libmemcached-0.30/libmemcached/libmemcached_config.h)
AC_PROG_CC
AC_PROG_CXX
@@ -120,17 +119,6 @@ AC_HEADER_TIME
AC_SUBST(NO_STRICT_ALIASING)
-sinclude(libmemcached-0.30/m4/pod2man.m4)
-sinclude(libmemcached-0.30/m4/debug.m4)
-sinclude(libmemcached-0.30/m4/dtrace.m4)
-sinclude(libmemcached-0.30/m4/byteorder.m4)
-sinclude(libmemcached-0.30/m4/64bit.m4)
-sinclude(libmemcached-0.30/m4/protocol_binary.m4)
-sinclude(libmemcached-0.30/m4/memcached.m4)
-sinclude(libmemcached-0.30/m4/setsockopt.m4)
-sinclude(libmemcached-0.30/m4/hsieh.m4)
-sinclude(libmemcached-0.30/m4/util.m4)
-
AC_ARG_ENABLE(coverage,
[AS_HELP_STRING([--disable-coverage],[Disable code coverage])])
@@ -480,6 +468,6 @@ AC_SUBST([DATE], [`LANG=C date -R`])
LIBS="$LIBS -lm"
-AC_CONFIG_FILES(Makefile doc/Makefile libmemcached-0.30/libmemcached/Makefile debian/changelog scripts/rpm/moxi.spec)
+AC_CONFIG_FILES(Makefile doc/Makefile debian/changelog scripts/rpm/moxi.spec)
AC_OUTPUT
View
1 cproxy.c
@@ -1,6 +1,7 @@
/* -*- Mode: C; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
#include <stdio.h>
+#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <sysexits.h>
View
1 cproxy_config.c
@@ -1,6 +1,7 @@
/* -*- Mode: C; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
#include <stdio.h>
+#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <ctype.h>
View
1 cproxy_front.c
@@ -1,6 +1,7 @@
/* -*- Mode: C; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
#include <stdio.h>
+#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <sysexits.h>
View
1 cproxy_multiget.c
@@ -1,6 +1,7 @@
/* -*- Mode: C; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
#include <stdio.h>
+#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <sysexits.h>
View
6 cproxy_protocol_a2b.c
@@ -1,6 +1,7 @@
/* -*- Mode: C; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
#include <stdio.h>
+#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <sysexits.h>
@@ -11,11 +12,6 @@
#include "cproxy.h"
#include "work.h"
-#ifndef HAVE_HTONLL
-extern uint64_t ntohll(uint64_t);
-extern uint64_t htonll(uint64_t);
-#endif
-
// Internal declarations.
//
protocol_binary_request_noop req_noop = {
View
1 cproxy_stats.c
@@ -1,6 +1,7 @@
/* -*- Mode: C; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
#include <stdio.h>
+#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <sysexits.h>
View
46 mcs.h
@@ -3,39 +3,23 @@
#ifndef MCS_H
#define MCS_H
-#include <libmemcached/memcached.h>
-
#undef MOXI_USE_VBUCKET
#define MOXI_USE_VBUCKET 1
#ifdef MOXI_USE_VBUCKET
#include <libvbucket/vbucket.h>
#endif // MOXI_USE_VBUCKET
-// From libmemcached.
-//
-memcached_return memcached_connect(memcached_server_st *ptr);
-memcached_return memcached_version(memcached_st *ptr);
-void memcached_quit_server(memcached_server_st *ptr,
- uint8_t io_death);
-memcached_return memcached_safe_read(memcached_server_st *ptr,
- void *dta,
- size_t size);
-ssize_t memcached_io_write(memcached_server_st *ptr,
- const void *buffer,
- size_t length, char with_flush);
-void memcached_io_reset(memcached_server_st *ptr);
-memcached_return memcached_do(memcached_server_st *ptr,
- const void *command,
- size_t command_length,
- uint8_t with_flush);
-
// The mcs API's are a level of indirection from direct libmemcached
// API usage.
//
#ifdef MOXI_USE_VBUCKET
-#define mcs_return uint32_t
+typedef enum {
+ MEMCACHED_SUCCESS,
+ MEMCACHED_FAILURE,
+ MEMCACHED_MAXIMUM_RETURN /* Always add new error code before */
+} mcs_return;
typedef struct {
char hostname[200];
@@ -50,6 +34,26 @@ typedef struct {
#else // !MOXI_US_VBUCKET
+#include <libmemcached/memcached.h>
+
+// From libmemcached.
+//
+memcached_return memcached_connect(memcached_server_st *ptr);
+memcached_return memcached_version(memcached_st *ptr);
+void memcached_quit_server(memcached_server_st *ptr,
+ uint8_t io_death);
+memcached_return memcached_safe_read(memcached_server_st *ptr,
+ void *dta,
+ size_t size);
+ssize_t memcached_io_write(memcached_server_st *ptr,
+ const void *buffer,
+ size_t length, char with_flush);
+void memcached_io_reset(memcached_server_st *ptr);
+memcached_return memcached_do(memcached_server_st *ptr,
+ const void *command,
+ size_t command_length,
+ uint8_t with_flush);
+
#define mcs_return memcached_return
#define mcs_st memcached_st
#define mcs_server_st memcached_server_st
View
81 murmur_hash.c
@@ -0,0 +1,81 @@
+/* -*- Mode: C; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
+
+#include <sys/types.h>
+#include <stdbool.h>
+#include <stdint.h>
+
+/*
+ "Murmur" hash provided by Austin, tanjent@gmail.com
+ http://murmurhash.googlepages.com/
+
+ Note - This code makes a few assumptions about how your machine behaves -
+
+ 1. We can read a 4-byte value from any address without crashing
+ 2. sizeof(int) == 4
+
+ And it has a few limitations -
+ 1. It will not work incrementally.
+ 2. It will not produce the same results on little-endian and big-endian
+ machines.
+
+ Updated to murmur2 hash - BP
+*/
+
+uint32_t murmur_hash(const char *key, size_t length);
+
+uint32_t murmur_hash(const char *key, size_t length)
+{
+ /*
+ 'm' and 'r' are mixing constants generated offline. They're not
+ really 'magic', they just happen to work well.
+ */
+
+ const unsigned int m= 0x5bd1e995;
+ const unsigned int seed= (0xdeadbeef * length);
+ const int r= 24;
+
+
+ // Initialize the hash to a 'random' value
+
+ unsigned int h= seed ^ length;
+
+ // Mix 4 bytes at a time into the hash
+
+ const unsigned char * data= (const unsigned char *)key;
+
+ while(length >= 4)
+ {
+ unsigned int k = *(unsigned int *)data;
+
+ k *= m;
+ k ^= k >> r;
+ k *= m;
+
+ h *= m;
+ h ^= k;
+
+ data += 4;
+ length -= 4;
+ }
+
+ // Handle the last few bytes of the input array
+
+ switch(length)
+ {
+ case 3: h ^= data[2] << 16;
+ case 2: h ^= data[1] << 8;
+ case 1: h ^= data[0];
+ h *= m;
+ };
+
+ /*
+ Do a few final mixes of the hash to ensure the last few bytes are
+ well-incorporated.
+ */
+
+ h ^= h >> 13;
+ h *= m;
+ h ^= h >> 15;
+
+ return h;
+}
View
32 util.c
@@ -174,3 +174,35 @@ void vperror(const char *fmt, ...) {
perror(buf);
}
+
+// The following are from libmemcached/byteorder.c
+
+/* Byte swap a 64-bit number. */
+static inline uint64_t swap64(uint64_t in)
+{
+#ifndef BYTEORDER_BIG_ENDIAN
+ /* Little endian, flip the bytes around until someone makes a faster/better
+ * way to do this. */
+ uint64_t rv= 0;
+ uint8_t x= 0;
+ for(x= 0; x < 8; x++)
+ {
+ rv= (rv << 8) | (in & 0xff);
+ in >>= 8;
+ }
+ return rv;
+#else
+ /* big-endian machines don't need byte swapping */
+ return in;
+#endif
+}
+
+uint64_t ntohll(uint64_t value)
+{
+ return swap64(value);
+}
+
+uint64_t htonll(uint64_t value)
+{
+ return swap64(value);
+}
View
3 util.h
@@ -60,3 +60,6 @@ void vperror(const char *fmt, ...)
__gcc_attribute__ ((format (printf, 1, 2)));
#undef __gcc_attribute__
+
+uint64_t ntohll(uint64_t value);
+uint64_t htonll(uint64_t value);

0 comments on commit 0577ccb

Please sign in to comment.