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 2013/02/04 10:16:58 UTC

svn commit: r1442051 - in /subversion/branches/fsfs-format7/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: Mon Feb  4 09:16:58 2013
New Revision: 1442051

URL: http://svn.apache.org/viewvc?rev=1442051&view=rev
Log:
On the fsfs-format7 branch:  Add svn_cache__has_key() function
to our cache API.  Semantically, it is a stripped-down version
of svn_cache__get() but without actually copying and returning
any data.

* subversion/include/private/svn_cache.h
  (svn_cache__has_key): declare new API function

* cache.h
  (svn_cache__vtable_t): add has_key entry to cache vtable
* cache.c
  (svn_cache__has_key): implement new API function as forwarding
   to the actual cache implementation

* cache-inprocess.c
  (inprocess_cache_has_key_internal,
   inprocess_cache_has_key): implement has_key for in-process caches
  (inprocess_cache_vtable): update its vtable

* cache-memcache.c
  (memcache_has_key): implement has_key for memcached caches
  (memcache_vtable): update its vtable

* cache-membuffer.c
  (membuffer_cache_has_key_internal,
   membuffer_cache_has_key): implemente the has_key core functionality
  (svn_membuffer_cache_has_key,
   svn_membuffer_cache_has_key_synced): implement vtable functions
  (membuffer_cache_vtable,
   membuffer_cache_synced_vtable): update vtables

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

Modified: subversion/branches/fsfs-format7/subversion/include/private/svn_cache.h
URL: http://svn.apache.org/viewvc/subversion/branches/fsfs-format7/subversion/include/private/svn_cache.h?rev=1442051&r1=1442050&r2=1442051&view=diff
==============================================================================
--- subversion/branches/fsfs-format7/subversion/include/private/svn_cache.h (original)
+++ subversion/branches/fsfs-format7/subversion/include/private/svn_cache.h Mon Feb  4 09:16:58 2013
@@ -371,6 +371,18 @@ svn_cache__get(void **value,
                apr_pool_t *result_pool);
 
 /**
+ * Looks for an entry indexed by @a key in @a cache,  setting @a *found
+ * to TRUE if an entry has been found and FALSE otherwise.  @a key may be
+ * NULL in which case @a *found will be FALSE.  Temporary allocations will
+ * be made from @a scratch_pool.
+ */
+svn_error_t *
+svn_cache__has_key(svn_boolean_t *found,
+                   svn_cache__t *cache,
+                   const void *key,
+                   apr_pool_t *scratch_pool);
+
+/**
  * 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

Modified: subversion/branches/fsfs-format7/subversion/libsvn_subr/cache-inprocess.c
URL: http://svn.apache.org/viewvc/subversion/branches/fsfs-format7/subversion/libsvn_subr/cache-inprocess.c?rev=1442051&r1=1442050&r2=1442051&view=diff
==============================================================================
--- subversion/branches/fsfs-format7/subversion/libsvn_subr/cache-inprocess.c (original)
+++ subversion/branches/fsfs-format7/subversion/libsvn_subr/cache-inprocess.c Mon Feb  4 09:16:58 2013
@@ -234,6 +234,37 @@ inprocess_cache_get(void **value_p,
     : SVN_NO_ERROR;
 }
 
+static svn_error_t *
+inprocess_cache_has_key_internal(svn_boolean_t *found,
+                                 inprocess_cache_t *cache,
+                                 const void *key,
+                                 apr_pool_t *scratch_pool)
+{
+  *found = apr_hash_get(cache->hash, key, cache->klen) != NULL;
+
+  return SVN_NO_ERROR;
+}
+
+static svn_error_t *
+inprocess_cache_has_key(svn_boolean_t *found,
+                        void *cache_void,
+                        const void *key,
+                        apr_pool_t *scratch_pool)
+{
+  inprocess_cache_t *cache = cache_void;
+
+  if (key)
+    SVN_MUTEX__WITH_LOCK(cache->mutex,
+                         inprocess_cache_has_key_internal(found,
+                                                          cache,
+                                                          key,
+                                                          scratch_pool));
+  else
+    *found = FALSE;
+
+  return SVN_NO_ERROR;
+}
+
 /* Removes PAGE from the LRU list, removes all of its entries from
  * CACHE's hash, clears its pool, and sets its entry pointer to NULL.
  * Finally, puts it in the "partial page" slot in the cache and sets
@@ -592,6 +623,7 @@ inprocess_cache_get_info(void *cache_voi
 
 static svn_cache__vtable_t inprocess_cache_vtable = {
   inprocess_cache_get,
+  inprocess_cache_has_key,
   inprocess_cache_set,
   inprocess_cache_iter,
   inprocess_cache_is_cachable,

Modified: subversion/branches/fsfs-format7/subversion/libsvn_subr/cache-membuffer.c
URL: http://svn.apache.org/viewvc/subversion/branches/fsfs-format7/subversion/libsvn_subr/cache-membuffer.c?rev=1442051&r1=1442050&r2=1442051&view=diff
==============================================================================
--- subversion/branches/fsfs-format7/subversion/libsvn_subr/cache-membuffer.c (original)
+++ subversion/branches/fsfs-format7/subversion/libsvn_subr/cache-membuffer.c Mon Feb  4 09:16:58 2013
@@ -1587,6 +1587,43 @@ membuffer_cache_get(svn_membuffer_t *cac
 }
 
 /* Look for the cache entry in group GROUP_INDEX of CACHE, identified
+ * by the hash value TO_FIND.  If no item has been stored for KEY, *FOUND
+ * will be FALSE and TRUE otherwise.
+ */
+static svn_error_t *
+membuffer_cache_has_key_internal(svn_membuffer_t *cache,
+                                 apr_uint32_t group_index,
+                                 entry_key_t to_find,
+                                 svn_boolean_t *found)
+{
+  *found = find_entry(cache, group_index, to_find, FALSE) != NULL;
+
+  return SVN_NO_ERROR;
+}
+
+/* Look for an entry identified by KEY.  If no item has been stored
+ * for KEY, *FOUND will be set to FALSE and TRUE otherwise.
+ */
+/* Implements svn_cache__has_key for membuffer caches.
+ */
+static svn_error_t *
+membuffer_cache_has_key(svn_membuffer_t *cache,
+                        entry_key_t key,
+                        svn_boolean_t *found)
+{
+  /* find the entry group that will hold the key.
+   */
+  apr_uint32_t group_index = get_group_index(&cache, key);
+  WITH_READ_LOCK(cache,
+                 membuffer_cache_has_key_internal(cache,
+                                                  group_index,
+                                                  key,
+                                                  found));
+
+  return SVN_NO_ERROR;
+}
+
+/* Look for the cache entry in group GROUP_INDEX of CACHE, identified
  * by the hash value TO_FIND. FOUND indicates whether that entry exists.
  * If not found, *ITEM will be NULL.
  *
@@ -1979,6 +2016,37 @@ svn_membuffer_cache_get(void **value_p,
 
   /* return result */
   *found = *value_p != NULL;
+}
+
+/* Implement svn_cache__vtable_t.has_key (not thread-safe)
+ */
+static svn_error_t *
+svn_membuffer_cache_has_key(svn_boolean_t *found,
+                            void *cache_void,
+                            const void *key,
+                            apr_pool_t *scratch_pool)
+{
+  svn_membuffer_cache_t *cache = cache_void;
+
+  /* special case */
+  if (key == NULL)
+    {
+      *found = FALSE;
+
+      return SVN_NO_ERROR;
+    }
+
+  /* construct the full, i.e. globally unique, key by adding
+   * this cache instances' prefix
+   */
+  combine_key(cache, key, cache->key_len);
+
+  /* Look the item up. */
+  SVN_ERR(membuffer_cache_has_key(cache->membuffer,
+                                  cache->combined_key,
+                                  found));
+
+  /* return result */
   return SVN_NO_ERROR;
 }
 
@@ -2176,6 +2244,7 @@ svn_membuffer_cache_get_info(void *cache
  */
 static svn_cache__vtable_t membuffer_cache_vtable = {
   svn_membuffer_cache_get,
+  svn_membuffer_cache_has_key,
   svn_membuffer_cache_set,
   svn_membuffer_cache_iter,
   svn_membuffer_cache_is_cachable,
@@ -2204,6 +2273,24 @@ svn_membuffer_cache_get_synced(void **va
   return SVN_NO_ERROR;
 }
 
+/* Implement svn_cache__vtable_t.has_key and serialize all cache access.
+ */
+static svn_error_t *
+svn_membuffer_cache_has_key_synced(svn_boolean_t *found,
+                                   void *cache_void,
+                                   const void *key,
+                                   apr_pool_t *result_pool)
+{
+  svn_membuffer_cache_t *cache = cache_void;
+  SVN_MUTEX__WITH_LOCK(cache->mutex,
+                       svn_membuffer_cache_has_key(found,
+                                                   cache_void,
+                                                   key,
+                                                   result_pool));
+
+  return SVN_NO_ERROR;
+}
+
 /* Implement svn_cache__vtable_t.set and serialize all cache access.
  */
 static svn_error_t *
@@ -2270,6 +2357,7 @@ svn_membuffer_cache_set_partial_synced(v
  */
 static svn_cache__vtable_t membuffer_cache_synced_vtable = {
   svn_membuffer_cache_get_synced,
+  svn_membuffer_cache_has_key_synced,
   svn_membuffer_cache_set_synced,
   svn_membuffer_cache_iter,               /* no sync required */
   svn_membuffer_cache_is_cachable,        /* no sync required */

Modified: subversion/branches/fsfs-format7/subversion/libsvn_subr/cache-memcache.c
URL: http://svn.apache.org/viewvc/subversion/branches/fsfs-format7/subversion/libsvn_subr/cache-memcache.c?rev=1442051&r1=1442050&r2=1442051&view=diff
==============================================================================
--- subversion/branches/fsfs-format7/subversion/libsvn_subr/cache-memcache.c (original)
+++ subversion/branches/fsfs-format7/subversion/libsvn_subr/cache-memcache.c Mon Feb  4 09:16:58 2013
@@ -213,6 +213,26 @@ memcache_get(void **value_p,
   return SVN_NO_ERROR;
 }
 
+/* Implement vtable.has_key in terms of the getter.
+ */
+static svn_error_t *
+memcache_has_key(svn_boolean_t *found,
+                 void *cache_void,
+                 const void *key,
+                 apr_pool_t *scratch_pool)
+{
+  char *data;
+  apr_size_t data_len;
+  SVN_ERR(memcache_internal_get(&data,
+                                &data_len,
+                                found,
+                                cache_void,
+                                key,
+                                scratch_pool));
+
+  return SVN_NO_ERROR;
+}
+
 /* Core functionality of our setter functions: store LENGH bytes of DATA
  * to be identified by KEY in the memcached given by CACHE_VOID. Use POOL
  * for temporary allocations.
@@ -377,6 +397,7 @@ memcache_get_info(void *cache_void,
 
 static svn_cache__vtable_t memcache_vtable = {
   memcache_get,
+  memcache_has_key,
   memcache_set,
   memcache_iter,
   memcache_is_cachable,

Modified: subversion/branches/fsfs-format7/subversion/libsvn_subr/cache.c
URL: http://svn.apache.org/viewvc/subversion/branches/fsfs-format7/subversion/libsvn_subr/cache.c?rev=1442051&r1=1442050&r2=1442051&view=diff
==============================================================================
--- subversion/branches/fsfs-format7/subversion/libsvn_subr/cache.c (original)
+++ subversion/branches/fsfs-format7/subversion/libsvn_subr/cache.c Mon Feb  4 09:16:58 2013
@@ -92,6 +92,21 @@ svn_cache__get(void **value_p,
 }
 
 svn_error_t *
+svn_cache__has_key(svn_boolean_t *found,
+                   svn_cache__t *cache,
+                   const void *key,
+                   apr_pool_t *scratch_pool)
+{
+  *found = FALSE;
+  return handle_error(cache,
+                      (cache->vtable->has_key)(found,
+                                               cache->cache_internal,
+                                               key,
+                                               scratch_pool),
+                      scratch_pool);
+}
+
+svn_error_t *
 svn_cache__set(svn_cache__t *cache,
                const void *key,
                void *value,

Modified: subversion/branches/fsfs-format7/subversion/libsvn_subr/cache.h
URL: http://svn.apache.org/viewvc/subversion/branches/fsfs-format7/subversion/libsvn_subr/cache.h?rev=1442051&r1=1442050&r2=1442051&view=diff
==============================================================================
--- subversion/branches/fsfs-format7/subversion/libsvn_subr/cache.h (original)
+++ subversion/branches/fsfs-format7/subversion/libsvn_subr/cache.h Mon Feb  4 09:16:58 2013
@@ -38,6 +38,12 @@ typedef struct svn_cache__vtable_t {
                       const void *key,
                       apr_pool_t *result_pool);
 
+  /* See svn_cache__has_key(). */
+  svn_error_t *(*has_key)(svn_boolean_t *found,
+                          void *cache_implementation,
+                          const void *key,
+                          apr_pool_t *scratch_pool);
+
   /* See svn_cache__set(). */
   svn_error_t *(*set)(void *cache_implementation,
                       const void *key,