From: Howard Chu Date: Mon, 21 Apr 2003 18:28:38 +0000 (+0000) Subject: memory context tweaks X-Git-Tag: OPENLDAP_REL_ENG_2_2_0ALPHA~303 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=d290145776d05eacf6e74dff535eb201cdd59287;p=openldap memory context tweaks --- diff --git a/servers/slapd/back-bdb/add.c b/servers/slapd/back-bdb/add.c index e52174153d..eb63d7c146 100644 --- a/servers/slapd/back-bdb/add.c +++ b/servers/slapd/back-bdb/add.c @@ -384,7 +384,8 @@ retry: /* transaction retry */ } /* dn2id index */ - rs->sr_err = bdb_dn2id_add( op->o_bd, lt2, &pdn, op->oq_add.rs_e ); + rs->sr_err = bdb_dn2id_add( op->o_bd, lt2, &pdn, op->oq_add.rs_e, + op->o_tmpmemctx ); if ( rs->sr_err != 0 ) { #ifdef NEW_LOGGING LDAP_LOG ( OPERATION, ERR, diff --git a/servers/slapd/back-bdb/back-bdb.h b/servers/slapd/back-bdb/back-bdb.h index feccc5bf4e..9801243cb0 100644 --- a/servers/slapd/back-bdb/back-bdb.h +++ b/servers/slapd/back-bdb/back-bdb.h @@ -176,11 +176,7 @@ struct bdb_info { }; #define bi_id2entry bi_databases[BDB_ID2ENTRY] -#ifdef BDB_HIER -#define bi_id2parent bi_databases[BDB_ID2PARENT] -#else #define bi_dn2id bi_databases[BDB_DN2ID] -#endif struct bdb_op_info { BackendDB* boi_bdb; diff --git a/servers/slapd/back-bdb/cache.c b/servers/slapd/back-bdb/cache.c index e43248de17..7fee76c2ab 100644 --- a/servers/slapd/back-bdb/cache.c +++ b/servers/slapd/back-bdb/cache.c @@ -314,7 +314,6 @@ bdb_cache_find_entry_ndn2id( { struct bdb_info *bdb = (struct bdb_info *) be->be_private; EntryInfo ei, *eip, *ei2; - ID id; int rc = 0; char *ptr; @@ -340,7 +339,7 @@ bdb_cache_find_entry_ndn2id( ei.bei_nrdn.bv_len = ndn->bv_len - (ei.bei_nrdn.bv_val - ndn->bv_val); bdb_cache_entryinfo_unlock( eip ); - rc = bdb_dn2id( be, txn, &ei.bei_nrdn, &id, ctx ); + rc = bdb_dn2id( be, txn, &ei.bei_nrdn, &ei, ctx ); if (rc) { bdb_cache_entryinfo_lock( eip ); *res = eip; @@ -350,7 +349,7 @@ bdb_cache_find_entry_ndn2id( /* DN exists but needs to be added to cache */ ei.bei_nrdn.bv_len = len; rc = bdb_entryinfo_add_internal( bdb, - eip, id, &ei.bei_nrdn, &ei2, locker ); + eip, ei.bei_id, &ei.bei_nrdn, &ei2, locker ); /* add_internal left eip and c_rwlock locked */ ldap_pvt_thread_rdwr_wunlock( &bdb->bi_cache.c_rwlock ); if ( rc ) { diff --git a/servers/slapd/back-bdb/delete.c b/servers/slapd/back-bdb/delete.c index 1ba9c5483a..cd4274d5c8 100644 --- a/servers/slapd/back-bdb/delete.c +++ b/servers/slapd/back-bdb/delete.c @@ -358,7 +358,8 @@ retry: /* transaction retry */ } /* delete from dn2id */ - rs->sr_err = bdb_dn2id_delete( op->o_bd, lt2, pdn.bv_val, e ); + rs->sr_err = bdb_dn2id_delete( op->o_bd, lt2, pdn.bv_val, e, + op->o_tmpmemctx ); if ( rs->sr_err != 0 ) { 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 736409b63c..4b6902b609 100644 --- a/servers/slapd/back-bdb/dn2id.c +++ b/servers/slapd/back-bdb/dn2id.c @@ -20,7 +20,8 @@ bdb_dn2id_add( BackendDB *be, DB_TXN *txn, struct berval *pbv, - Entry *e ) + Entry *e, + void *ctx ) { struct bdb_info *bdb = (struct bdb_info *) be->be_private; DB *db = bdb->bi_dn2id->bdi_db; @@ -42,7 +43,7 @@ bdb_dn2id_add( key.size = e->e_nname.bv_len + 2; key.ulen = key.size; key.flags = DB_DBT_USERMEM; - buf = ch_malloc( key.size ); + buf = sl_malloc( key.size, ctx ); key.data = buf; buf[0] = DN_BASE_PREFIX; ptr.bv_val = buf + 1; @@ -148,7 +149,7 @@ bdb_dn2id_add( #endif done: - ch_free( buf ); + sl_free( buf, ctx ); #ifdef NEW_LOGGING LDAP_LOG ( INDEX, RESULTS, "<= bdb_dn2id_add: %d\n", rc, 0, 0 ); #else @@ -162,7 +163,8 @@ bdb_dn2id_delete( BackendDB *be, DB_TXN *txn, char *pdnc, - Entry *e ) + Entry *e, + void *ctx ) { struct bdb_info *bdb = (struct bdb_info *) be->be_private; DB *db = bdb->bi_dn2id->bdi_db; @@ -181,7 +183,7 @@ bdb_dn2id_delete( DBTzero( &key ); key.size = e->e_nname.bv_len + 2; - buf = ch_malloc( key.size ); + buf = sl_malloc( key.size, ctx ); key.data = buf; key.flags = DB_DBT_USERMEM; buf[0] = DN_BASE_PREFIX; @@ -284,7 +286,7 @@ bdb_dn2id_delete( #endif done: - ch_free( buf ); + sl_free( buf, ctx ); #ifdef NEW_LOGGING LDAP_LOG ( INDEX, RESULTS, "<= bdb_dn2id_delete %d\n", rc, 0, 0 ); #else @@ -298,7 +300,7 @@ bdb_dn2id( BackendDB *be, DB_TXN *txn, struct berval *dn, - ID *id, + EntryInfo *ei, void *ctx ) { int rc; @@ -312,8 +314,6 @@ bdb_dn2id( Debug( LDAP_DEBUG_TRACE, "=> bdb_dn2id( \"%s\" )\n", dn->bv_val, 0, 0 ); #endif - assert (id); - DBTzero( &key ); key.size = dn->bv_len + 2; key.data = sl_malloc( key.size, ctx ); @@ -322,7 +322,7 @@ bdb_dn2id( /* store the ID */ DBTzero( &data ); - data.data = id; + data.data = &ei->bei_id; data.ulen = sizeof(ID); data.flags = DB_DBT_USERMEM; @@ -340,10 +340,10 @@ bdb_dn2id( } else { #ifdef NEW_LOGGING LDAP_LOG ( INDEX, RESULTS, - "<= bdb_dn2id: got id=0x%08lx\n", *id, 0, 0 ); + "<= bdb_dn2id: got id=0x%08lx\n", ei->bei_id, 0, 0 ); #else Debug( LDAP_DEBUG_TRACE, "<= bdb_dn2id: got id=0x%08lx\n", - *id, 0, 0 ); + ei->bei_id, 0, 0 ); #endif } diff --git a/servers/slapd/back-bdb/init.c b/servers/slapd/back-bdb/init.c index b1314af509..72f88232b9 100644 --- a/servers/slapd/back-bdb/init.c +++ b/servers/slapd/back-bdb/init.c @@ -23,11 +23,7 @@ static struct bdbi_database { int flags; } bdbi_databases[] = { { "id2entry" BDB_SUFFIX, "id2entry", DB_BTREE, 0 }, -#ifdef BDB_HIER - { "id2parent" BDB_SUFFIX, "id2parent", DB_BTREE, 0 }, -#else { "dn2id" BDB_SUFFIX, "dn2id", DB_BTREE, 0 }, -#endif { NULL, NULL, 0, 0 } }; @@ -101,9 +97,6 @@ bdb_db_init( BackendDB *be ) ldap_pvt_thread_mutex_init( &bdb->bi_lastid_mutex ); ldap_pvt_thread_mutex_init( &bdb->bi_cache.lru_mutex ); ldap_pvt_thread_rdwr_init ( &bdb->bi_cache.c_rwlock ); -#ifdef BDB_HIER - ldap_pvt_thread_rdwr_init( &bdb->bi_tree_rdwr ); -#endif be->be_private = bdb; @@ -437,9 +430,6 @@ bdb_db_open( BackendDB *be ) } /* open (and create) index databases */ -#ifdef BDB_HIER - rc = bdb_build_tree( be ); -#endif return 0; } @@ -527,9 +517,6 @@ bdb_db_destroy( BackendDB *be ) if( bdb->bi_dbenv_home ) ch_free( bdb->bi_dbenv_home ); -#ifdef BDB_HIER - ldap_pvt_thread_rdwr_destroy( &bdb->bi_tree_rdwr ); -#endif ldap_pvt_thread_rdwr_destroy ( &bdb->bi_cache.c_rwlock ); ldap_pvt_thread_mutex_destroy( &bdb->bi_cache.lru_mutex ); ldap_pvt_thread_mutex_destroy( &bdb->bi_lastid_mutex ); diff --git a/servers/slapd/back-bdb/modrdn.c b/servers/slapd/back-bdb/modrdn.c index cf240d191f..c394c18048 100644 --- a/servers/slapd/back-bdb/modrdn.c +++ b/servers/slapd/back-bdb/modrdn.c @@ -775,7 +775,8 @@ retry: /* transaction retry */ e = &dummy; /* delete old one */ - rs->sr_err = bdb_dn2id_delete( op->o_bd, lt2, p_ndn.bv_val, e ); + rs->sr_err = bdb_dn2id_delete( op->o_bd, lt2, p_ndn.bv_val, e, + op->o_tmpmemctx ); if ( rs->sr_err != 0 ) { switch( rs->sr_err ) { case DB_LOCK_DEADLOCK: @@ -811,7 +812,8 @@ retry: /* transaction retry */ new_ndn.bv_val = NULL; #endif /* add new one */ - rs->sr_err = bdb_dn2id_add( op->o_bd, lt2, np_ndn, e ); + rs->sr_err = bdb_dn2id_add( op->o_bd, lt2, np_ndn, e, + op->o_tmpmemctx ); if ( rs->sr_err != 0 ) { switch( rs->sr_err ) { case DB_LOCK_DEADLOCK: diff --git a/servers/slapd/back-bdb/proto-bdb.h b/servers/slapd/back-bdb/proto-bdb.h index 80ddbda0a0..b688edc8df 100644 --- a/servers/slapd/back-bdb/proto-bdb.h +++ b/servers/slapd/back-bdb/proto-bdb.h @@ -63,20 +63,22 @@ int bdb_dn2id( BackendDB *be, DB_TXN *tid, struct berval *dn, - ID *id, + EntryInfo *ei, void *ctx ); int bdb_dn2id_add( BackendDB *be, DB_TXN *tid, struct berval *pdn, - Entry *e ); + Entry *e, + void *ctx ); int bdb_dn2id_delete( BackendDB *be, DB_TXN *tid, char *pdn, - Entry *e ); + Entry *e, + void *ctx ); int bdb_dn2id_children( Operation *op, diff --git a/servers/slapd/back-bdb/referral.c b/servers/slapd/back-bdb/referral.c index 6b6e741041..4ec6c7b09f 100644 --- a/servers/slapd/back-bdb/referral.c +++ b/servers/slapd/back-bdb/referral.c @@ -75,11 +75,10 @@ dn2entry_retry: if ( rc == DB_NOTFOUND ) { rc = 0; + rs->sr_matched = NULL; if ( e != NULL ) { - rs->sr_matched = ch_strdup( e->e_name.bv_val ); - #ifdef NEW_LOGGING - LDAP_LOG ( OPERATION, DETAIL1, + LDAP_LOG ( OPERATION, DETAIL1, "bdb_referrals: op=%ld target=\"%s\" matched=\"%s\"\n", (long) op->o_tag, op->o_req_dn.bv_val, rs->sr_matched ); #else @@ -91,6 +90,10 @@ dn2entry_retry: if( is_entry_referral( e ) ) { rc = LDAP_OTHER; rs->sr_ref = get_entry_referrals( op, e ); + if ( rs->sr_ref ) { + rs->sr_matched = ber_strdup_x( + e->e_name.bv_val, op->o_tmpmemctx ); + } } bdb_cache_return_entry_r (bdb->bi_dbenv, &bdb->bi_cache, e, &lock); @@ -114,8 +117,10 @@ dn2entry_retry: } LOCK_ID_FREE ( bdb->bi_dbenv, locker ); - free( (char *)rs->sr_matched ); - rs->sr_matched = NULL; + if (rs->sr_matched) { + sl_free( (char *)rs->sr_matched, op->o_tmpmemctx ); + rs->sr_matched = NULL; + } return rc; } diff --git a/servers/slapd/back-bdb/tools.c b/servers/slapd/back-bdb/tools.c index ba8287aa6b..1c0413e695 100644 --- a/servers/slapd/back-bdb/tools.c +++ b/servers/slapd/back-bdb/tools.c @@ -170,7 +170,7 @@ int bdb_tool_next_id( return rc; } e->e_nname = dn; - rc = bdb_dn2id_add( be, tid, &pdn, e ); + rc = bdb_dn2id_add( be, tid, &pdn, e, NULL ); if ( rc ) { snprintf( text->bv_val, text->bv_len, "dn2id_add failed: %s (%d)", @@ -404,7 +404,7 @@ int bdb_tool_entry_reindex( } else { dnParent( &e->e_nname, &pdn ); } - rc = bdb_dn2id_add( be, tid, &pdn, e ); + rc = bdb_dn2id_add( be, tid, &pdn, e, NULL ); if( rc != 0 && rc != DB_KEYEXIST ) { #ifdef NEW_LOGGING LDAP_LOG ( TOOLS, ERR,