]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/back-bdb/id2entry.c
Trim dead BDB_HIER stuff
[openldap] / servers / slapd / back-bdb / id2entry.c
index 598ee76ce878549889127b977fa9519bed407da0..864d90b044c0f8ded602f5295c199323740a2153 100644 (file)
@@ -26,7 +26,7 @@ int bdb_id2entry_put(
 #ifdef BDB_HIER
        struct berval odn, ondn;
 
-       /* We only store rdns, and they go in the id2parent database. */
+       /* We only store rdns, and they go in the dn2id database. */
 
        odn = e->e_name; ondn = e->e_nname;
 
@@ -76,14 +76,11 @@ int bdb_id2entry_update(
        return bdb_id2entry_put(be, tid, e, 0);
 }
 
-int bdb_id2entry_rw(
+int bdb_id2entry(
        BackendDB *be,
        DB_TXN *tid,
        ID id,
-       Entry **e,
-       int rw,
-       u_int32_t locker,
-       DB_LOCK *lock )
+       Entry **e )
 {
        struct bdb_info *bdb = (struct bdb_info *) be->be_private;
        DB *db = bdb->bi_id2entry->bdi_db;
@@ -100,12 +97,8 @@ int bdb_id2entry_rw(
        DBTzero( &data );
        data.flags = DB_DBT_MALLOC;
 
-       if ((*e = bdb_cache_find_entry_id(bdb->bi_dbenv, &bdb->bi_cache, id, rw, locker, lock)) != NULL) {
-               return 0;
-       }
-
        /* fetch it */
-       rc = db->get( db, tid, &key, &data, bdb->bi_db_opflags | ( rw ? DB_RMW : 0 ));
+       rc = db->get( db, tid, &key, &data, bdb->bi_db_opflags );
 
        if( rc != 0 ) {
                return rc;
@@ -124,44 +117,6 @@ int bdb_id2entry_rw(
                ch_free( data.data );
        }
 
-       if ( rc == 0 ) {
-#ifdef BDB_HIER
-               bdb_fix_dn(be, id, *e);
-#endif
-               ret = bdb_cache_add_entry_rw( bdb->bi_dbenv,
-                               &bdb->bi_cache, *e, rw, locker, lock);
-               while ( ret == 1 || ret == -1 ) {
-                       Entry *ee;
-                       int add_loop_cnt = 0;
-                       if ( (*e)->e_private != NULL ) {
-                               free ((*e)->e_private);
-                       }
-                       (*e)->e_private = NULL;
-                       if ( (ee = bdb_cache_find_entry_id
-                                       (bdb->bi_dbenv, &bdb->bi_cache, id, rw, locker, lock) ) != NULL) {
-                               bdb_entry_return ( *e );
-                               *e = ee;
-                               return 0;
-                       }
-                       if ( ++add_loop_cnt == BDB_MAX_ADD_LOOP ) {
-                               bdb_entry_return ( *e );
-                               *e = NULL;
-                               return LDAP_BUSY;
-                       }
-               }
-               if ( ret != 0 ) {
-                       if ( (*e)->e_private != NULL )
-                               free ( (*e)->e_private );
-                       bdb_entry_return( *e );
-                       *e = NULL;
-               }
-               rc = ret;
-       }
-
-       if (rc == 0) {
-               bdb_cache_entry_commit(*e);
-       }
-
        return rc;
 }
 
@@ -175,8 +130,6 @@ int bdb_id2entry_delete(
        DBT key;
        int rc;
 
-       bdb_cache_delete_entry(&bdb->bi_cache, e);
-
        DBTzero( &key );
        key.data = (char *) &e->e_id;
        key.size = sizeof(ID);
@@ -205,18 +158,6 @@ int bdb_entry_return(
        if( (void *) e->e_attrs != (void *) (e+1)) {
                attrs_free( e->e_attrs );
        }
-#if defined(SLAP_NVALUES) && !defined(SLAP_NVALUES_ON_DISK)
-       else {
-               /* nvals are not contiguous with the rest. oh well. */
-               Attribute *a;
-               for (a = e->e_attrs; a; a=a->a_next) {
-                       if (a->a_nvals != a->a_vals) {
-                               ber_bvarray_free( a->a_nvals );
-                               a->a_nvals = NULL;
-                       }
-               }
-       }
-#endif
 
 #ifndef BDB_HIER
        /* See if the DNs were changed by modrdn */
@@ -244,23 +185,32 @@ int bdb_entry_return(
 }
 
 int bdb_entry_release(
-       BackendDB *be,
-       Connection *c,
        Operation *o,
        Entry *e,
        int rw )
 {
-       struct bdb_info *bdb = (struct bdb_info *) be->be_private;
+       struct bdb_info *bdb = (struct bdb_info *) o->o_bd->be_private;
+       struct bdb_op_info *boi = NULL;
  
        /* slapMode : SLAP_SERVER_MODE, SLAP_TOOL_MODE,
                        SLAP_TRUNCATE_MODE, SLAP_UNDEFINED_MODE */
  
        if ( slapMode == SLAP_SERVER_MODE ) {
                /* free entry and reader or writer lock */
-               bdb_unlocked_cache_return_entry_rw( &bdb->bi_cache, e, rw );
+               if ( o ) {
+                       boi = (struct bdb_op_info *)o->o_private;
+               }
+               /* lock is freed with txn */
+               if ( !boi || boi->boi_txn ) {
+                       bdb_unlocked_cache_return_entry_rw( &bdb->bi_cache, e, rw );
+               } else {
+                       bdb_cache_return_entry_rw( bdb->bi_dbenv, &bdb->bi_cache, e, rw, &boi->boi_lock );
+                       sl_free( boi, o->o_tmpmemctx );
+                       o->o_private = NULL;
+               }
        } else {
                if (e->e_private != NULL)
-                       free (e->e_private);
+                       BEI(e)->bei_e = NULL;
                e->e_private = NULL;
                bdb_entry_return ( e );
        }
@@ -271,8 +221,6 @@ int bdb_entry_release(
 /* return LDAP_SUCCESS IFF we can retrieve the specified entry.
  */
 int bdb_entry_get(
-       BackendDB *be,
-       Connection *c,
        Operation *op,
        struct berval *ndn,
        ObjectClass *oc,
@@ -280,10 +228,11 @@ int bdb_entry_get(
        int rw,
        Entry **ent )
 {
-       struct bdb_info *bdb = (struct bdb_info *) be->be_private;
+       struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
        struct bdb_op_info *boi = NULL;
        DB_TXN *txn = NULL;
        Entry *e;
+       EntryInfo *ei;
        int     rc;
        const char *at_name = at->ad_cname.bv_val;
 
@@ -306,7 +255,7 @@ int bdb_entry_get(
 #endif
 
        if( op ) boi = (struct bdb_op_info *) op->o_private;
-       if( boi != NULL && be == boi->boi_bdb ) {
+       if( boi != NULL && op->o_bd == boi->boi_bdb ) {
                txn = boi->boi_txn;
                locker = boi->boi_locker;
        }
@@ -326,7 +275,7 @@ int bdb_entry_get(
 
 dn2entry_retry:
        /* can we find entry */
-       rc = bdb_dn2entry_rw( be, txn, ndn, &e, NULL, 0, rw, locker, &lock );
+       rc = bdb_dn2entry( op->o_bd, txn, ndn, &ei, 0, locker, &lock, op->o_tmpmemctx );
        switch( rc ) {
        case DB_NOTFOUND:
        case 0:
@@ -347,6 +296,7 @@ dn2entry_retry:
                }
                return (rc != LDAP_BUSY) ? LDAP_OTHER : LDAP_BUSY;
        }
+       if (ei) e = ei->bei_e;
        if (e == NULL) {
 #ifdef NEW_LOGGING
                LDAP_LOG( BACK_BDB, INFO, 
@@ -418,6 +368,14 @@ return_results:
                bdb_cache_return_entry_rw(bdb->bi_dbenv, &bdb->bi_cache, e, rw, &lock);
        } else {
                *ent = e;
+               /* big drag. we need a place to store a read lock so we can
+                * release it later??
+                */
+               if ( op && !boi ) {
+                       boi = sl_calloc(1,sizeof(struct bdb_op_info),op->o_tmpmemctx);
+                       boi->boi_lock = lock;
+                       op->o_private = boi;
+               }
        }
 
        if ( free_lock_id ) {