[Fedora-directory-commits] ldapserver/ldap/servers/slapd/back-ldbm back-ldbm.h, 1.18, 1.19 cache.c, 1.6, 1.7

Nathan Kinder nkinder at fedoraproject.org
Fri Oct 24 22:37:01 UTC 2008


Author: nkinder

Update of /cvs/dirsec/ldapserver/ldap/servers/slapd/back-ldbm
In directory cvs1.fedora.phx.redhat.com:/tmp/cvs-serv9308/ldap/servers/slapd/back-ldbm

Modified Files:
	back-ldbm.h cache.c 
Log Message:
Resolves: 207457
Summary: Convert counters to 64-bit capable Slapi_Counter type.



Index: back-ldbm.h
===================================================================
RCS file: /cvs/dirsec/ldapserver/ldap/servers/slapd/back-ldbm/back-ldbm.h,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -r1.18 -r1.19
--- back-ldbm.h	17 Oct 2008 22:12:48 -0000	1.18
+++ back-ldbm.h	24 Oct 2008 22:36:59 -0000	1.19
@@ -339,7 +339,7 @@
 /* for the in-core cache of entries */
 struct cache {
     size_t c_maxsize;		/* max size in bytes */
-    size_t c_cursize;		/* size in bytes */
+    Slapi_Counter *c_cursize;		/* size in bytes */
     long c_maxentries;		/* max entries allowed (-1: no limit) */
     long c_curentries;		/* current # entries in cache */
     Hashtable *c_dntable;
@@ -347,8 +347,8 @@
 #ifdef UUIDCACHE_ON 
     Hashtable *c_uuidtable;
 #endif
-    u_long c_hits;		/* for analysis of hits/misses */
-    u_long c_tries;
+    Slapi_Counter *c_hits;		/* for analysis of hits/misses */
+    Slapi_Counter *c_tries;
     struct backentry *c_lruhead;	/* add entries here */
     struct backentry *c_lrutail;	/* remove entries here */
     PRLock *c_mutex;			/* lock for cache operations */


Index: cache.c
===================================================================
RCS file: /cvs/dirsec/ldapserver/ldap/servers/slapd/back-ldbm/cache.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- cache.c	15 Oct 2008 06:30:06 -0000	1.6
+++ cache.c	24 Oct 2008 22:36:59 -0000	1.7
@@ -405,8 +405,15 @@
     LDAPDebug(LDAP_DEBUG_TRACE, "=> cache_init\n", 0, 0, 0);
     cache->c_maxsize = maxsize;
     cache->c_maxentries = maxentries;
-    cache->c_cursize = cache->c_curentries = 0;
-    cache->c_hits = cache->c_tries = 0;
+    cache->c_cursize = slapi_counter_new();
+    cache->c_curentries = 0;
+    if (config_get_slapi_counters()) {
+        cache->c_hits = slapi_counter_new();
+        cache->c_tries = slapi_counter_new();
+    } else {
+        cache->c_hits = NULL;
+        cache->c_tries = NULL;
+    }
     cache->c_lruhead = cache->c_lrutail = NULL;
     cache_make_hashes(cache);
 
@@ -421,7 +428,7 @@
 }
 
 #define  CACHE_FULL(cache) \
-       (((cache)->c_cursize > (cache)->c_maxsize) || \
+       ((slapi_counter_get_value((cache)->c_cursize) > (cache)->c_maxsize) || \
         (((cache)->c_maxentries > 0) && \
          ((cache)->c_curentries > (cache)->c_maxentries)))
 
@@ -466,7 +473,7 @@
     if (e)
         lru_detach(cache, e);
     LOG("<= cache_flush (down to %lu entries, %lu bytes)\n", cache->c_curentries,
-        cache->c_cursize, 0);
+        slapi_counter_get_value(cache->c_cursize), 0);
     return e;
 }
 
@@ -623,16 +630,16 @@
  * if it ever wants to pull out more info, we might want to change all
  * these u_long *'s to a struct
  */
-void cache_get_stats(struct cache *cache, u_long *hits, u_long *tries,
+void cache_get_stats(struct cache *cache, PRUint64 *hits, PRUint64 *tries,
                      long *nentries, long *maxentries,
                      size_t *size, size_t *maxsize)
 {
     PR_Lock(cache->c_mutex);
-    if (hits) *hits = cache->c_hits;
-    if (tries) *tries = cache->c_tries;
+    if (hits) *hits = slapi_counter_get_value(cache->c_hits);
+    if (tries) *tries = slapi_counter_get_value(cache->c_tries);
     if (nentries) *nentries = cache->c_curentries;
     if (maxentries) *maxentries = cache->c_maxentries;
-    if (size) *size = cache->c_cursize;
+    if (size) *size = slapi_counter_get_value(cache->c_cursize);
     if (maxsize) *maxsize = cache->c_maxsize;
     PR_Unlock(cache->c_mutex);
 }
@@ -735,10 +742,11 @@
     if (ret == 0) {
         /* won't be on the LRU list since it has a refcount on it */
         /* adjust cache size */
-        cache->c_cursize -= e->size;
+        slapi_counter_subtract(cache->c_cursize, e->size);
         cache->c_curentries--;
         LOG("<= cache_remove (size %lu): cache now %lu entries, %lu bytes\n",
-            e->size, cache->c_curentries, cache->c_cursize);
+            e->size, cache->c_curentries,
+            slapi_counter_get_value(cache->c_cursize));
     }
 
     /* mark for deletion (will be erased when refcount drops to zero) */
@@ -775,7 +783,7 @@
 int cache_replace(struct cache *cache, struct backentry *olde,
                 struct backentry *newe)
 {
-	int found;
+    int found;
     const char *oldndn;
     const char *newndn;
 #ifdef UUIDCACHE_ON 
@@ -799,31 +807,31 @@
     PR_Lock(cache->c_mutex);
 
     /*
-	 * First, remove the old entry from all the hashtables.
-	 * If the old entry is in cache but not in at least one of the
-	 * cache tables, operation error 
-	 */
-	if ( (olde->ep_state & ENTRY_STATE_NOTINCACHE) == 0 ) {
+     * First, remove the old entry from all the hashtables.
+     * If the old entry is in cache but not in at least one of the
+     * cache tables, operation error 
+     */
+    if ( (olde->ep_state & ENTRY_STATE_NOTINCACHE) == 0 ) {
 
-		found = remove_hash(cache->c_dntable, (void *)oldndn, strlen(oldndn));
-		found &= remove_hash(cache->c_idtable, &(olde->ep_id), sizeof(ID));
+        found = remove_hash(cache->c_dntable, (void *)oldndn, strlen(oldndn));
+        found &= remove_hash(cache->c_idtable, &(olde->ep_id), sizeof(ID));
 #ifdef UUIDCACHE_ON
-		found &= remove_hash(cache->c_uuidtable, (void *)olduuid, strlen(olduuid));
+        found &= remove_hash(cache->c_uuidtable, (void *)olduuid, strlen(olduuid));
 #endif
-		if (!found) {
-			LOG("cache replace: cache index tables out of sync\n", 0, 0, 0);
-			PR_Unlock(cache->c_mutex);
-			return 1;
-		}
-	}
+        if (!found) {
+            LOG("cache replace: cache index tables out of sync\n", 0, 0, 0);
+            PR_Unlock(cache->c_mutex);
+            return 1;
+        }
+    }
     if (! entry_same_dn(newe, (void *)oldndn) &&
-		 (newe->ep_state & ENTRY_STATE_NOTINCACHE) == 0) {
+         (newe->ep_state & ENTRY_STATE_NOTINCACHE) == 0) {
         /* if we're doing a modrdn, the new entry can be in the dn table
          * already, so we need to remove that too.
          */
         if (remove_hash(cache->c_dntable, (void *)newndn, strlen(newndn)))
         {
-            cache->c_cursize -= newe->size;
+            slapi_counter_subtract(cache->c_cursize, newe->size);
             cache->c_curentries--;
             LOG("cache replace remove entry size %lu\n", newe->size, 0, 0);
         }
@@ -857,12 +865,12 @@
     /* adjust cache meta info */
     newe->ep_refcnt = 1;
     newe->size = cache_entry_size(newe);
-    cache->c_cursize += (newe->size - olde->size);
+    slapi_counter_add(cache->c_cursize, newe->size - olde->size);
     olde->ep_state = ENTRY_STATE_DELETED;
     newe->ep_state = 0;
     PR_Unlock(cache->c_mutex);
     LOG("<= cache_replace OK,  cache size now %lu cache count now %ld\n",
-               cache->c_cursize, cache->c_curentries, 0);
+             slapi_counter_get_value(cache->c_cursize), cache->c_curentries, 0);
     return 0;
 }
 
@@ -930,11 +938,13 @@
        }
        if (e->ep_refcnt == 0)
            lru_delete(cache, e);
+       PR_Unlock(cache->c_mutex);
        e->ep_refcnt++;
-       cache->c_hits++;
+       slapi_counter_increment(cache->c_hits);
+    } else {
+       PR_Unlock(cache->c_mutex);
     }
-    cache->c_tries++;
-    PR_Unlock(cache->c_mutex);
+    slapi_counter_increment(cache->c_tries);
 
     LOG("<= cache_find_dn (%sFOUND)\n", e ? "" : "NOT ", 0, 0);
     return e;
@@ -959,11 +969,13 @@
        }
        if (e->ep_refcnt == 0)
            lru_delete(cache, e);
+       PR_Unlock(cache->c_mutex);
        e->ep_refcnt++;
-       cache->c_hits++;
+       slapi_counter_increment(cache->c_hits);
+    } else {
+       PR_Unlock(cache->c_mutex);
     }
-    cache->c_tries++;
-    PR_Unlock(cache->c_mutex);
+    slapi_counter_increment(cache->c_tries);
 
     LOG("<= cache_find_id (%sFOUND)\n", e ? "" : "NOT ", 0, 0);
     return e;
@@ -988,11 +1000,13 @@
        }
        if (e->ep_refcnt == 0)
            lru_delete(cache, e);
+       PR_Unlock(cache->c_mutex);
        e->ep_refcnt++;
-       cache->c_hits++;
+       slapi_counter_increment(cache->c_hits);
+    } else {
+       PR_Unlock(cache->c_mutex);
     }
-    cache->c_tries++;
-    PR_Unlock(cache->c_mutex);
+    slapi_counter_increment(cache->c_tries);
 
     LOG("<= cache_find_uuid (%sFOUND)\n", e ? "" : "NOT ", 0, 0);
     return e;
@@ -1126,7 +1140,7 @@
                             0, 0);
                 remove_hash(cache->c_dntable, (void *)ndn, strlen(ndn));
                 remove_hash(cache->c_idtable, &(e->ep_id), sizeof(ID));
-            	e->ep_state |= ENTRY_STATE_NOTINCACHE;
+                e->ep_state |= ENTRY_STATE_NOTINCACHE;
                 PR_Unlock(cache->c_mutex);
                 return -1;
             }
@@ -1140,11 +1154,11 @@
         e->ep_refcnt = 1;
         e->size = cache_entry_size(e);
     
-        cache->c_cursize += e->size;
+        slapi_counter_add(cache->c_cursize, e->size);
         cache->c_curentries++;
         /* don't add to lru since refcnt = 1 */
         LOG("added entry of size %lu -> total now %lu out of max %lu\n",
-                e->size, cache->c_cursize, cache->c_maxsize);
+          e->size, slapi_counter_get_value(cache->c_cursize), cache->c_maxsize);
         if (cache->c_maxentries >= 0) {
             LOG("    total entries %ld out of %ld\n",
                     cache->c_curentries, cache->c_maxentries, 0);




More information about the Fedora-directory-commits mailing list