/* 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
/*
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
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 */
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 */
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 );
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);
return( id );
}
+ free(e.e_ndn);
+
/* free cache mutex */
pthread_mutex_unlock( &cache->c_mutex );
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 );
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 */
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 );
}
}