]> git.ipfire.org Git - thirdparty/openldap.git/commitdiff
Indexing fixes
authorHoward Chu <hyc@openldap.org>
Wed, 24 Aug 2011 12:22:46 +0000 (05:22 -0700)
committerHoward Chu <hyc@openldap.org>
Wed, 24 Aug 2011 12:22:46 +0000 (05:22 -0700)
servers/slapd/back-mdb/attr.c
servers/slapd/back-mdb/dn2id.c
servers/slapd/back-mdb/id2entry.c
servers/slapd/back-mdb/libmdb
servers/slapd/back-mdb/search.c
servers/slapd/back-mdb/tools.c

index bc84d30a5b91515ddf2f3b016cd28ab86390e805..47dae95e283bea11bc10c4adf89a446e0e66b6d4 100644 (file)
@@ -358,6 +358,7 @@ mdb_attr_index_config(
                a->ai_cr = NULL;
 #endif
                a->ai_desc = ad;
+               a->ai_dbi = 0;
 
                if ( mdb->mi_flags & MDB_IS_OPEN ) {
                        a->ai_indexmask = 0;
index 24f1228d44e86eec07f9028adbdaafd5eec9bcec..f3dcfe0b3bd4b02714bbc926eaec494cb8f98f48 100644 (file)
@@ -310,13 +310,6 @@ mdb_dn2id(
                data.mv_data = d;
                rc = mdb_cursor_get( cursor, &key, &data, MDB_GET_BOTH );
                op->o_tmpfree( d, op->o_tmpmemctx );
-               if ( rc == MDB_NOTFOUND ) {
-                       if ( matched && matched->bv_len ) {
-                               ptr = op->o_tmpalloc( matched->bv_len+1, op->o_tmpmemctx );
-                               strcpy( ptr, matched->bv_val );
-                               matched->bv_val = ptr;
-                       }
-               }
                if ( rc ) {
                        mdb_cursor_close( cursor );
                        break;
@@ -350,6 +343,11 @@ mdb_dn2id(
                }
        }
        *id = nid; 
+       if ( matched && matched->bv_len ) {
+               ptr = op->o_tmpalloc( matched->bv_len+1, op->o_tmpmemctx );
+               strcpy( ptr, matched->bv_val );
+               matched->bv_val = ptr;
+       }
 
 done:
        if( rc != 0 ) {
@@ -597,7 +595,6 @@ mdb_id2name(
                memcpy( nname->bv_val, ndn, nname->bv_len );
                nname->bv_val[nname->bv_len] = '\0';
        }
-       mdb_cursor_close( cursor );
        return rc;
 }
 
index b55611ef74a57b358ac5cbdb68d46330ec888093..8c3b0cf2bd3ebd960bbea6ab6ec20bcc668ab0fc 100644 (file)
@@ -115,6 +115,8 @@ int mdb_id2entry(
        if( rc == 0 ) {
                (*e)->e_id = id;
                (*e)->e_bv = eh.bv;
+               (*e)->e_name.bv_val = NULL;
+               (*e)->e_nname.bv_val = NULL;
        } else {
                ch_free( eh.bv.bv_val );
        }
@@ -156,7 +158,6 @@ int mdb_entry_release(
 {
        struct mdb_info *mdb = (struct mdb_info *) op->o_bd->be_private;
        struct mdb_op_info *moi = NULL;
-       MDB_txn *txn = NULL;
        int rc;
  
        /* slapMode : SLAP_SERVER_MODE, SLAP_TOOL_MODE,
@@ -293,6 +294,8 @@ mdb_opinfo_get( Operation *op, struct mdb_info *mdb, int rdonly, mdb_op_info **m
        mdb_op_info *moi = NULL;
        OpExtra *oex;
 
+       assert( op != NULL );
+
        if ( !mdb || !moip ) return -1;
 
        /* If no op was provided, try to find the ctx anyway... */
@@ -315,13 +318,13 @@ mdb_opinfo_get( Operation *op, struct mdb_info *mdb, int rdonly, mdb_op_info **m
                if ( !moi ) {
                        if ( op ) {
                                moi = op->o_tmpalloc(sizeof(struct mdb_op_info),op->o_tmpmemctx);
-                               LDAP_SLIST_INSERT_HEAD( &op->o_extra, &moi->moi_oe, oe_next );
                        } else {
                                moi = ch_malloc(sizeof(mdb_op_info));
                        }
                        moi->moi_flag = MOI_FREEIT;
                        *moip = moi;
                }
+               LDAP_SLIST_INSERT_HEAD( &op->o_extra, &moi->moi_oe, oe_next );
                moi->moi_oe.oe_key = mdb;
                moi->moi_ref = 0;
                moi->moi_txn = NULL;
@@ -378,6 +381,7 @@ mdb_opinfo_get( Operation *op, struct mdb_info *mdb, int rdonly, mdb_op_info **m
                } else {
                        moi->moi_txn = data;
                }
+               moi->moi_flag |= MOI_READER;
        } else {
                if ( moi->moi_ref < 1 ) {
                        moi->moi_ref = 0;
index 96aa7f066185995c6465448661217ede44d6b2ef..064abca17d78492a0e00ff529043ca432041cb46 160000 (submodule)
@@ -1 +1 @@
-Subproject commit 96aa7f066185995c6465448661217ede44d6b2ef
+Subproject commit 064abca17d78492a0e00ff529043ca432041cb46
index cb68f4ef0f538ca0a0e8b5c5b590b86e83c2af81..52435884a337f5883836fe48bde89b25f5d392f8 100644 (file)
@@ -665,8 +665,13 @@ loop_begin:
                        if ( id == base.e_id ) break;
                        /* Fall-thru */
 #endif
-               case LDAP_SCOPE_ONELEVEL:
                case LDAP_SCOPE_SUBTREE:
+                       if ( id == base.e_id ) {
+                               scopeok = 1;
+                               break;
+                       }
+                       /* Fall-thru */
+               case LDAP_SCOPE_ONELEVEL:
                        if ( mdb_idscopes( op, ltid, &idcursor, id, scopes ) == MDB_SUCCESS ) scopeok = 1;
                        break;
                }
index a44a018dff809a0e2c3df181c3b579086c86d4c1..acf8799d31e68f5ee4fcbc66e8f42aff31f7097b 100644 (file)
@@ -24,7 +24,7 @@
 #include "back-mdb.h"
 #include "idl.h"
 
-static MDB_txn *txn = NULL;
+static MDB_txn *txn = NULL, *txi = NULL;
 static MDB_cursor *cursor = NULL, *idcursor = NULL;
 static MDB_val key, data;
 static EntryHeader eh;
@@ -328,6 +328,9 @@ mdb_tool_entry_get_int( BackendDB *be, ID id, Entry **ep )
        if ( !BER_BVISNULL( &dn )) {
                e->e_name = dn;
                e->e_nname = ndn;
+       } else {
+               e->e_name.bv_val = NULL;
+               e->e_nname.bv_val = NULL;
        }
        e->e_bv = eh.bv;
 
@@ -551,20 +554,17 @@ ID mdb_tool_entry_put(
                goto done;
        }
 
-#if 0
-       if ( !mdb->bi_linear_index )
-               rc = mdb_tool_index_add( &op, tid, e );
+       rc = mdb_tool_index_add( &op, txn, e );
        if( rc != 0 ) {
                snprintf( text->bv_val, text->bv_len,
                                "index_entry_add failed: %s (%d)",
                                rc == LDAP_OTHER ? "Internal error" :
-                               db_strerror(rc), rc );
+                               mdb_strerror(rc), rc );
                Debug( LDAP_DEBUG_ANY,
                        "=> " LDAP_XSTRING(mdb_tool_entry_put) ": %s\n",
                        text->bv_val, 0, 0 );
                goto done;
        }
-#endif
 
 
        /* id2entry index */
@@ -621,7 +621,6 @@ int mdb_tool_entry_reindex(
        struct mdb_info *mi = (struct mdb_info *) be->be_private;
        int rc;
        Entry *e;
-       MDB_txn *tid = NULL;
        Operation op = {0};
        Opheader ohdr = {0};
 
@@ -689,8 +688,8 @@ int mdb_tool_entry_reindex(
                return -1;
        }
 
-       if ( !txn ) {
-               rc = mdb_txn_begin( mi->mi_dbenv, 0, &tid );
+       if ( !txi ) {
+               rc = mdb_txn_begin( mi->mi_dbenv, 0, &txi );
                if( rc != 0 ) {
                        Debug( LDAP_DEBUG_ANY,
                                "=> " LDAP_XSTRING(mdb_tool_entry_reindex) ": "
@@ -716,13 +715,13 @@ int mdb_tool_entry_reindex(
        op.o_tmpmemctx = NULL;
        op.o_tmpmfuncs = &ch_mfuncs;
 
-       rc = mdb_tool_index_add( &op, tid, e );
+       rc = mdb_tool_index_add( &op, txi, e );
 
 done:
        if( rc == 0 ) {
                mdb_writes++;
                if ( mdb_writes >= mdb_writes_per_commit ) {
-                       rc = mdb_txn_commit( tid );
+                       rc = mdb_txn_commit( txi );
                        if( rc != 0 ) {
                                Debug( LDAP_DEBUG_ANY,
                                        "=> " LDAP_XSTRING(mdb_tool_entry_reindex)
@@ -730,15 +729,17 @@ done:
                                        mdb_strerror(rc), rc, 0 );
                                e->e_id = NOID;
                        }
+                       txi = NULL;
                }
 
        } else {
-               mdb_txn_abort( tid );
+               mdb_txn_abort( txi );
                Debug( LDAP_DEBUG_ANY,
                        "=> " LDAP_XSTRING(mdb_tool_entry_reindex)
                        ": txn_aborted! %s (%d)\n",
                        mdb_strerror(rc), rc, 0 );
                e->e_id = NOID;
+               txi = NULL;
        }
        mdb_entry_release( &op, e, 0 );