]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/back-mdb/tools.c
Merge branch 'mdb.master' of ssh://git-master.openldap.org/~git/git/openldap
[openldap] / servers / slapd / back-mdb / tools.c
index 1e95a48d537ca5439a1180cc9d9fb92d6f6b036f..1d2c625ad86162bdc65c58eb45b2c43c945ae6f0 100644 (file)
@@ -27,7 +27,6 @@
 static MDB_txn *txn = NULL, *txi = NULL;
 static MDB_cursor *cursor = NULL, *idcursor = NULL;
 static MDB_val key, data;
-static EntryHeader eh;
 static ID previd = NOID;
 
 typedef struct dn_id {
@@ -155,7 +154,7 @@ int mdb_tool_entry_close(
                nholes = 0;
                return -1;
        }
-                       
+
        return 0;
 }
 
@@ -169,7 +168,7 @@ mdb_tool_entry_first_x(
        tool_base = base;
        tool_scope = scope;
        tool_filter = f;
-       
+
        return mdb_tool_entry_next( be );
 }
 
@@ -270,13 +269,16 @@ ID mdb_tool_dn2id_get(
        rc = mdb_dn2id( &op, txn, dn, &id, NULL, NULL );
        if ( rc == MDB_NOTFOUND )
                return NOID;
-       
+
        return id;
 }
 
 static int
 mdb_tool_entry_get_int( BackendDB *be, ID id, Entry **ep )
 {
+       Operation op = {0};
+       Opheader ohdr = {0};
+
        Entry *e = NULL;
        struct berval dn = BER_BVNULL, ndn = BER_BVNULL;
        int rc;
@@ -300,19 +302,15 @@ mdb_tool_entry_get_int( BackendDB *be, ID id, Entry **ep )
                }
        }
 
+       op.o_hdr = &ohdr;
+       op.o_bd = be;
+       op.o_tmpmemctx = NULL;
+       op.o_tmpmfuncs = &ch_mfuncs;
        if ( slapMode & SLAP_TOOL_READONLY ) {
-               Operation op = {0};
-               Opheader ohdr = {0};
-
-               op.o_hdr = &ohdr;
-               op.o_bd = be;
-               op.o_tmpmemctx = NULL;
-               op.o_tmpmfuncs = &ch_mfuncs;
-
                rc = mdb_id2name( &op, txn, &idcursor, id, &dn, &ndn );
                if ( rc  ) {
                        rc = LDAP_OTHER;
-                       mdb_entry_return( e );
+                       mdb_entry_return( &op, e );
                        e = NULL;
                        goto done;
                }
@@ -324,18 +322,7 @@ mdb_tool_entry_get_int( BackendDB *be, ID id, Entry **ep )
                        }
                }
        }
-       /* Get the header */
-       eh.bv.bv_val = data.mv_data;
-       eh.bv.bv_len = data.mv_size;
-
-       rc = entry_header( &eh );
-       if ( rc ) {
-               rc = LDAP_OTHER;
-               goto done;
-       }
-       eh.bv.bv_len = eh.nvals * sizeof( struct berval );
-       eh.bv.bv_val = ch_malloc( eh.bv.bv_len );
-       rc = entry_decode( &eh, &e );
+       rc = mdb_entry_decode( &op, &data, &e );
        e->e_id = id;
        if ( !BER_BVISNULL( &dn )) {
                e->e_name = dn;
@@ -344,7 +331,6 @@ mdb_tool_entry_get_int( BackendDB *be, ID id, Entry **ep )
                e->e_name.bv_val = NULL;
                e->e_nname.bv_val = NULL;
        }
-       e->e_bv = eh.bv;
 
 done:
        if ( e != NULL ) {
@@ -370,6 +356,7 @@ static int mdb_tool_next_id(
        struct berval *text,
        int hole )
 {
+       struct mdb_info *mdb = (struct mdb_info *) op->o_bd->be_private;
        struct berval dn = e->e_name;
        struct berval ndn = e->e_nname;
        struct berval pdn, npdn, nmatched;
@@ -418,12 +405,13 @@ static int mdb_tool_next_id(
                }
                rc = mdb_dn2id_add( op, tid, pid, e );
                if ( rc ) {
-                       snprintf( text->bv_val, text->bv_len, 
+                       snprintf( text->bv_val, text->bv_len,
                                "dn2id_add failed: %s (%d)",
                                mdb_strerror(rc), rc );
-               Debug( LDAP_DEBUG_ANY,
-                       "=> mdb_tool_next_id: %s\n", text->bv_val, 0, 0 );
+                       Debug( LDAP_DEBUG_ANY,
+                               "=> mdb_tool_next_id: %s\n", text->bv_val, 0, 0 );
                } else if ( hole ) {
+                       MDB_val key, data;
                        if ( nholes == nhmax - 1 ) {
                                if ( holes == hbuf ) {
                                        holes = ch_malloc( nhmax * sizeof(dn_id) * 2 );
@@ -435,6 +423,20 @@ static int mdb_tool_next_id(
                        }
                        ber_dupbv( &holes[nholes].dn, &ndn );
                        holes[nholes++].id = e->e_id;
+                       key.mv_size = sizeof(ID);
+                       key.mv_data = &e->e_id;
+                       data.mv_size = 0;
+                       data.mv_data = NULL;
+                       rc = mdb_put( tid, mdb->mi_id2entry, &key, &data, MDB_NOOVERWRITE );
+                       if ( rc == MDB_KEYEXIST )
+                               rc = 0;
+                       if ( rc ) {
+                               snprintf( text->bv_val, text->bv_len,
+                                       "dummy id2entry add failed: %s (%d)",
+                                       mdb_strerror(rc), rc );
+                               Debug( LDAP_DEBUG_ANY,
+                                       "=> mdb_tool_next_id: %s\n", text->bv_val, 0, 0 );
+                       }
                }
        } else if ( !hole ) {
                unsigned i, j;
@@ -472,12 +474,12 @@ mdb_tool_index_add(
                IndexRec *ir;
                int i, rc;
                Attribute *a;
-               
+
                ir = mdb_tool_index_rec;
                memset(ir, 0, mdb->bi_nattrs * sizeof( IndexRec ));
 
                for ( a = e->e_attrs; a != NULL; a = a->a_next ) {
-                       rc = mdb_index_recset( mdb, a, a->a_desc->ad_type, 
+                       rc = mdb_index_recset( mdb, a, a->a_desc->ad_type,
                                &a->a_desc->ad_tags, ir );
                        if ( rc )
                                return rc;
@@ -487,7 +489,7 @@ mdb_tool_index_add(
                ldap_pvt_thread_mutex_lock( &mdb_tool_index_mutex );
                /* Wait for all threads to be ready */
                while ( mdb_tool_index_tcount ) {
-                       ldap_pvt_thread_cond_wait( &mdb_tool_index_cond_main, 
+                       ldap_pvt_thread_cond_wait( &mdb_tool_index_cond_main,
                                &mdb_tool_index_mutex );
                }
                for ( i=1; i<slap_tool_thread_max; i++ )
@@ -501,7 +503,7 @@ mdb_tool_index_add(
                ldap_pvt_thread_mutex_lock( &mdb_tool_index_mutex );
                for ( i=1; i<slap_tool_thread_max; i++ ) {
                        if ( mdb_tool_index_threads[i] == LDAP_BUSY ) {
-                               ldap_pvt_thread_cond_wait( &mdb_tool_index_cond_main, 
+                               ldap_pvt_thread_cond_wait( &mdb_tool_index_cond_main,
                                        &mdb_tool_index_mutex );
                                i--;
                                continue;
@@ -569,9 +571,7 @@ ID mdb_tool_entry_put(
        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" :
-                               mdb_strerror(rc), rc );
+                               "index_entry_add failed: err=%d", rc );
                Debug( LDAP_DEBUG_ANY,
                        "=> " LDAP_XSTRING(mdb_tool_entry_put) ": %s\n",
                        text->bv_val, 0, 0 );
@@ -583,8 +583,7 @@ ID mdb_tool_entry_put(
        rc = mdb_id2entry_add( &op, txn, e );
        if( rc != 0 ) {
                snprintf( text->bv_val, text->bv_len,
-                               "id2entry_add failed: %s (%d)",
-                               mdb_strerror(rc), rc );
+                               "id2entry_add failed: err=%d", rc );
                Debug( LDAP_DEBUG_ANY,
                        "=> " LDAP_XSTRING(mdb_tool_entry_put) ": %s\n",
                        text->bv_val, 0, 0 );
@@ -710,7 +709,7 @@ int mdb_tool_entry_reindex(
                        goto done;
                }
        }
-       
+
        /*
         * just (re)add them for now
         * assume that some other routine (not yet implemented)
@@ -748,8 +747,8 @@ done:
                mdb_txn_abort( txi );
                Debug( LDAP_DEBUG_ANY,
                        "=> " LDAP_XSTRING(mdb_tool_entry_reindex)
-                       ": txn_aborted! %s (%d)\n",
-                       mdb_strerror(rc), rc, 0 );
+                       ": txn_aborted! err=%d\n",
+                       rc, 0, 0 );
                e->e_id = NOID;
                txi = NULL;
        }
@@ -808,8 +807,7 @@ ID mdb_tool_entry_modify(
        rc = mdb_id2entry_update( &op, tid, e );
        if( rc != 0 ) {
                snprintf( text->bv_val, text->bv_len,
-                               "id2entry_add failed: %s (%d)",
-                               mdb_strerror(rc), rc );
+                               "id2entry_update failed: err=%d", rc );
                Debug( LDAP_DEBUG_ANY,
                        "=> " LDAP_XSTRING(mdb_tool_entry_modify) ": %s\n",
                        text->bv_val, 0, 0 );