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 2012/02/12 18:42:20 UTC

svn commit: r1243283 - in /subversion/trunk/subversion: include/private/svn_cache.h libsvn_subr/cache-inprocess.c libsvn_subr/cache-membuffer.c libsvn_subr/cache-memcache.c

Author: stefan2
Date: Sun Feb 12 17:42:20 2012
New Revision: 1243283

URL: http://svn.apache.org/viewvc?rev=1243283&view=rev
Log:
Extend svn_cache__t API to support NULL keys.  Attempts to
store a value under a NULL key will be ignored and get()
requests for NULL keys will always return "not found".

Also, fix a number of API documentation issues in the
affected functions.

* subversion/include/private/svn_cache.h 
  (svn_cache__get): mention support for NULL keys;
   address ### review comment
  (svn_cache__set, svn_cache__set_partial): 
   mention support for NULL keys
  (svn_cache__get_partial): ditto; document pool usage

* subversion/libsvn_subr/cache-memcache.c
  (memcache_internal_get): return "not found" for NULL keys
  (memcache_set): be a no-op for NULL keys
* subversion/libsvn_subr/cache-membuffer.c
  (get_group_index): make NULL keys refer to invalid groups
  (membuffer_cache_get_partial, membuffer_cache_set_partial):
   add check for invalid groups
  (combine_key): a NULL user key results in a NULL internal key
* subversion/libsvn_subr/cache-inprocess.c
  (inprocess_cache_get_internal, inprocess_cache_get_partial):
   return "not found" for NULL keys
  (inprocess_cache_set, inprocess_cache_set_partial):
   be a no-op for NULL keys

Modified:
    subversion/trunk/subversion/include/private/svn_cache.h
    subversion/trunk/subversion/libsvn_subr/cache-inprocess.c
    subversion/trunk/subversion/libsvn_subr/cache-membuffer.c
    subversion/trunk/subversion/libsvn_subr/cache-memcache.c

Modified: subversion/trunk/subversion/include/private/svn_cache.h
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/include/private/svn_cache.h?rev=1243283&r1=1243282&r2=1243283&view=diff
==============================================================================
--- subversion/trunk/subversion/include/private/svn_cache.h (original)
+++ subversion/trunk/subversion/include/private/svn_cache.h Sun Feb 12 17:42:20 2012
@@ -342,9 +342,9 @@ svn_cache__is_cachable(svn_cache__t *cac
 /**
  * Fetches a value indexed by @a key from @a cache into @a *value,
  * setting @a *found to TRUE iff it is in the cache and FALSE if it is
- * not found.  The value is copied into @a result_pool using the copy
+ * not found.  @a key may be NULL in which case @a *found will be
+ * FALSE.  The value is copied into @a result_pool using the deserialize
  * function provided to the cache's constructor.
- * ### what copy function? there are serialize/deserialize functions, no copy functions
  */
 svn_error_t *
 svn_cache__get(void **value,
@@ -357,7 +357,8 @@ svn_cache__get(void **value,
  * Stores the value @a value under the key @a key in @a cache.  Uses @a
  * scratch_pool for temporary allocations.  The cache makes copies of
  * @a key and @a value if necessary (that is, @a key and @a value may
- * have shorter lifetimes than the cache).
+ * have shorter lifetimes than the cache).  @a key may be NULL in which
+ * case the cache will remain unchanged.
  *
  * If there is already a value for @a key, this will replace it.  Bear
  * in mind that in some circumstances this may leak memory (that is,
@@ -401,8 +402,10 @@ svn_cache__iter(svn_boolean_t *completed
 /**
  * Similar to svn_cache__get() but will call a specific de-serialization
  * function @a func. @a found will be set depending on whether the @a key
- * has been found. Even if that reports @c TRUE, @a values may still return
- * a @c NULL pointer depending on the logic inside @a func.
+ * has been found. Even if that reports @c TRUE, @a value may still return
+ * a @c NULL pointer depending on the logic inside @a func.  For a @a NULL
+ * @a key, no data will be found.  @a value will be allocated in
+ * @a result_pool.
  */
 svn_error_t *
 svn_cache__get_partial(void **value,
@@ -417,8 +420,8 @@ svn_cache__get_partial(void **value,
  * Find the item identified by @a key in the @a cache. If it has been found,
  * call @a func for it and @a baton to potentially modify the data. Changed
  * data will be written back to the cache. If the item cannot be found,
- * @a func does not get called. @a scratch_pool is used for temporary
- * allocations.
+ * or if @a key is NULL, @a func does not get called. @a scratch_pool is
+ * used for temporary allocations.
  */
 svn_error_t *
 svn_cache__set_partial(svn_cache__t *cache,

Modified: subversion/trunk/subversion/libsvn_subr/cache-inprocess.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_subr/cache-inprocess.c?rev=1243283&r1=1243282&r2=1243283&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_subr/cache-inprocess.c (original)
+++ subversion/trunk/subversion/libsvn_subr/cache-inprocess.c Sun Feb 12 17:42:20 2012
@@ -213,15 +213,16 @@ inprocess_cache_get(void **value_p,
                     apr_pool_t *result_pool)
 {
   inprocess_cache_t *cache = cache_void;
-  char* buffer;
+  char* buffer = NULL;
   apr_size_t size;
 
-  SVN_MUTEX__WITH_LOCK(cache->mutex,
-                       inprocess_cache_get_internal(&buffer,
-                                                    &size,
-                                                    cache,
-                                                    key,
-                                                    result_pool));
+  if (key)
+    SVN_MUTEX__WITH_LOCK(cache->mutex,
+                         inprocess_cache_get_internal(&buffer,
+                                                      &size,
+                                                      cache,
+                                                      key,
+                                                      result_pool));
     
   /* deserialize the buffer content. Usually, this will directly
      modify the buffer content directly.
@@ -400,11 +401,12 @@ inprocess_cache_set(void *cache_void,
 {
   inprocess_cache_t *cache = cache_void;
 
-  SVN_MUTEX__WITH_LOCK(cache->mutex,
-                       inprocess_cache_set_internal(cache,
-                                                    key,
-                                                    value,
-                                                    scratch_pool));
+  if (key)
+    SVN_MUTEX__WITH_LOCK(cache->mutex,
+                         inprocess_cache_set_internal(cache,
+                                                      key,
+                                                      value,
+                                                      scratch_pool));
 
   return SVN_NO_ERROR;
 }
@@ -482,14 +484,17 @@ inprocess_cache_get_partial(void **value
 {
   inprocess_cache_t *cache = cache_void;
 
-  SVN_MUTEX__WITH_LOCK(cache->mutex,
-                       inprocess_cache_get_partial_internal(value_p,
-                                                            found,
-                                                            cache,
-                                                            key,
-                                                            func,
-                                                            baton,
-                                                            result_pool));
+  if (key)
+    SVN_MUTEX__WITH_LOCK(cache->mutex,
+                         inprocess_cache_get_partial_internal(value_p,
+                                                              found,
+                                                              cache,
+                                                              key,
+                                                              func,
+                                                              baton,
+                                                              result_pool));
+  else
+    *found = FALSE;
 
   return SVN_NO_ERROR;
 }
@@ -526,12 +531,13 @@ inprocess_cache_set_partial(void *cache_
 {
   inprocess_cache_t *cache = cache_void;
 
-  SVN_MUTEX__WITH_LOCK(cache->mutex,
-                       inprocess_cache_set_partial_internal(cache,
-                                                            key,
-                                                            func,
-                                                            baton,
-                                                            scratch_pool));
+  if (key)
+    SVN_MUTEX__WITH_LOCK(cache->mutex,
+                         inprocess_cache_set_partial_internal(cache,
+                                                              key,
+                                                              func,
+                                                              baton,
+                                                              scratch_pool));
 
   return SVN_NO_ERROR;
 }

Modified: subversion/trunk/subversion/libsvn_subr/cache-membuffer.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_subr/cache-membuffer.c?rev=1243283&r1=1243282&r2=1243283&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_subr/cache-membuffer.c (original)
+++ subversion/trunk/subversion/libsvn_subr/cache-membuffer.c Sun Feb 12 17:42:20 2012
@@ -589,6 +589,9 @@ get_group_index(svn_membuffer_t **cache,
   svn_checksum_t *checksum;
   svn_error_t *err;
 
+  if (key == NULL)
+    return NO_INDEX;
+  
   err = svn_checksum(&checksum, svn_checksum_md5, key, len, pool);
   if (err != NULL)
   {
@@ -1363,11 +1366,12 @@ membuffer_cache_get_partial(svn_membuffe
 
   group_index = get_group_index(&cache, key, key_len, to_find, result_pool);
 
-  SVN_MUTEX__WITH_LOCK(cache->mutex,
-                       membuffer_cache_get_partial_internal
-                           (cache, group_index, to_find, item, found,
-                            deserializer, baton, DEBUG_CACHE_MEMBUFFER_TAG
-                            result_pool));
+  if (group_index != NO_INDEX)
+    SVN_MUTEX__WITH_LOCK(cache->mutex,
+                         membuffer_cache_get_partial_internal
+                             (cache, group_index, to_find, item, found,
+                              deserializer, baton, DEBUG_CACHE_MEMBUFFER_TAG
+                              result_pool));
 
   return SVN_NO_ERROR;
 }
@@ -1499,11 +1503,12 @@ membuffer_cache_set_partial(svn_membuffe
    */
   group_index = get_group_index(&cache, key, key_len, to_find, scratch_pool);
 
-  SVN_MUTEX__WITH_LOCK(cache->mutex,
-                       membuffer_cache_set_partial_internal
-                           (cache, group_index, to_find, func, baton,
-                            DEBUG_CACHE_MEMBUFFER_TAG_ARG
-                            scratch_pool));
+  if (group_index != NO_INDEX)
+    SVN_MUTEX__WITH_LOCK(cache->mutex,
+                         membuffer_cache_set_partial_internal
+                             (cache, group_index, to_find, func, baton,
+                              DEBUG_CACHE_MEMBUFFER_TAG_ARG
+                              scratch_pool));
 
   /* done here -> unlock the cache
    */
@@ -1597,14 +1602,22 @@ combine_key(const void *prefix,
             apr_size_t *full_key_len,
             apr_pool_t *pool)
 {
-  if (key_len == APR_HASH_KEY_STRING)
-    key_len = strlen((const char *) key);
+  if (key == NULL)
+    {
+      *full_key = NULL;
+      *full_key_len = 0;
+    }
+  else
+    {
+      if (key_len == APR_HASH_KEY_STRING)
+        key_len = strlen((const char *) key);
 
-  *full_key_len = prefix_len + key_len;
-  *full_key = apr_palloc(pool, *full_key_len);
+      *full_key_len = prefix_len + key_len;
+      *full_key = apr_palloc(pool, *full_key_len);
 
-  memcpy(*full_key, prefix, prefix_len);
-  memcpy((char *)*full_key + prefix_len, key, key_len);
+      memcpy(*full_key, prefix, prefix_len);
+      memcpy((char *)*full_key + prefix_len, key, key_len);
+    }
 }
 
 /* Implement svn_cache__vtable_t.get (not thread-safe)

Modified: subversion/trunk/subversion/libsvn_subr/cache-memcache.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_subr/cache-memcache.c?rev=1243283&r1=1243282&r2=1243283&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_subr/cache-memcache.c (original)
+++ subversion/trunk/subversion/libsvn_subr/cache-memcache.c Sun Feb 12 17:42:20 2012
@@ -141,8 +141,15 @@ memcache_internal_get(char **data,
   memcache_t *cache = cache_void;
   apr_status_t apr_err;
   const char *mc_key;
-  apr_pool_t *subpool = svn_pool_create(pool);
+  apr_pool_t *subpool;
 
+  if (key == NULL)
+    {
+      *found = FALSE;
+      return SVN_NO_ERROR;
+    }
+  
+  subpool = svn_pool_create(pool);
   SVN_ERR(build_key(&mc_key, cache, key, subpool));
 
   apr_err = apr_memcache_getp(cache->memcache,
@@ -244,6 +251,9 @@ memcache_set(void *cache_void,
   apr_size_t data_len;
   svn_error_t *err;
 
+  if (key == NULL)
+    return SVN_NO_ERROR;
+  
   if (cache->serialize_func)
     {
       SVN_ERR((cache->serialize_func)(&data, &data_len, value, subpool));