You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@apr.apache.org by pq...@apache.org on 2007/06/08 08:09:50 UTC
svn commit: r545431 - in /apr/apr-util/trunk: include/apr_memcache.h
memcache/apr_memcache.c
Author: pquerna
Date: Thu Jun 7 23:09:49 2007
New Revision: 545431
URL: http://svn.apache.org/viewvc?view=rev&rev=545431
Log:
Make the server selection pluggable. This should be all that is needed to plug in one of the newer consistent hashing libraries, like libketama.
Modified:
apr/apr-util/trunk/include/apr_memcache.h
apr/apr-util/trunk/memcache/apr_memcache.c
Modified: apr/apr-util/trunk/include/apr_memcache.h
URL: http://svn.apache.org/viewvc/apr/apr-util/trunk/include/apr_memcache.h?view=diff&rev=545431&r1=545430&r2=545431
==============================================================================
--- apr/apr-util/trunk/include/apr_memcache.h (original)
+++ apr/apr-util/trunk/include/apr_memcache.h Thu Jun 7 23:09:49 2007
@@ -83,8 +83,19 @@
const char *data,
apr_size_t data_len);
+typedef struct apr_memcache_t apr_memcache_t;
+
+/* Custom Server Select callback function prototype.
+* @param baton user selected baton
+* @param mc memcache instance, use mc->live_servers to select a node
+* @param hash hash of the selected key.
+*/
+typedef apr_memcache_server_t* (*apr_memcahce_server_func)(void *baton,
+ apr_memcache_t *mc,
+ const apr_uint32_t hash);
+
/** Container for a set of memcached servers */
-typedef struct
+struct apr_memcache_t
{
apr_uint32_t flags; /**< Flags, Not currently used */
apr_uint16_t nalloc; /**< Number of Servers Allocated */
@@ -93,7 +104,9 @@
apr_pool_t *p; /** Pool to use for allocations */
void *hash_baton;
apr_memcahce_hash_func hash_func;
-} apr_memcache_t;
+ void *server_baton;
+ apr_memcahce_server_func server_func;
+};
/** Returned Data from a multiple get */
typedef struct
@@ -139,6 +152,14 @@
*/
APR_DECLARE(apr_memcache_server_t *) apr_memcache_find_server_hash(apr_memcache_t *mc,
const apr_uint32_t hash);
+
+/**
+ * server selection compatible with the standard Perl Client.
+ */
+APR_DECLARE(apr_memcache_server_t *)
+apr_memcache_find_server_hash_default(void *baton,
+ apr_memcache_t *mc,
+ const apr_uint32_t hash);
/**
* Adds a server to a client object
Modified: apr/apr-util/trunk/memcache/apr_memcache.c
URL: http://svn.apache.org/viewvc/apr/apr-util/trunk/memcache/apr_memcache.c?view=diff&rev=545431&r1=545430&r2=545431
==============================================================================
--- apr/apr-util/trunk/memcache/apr_memcache.c (original)
+++ apr/apr-util/trunk/memcache/apr_memcache.c Thu Jun 7 23:09:49 2007
@@ -148,6 +148,18 @@
APR_DECLARE(apr_memcache_server_t *)
apr_memcache_find_server_hash(apr_memcache_t *mc, const apr_uint32_t hash)
{
+ if (mc->server_func) {
+ return mc->server_func(mc->server_baton, mc, hash);
+ }
+ else {
+ return apr_memcache_find_server_hash_default(NULL, mc, hash);
+ }
+}
+
+APR_DECLARE(apr_memcache_server_t *)
+apr_memcache_find_server_hash_default(void *baton, apr_memcache_t *mc,
+ const apr_uint32_t hash)
+{
apr_memcache_server_t *ms = NULL;
apr_uint32_t h = hash;
apr_uint32_t i = 0;
@@ -410,6 +422,8 @@
mc->live_servers = apr_palloc(p, mc->nalloc * sizeof(struct apr_memcache_server_t *));
mc->hash_func = NULL;
mc->hash_baton = NULL;
+ mc->server_func = NULL;
+ mc->server_baton = NULL;
*memcache = mc;
return rv;
}