Added CACHE_ENTRY_NO_KIDS flag to bei_state to shortcut dn2id_children.

This commit is contained in:
Howard Chu 2003-04-17 00:52:31 +00:00
parent ab9f7108f1
commit 2048c05a82
7 changed files with 42 additions and 28 deletions

View file

@ -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

View file

@ -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 );
}

View file

@ -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:

View file

@ -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

View file

@ -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 */

View file

@ -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:

View file

@ -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(