]> git.sur5r.net Git - openldap/commitdiff
Added CACHE_ENTRY_NO_KIDS flag to bei_state to shortcut dn2id_children.
authorHoward Chu <hyc@openldap.org>
Thu, 17 Apr 2003 00:52:31 +0000 (00:52 +0000)
committerHoward Chu <hyc@openldap.org>
Thu, 17 Apr 2003 00:52:31 +0000 (00:52 +0000)
servers/slapd/back-bdb/back-bdb.h
servers/slapd/back-bdb/cache.c
servers/slapd/back-bdb/delete.c
servers/slapd/back-bdb/dn2id.c
servers/slapd/back-bdb/modrdn.c
servers/slapd/back-bdb/operational.c
servers/slapd/back-bdb/proto-bdb.h

index 3fcd17f8d6dd967522f09e6c77efbec1bc5ed0de..30640a0e455baeeb44118dd75df14952d4ac6a61 100644 (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
index 457ab3acedbf92672ac131f8c3dcdd13d74e57b1..e43248de17b696a7ebf7f740a3262a1d19a66e16 100644 (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 );
 }
index ac185525360af836be8bd0ab5514a019924d2df7..1ba9c5483a76c6275da70dcc4840bcd2795197c5 100644 (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:
index 3352c420f85d8596d4fa2197b8534c6293efd3a5..736409b63ce47237a1410a7d175be94b8dc4279d 100644 (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
index a606107070f217b8340a7dfc7a0cb2d4cc61a600..cf240d191f777c1ab4dc83a30969bcbc460b08d3 100644 (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 */
index 53f7acf23e3c3dc8aa5d72904d8c46c7d310282e..b18947655915dc568736a6c8c2b5e9680027bd9a 100644 (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:
index 2ac96d52a1a05c23984d6569a9d429aa5f61f7c7..80ddbda0a03552a81d58b2379a206e5fc6d61048 100644 (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(