]> git.sur5r.net Git - openldap/commitdiff
memory context tweaks
authorHoward Chu <hyc@openldap.org>
Mon, 21 Apr 2003 18:28:38 +0000 (18:28 +0000)
committerHoward Chu <hyc@openldap.org>
Mon, 21 Apr 2003 18:28:38 +0000 (18:28 +0000)
servers/slapd/back-bdb/add.c
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/init.c
servers/slapd/back-bdb/modrdn.c
servers/slapd/back-bdb/proto-bdb.h
servers/slapd/back-bdb/referral.c
servers/slapd/back-bdb/tools.c

index e52174153dbb31047feace028b3b89ac5a17ab3d..eb63d7c146b7d52e545ce577a7c4c1f1ccc997d0 100644 (file)
@@ -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, 
index feccc5bf4efc6b1785982709f2c7e97ea9f7d8ec..9801243cb0d4905caae3edd3fab934cef2664643 100644 (file)
@@ -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;
index e43248de17b696a7ebf7f740a3262a1d19a66e16..7fee76c2abefb52a7f5a6b085f553e38a235413a 100644 (file)
@@ -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 ) {
index 1ba9c5483a76c6275da70dcc4840bcd2795197c5..cd4274d5c8fd497ba6e9e9db490b42fbfe228fa2 100644 (file)
@@ -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:
index 736409b63ce47237a1410a7d175be94b8dc4279d..4b6902b609b52d37050c270600c349e872916639 100644 (file)
@@ -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
        }
 
index b1314af50975d1375f3d3a77df0f377c3e006c81..72f88232b908a46f1d28d6d0ce5caa2cd555dbbc 100644 (file)
@@ -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 )
        }
 
        /* <insert> 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 );
index cf240d191f777c1ab4dc83a30969bcbc460b08d3..c394c18048199c8603db7e52fbcf2fbaeee372b1 100644 (file)
@@ -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:
index 80ddbda0a03552a81d58b2379a206e5fc6d61048..b688edc8df5d9afc8a0fae709c5a4498704b66ff 100644 (file)
@@ -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,
index 6b6e741041dda3f6dcc6f49f0bae34f015f8ac81..4ec6c7b09fb178fda16ffe8aca5b77517de7267d 100644 (file)
@@ -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;
        }
 
index ba8287aa6b2b3e2671458eb592b4b430e17777ce..1c0413e695c41f506e4ade6c66e11329e48176d3 100644 (file)
@@ -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,