You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@subversion.apache.org by st...@apache.org on 2010/08/18 11:21:26 UTC
svn commit: r986605 - in /subversion/branches/performance/subversion:
include/private/svn_cache.h libsvn_subr/cache-inprocess.c
libsvn_subr/cache-membuffer.c libsvn_subr/cache-memcache.c
libsvn_subr/cache.c libsvn_subr/cache.h
Author: stefan2
Date: Wed Aug 18 09:21:18 2010
New Revision: 986605
URL: http://svn.apache.org/viewvc?rev=986605&view=rev
Log:
Extend cache API with a function that effectively allows partial de-
serialization as an alternative to the mandatory full de-serialization
in svn_cache__get. This can be used to read a single element from
a cached container, for instance.
* subversion/include/private/svn_cache.h
(svn_cache__partial_getter_func_t): declare new callback type
(svn_cache__get_partial): declare new API function
* subversion/libsvn_subr/cache.h
(svn_cache__vtable_t): extend vtable
* subversion/libsvn_subr/cache.c
(svn_cache__get_partial): implement new API function
* subversion/libsvn_subr/cache-memcache.c
(memcache_get_partial): implement new API for memcached caches
(memcache_vtable): extend vtable
* subversion/libsvn_subr/cache-membuffer.c
(membuffer_cache_get_partial, svn_membuffer_cache_get_partial):
implement new API for membuffer caches
(membuffer_cache_vtable): extend vtable
* subversion/libsvn_subr/cache-inprocess.c
(inprocess_cache_get_partial): implement new API for in-process caches
(inprocess_cache_vtable): extend vtable
Modified:
subversion/branches/performance/subversion/include/private/svn_cache.h
subversion/branches/performance/subversion/libsvn_subr/cache-inprocess.c
subversion/branches/performance/subversion/libsvn_subr/cache-membuffer.c
subversion/branches/performance/subversion/libsvn_subr/cache-memcache.c
subversion/branches/performance/subversion/libsvn_subr/cache.c
subversion/branches/performance/subversion/libsvn_subr/cache.h
Modified: subversion/branches/performance/subversion/include/private/svn_cache.h
URL: http://svn.apache.org/viewvc/subversion/branches/performance/subversion/include/private/svn_cache.h?rev=986605&r1=986604&r2=986605&view=diff
==============================================================================
--- subversion/branches/performance/subversion/include/private/svn_cache.h (original)
+++ subversion/branches/performance/subversion/include/private/svn_cache.h Wed Aug 18 09:21:18 2010
@@ -68,6 +68,19 @@ typedef svn_error_t *(*svn_cache__deseri
apr_pool_t *pool);
/**
+ * A function type for deserializing an object @a *out from the string
+ * @a data of length @a data_len in the pool @a pool. The extra information
+ * @a baton passed into can be used to deserialize only a specific part or
+ * sub-structure or to perform any other non-modifying operation that may
+ * not require the whole structure to be processed.
+ */
+typedef svn_error_t *(*svn_cache__partial_getter_func_t)(void **out,
+ const char *data,
+ apr_size_t data_len,
+ void *baton,
+ apr_pool_t *pool);
+
+/**
* A function type for serializing an object @a in into bytes. The
* function should allocate the serialized value in @a pool, set @a
* *data to the serialized value, and set *data_len to its length.
@@ -315,6 +328,19 @@ svn_cache__iter(svn_boolean_t *completed
svn_iter_apr_hash_cb_t func,
void *baton,
apr_pool_t *pool);
+
+/**
+ * Similar to @ref svn_cache__set but will call a specific de-serialization
+ * function @a func.
+ */
+svn_error_t *
+svn_cache__get_partial(void **value,
+ svn_boolean_t *found,
+ const svn_cache__t *cache,
+ const void *key,
+ svn_cache__partial_getter_func_t func,
+ void *baton,
+ apr_pool_t *scratch_pool);
/** @} */
Modified: subversion/branches/performance/subversion/libsvn_subr/cache-inprocess.c
URL: http://svn.apache.org/viewvc/subversion/branches/performance/subversion/libsvn_subr/cache-inprocess.c?rev=986605&r1=986604&r2=986605&view=diff
==============================================================================
--- subversion/branches/performance/subversion/libsvn_subr/cache-inprocess.c (original)
+++ subversion/branches/performance/subversion/libsvn_subr/cache-inprocess.c Wed Aug 18 09:21:18 2010
@@ -425,7 +425,35 @@ inprocess_cache_iter(svn_boolean_t *comp
return unlock_cache(cache,
svn_iter_apr_hash(completed, cache->hash, iter_cb, &b,
pool));
+}
+
+static svn_error_t *
+inprocess_cache_get_partial(void **value_p,
+ svn_boolean_t *found,
+ void *cache_void,
+ const void *key,
+ svn_cache__partial_getter_func_t func,
+ void *baton,
+ apr_pool_t *pool)
+{
+ inprocess_cache_t *cache = cache_void;
+ struct cache_entry *entry;
+ svn_error_t *err;
+
+ SVN_ERR(lock_cache(cache));
+ entry = apr_hash_get(cache->hash, key, cache->klen);
+ if (! entry)
+ {
+ *found = FALSE;
+ return unlock_cache(cache, SVN_NO_ERROR);
+ }
+
+ move_page_to_front(cache, entry->page);
+
+ *found = TRUE;
+ err = func(value_p, entry->value, 0, baton, pool);
+ return unlock_cache(cache, err);
}
static svn_boolean_t
@@ -444,6 +472,7 @@ static svn_cache__vtable_t inprocess_cac
inprocess_cache_get,
inprocess_cache_set,
inprocess_cache_iter,
+ inprocess_cache_get_partial,
inprocess_cache_is_cachable
};
Modified: subversion/branches/performance/subversion/libsvn_subr/cache-membuffer.c
URL: http://svn.apache.org/viewvc/subversion/branches/performance/subversion/libsvn_subr/cache-membuffer.c?rev=986605&r1=986604&r2=986605&view=diff
==============================================================================
--- subversion/branches/performance/subversion/libsvn_subr/cache-membuffer.c (original)
+++ subversion/branches/performance/subversion/libsvn_subr/cache-membuffer.c Wed Aug 18 09:21:18 2010
@@ -864,6 +864,48 @@ membuffer_cache_get(svn_membuffer_t *cac
return unlock_cache(cache, err);
}
+svn_error_t*
+membuffer_cache_get_partial(svn_membuffer_t *cache,
+ const void *key,
+ apr_size_t key_len,
+ void **item,
+ svn_cache__partial_getter_func_t deserializer,
+ void *baton,
+ apr_pool_t *pool)
+{
+ apr_uint32_t group_index;
+ unsigned char to_find[KEY_SIZE];
+ entry_t *entry;
+ svn_error_t *err = SVN_NO_ERROR;
+
+ group_index = get_group_index(cache, key, key_len, to_find, pool);
+
+ SVN_ERR(lock_cache(cache));
+
+ entry = find_entry(cache, group_index, to_find, FALSE);
+ cache->total_reads++;
+ if (entry == NULL)
+ {
+ *item = NULL;
+ }
+ else
+ {
+ entry->hit_count++;
+ cache->hit_count++;
+ cache->total_hits++;
+
+ err = deserializer(item,
+ (const char*)cache->data + entry->offset,
+ entry->size,
+ baton,
+ pool);
+ }
+
+ /* done here -> unlock the cache
+ */
+ return unlock_cache(cache, err);
+}
+
/* Implement the svn_cache__t interface on top of a shared membuffer cache.
*
* Because membuffer caches tend to be very large, there will be rather few
@@ -1051,6 +1093,39 @@ svn_membuffer_cache_iter(svn_boolean_t *
_("Can't iterate a membuffer-based cache"));
}
+static svn_error_t *
+svn_membuffer_cache_get_partial(void **value_p,
+ svn_boolean_t *found,
+ void *cache_void,
+ const void *key,
+ svn_cache__partial_getter_func_t func,
+ void *baton,
+ apr_pool_t *pool)
+{
+ svn_membuffer_cache_t *cache = cache_void;
+
+ void *full_key;
+ apr_size_t full_key_len;
+
+ combine_key(cache->prefix,
+ sizeof(cache->prefix),
+ key,
+ cache->key_len,
+ &full_key,
+ &full_key_len,
+ pool);
+
+ SVN_ERR(membuffer_cache_get_partial(cache->membuffer,
+ full_key,
+ full_key_len,
+ value_p,
+ func,
+ baton,
+ pool));
+ *found = *value_p != NULL;
+ return SVN_NO_ERROR;
+}
+
static svn_boolean_t
svn_membuffer_cache_is_cachable(void *cache_void, apr_size_t size)
{
@@ -1067,6 +1142,7 @@ static svn_cache__vtable_t membuffer_cac
svn_membuffer_cache_get,
svn_membuffer_cache_set,
svn_membuffer_cache_iter,
+ svn_membuffer_cache_get_partial,
svn_membuffer_cache_is_cachable
};
Modified: subversion/branches/performance/subversion/libsvn_subr/cache-memcache.c
URL: http://svn.apache.org/viewvc/subversion/branches/performance/subversion/libsvn_subr/cache-memcache.c?rev=986605&r1=986604&r2=986605&view=diff
==============================================================================
--- subversion/branches/performance/subversion/libsvn_subr/cache-memcache.c (original)
+++ subversion/branches/performance/subversion/libsvn_subr/cache-memcache.c Wed Aug 18 09:21:18 2010
@@ -210,6 +210,49 @@ memcache_set(void *cache_void,
return SVN_NO_ERROR;
}
+static svn_error_t *
+memcache_get_partial(void **value_p,
+ svn_boolean_t *found,
+ void *cache_void,
+ const void *key,
+ svn_cache__partial_getter_func_t func,
+ void *baton,
+ apr_pool_t *pool)
+{
+ memcache_t *cache = cache_void;
+ svn_error_t *err;
+ apr_status_t apr_err;
+ char *data;
+ const char *mc_key;
+ apr_size_t data_len;
+ apr_pool_t *subpool = svn_pool_create(pool);
+
+ mc_key = build_key(cache, key, subpool);
+
+ apr_err = apr_memcache_getp(cache->memcache,
+ subpool,
+ mc_key,
+ &data,
+ &data_len,
+ NULL /* ignore flags */);
+ if (apr_err == APR_NOTFOUND)
+ {
+ *found = FALSE;
+ svn_pool_destroy(subpool);
+ return SVN_NO_ERROR;
+ }
+ else if (apr_err != APR_SUCCESS || !data)
+ return svn_error_wrap_apr(apr_err,
+ _("Unknown memcached error while reading"));
+
+ /* We found it! */
+ *found = TRUE;
+ err = func(value_p, data, data_len, baton, pool);
+
+ svn_pool_destroy(subpool);
+ return err;
+}
+
static svn_error_t *
memcache_iter(svn_boolean_t *completed,
@@ -235,6 +278,7 @@ static svn_cache__vtable_t memcache_vtab
memcache_get,
memcache_set,
memcache_iter,
+ memcache_get_partial,
memcache_is_cachable
};
Modified: subversion/branches/performance/subversion/libsvn_subr/cache.c
URL: http://svn.apache.org/viewvc/subversion/branches/performance/subversion/libsvn_subr/cache.c?rev=986605&r1=986604&r2=986605&view=diff
==============================================================================
--- subversion/branches/performance/subversion/libsvn_subr/cache.c (original)
+++ subversion/branches/performance/subversion/libsvn_subr/cache.c Wed Aug 18 09:21:18 2010
@@ -106,3 +106,21 @@ svn_cache__iter(svn_boolean_t *completed
pool);
}
+svn_error_t *
+svn_cache__get_partial(void **value,
+ svn_boolean_t *found,
+ const svn_cache__t *cache,
+ const void *key,
+ svn_cache__partial_getter_func_t func,
+ void *baton,
+ apr_pool_t *scratch_pool)
+{
+ return (cache->vtable->get_partial)(value,
+ found,
+ cache->cache_internal,
+ key,
+ func,
+ baton,
+ scratch_pool);
+}
+
Modified: subversion/branches/performance/subversion/libsvn_subr/cache.h
URL: http://svn.apache.org/viewvc/subversion/branches/performance/subversion/libsvn_subr/cache.h?rev=986605&r1=986604&r2=986605&view=diff
==============================================================================
--- subversion/branches/performance/subversion/libsvn_subr/cache.h (original)
+++ subversion/branches/performance/subversion/libsvn_subr/cache.h Wed Aug 18 09:21:18 2010
@@ -48,6 +48,14 @@ typedef struct {
void *baton,
apr_pool_t *pool);
+ svn_error_t *(*get_partial)(void **value,
+ svn_boolean_t *found,
+ void *cache_implementation,
+ const void *key,
+ svn_cache__partial_getter_func_t func,
+ void *baton,
+ apr_pool_t *pool);
+
svn_boolean_t (*is_cachable)(void *cache_implementation,
apr_size_t size);
} svn_cache__vtable_t;
Re: svn commit: r986605 - in /subversion/branches/performance/subversion:
include/private/svn_cache.h libsvn_subr/cache-inprocess.c libsvn_subr/cache-membuffer.c
libsvn_subr/cache-memcache.c libsvn_subr/cache.c libsvn_subr/cache.h
Posted by Lieven Govaerts <sv...@mobsol.be>.
On Wed, Aug 18, 2010 at 11:21 AM, <st...@apache.org> wrote:
> Author: stefan2
> Date: Wed Aug 18 09:21:18 2010
> New Revision: 986605
>
> URL: http://svn.apache.org/viewvc?rev=986605&view=rev
> Log:
> Extend cache API with a function that effectively allows partial de-
> serialization as an alternative to the mandatory full de-serialization
> in svn_cache__get. This can be used to read a single element from
> a cached container, for instance.
>
> * subversion/include/private/svn_cache.h
> (svn_cache__partial_getter_func_t): declare new callback type
> (svn_cache__get_partial): declare new API function
>
> * subversion/libsvn_subr/cache.h
> (svn_cache__vtable_t): extend vtable
> * subversion/libsvn_subr/cache.c
> (svn_cache__get_partial): implement new API function
>
> * subversion/libsvn_subr/cache-memcache.c
> (memcache_get_partial): implement new API for memcached caches
> (memcache_vtable): extend vtable
> * subversion/libsvn_subr/cache-membuffer.c
> (membuffer_cache_get_partial, svn_membuffer_cache_get_partial):
> implement new API for membuffer caches
>
[..]
> +svn_error_t*
> +membuffer_cache_get_partial(svn_membuffer_t *cache,
> + const void *key,
> + apr_size_t key_len,
> + void **item,
> + svn_cache__partial_getter_func_t deserializer,
> + void *baton,
> + apr_pool_t *pool)
> +{
This function should probably be static? Results in a gcc warning now.
Lieven