]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/back-ldbm/cache.c
If dn2id returns ID but id2entry returns NULL, log it.
[openldap] / servers / slapd / back-ldbm / cache.c
index 819b1f2712cd7ea1e7bd65050bafc062c9998633..a9c31cc3eb68bff427e6c6193ef39255228d6610 100644 (file)
@@ -1,14 +1,19 @@
 /* cache.c - routines to maintain an in-core cache of entries */
 
+#include "portable.h"
+
 #include <stdio.h>
-#include <sys/types.h>
-#include <sys/socket.h>
+
+#include <ac/string.h>
+#include <ac/socket.h>
+
 #include "slap.h"
+
 #include "back-ldbm.h"
 
-static int     cache_delete_entry_internal();
+static int     cache_delete_entry_internal(struct cache *cache, Entry *e);
 #ifdef LDAP_DEBUG
-static void    lru_print();
+static void    lru_print(struct cache *cache);
 #endif
 
 /*
@@ -31,7 +36,8 @@ cache_entry_cmp( Entry *e1, Entry *e2 )
 static int
 cache_entrydn_cmp( Entry *e1, Entry *e2 )
 {
-       return( strcasecmp( e1->e_dn, e2->e_dn ) );
+       /* compare their normalized UPPERCASED dn's */
+       return( strcmp( e1->e_ndn, e2->e_ndn ) );
 }
 
 static int
@@ -136,7 +142,7 @@ cache_add_entry_lock(
                cache_entrydn_cmp, avl_dup_error ) != 0 )
        {
                Debug( LDAP_DEBUG_TRACE,
-                       "====> cache_add_entry lock: entry %20s id %d already in dn cache\n",
+                       "====> cache_add_entry lock: entry %20s id %lu already in dn cache\n",
                    e->e_dn, e->e_id, 0 );
 
                /* free cache mutex */
@@ -149,7 +155,7 @@ cache_add_entry_lock(
                cache_entryid_cmp, avl_dup_error ) != 0 )
        {
                Debug( LDAP_DEBUG_ANY,
-                       "====> entry %20s id %d already in id cache\n",
+                       "====> entry %20s id %lu already in id cache\n",
                    e->e_dn, e->e_id, 0 );
 
                /* delete from dn tree inserted above */
@@ -195,7 +201,9 @@ cache_add_entry_lock(
                        e = cache->c_lrutail;
 
                        /* XXX check for writer lock - should also check no readers pending */
-                       assert(pthread_rdwr_wchk_np(&e->e_rdwr));
+#ifdef LDAP_DEBUG
+                       assert(!pthread_rdwr_rwchk_np(&e->e_rdwr));
+#endif
 
                        /* delete from cache and lru q */
                        rc = cache_delete_entry_internal( cache, e );
@@ -228,10 +236,13 @@ cache_find_entry_dn2id(
        pthread_mutex_lock( &cache->c_mutex );
 
        e.e_dn = dn;
+       e.e_ndn = dn_normalize_case( ch_strdup( dn ) );
 
        if ( (ep = (Entry *) avl_find( cache->c_dntree, (caddr_t) &e,
                cache_entrydn_cmp )) != NULL )
        {
+               free(e.e_ndn);
+
                Debug(LDAP_DEBUG_TRACE, "====> cache_find_entry_dn2id: found dn: %s\n",
                        dn, 0, 0);
 
@@ -285,6 +296,8 @@ cache_find_entry_dn2id(
                return( id );
        }
 
+       free(e.e_ndn);
+
        /* free cache mutex */
        pthread_mutex_unlock( &cache->c_mutex );
 
@@ -391,7 +404,9 @@ cache_delete_entry(
        Debug( LDAP_DEBUG_TRACE, "====> cache_delete_entry:\n", 0, 0, 0 );
 
        /* XXX check for writer lock - should also check no readers pending */
+#ifdef LDAP_DEBUG
        assert(pthread_rdwr_wchk_np(&e->e_rdwr));
+#endif
 
        /* set cache mutex */
        pthread_mutex_lock( &cache->c_mutex );
@@ -409,18 +424,24 @@ cache_delete_entry_internal(
     Entry              *e
 )
 {
+       int rc = 0;     /* return code */
+
        /* dn tree */
        if ( avl_delete( &cache->c_dntree, (caddr_t) e, cache_entrydn_cmp )
                == NULL )
        {
-               return( -1 );
+               rc = -1;
        }
 
        /* id tree */
        if ( avl_delete( &cache->c_idtree, (caddr_t) e, cache_entryid_cmp )
                == NULL )
        {
-               return( -1 );
+               rc = -1;
+       }
+
+       if (rc != 0) {
+               return rc;
        }
 
        /* lru */
@@ -444,12 +465,12 @@ lru_print( struct cache *cache )
 
        fprintf( stderr, "LRU queue (head to tail):\n" );
        for ( e = cache->c_lruhead; e != NULL; e = e->e_lrunext ) {
-               fprintf( stderr, "\tdn %20s id %d refcnt %d\n", e->e_dn,
+               fprintf( stderr, "\tdn %20s id %lu refcnt %d\n", e->e_dn,
                    e->e_id, e->e_refcnt );
        }
        fprintf( stderr, "LRU queue (tail to head):\n" );
        for ( e = cache->c_lrutail; e != NULL; e = e->e_lruprev ) {
-               fprintf( stderr, "\tdn %20s id %d refcnt %d\n", e->e_dn,
+               fprintf( stderr, "\tdn %20s id %lu refcnt %d\n", e->e_dn,
                    e->e_id, e->e_refcnt );
        }
 }