From: Howard Chu Date: Thu, 17 Apr 2003 00:52:31 +0000 (+0000) Subject: Added CACHE_ENTRY_NO_KIDS flag to bei_state to shortcut dn2id_children. X-Git-Tag: OPENLDAP_REL_ENG_2_2_0ALPHA~339 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=2048c05a82b5152cb291846109b56fcfe4cfb1a2;p=openldap Added CACHE_ENTRY_NO_KIDS flag to bei_state to shortcut dn2id_children. --- diff --git a/servers/slapd/back-bdb/back-bdb.h b/servers/slapd/back-bdb/back-bdb.h index 3fcd17f8d6..30640a0e45 100644 --- a/servers/slapd/back-bdb/back-bdb.h +++ b/servers/slapd/back-bdb/back-bdb.h @@ -89,6 +89,7 @@ typedef struct bdb_entry_info { int bei_state; #define CACHE_ENTRY_DELETED 1 +#define CACHE_ENTRY_NO_KIDS 2 /* * remaining fields require backend cache lock to access diff --git a/servers/slapd/back-bdb/cache.c b/servers/slapd/back-bdb/cache.c index 457ab3aced..e43248de17 100644 --- a/servers/slapd/back-bdb/cache.c +++ b/servers/slapd/back-bdb/cache.c @@ -357,7 +357,7 @@ bdb_cache_find_entry_ndn2id( *res = eip; return rc; } - } else if ( ei2->bei_state == CACHE_ENTRY_DELETED ) { + } else if ( ei2->bei_state & CACHE_ENTRY_DELETED ) { /* In the midst of deleting? Give it a chance to * complete. */ @@ -443,7 +443,7 @@ bdb_cache_find_entry_id( /* Ok, we found the info, do we have the entry? */ if ( *eip && rc == 0 ) { - if ( (*eip)->bei_state == CACHE_ENTRY_DELETED ) { + if ( (*eip)->bei_state & CACHE_ENTRY_DELETED ) { rc = DB_NOTFOUND; } else if (!(*eip)->bei_e ) { if (!ep) { @@ -492,6 +492,8 @@ bdb_cache_add( rc = bdb_entryinfo_add_internal( bdb, ei, e->e_id, nrdn, &new, locker ); new->bei_e = e; e->e_private = new; + new->bei_state = CACHE_ENTRY_NO_KIDS; + ei->bei_state &= ~CACHE_ENTRY_NO_KIDS; bdb_cache_entryinfo_unlock( ei ); ldap_pvt_thread_rdwr_wunlock( &bdb->bi_cache.c_rwlock ); return rc; @@ -600,7 +602,7 @@ bdb_cache_delete_entry( assert( e->e_private ); /* Set this early, warn off any queriers */ - ei->bei_state = CACHE_ENTRY_DELETED; + ei->bei_state |= CACHE_ENTRY_DELETED; /* Get write lock on the data */ bdb_cache_entry_db_relock( env, locker, ei, 1, 0, lock ); @@ -670,7 +672,7 @@ bdb_cache_delete_entry_internal( /* * flag entry to be freed later by a call to cache_return_entry() */ - e->bei_state = CACHE_ENTRY_DELETED; + e->bei_state |= CACHE_ENTRY_DELETED; return( 0 ); } diff --git a/servers/slapd/back-bdb/delete.c b/servers/slapd/back-bdb/delete.c index ac18552536..1ba9c5483a 100644 --- a/servers/slapd/back-bdb/delete.c +++ b/servers/slapd/back-bdb/delete.c @@ -323,8 +323,7 @@ retry: /* transaction retry */ } /* Can't do it if we have kids */ - rs->sr_err = ei->bei_kids ? 0 : bdb_dn2id_children( op->o_bd, lt2, - &e->e_nname, 0 ); + rs->sr_err = bdb_dn2id_children( op, lt2, e ); if( rs->sr_err != DB_NOTFOUND ) { switch( rs->sr_err ) { case DB_LOCK_DEADLOCK: diff --git a/servers/slapd/back-bdb/dn2id.c b/servers/slapd/back-bdb/dn2id.c index 3352c420f8..736409b63c 100644 --- a/servers/slapd/back-bdb/dn2id.c +++ b/servers/slapd/back-bdb/dn2id.c @@ -353,30 +353,37 @@ bdb_dn2id( int bdb_dn2id_children( - BackendDB *be, + Operation *op, DB_TXN *txn, - struct berval *dn, - int flags ) + Entry *e ) { int rc; - DBT key, data; - struct bdb_info *bdb = (struct bdb_info *) be->be_private; - DB *db = bdb->bi_dn2id->bdi_db; - ID id; #ifdef NEW_LOGGING LDAP_LOG ( INDEX, ARGS, - "=> bdb_dn2id_children( %s )\n", dn->bv_val, 0, 0 ); + "=> bdb_dn2id_children( %s )\n", e->e_nname.bv_val, 0, 0 ); #else Debug( LDAP_DEBUG_TRACE, "=> bdb_dn2id_children( %s )\n", - dn->bv_val, 0, 0 ); + e->e_nname.bv_val, 0, 0 ); #endif + if ( BEI(e)->bei_kids ) { + rc = 0; + } + if ( BEI(e)->bei_state & CACHE_ENTRY_NO_KIDS ) { + rc = DB_NOTFOUND; + } else { + + DBT key, data; + struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private; + DB *db = bdb->bi_dn2id->bdi_db; + ID id; + DBTzero( &key ); - key.size = dn->bv_len + 2; - key.data = ch_malloc( key.size ); + key.size = e->e_nname.bv_len + 2; + key.data = sl_malloc( key.size, op->o_tmpmemctx ); ((char *)key.data)[0] = DN_ONE_PREFIX; - AC_MEMCPY( &((char *)key.data)[1], dn->bv_val, key.size - 1 ); + AC_MEMCPY( &((char *)key.data)[1], e->e_nname.bv_val, key.size - 1 ); /* we actually could do a empty get... */ DBTzero( &data ); @@ -386,17 +393,23 @@ bdb_dn2id_children( data.doff = 0; data.dlen = sizeof(id); - rc = db->get( db, txn, &key, &data, bdb->bi_db_opflags | flags ); - free( key.data ); + rc = db->get( db, txn, &key, &data, bdb->bi_db_opflags ); + sl_free( key.data, op->o_tmpmemctx ); + + if ( rc == DB_NOTFOUND ) { + BEI(e)->bei_state |= CACHE_ENTRY_NO_KIDS; + } + + } #ifdef NEW_LOGGING LDAP_LOG ( INDEX, DETAIL1, "<= bdb_dn2id_children( %s ): %s (%d)\n", - dn->bv_val, rc == 0 ? "" : ( rc == DB_NOTFOUND ? "no " : + e->e_nname.bv_val, rc == 0 ? "" : ( rc == DB_NOTFOUND ? "no " : db_strerror(rc)), rc ); #else Debug( LDAP_DEBUG_TRACE, "<= bdb_dn2id_children( %s ): %s (%d)\n", - dn->bv_val, + e->e_nname.bv_val, rc == 0 ? "" : ( rc == DB_NOTFOUND ? "no " : db_strerror(rc) ), rc ); #endif diff --git a/servers/slapd/back-bdb/modrdn.c b/servers/slapd/back-bdb/modrdn.c index a606107070..cf240d191f 100644 --- a/servers/slapd/back-bdb/modrdn.c +++ b/servers/slapd/back-bdb/modrdn.c @@ -205,8 +205,7 @@ retry: /* transaction retry */ } #ifndef BDB_HIER - rs->sr_err = ei->bei_kids ? 0 : bdb_dn2id_children( op->o_bd, ltid, - &e->e_nname, 0 ); + rs->sr_err = bdb_dn2id_children( op, ltid, e ); if ( rs->sr_err != DB_NOTFOUND ) { switch( rs->sr_err ) { case DB_LOCK_DEADLOCK: @@ -239,6 +238,7 @@ retry: /* transaction retry */ } goto return_results; } + ei->bei_state |= CACHE_ENTRY_NO_KIDS; #endif if (!manageDSAit && is_entry_referral( e ) ) { /* parent is a referral, don't allow add */ diff --git a/servers/slapd/back-bdb/operational.c b/servers/slapd/back-bdb/operational.c index 53f7acf23e..b189476559 100644 --- a/servers/slapd/back-bdb/operational.c +++ b/servers/slapd/back-bdb/operational.c @@ -31,7 +31,7 @@ bdb_hasSubordinates( assert( e ); retry: - rc = bdb_dn2id_children( op->o_bd, NULL, &e->e_nname, 0 ); + rc = bdb_dn2id_children( op, NULL, e ); switch( rc ) { case DB_LOCK_DEADLOCK: diff --git a/servers/slapd/back-bdb/proto-bdb.h b/servers/slapd/back-bdb/proto-bdb.h index 2ac96d52a1..80ddbda0a0 100644 --- a/servers/slapd/back-bdb/proto-bdb.h +++ b/servers/slapd/back-bdb/proto-bdb.h @@ -79,10 +79,9 @@ int bdb_dn2id_delete( Entry *e ); int bdb_dn2id_children( - BackendDB *be, + Operation *op, DB_TXN *tid, - struct berval *dn, - int flags ); + Entry *e ); int bdb_dn2idl(