[Opensrf-commits] r1869 - in trunk: . include/opensrf src/extras src/libopensrf (dbs)
svn at svn.open-ils.org
svn at svn.open-ils.org
Thu Dec 10 00:09:57 EST 2009
Author: dbs
Date: 2009-12-10 00:09:53 -0500 (Thu, 10 Dec 2009)
New Revision: 1869
Modified:
trunk/configure.ac
trunk/include/opensrf/osrf_cache.h
trunk/src/extras/Makefile.install
trunk/src/libopensrf/Makefile.am
trunk/src/libopensrf/osrf_cache.c
Log:
Transition from libmemcache to libmemcached - an actively maintained memcached client library.
As of this commit, you (I'm looking at you, buildbot) will require the pkg-config and
libmemcached development packages to build and run OpenSRF.
Modified: trunk/configure.ac
===================================================================
--- trunk/configure.ac 2009-12-08 03:40:00 UTC (rev 1868)
+++ trunk/configure.ac 2009-12-10 05:09:53 UTC (rev 1869)
@@ -255,13 +255,14 @@
#-----------------------------
AC_CHECK_LIB([dl], [dlerror], [],AC_MSG_ERROR(***OpenSRF requires libdl))
- AC_SEARCH_LIBS([mc_req_free], [memcache], [], AC_MSG_ERROR(***OpenSRF requires memcache headers))
AC_CHECK_LIB([ncurses], [initscr], [], AC_MSG_ERROR(***OpenSRF requires ncurses headers))
AC_CHECK_LIB([readline], [readline], [], AC_MSG_ERROR(***OpenSRF requires readline headers))
AC_CHECK_LIB([xml2], [xmlAddID], [], AC_MSG_ERROR(***OpenSRF requires libxml2 headers))
+ # Check for libmemcached and set flags accordingly
+ PKG_CHECK_MODULES(memcached, libmemcached >= 0.8.0)
+ AC_SUBST(memcached_CFLAGS)
+ AC_SUBST(memcached_LIBS)
-
-
#-----------------------------
# Checks for header files.
#-----------------------------
Modified: trunk/include/opensrf/osrf_cache.h
===================================================================
--- trunk/include/opensrf/osrf_cache.h 2009-12-08 03:40:00 UTC (rev 1868)
+++ trunk/include/opensrf/osrf_cache.h 2009-12-10 05:09:53 UTC (rev 1869)
@@ -17,7 +17,7 @@
#define OSRF_CACHE_H
#include <opensrf/osrf_json.h>
-#include <memcache.h>
+#include <libmemcached/memcached.h>
#include <opensrf/log.h>
#ifdef __cplusplus
Modified: trunk/src/extras/Makefile.install
===================================================================
--- trunk/src/extras/Makefile.install 2009-12-08 03:40:00 UTC (rev 1868)
+++ trunk/src/extras/Makefile.install 2009-12-10 05:09:53 UTC (rev 1869)
@@ -51,10 +51,6 @@
EJABBERD_PKG_x64=ejabberd-2.0.2_2-linux-x86_64-installer.bin
EJABBERD_HOST=http://www.process-one.net/downloads/ejabberd
-# libmemcache is not packaged on CentOS/RHEL
-LIBMEMCACHE=libmemcache-1.4.0.rc2
-LIBMEMCACHE_HOST=http://people.freebsd.org/~seanc/libmemcache/
-
# XML::LibXSLT fails due to old libxslt
XSLT=libxslt-1.1.22
XSLT_HOST=ftp://ftp.gnome.org/pub/GNOME/sources/libxslt/1.1
@@ -85,7 +81,7 @@
libgcrypt11-dev \
libgdbm-dev \
liblog-log4perl-perl\
- libmemcache-dev\
+ libmemcached-dev\
libmodule-build-perl\
libnet-jabber-perl\
libperl-dev\
@@ -105,6 +101,7 @@
libxslt1-dev\
memcached\
ntpdate\
+ pkg-config\
psmisc\
python-dev\
python-libxml2\
@@ -165,7 +162,7 @@
vim\
ntp\
memcached\
- libmemcache\
+ libmemcached\
net-misc/telnet-bsd\
app-portage/gentoolkit\
gsasl\
@@ -235,7 +232,7 @@
@echo "please specify an OS" && exit 0
-centos: install_centos_rpms install_ejabberd install_libmemcache install_libxml2 install_libxslt install_centos_perl create_ld_local
+centos: install_centos_rpms install_ejabberd install_libmemcached install_libxml2 install_libxslt install_centos_perl create_ld_local
debian-etch: generic_debian etch
debian-lenny: generic_debian lenny
@@ -277,11 +274,9 @@
chmod u+x $(EJABBERD_PKG)
./$(EJABBERD_PKG) --mode unattended --prefix /opt/ejabberd --adminpw opensrf
-# Install libmemcache from the official project source
-install_libmemcache:
- if [ ! -d $(LIBMEMCACHE) ]; then wget $(LIBMEMCACHE_HOST)/$(LIBMEMCACHE).tar.bz2; fi;
- tar xjf $(LIBMEMCACHE).tar.bz2
- cd $(LIBMEMCACHE) && ./configure && make && make install
+# Install libmemcached from the official project source
+install_libmemcached:
+ @echo "TODO: work out how to build or grab libmemcached packages for CentOS/RHEL"
# Install a newer version of libxslt
install_libxslt:
Modified: trunk/src/libopensrf/Makefile.am
===================================================================
--- trunk/src/libopensrf/Makefile.am 2009-12-08 03:40:00 UTC (rev 1868)
+++ trunk/src/libopensrf/Makefile.am 2009-12-10 05:09:53 UTC (rev 1869)
@@ -14,7 +14,7 @@
AM_CFLAGS = $(DEF_CFLAGS) -DASSUME_STATELESS -DOSRF_STRICT_PARAMS -rdynamic -fno-strict-aliasing -DOSRF_JSON_ENABLE_XML_UTILS
AM_LDFLAGS = $(DEF_LDFLAGS) -R $(libdir)
-LDADD = -lxml2 -ldl -lmemcache -lopensrf
+LDADD = -lxml2 -ldl -lopensrf
DISTCLEANFILES = Makefile.in Makefile
@@ -109,8 +109,9 @@
libosrf_json_la_SOURCES = $(JSON_TARGS) $(JSON_DEP) $(JSON_TARGS_HEADS) $(JSON_DEP_HEADS)
libosrf_json_la_CFLAGS = $(AM_CFLAGS)
-libopensrf_la_CFLAGS = $(AM_CFLAGS)
+libopensrf_la_CFLAGS = $(AM_CFLAGS) $(memcached_CFLAGS)
libopensrf_la_DEPENDENCIES = libosrf_json.la
+libopensrf_la_LIBADD = $(memcached_LIBS)
libopensrf_la_SOURCES = $(TARGS) $(TARGS_HEADS) $(JSON_TARGS) $(JSON_TARGS_HEADS)
Modified: trunk/src/libopensrf/osrf_cache.c
===================================================================
--- trunk/src/libopensrf/osrf_cache.c 2009-12-08 03:40:00 UTC (rev 1868)
+++ trunk/src/libopensrf/osrf_cache.c 2009-12-10 05:09:53 UTC (rev 1869)
@@ -15,19 +15,30 @@
#include <opensrf/osrf_cache.h>
-static struct memcache* _osrfCache = NULL;
+static struct memcached_st* _osrfCache = NULL;
static time_t _osrfCacheMaxSeconds = -1;
int osrfCacheInit( const char* serverStrings[], int size, time_t maxCacheSeconds ) {
+ memcached_server_st *server_pool;
+ memcached_return rc;
+
if( !(serverStrings && size > 0) ) return -1;
- osrfCacheCleanup(); /* in case we've already been init-ed */
+ osrfCacheCleanup(); /* in case we've already been init-ed */
int i;
- _osrfCache = mc_new();
+ _osrfCache = memcached_create(NULL);
_osrfCacheMaxSeconds = maxCacheSeconds;
- for( i = 0; i < size && serverStrings[i]; i++ )
- mc_server_add4( _osrfCache, serverStrings[i] );
+ for( i = 0; i < size && serverStrings[i]; i++ ) {
+ /* TODO: modify caller to pass a list of servers all at once */
+ server_pool = memcached_servers_parse(serverStrings[i]);
+ rc = memcached_server_push(_osrfCache, server_pool);
+ if (rc != MEMCACHED_SUCCESS) {
+ osrfLogError(OSRF_LOG_MARK,
+ "Failed to add memcached server: %s - %s",
+ serverStrings[i], memcached_strerror(_osrfCache, rc));
+ }
+ }
return 0;
}
@@ -36,24 +47,37 @@
if( !(key && obj) ) return -1;
char* s = jsonObjectToJSON( obj );
osrfLogInternal( OSRF_LOG_MARK, "osrfCachePut(): Putting object (key=%s): %s", key, s);
- osrfCachePutString(key, s, seconds);
+ osrfCachePutString(key, s, seconds);
free(s);
return 0;
}
int osrfCachePutString( char* key, const char* value, time_t seconds ) {
+ memcached_return rc;
if( !(key && value) ) return -1;
- seconds = (seconds <= 0 || seconds > _osrfCacheMaxSeconds) ? _osrfCacheMaxSeconds : seconds;
+ seconds = (seconds <= 0 || seconds > _osrfCacheMaxSeconds) ? _osrfCacheMaxSeconds : seconds;
osrfLogInternal( OSRF_LOG_MARK, "osrfCachePutString(): Putting string (key=%s): %s", key, value);
- mc_set(_osrfCache, key, strlen(key), value, strlen(value), seconds, 0);
+ /* add or overwrite existing key:value pair */
+ rc = memcached_set(_osrfCache, key, strlen(key), value, strlen(value), seconds, 0);
+ if (rc != MEMCACHED_SUCCESS) {
+ osrfLogError(OSRF_LOG_MARK, "Failed to cache key:value [%s]:[%s] - %s",
+ key, value, memcached_strerror(_osrfCache, rc));
+ }
return 0;
}
jsonObject* osrfCacheGetObject( const char* key, ... ) {
+ size_t val_len;
+ uint32_t flags;
+ memcached_return rc;
jsonObject* obj = NULL;
if( key ) {
VA_LIST_TO_STRING(key);
- const char* data = (const char*) mc_aget( _osrfCache, VA_BUF, strlen(VA_BUF) );
+ const char* data = (const char*) memcached_get(_osrfCache, VA_BUF, strlen(VA_BUF), &val_len, &flags, &rc);
+ if (rc != MEMCACHED_SUCCESS) {
+ osrfLogDebug(OSRF_LOG_MARK, "Failed to get key [%s] - %s",
+ VA_BUF, memcached_strerror(_osrfCache, rc));
+ }
if( data ) {
osrfLogInternal( OSRF_LOG_MARK, "osrfCacheGetObject(): Returning object (key=%s): %s", VA_BUF, data);
obj = jsonParse( data );
@@ -65,9 +89,16 @@
}
char* osrfCacheGetString( const char* key, ... ) {
+ size_t val_len;
+ uint32_t flags;
+ memcached_return rc;
if( key ) {
VA_LIST_TO_STRING(key);
- char* data = (char*) mc_aget(_osrfCache, VA_BUF, strlen(VA_BUF) );
+ char* data = (char*) memcached_get(_osrfCache, VA_BUF, strlen(VA_BUF), &val_len, &flags, &rc);
+ if (rc != MEMCACHED_SUCCESS) {
+ osrfLogDebug(OSRF_LOG_MARK, "Failed to get key [%s] - %s",
+ VA_BUF, memcached_strerror(_osrfCache, rc));
+ }
osrfLogInternal( OSRF_LOG_MARK, "osrfCacheGetString(): Returning object (key=%s): %s", VA_BUF, data);
if(!data) osrfLogDebug(OSRF_LOG_MARK, "No cache data exists with key %s", VA_BUF);
return data;
@@ -77,9 +108,15 @@
int osrfCacheRemove( const char* key, ... ) {
+ memcached_return rc;
if( key ) {
VA_LIST_TO_STRING(key);
- return mc_delete(_osrfCache, VA_BUF, strlen(VA_BUF), 0 );
+ rc = memcached_delete(_osrfCache, VA_BUF, strlen(VA_BUF), 0 );
+ if (rc != MEMCACHED_SUCCESS && rc != MEMCACHED_BUFFERED) {
+ osrfLogDebug(OSRF_LOG_MARK, "Failed to delete key [%s] - %s",
+ VA_BUF, memcached_strerror(_osrfCache, rc));
+ }
+ return 0;
}
return -1;
}
@@ -98,8 +135,9 @@
}
void osrfCacheCleanup() {
- if(_osrfCache)
- mc_free(_osrfCache);
+ if(_osrfCache) {
+ memcached_free(_osrfCache);
+ }
}
More information about the opensrf-commits
mailing list