]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/back-mdb/tools.c
Happy New Year
[openldap] / servers / slapd / back-mdb / tools.c
index 90cbd320b1e2159da36ea85fe0834cb4c6039deb..7b490a595fc2722d9e104e9580dbcc5a0b8cbd3d 100644 (file)
@@ -2,7 +2,7 @@
 /* $OpenLDAP$ */
 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
  *
- * Copyright 2011-2012 The OpenLDAP Foundation.
+ * Copyright 2011-2013 The OpenLDAP Foundation.
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -106,7 +106,9 @@ int mdb_tool_entry_open(
                        ldap_pvt_thread_cond_init( &mdb_tool_index_cond_work );
                        if ( mdb->mi_nattrs ) {
                                int i;
+#if 0                  /* threaded indexing has no performance advantage */
                                mdb_tool_threads = slap_tool_thread_max - 1;
+#endif
                                if ( mdb_tool_threads > 1 ) {
                                        mdb_tool_index_rec = ch_calloc( mdb->mi_nattrs, sizeof( IndexRec ));
                                        mdb_tool_index_tcount = mdb_tool_threads - 1;
@@ -231,6 +233,9 @@ next:;
        previd = *(ID *)key.mv_data;
        id = previd;
 
+       if ( !data.mv_size )
+               goto next;
+
        if ( tool_filter || tool_base ) {
                static Operation op = {0};
                static Opheader ohdr = {0};
@@ -326,6 +331,10 @@ mdb_tool_entry_get_int( BackendDB *be, ID id, Entry **ep )
                        goto done;
                }
        }
+       if ( !data.mv_size ) {
+               rc = LDAP_NO_SUCH_OBJECT;
+               goto done;
+       }
 
        op.o_hdr = &ohdr;
        op.o_bd = be;
@@ -346,6 +355,7 @@ mdb_tool_entry_get_int( BackendDB *be, ID id, Entry **ep )
                                ch_free( dn.bv_val );
                                ch_free( ndn.bv_val );
                                rc = LDAP_NO_SUCH_OBJECT;
+                               goto done;
                        }
                }
        }
@@ -844,6 +854,7 @@ done:
        if( rc == 0 ) {
                mdb_writes++;
                if ( mdb_writes >= mdb_writes_per_commit ) {
+                       MDB_val key;
                        unsigned i;
                        MDB_TOOL_IDL_FLUSH( be, txi );
                        rc = mdb_txn_commit( txi );
@@ -857,12 +868,23 @@ done:
                                        mdb_strerror(rc), rc, 0 );
                                e->e_id = NOID;
                        }
+                       mdb_cursor_close( cursor );
                        txi = NULL;
+                       /* Must close the read txn to allow old pages to be reclaimed. */
+                       mdb_txn_abort( txn );
+                       /* and then reopen it so that tool_entry_next still works. */
+                       mdb_txn_begin( mi->mi_dbenv, NULL, MDB_RDONLY, &txn );
+                       mdb_cursor_open( txn, mi->mi_id2entry, &cursor );
+                       key.mv_data = &id;
+                       key.mv_size = sizeof(ID);
+                       mdb_cursor_get( cursor, &key, NULL, MDB_SET );
                }
 
        } else {
                unsigned i;
                mdb_writes = 0;
+               mdb_cursor_close( cursor );
+               cursor = NULL;
                mdb_txn_abort( txi );
                for ( i=0; i<mi->mi_nattrs; i++ )
                        mi->mi_attrs[i]->ai_cursor = NULL;