From: Kurt Zeilenga Date: Thu, 11 Feb 1999 17:46:56 +0000 (+0000) Subject: Update LDBM cache so that it manages it's own state. X-Git-Tag: OPENLDAP_SLAPD_BACK_LDAP~597 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=745a10f080251e46808535dcdd9ad80d9c76146e;p=openldap Update LDBM cache so that it manages it's own state. cache_set_state() and state args are no history. Move cache_entry_cmp() and friends to slapd/entry.c to allow sharing of functions between backends.. Renamed to entry_cmp(). --- diff --git a/servers/slapd/back-bdb2/cache.c b/servers/slapd/back-bdb2/cache.c index e7ec725721..8c95392d28 100644 --- a/servers/slapd/back-bdb2/cache.c +++ b/servers/slapd/back-bdb2/cache.c @@ -27,25 +27,9 @@ static void lru_print(struct cache *cache); * * these correspond to three different avl trees that are maintained. */ - -static int -cache_entry_cmp( Entry *e1, Entry *e2 ) -{ - return( e1 < e2 ? -1 : (e1 > e2 ? 1 : 0) ); -} - -static int -cache_entrydn_cmp( Entry *e1, Entry *e2 ) -{ - /* compare their normalized UPPERCASED dn's */ - return( strcmp( e1->e_ndn, e2->e_ndn ) ); -} - -static int -cache_entryid_cmp( Entry *e1, Entry *e2 ) -{ - return( e1->e_id < e2->e_id ? -1 : (e1->e_id > e2->e_id ? 1 : 0) ); -} +#define cache_entry_cmp entry_cmp +#define cache_entrydn_cmp entry_dn_cmp +#define cache_entryid_cmp entry_id_cmp void bdb2i_cache_set_state( struct cache *cache, Entry *e, int state ) diff --git a/servers/slapd/back-ldbm/add.c b/servers/slapd/back-ldbm/add.c index b99ade9cf5..4b929987ae 100644 --- a/servers/slapd/back-ldbm/add.c +++ b/servers/slapd/back-ldbm/add.c @@ -126,7 +126,7 @@ ldbm_back_add( /* * Try to add the entry to the cache, assign it a new dnid. */ - rc = cache_add_entry_rw(&li->li_cache, e, ENTRY_STATE_CREATING, 1); + rc = cache_add_entry_rw(&li->li_cache, e, CACHE_WRITE_LOCK); if ( rc != 0 ) { if( p != NULL) { @@ -218,8 +218,6 @@ return_results:; ldap_pvt_thread_mutex_unlock(&li->li_root_mutex); } - cache_set_state( &li->li_cache, e, 0 ); - /* free entry and writer lock */ cache_return_entry_w( &li->li_cache, e ); diff --git a/servers/slapd/back-ldbm/back-ldbm.h b/servers/slapd/back-ldbm/back-ldbm.h index 9b98c02cb0..417027f3cc 100644 --- a/servers/slapd/back-ldbm/back-ldbm.h +++ b/servers/slapd/back-ldbm/back-ldbm.h @@ -79,8 +79,8 @@ struct cache { ldap_pvt_thread_mutex_t c_mutex; }; -#define ENTRY_STATE_DELETED 1 -#define ENTRY_STATE_CREATING 2 +#define CACHE_READ_LOCK 0 +#define CACHE_WRITE_LOCK 1 /* for the cache of open index files */ struct dbcache { diff --git a/servers/slapd/back-ldbm/cache.c b/servers/slapd/back-ldbm/cache.c index 0a2b3c97b1..a1877e0738 100644 --- a/servers/slapd/back-ldbm/cache.c +++ b/servers/slapd/back-ldbm/cache.c @@ -22,6 +22,10 @@ struct ldbm_entry_info { * be hidden. */ int lei_state; /* for the cache */ +#define CACHE_ENTRY_UNDEFINED 0 +#define CACHE_ENTRY_CREATING 1 +#define CACHE_ENTRY_READY 2 +#define CACHE_ENTRY_DELETED 3 int lei_refcnt; /* # threads ref'ing this entry */ struct entry *lei_lrunext; /* for cache lru list */ @@ -44,42 +48,14 @@ static void lru_print(struct cache *cache); * * these correspond to three different avl trees that are maintained. */ - -static int -cache_entry_cmp( Entry *e1, Entry *e2 ) -{ - return( e1 < e2 ? -1 : (e1 > e2 ? 1 : 0) ); -} - -static int -cache_entrydn_cmp( Entry *e1, Entry *e2 ) -{ - /* compare their normalized UPPERCASED dn's */ - return( strcmp( e1->e_ndn, e2->e_ndn ) ); -} - -static int -cache_entryid_cmp( Entry *e1, Entry *e2 ) -{ - return( e1->e_id < e2->e_id ? -1 : (e1->e_id > e2->e_id ? 1 : 0) ); -} - -void -cache_set_state( struct cache *cache, Entry *e, int state ) -{ - /* set cache mutex */ - ldap_pvt_thread_mutex_lock( &cache->c_mutex ); - - LEI(e)->lei_state = state; - - /* free cache mutex */ - ldap_pvt_thread_mutex_unlock( &cache->c_mutex ); -} +#define cache_entry_cmp entry_cmp +#define cache_entrydn_cmp entry_dn_cmp +#define cache_entryid_cmp entry_id_cmp static int cache_entry_rdwr_lock(Entry *e, int rw) { - Debug( LDAP_DEBUG_ARGS, "entry_rdwr_%slock: ID: %ld\n", + Debug( LDAP_DEBUG_ARGS, "entry_rdwr_%slock: ID: %lu\n", rw ? "w" : "r", e->e_id, 0); if (rw) @@ -91,7 +67,7 @@ cache_entry_rdwr_lock(Entry *e, int rw) static int cache_entry_rdwr_trylock(Entry *e, int rw) { - Debug( LDAP_DEBUG_ARGS, "entry_rdwr_%strylock: ID: %ld\n", + Debug( LDAP_DEBUG_ARGS, "entry_rdwr_%strylock: ID: %lu\n", rw ? "w" : "r", e->e_id, 0); if (rw) @@ -103,7 +79,7 @@ cache_entry_rdwr_trylock(Entry *e, int rw) static int cache_entry_rdwr_unlock(Entry *e, int rw) { - Debug( LDAP_DEBUG_ARGS, "entry_rdwr_%sunlock: ID: %ld\n", + Debug( LDAP_DEBUG_ARGS, "entry_rdwr_%sunlock: ID: %lu\n", rw ? "w" : "r", e->e_id, 0); if (rw) @@ -129,7 +105,12 @@ cache_entry_private_init( Entry*e ) { struct ldbm_entry_info *lei; +#ifdef LDAP_DEBUG + assert( e->e_private == NULL ); +#endif + if( e->e_private != NULL ) { + /* this should never happen */ return 1; } @@ -137,6 +118,7 @@ cache_entry_private_init( Entry*e ) if( cache_entry_rdwr_init( e ) != 0 ) { free( LEI(e) ); + e->e_private = NULL; return 1; } @@ -148,9 +130,9 @@ cache_entry_private_destroy( Entry*e ) { struct ldbm_entry_info *lei; - if( e->e_private == NULL ) { - return 1; - } +#ifdef LDAP_DEBUG + assert( e->e_private ); +#endif cache_entry_rdwr_destroy( e ); @@ -159,41 +141,53 @@ cache_entry_private_destroy( Entry*e ) return 0; } -static void +void cache_return_entry_rw( struct cache *cache, Entry *e, int rw ) { - Debug( LDAP_DEBUG_TRACE, "====> cache_return_entry_%s\n", - rw ? "w" : "r", 0, 0); - /* set cache mutex */ ldap_pvt_thread_mutex_lock( &cache->c_mutex ); +#ifdef LDAP_DEBUG + assert( e->e_private ); +#endif + cache_entry_rdwr_unlock(e, rw); - if ( --LEI(e)->lei_refcnt == 0 && - LEI(e)->lei_state == ENTRY_STATE_DELETED ) - { - cache_entry_private_destroy( e ); - entry_free( e ); + LEI(e)->lei_refcnt--; + + if ( LEI(e)->lei_state == CACHE_ENTRY_CREATING ) { + Debug( LDAP_DEBUG_TRACE, + "====> cache_return_entry_%s( %lu ): created (%d)\n", + rw ? "w" : "r", e->e_id, LEI(e)->lei_refcnt ); + + LEI(e)->lei_state = CACHE_ENTRY_READY; + + } else if ( LEI(e)->lei_state == CACHE_ENTRY_DELETED ) { + if( LEI(e)->lei_refcnt > 0 ) { + Debug( LDAP_DEBUG_TRACE, + "====> cache_return_entry_%s( %lu ): delete pending (%d)\n", + rw ? "w" : "r", e->e_id, LEI(e)->lei_refcnt ); + + } else { + Debug( LDAP_DEBUG_TRACE, + "====> cache_return_entry_%s( %lu ): deleted (%d)\n", + rw ? "w" : "r", e->e_id, LEI(e)->lei_refcnt ); + + cache_entry_private_destroy( e ); + entry_free( e ); + } + + } else { + Debug( LDAP_DEBUG_TRACE, + "====> cache_return_entry_%s( %lu ): returned (%d)\n", + rw ? "w" : "r", e->e_id, LEI(e)->lei_refcnt); } + /* free cache mutex */ ldap_pvt_thread_mutex_unlock( &cache->c_mutex ); } -void -cache_return_entry_r( struct cache *cache, Entry *e ) -{ - cache_return_entry_rw(cache, e, 0); -} - -void -cache_return_entry_w( struct cache *cache, Entry *e ) -{ - cache_return_entry_rw(cache, e, 1); -} - - #define LRU_DELETE( cache, e ) { \ if ( LEI(e)->lei_lruprev != NULL ) { \ LEI(LEI(e)->lei_lruprev)->lei_lrunext = LEI(e)->lei_lrunext; \ @@ -229,7 +223,6 @@ int cache_add_entry_rw( struct cache *cache, Entry *e, - int state, int rw ) { @@ -239,17 +232,14 @@ cache_add_entry_rw( /* set cache mutex */ ldap_pvt_thread_mutex_lock( &cache->c_mutex ); - if ( e->e_private != NULL ) { - Debug( LDAP_DEBUG_ANY, - "====> cache_add_entry: entry %20s id %lu already cached.\n", - e->e_dn, e->e_id, 0 ); - return( -1 ); - } +#ifdef LDAP_DEBUG + assert( e->e_private == NULL ); +#endif if( cache_entry_private_init(e) != 0 ) { Debug( LDAP_DEBUG_ANY, - "====> cache_add_entry: entry %20s id %lu: private init failed!\n", - e->e_dn, e->e_id, 0 ); + "====> cache_add_entry( %lu ): \"%s\": private init failed!\n", + e->e_id, e->e_dn, 0 ); return( -1 ); } @@ -257,8 +247,8 @@ cache_add_entry_rw( cache_entrydn_cmp, avl_dup_error ) != 0 ) { Debug( LDAP_DEBUG_TRACE, - "====> cache_add_entry: entry %20s id %lu already in dn cache\n", - e->e_dn, e->e_id, 0 ); + "====> cache_add_entry( %lu ): \"%s\": already in dn cache\n", + e->e_id, e->e_dn, 0 ); cache_entry_private_destroy(e); @@ -272,8 +262,9 @@ cache_add_entry_rw( cache_entryid_cmp, avl_dup_error ) != 0 ) { Debug( LDAP_DEBUG_ANY, - "====> entry %20s id %lu already in id cache\n", - e->e_dn, e->e_id, 0 ); + "====> cache_add_entry( %lu ): \"%s\": already in id cache\n", + e->e_id, e->e_dn, 0 ); + /* delete from dn tree inserted above */ if ( avl_delete( &cache->c_dntree, (caddr_t) e, @@ -292,7 +283,9 @@ cache_add_entry_rw( cache_entry_rdwr_lock( e, rw ); - LEI(e)->lei_state = state; + /* put the entry into 'CREATING' state */ + /* will be marked after when entry is returned */ + LEI(e)->lei_state = CACHE_ENTRY_CREATING; LEI(e)->lei_refcnt = 1; /* lru */ @@ -327,7 +320,7 @@ cache_add_entry_rw( /* delete from cache and lru q */ rc = cache_delete_entry_internal( cache, e ); - + cache_entry_private_destroy( e ); entry_free( e ); } } @@ -355,19 +348,16 @@ cache_update_entry( /* set cache mutex */ ldap_pvt_thread_mutex_lock( &cache->c_mutex ); - if ( e->e_private == NULL ) { - Debug( LDAP_DEBUG_ANY, - "====> cache_update_entry: entry %20s id %lu no private data.\n", - e->e_dn, e->e_id, 0 ); - return( -1 ); - } +#ifdef LDAP_DEBUG + assert( e->e_private ); +#endif if ( avl_insert( &cache->c_dntree, (caddr_t) e, cache_entrydn_cmp, avl_dup_error ) != 0 ) { Debug( LDAP_DEBUG_TRACE, - "====> cache_add_entry: entry %20s id %lu already in dn cache\n", - e->e_dn, e->e_id, 0 ); + "====> cache_update_entry( %lu ): \"%s\": already in dn cache\n", + e->e_id, e->e_dn, 0 ); /* free cache mutex */ ldap_pvt_thread_mutex_unlock( &cache->c_mutex ); @@ -379,8 +369,8 @@ cache_update_entry( cache_entryid_cmp, avl_dup_error ) != 0 ) { Debug( LDAP_DEBUG_ANY, - "====> entry %20s id %lu already in id cache\n", - e->e_dn, e->e_id, 0 ); + "====> cache_update_entry( %lu ): \"%s\": already in id cache\n", + e->e_id, e->e_dn, 0 ); /* delete from dn tree inserted above */ if ( avl_delete( &cache->c_dntree, (caddr_t) e, @@ -395,6 +385,11 @@ cache_update_entry( return( -1 ); } + + /* put the entry into 'CREATING' state */ + /* will be marked after when entry is returned */ + LEI(e)->lei_state = CACHE_ENTRY_CREATING; + /* lru */ LRU_ADD( cache, e ); if ( ++cache->c_cursize > cache->c_maxsize ) { @@ -427,7 +422,7 @@ cache_update_entry( /* delete from cache and lru q */ rc = cache_delete_entry_internal( cache, e ); - + cache_entry_private_destroy( e ); entry_free( e ); } } @@ -468,20 +463,29 @@ cache_find_entry_dn2id( */ free(e.e_ndn); - Debug(LDAP_DEBUG_TRACE, "====> cache_find_entry_dn2id: found dn: %s\n", - dn, 0, 0); - +#ifdef LDAP_DEBUG + assert( ep->e_private ); +#endif /* * entry is deleted or not fully created yet */ - if ( LEI(ep)->lei_state == ENTRY_STATE_DELETED || - LEI(ep)->lei_state == ENTRY_STATE_CREATING ) - { + if ( LEI(ep)->lei_state != CACHE_ENTRY_READY ) { +#ifdef LDAP_DEBUG + assert(LEI(ep)->lei_state != CACHE_ENTRY_UNDEFINED); +#endif + Debug(LDAP_DEBUG_TRACE, + "====> cache_find_entry_dn2id(\"%s\"): %lu (not ready) %d\n", + dn, ep->e_id, LEI(ep)->lei_state); + /* free cache mutex */ ldap_pvt_thread_mutex_unlock( &cache->c_mutex ); return( NOID ); } + Debug(LDAP_DEBUG_TRACE, + "====> cache_find_entry_dn2id(\"%s\"): %lu\n", + dn, ep->e_id, 0); + /* lru */ LRU_DELETE( cache, ep ); LRU_ADD( cache, ep ); @@ -526,21 +530,29 @@ try_again: if ( (ep = (Entry *) avl_find( cache->c_idtree, (caddr_t) &e, cache_entryid_cmp )) != NULL ) { - Debug(LDAP_DEBUG_TRACE, - "====> cache_find_entry_dn2id: found id: %ld rw: %d\n", - id, rw, 0); - +#ifdef LDAP_DEBUG + assert( ep->e_private ); +#endif /* * entry is deleted or not fully created yet */ - if ( LEI(ep)->lei_state == ENTRY_STATE_DELETED || - LEI(ep)->lei_state == ENTRY_STATE_CREATING ) - { + if ( LEI(ep)->lei_state != CACHE_ENTRY_READY ) { +#ifdef LDAP_DEBUG + assert(LEI(ep)->lei_state != CACHE_ENTRY_UNDEFINED); +#endif + Debug(LDAP_DEBUG_TRACE, + "====> cache_find_entry_id( %lu ): %lu (not ready) %d\n", + id, ep->e_id, LEI(ep)->lei_state); + /* free cache mutex */ ldap_pvt_thread_mutex_unlock( &cache->c_mutex ); return( NULL ); } + Debug(LDAP_DEBUG_TRACE, + "====> cache_find_entry_id( %lu, %s ) \"%s\" (found)\n", + id, rw ? "w" : "r", ep->e_dn); + /* acquire reader lock */ if ( cache_entry_rdwr_trylock(ep, rw) == LDAP_PVT_THREAD_EBUSY ) { /* could not acquire entry lock... @@ -591,11 +603,16 @@ cache_delete_entry( { int rc; - Debug( LDAP_DEBUG_TRACE, "====> cache_delete_entry:\n", 0, 0, 0 ); - /* set cache mutex */ ldap_pvt_thread_mutex_lock( &cache->c_mutex ); +#ifdef LDAP_DEBUG + assert( e->e_private ); +#endif + + Debug( LDAP_DEBUG_TRACE, "====> cache_delete_entry( %lu )\n", + e->e_id, 0, 0 ); + rc = cache_delete_entry_internal( cache, e ); /* free cache mutex */ @@ -636,7 +653,7 @@ cache_delete_entry_internal( /* * flag entry to be freed later by a call to cache_return_entry() */ - LEI(e)->lei_state = ENTRY_STATE_DELETED; + LEI(e)->lei_state = CACHE_ENTRY_DELETED; return( 0 ); } @@ -650,13 +667,13 @@ lru_print( struct cache *cache ) fprintf( stderr, "LRU queue (head to tail):\n" ); for ( e = cache->c_lruhead; e != NULL; e = LEI(e)->lei_lrunext ) { - fprintf( stderr, "\tdn %20s id %lu refcnt %d\n", e->e_dn, - e->e_id, LEI(e)->lei_refcnt ); + fprintf( stderr, "\tdn \"%20s\" id %lu refcnt %d\n", + e->e_dn, e->e_id, LEI(e)->lei_refcnt ); } fprintf( stderr, "LRU queue (tail to head):\n" ); for ( e = cache->c_lrutail; e != NULL; e = LEI(e)->lei_lruprev ) { - fprintf( stderr, "\tdn %20s id %lu refcnt %d\n", e->e_dn, - e->e_id, LEI(e)->lei_refcnt ); + fprintf( stderr, "\tdn \"%20s\" id %lu refcnt %d\n", + e->e_dn, e->e_id, LEI(e)->lei_refcnt ); } } diff --git a/servers/slapd/back-ldbm/dn2id.c b/servers/slapd/back-ldbm/dn2id.c index 3772b90281..38901c0249 100644 --- a/servers/slapd/back-ldbm/dn2id.c +++ b/servers/slapd/back-ldbm/dn2id.c @@ -153,7 +153,7 @@ dn2id_delete( * entry. */ -static Entry * +Entry * dn2entry_rw( Backend *be, char *dn, @@ -208,25 +208,3 @@ dn2entry_rw( return( NULL ); } -Entry * -dn2entry_r( - Backend *be, - char *dn, - char **matched -) -{ - return( dn2entry_rw( be, dn, matched, 0 ) ); -} - -Entry * -dn2entry_w( - Backend *be, - char *dn, - char **matched -) -{ - return( dn2entry_rw( be, dn, matched, 1 ) ); -} - - - diff --git a/servers/slapd/back-ldbm/id2entry.c b/servers/slapd/back-ldbm/id2entry.c index dad31af444..1e38d31a22 100644 --- a/servers/slapd/back-ldbm/id2entry.c +++ b/servers/slapd/back-ldbm/id2entry.c @@ -51,9 +51,6 @@ id2entry_add( Backend *be, Entry *e ) ldbm_cache_close( be, db ); - /* XXX entry should have already been added to the cache */ - /* (void) cache_add_entry_rw( &li->li_cache, e, 0 ); */ - Debug( LDAP_DEBUG_TRACE, "<= id2entry_add %d\n", rc, 0, 0 ); return( rc ); @@ -102,7 +99,7 @@ id2entry_delete( Backend *be, Entry *e ) return( rc ); } -/* XXX returns entry with reader/writer lock */ +/* returns entry with reader/writer lock */ Entry * id2entry_rw( Backend *be, ID id, int rw ) { @@ -118,8 +115,8 @@ id2entry_rw( Backend *be, ID id, int rw ) rw ? "w" : "r", id, 0 ); if ( (e = cache_find_entry_id( &li->li_cache, id, rw )) != NULL ) { - Debug( LDAP_DEBUG_TRACE, "<= id2entry_%s 0x%lx (cache)\n", - rw ? "w" : "r", (unsigned long)e, 0 ); + Debug( LDAP_DEBUG_TRACE, "<= id2entry_%s( %ld ) 0x%lx (cache)\n", + rw ? "w" : "r", id, (unsigned long) e ); return( e ); } @@ -153,27 +150,22 @@ id2entry_rw( Backend *be, ID id, int rw ) return( NULL ); } - e->e_id = id; + if ( e->e_id != id ) { + Debug( LDAP_DEBUG_TRACE, "<= id2entry_%s( %ld ) (wrong id %ld on disk)\n", + rw ? "w" : "r", id, e->e_id ); + entry_free( e ); + return( NULL ); + } - if( cache_add_entry_rw( &li->li_cache, e, 0, rw ) != 0 ) { + if( cache_add_entry_rw( &li->li_cache, e, rw ) != 0 ) { Debug( LDAP_DEBUG_TRACE, "<= id2entry_%s( %ld ) (cache add failed)\n", rw ? "w" : "r", id, 0 ); + entry_free( e ); + return NULL; } - Debug( LDAP_DEBUG_TRACE, "<= id2entry_%s( %ld ) (disk)\n", - rw ? "w" : "r", id, 0 ); - return( e ); -} - -Entry * -id2entry_r( Backend *be, ID id ) -{ - return( id2entry_rw( be, id, 0 ) ); -} + Debug( LDAP_DEBUG_TRACE, "<= id2entry_%s( %ld ) 0x%lx (disk)\n", + rw ? "w" : "r", id, (unsigned long) e ); -Entry * -id2entry_w( Backend *be, ID id ) -{ - return( id2entry_rw( be, id, 1 ) ); + return( e ); } - diff --git a/servers/slapd/back-ldbm/modrdn.c b/servers/slapd/back-ldbm/modrdn.c index 3c8c2f8511..f6ec2248fd 100644 --- a/servers/slapd/back-ldbm/modrdn.c +++ b/servers/slapd/back-ldbm/modrdn.c @@ -145,7 +145,6 @@ ldbm_back_modrdn( free( e->e_ndn ); e->e_dn = new_dn; e->e_ndn = new_ndn; - (void) cache_update_entry( &li->li_cache, e ); /* diff --git a/servers/slapd/back-ldbm/proto-back-ldbm.h b/servers/slapd/back-ldbm/proto-back-ldbm.h index a0abc0d867..ef7261e76a 100644 --- a/servers/slapd/back-ldbm/proto-back-ldbm.h +++ b/servers/slapd/back-ldbm/proto-back-ldbm.h @@ -34,12 +34,12 @@ void attr_index_config LDAP_P(( struct ldbminfo *li, char *fname, int lineno, * cache.c */ -void cache_set_state LDAP_P(( struct cache *cache, Entry *e, int state )); -void cache_return_entry_r LDAP_P(( struct cache *cache, Entry *e )); -void cache_return_entry_w LDAP_P(( struct cache *cache, Entry *e )); -int cache_add_entry_rw LDAP_P(( struct cache *cache, Entry *e, - int state, int rw )); +int cache_add_entry_rw LDAP_P(( struct cache *cache, Entry *e, int rw )); int cache_update_entry LDAP_P(( struct cache *cache, Entry *e )); +void cache_return_entry_rw LDAP_P(( struct cache *cache, Entry *e, int rw )); +#define cache_return_entry_r(c, e) cache_return_entry_rw((c), (e), 0) +#define cache_return_entry_w(c, e) cache_return_entry_rw((c), (e), 1) + ID cache_find_entry_dn2id LDAP_P(( Backend *be, struct cache *cache, char *dn )); Entry * cache_find_entry_id LDAP_P(( struct cache *cache, ID id, int rw )); int cache_delete_entry LDAP_P(( struct cache *cache, Entry *e )); @@ -64,8 +64,10 @@ int ldbm_cache_delete LDAP_P(( struct dbcache *db, Datum key )); int dn2id_add LDAP_P(( Backend *be, char *dn, ID id )); ID dn2id LDAP_P(( Backend *be, char *dn )); int dn2id_delete LDAP_P(( Backend *be, char *dn )); -Entry * dn2entry_r LDAP_P(( Backend *be, char *dn, char **matched )); -Entry * dn2entry_w LDAP_P(( Backend *be, char *dn, char **matched )); + +Entry * dn2entry_rw LDAP_P(( Backend *be, char *dn, char **matched, int rw )); +#define dn2entry_r(be, dn, m) dn2entry_rw((be), (dn), (m), 0) +#define dn2entry_w(be, dn, m) dn2entry_rw((be), (dn), (m), 1) /* * filterindex.c @@ -87,9 +89,10 @@ int has_children LDAP_P(( Backend *be, Entry *p )); int id2entry_add LDAP_P(( Backend *be, Entry *e )); int id2entry_delete LDAP_P(( Backend *be, Entry *e )); + Entry * id2entry_rw LDAP_P(( Backend *be, ID id, int rw )); -Entry * id2entry_r LDAP_P(( Backend *be, ID id )); -Entry * id2entry_w LDAP_P(( Backend *be, ID id )); +#define id2entry_r(be, id) id2entry_rw((be), (id), 0) +#define id2entry_w(be, id) id2entry_rw((be), (id), 1) /* * idl.c diff --git a/servers/slapd/entry.c b/servers/slapd/entry.c index 3755272d1f..7099931084 100644 --- a/servers/slapd/entry.c +++ b/servers/slapd/entry.c @@ -237,3 +237,35 @@ entry_free( Entry *e ) free( e ); } +/* + * These routines are used only by Backend. + * + * the Entry has three entry points (ways to find things): + * + * by entry e.g., if you already have an entry from the cache + * and want to delete it. (really by entry ptr) + * by dn e.g., when looking for the base object of a search + * by id e.g., for search candidates + * + * these correspond to three different avl trees that are maintained. + */ + +int +entry_cmp( Entry *e1, Entry *e2 ) +{ + return( e1 < e2 ? -1 : (e1 > e2 ? 1 : 0) ); +} + +int +entry_dn_cmp( Entry *e1, Entry *e2 ) +{ + /* compare their normalized UPPERCASED dn's */ + return( strcmp( e1->e_ndn, e2->e_ndn ) ); +} + +int +entry_id_cmp( Entry *e1, Entry *e2 ) +{ + return( e1->e_id < e2->e_id ? -1 : (e1->e_id > e2->e_id ? 1 : 0) ); +} + diff --git a/servers/slapd/proto-slap.h b/servers/slapd/proto-slap.h index a3f8b820c8..8fb59e2139 100644 --- a/servers/slapd/proto-slap.h +++ b/servers/slapd/proto-slap.h @@ -132,14 +132,9 @@ Entry * str2entry LDAP_P(( char *s )); char * entry2str LDAP_P(( Entry *e, int *len, int printid )); void entry_free LDAP_P(( Entry *e )); -int entry_rdwr_lock LDAP_P(( Entry *e, int rw )); -int entry_rdwr_rlock LDAP_P(( Entry *e )); -int entry_rdwr_wlock LDAP_P(( Entry *e )); -int entry_rdwr_trylock LDAP_P(( Entry *e, int rw )); -int entry_rdwr_unlock LDAP_P(( Entry *e, int rw )); -int entry_rdwr_runlock LDAP_P(( Entry *e )); -int entry_rdwr_wunlock LDAP_P(( Entry *e )); -int entry_rdwr_init LDAP_P(( Entry *e )); +int entry_cmp LDAP_P(( Entry *a, Entry *b )); +int entry_dn_cmp LDAP_P(( Entry *a, Entry *b )); +int entry_id_cmp LDAP_P(( Entry *a, Entry *b )); /* * filter.c