DB_TXN *tid,
ID id,
Entry **e,
- int rw )
+ int rw,
+ u_int32_t locker,
+ DB_LOCK *lock )
{
struct bdb_info *bdb = (struct bdb_info *) be->be_private;
DB *db = bdb->bi_id2entry->bdi_db;
DBT key, data;
struct berval bv;
- int rc = 0;
+ int rc = 0, ret = 0;
*e = NULL;
DBTzero( &data );
data.flags = DB_DBT_MALLOC;
- if ((*e = bdb_cache_find_entry_id(&bdb->bi_cache, id, rw)) != NULL) {
+ 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 );
+ rc = db->get( db, tid, &key, &data, bdb->bi_db_opflags | ( rw ? DB_RMW : 0 ));
if( rc != 0 ) {
return rc;
ch_free( data.data );
}
- if (rc == 0 && bdb_cache_add_entry_rw(&bdb->bi_cache, *e, rw) != 0) {
- if ((*e)->e_private != NULL)
- free ((*e)->e_private);
- (*e)->e_private = NULL;
- bdb_entry_return (*e);
- if ((*e=bdb_cache_find_entry_id(&bdb->bi_cache,id,rw)) != NULL) {
- return 0;
+ if ( rc == 0 ) {
+ 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;
+ ch_free( data.data );
}
+ rc = ret;
}
#ifdef BDB_HIER
bdb_fix_dn(be, id, *e);
#endif
- if (rc == 0)
+ if (rc == 0) {
bdb_cache_entry_commit(*e);
+ }
return rc;
}
attrs_free( e->e_attrs );
}
+#ifndef BDB_HIER
/* See if the DNs were changed by modrdn */
if( e->e_nname.bv_val < e->e_bv.bv_val || e->e_nname.bv_val >
e->e_bv.bv_val + e->e_bv.bv_len ) {
e->e_name.bv_val = NULL;
e->e_nname.bv_val = NULL;
}
-#ifdef BDB_HIER
+#else
/* We had to construct the dn and ndn as well, in a single block */
if( e->e_name.bv_val ) {
free( e->e_name.bv_val );
if ( slapMode == SLAP_SERVER_MODE ) {
/* free entry and reader or writer lock */
- bdb_cache_return_entry_rw( &bdb->bi_cache, e, rw );
+ bdb_unlocked_cache_return_entry_rw( &bdb->bi_cache, e, rw );
} else {
if (e->e_private != NULL)
free (e->e_private);