#-----------------------------
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.
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
libgcrypt11-dev \
libgdbm-dev \
liblog-log4perl-perl\
- libmemcache-dev\
+ libmemcached-dev\
libmodule-build-perl\
libnet-jabber-perl\
libperl-dev\
libxslt1-dev\
memcached\
ntpdate\
+ pkg-config\
psmisc\
python-dev\
python-libxml2\
vim\
ntp\
memcached\
- libmemcache\
+ libmemcached\
net-misc/telnet-bsd\
app-portage/gentoolkit\
gsasl\
@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
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:
#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;
}
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 );
}
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;
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;
}
}
void osrfCacheCleanup() {
- if(_osrfCache)
- mc_free(_osrfCache);
+ if(_osrfCache) {
+ memcached_free(_osrfCache);
+ }
}