1 /* tools.c - tools for slap tools */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2000-2005 The OpenLDAP Foundation.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted only as authorized by the OpenLDAP
12 * A copy of this license is available in the file LICENSE in the
13 * top-level directory of the distribution or, alternatively, at
14 * <http://www.OpenLDAP.org/license.html>.
20 #include <ac/string.h>
26 static DBC *cursor = NULL;
29 typedef struct dn_id {
34 #define HOLE_SIZE 4096
35 static dn_id hbuf[HOLE_SIZE], *holes = hbuf;
36 static unsigned nhmax = HOLE_SIZE;
37 static unsigned nholes;
39 static int index_nattrs;
41 #define bdb_tool_idl_cmp BDB_SYMBOL(tool_idl_cmp)
42 #define bdb_tool_idl_flush_one BDB_SYMBOL(tool_idl_flush_one)
43 #define bdb_tool_idl_flush BDB_SYMBOL(tool_idl_flush)
45 static int bdb_tool_idl_flush( BackendDB *be );
46 static int bdb_tool_ix_rec( int base );
47 static void * bdb_tool_index_task( void *ctx, void *ptr );
51 static ID *bdb_tool_idls;
52 static int bdb_tool_idl_next;
54 static ID bdb_tool_ix_id;
55 static Operation *bdb_tool_ix_op;
56 static volatile int *bdb_tool_index_threads;
57 static void *bdb_tool_index_rec;
58 static struct bdb_info *bdb_tool_info;
59 static ldap_pvt_thread_mutex_t bdb_tool_index_mutex;
60 static ldap_pvt_thread_cond_t bdb_tool_index_cond;
62 int bdb_tool_entry_open(
63 BackendDB *be, int mode )
65 struct bdb_info *bdb = (struct bdb_info *) be->be_private;
67 /* initialize key and data thangs */
70 key.flags = DB_DBT_REALLOC;
71 data.flags = DB_DBT_REALLOC;
74 int rc = bdb->bi_id2entry->bdi_db->cursor(
75 bdb->bi_id2entry->bdi_db, NULL, &cursor,
82 /* Set up for slapindex */
83 if ( !(slapMode & SLAP_TOOL_READONLY )) {
85 if ( bdb->bi_idl_cache_max_size )
86 bdb_tool_idls = ch_malloc( bdb->bi_idl_cache_max_size *
87 sizeof( ID ) * IDBLOCK );
88 if ( !bdb_tool_info && ( slapMode & SLAP_TOOL_QUICK )) {
89 ldap_pvt_thread_mutex_init( &bdb_tool_index_mutex );
90 ldap_pvt_thread_cond_init( &bdb_tool_index_cond );
91 bdb_tool_index_threads = ch_malloc( slap_tool_thread_max * sizeof( int ));
92 bdb_tool_index_rec = ch_malloc( bdb->bi_nattrs * sizeof( IndexRec ));
93 for (i=1; i<slap_tool_thread_max; i++) {
94 int *ptr = ch_malloc( sizeof( int ));
96 ldap_pvt_thread_pool_submit( &connection_pool,
97 bdb_tool_index_task, ptr );
98 ldap_pvt_thread_yield();
107 int bdb_tool_entry_close(
110 struct bdb_info *bdb = (struct bdb_info *) be->be_private;
112 if ( bdb_tool_info ) {
114 ldap_pvt_thread_mutex_lock( &bdb_tool_index_mutex );
115 ldap_pvt_thread_cond_broadcast( &bdb_tool_index_cond );
116 ldap_pvt_thread_mutex_unlock( &bdb_tool_index_mutex );
124 ch_free( data.data );
129 cursor->c_close( cursor );
133 bdb_tool_idl_flush( be );
135 free( bdb_tool_idls );
136 bdb_tool_idls = NULL;
137 bdb_tool_idl_next = 0;
141 fprintf( stderr, "Error, entries missing!\n");
142 for (i=0; i<nholes; i++) {
143 fprintf(stderr, " entry %ld: %s\n",
144 holes[i].id, holes[i].dn.bv_val);
152 ID bdb_tool_entry_next(
157 struct bdb_info *bdb = (struct bdb_info *) be->be_private;
159 assert( be != NULL );
160 assert( slapMode & SLAP_TOOL_MODE );
161 assert( bdb != NULL );
163 rc = cursor->c_get( cursor, &key, &data, DB_NEXT );
166 /* If we're doing linear indexing and there are more attrs to
167 * index, and we're at the end of the database, start over.
169 if ( index_nattrs && rc == DB_NOTFOUND ) {
170 /* optional - do a checkpoint here? */
171 bdb_attr_info_free( bdb->bi_attrs[0] );
172 bdb->bi_attrs[0] = bdb->bi_attrs[index_nattrs];
174 rc = cursor->c_get( cursor, &key, &data, DB_FIRST );
183 if( data.data == NULL ) {
187 BDB_DISK2ID( key.data, &id );
191 ID bdb_tool_dn2id_get(
198 EntryInfo *ei = NULL;
201 if ( BER_BVISEMPTY(dn) )
206 op.o_tmpmemctx = NULL;
207 op.o_tmpmfuncs = &ch_mfuncs;
209 rc = bdb_cache_find_ndn( &op, NULL, dn, &ei );
210 if ( ei ) bdb_cache_entryinfo_unlock( ei );
211 if ( rc == DB_NOTFOUND )
217 int bdb_tool_id2entry_get(
223 int rc = bdb_id2entry( be, NULL, 0, id, e );
225 if ( rc == DB_NOTFOUND && id == 0 ) {
226 Entry *dummy = ch_calloc( 1, sizeof(Entry) );
227 struct berval gluebv = BER_BVC("glue");
228 dummy->e_name.bv_val = ch_strdup( "" );
229 dummy->e_nname.bv_val = ch_strdup( "" );
230 attr_merge_one( dummy, slap_schema.si_ad_objectClass, &gluebv, NULL );
231 attr_merge_one( dummy, slap_schema.si_ad_structuralObjectClass,
239 Entry* bdb_tool_entry_get( BackendDB *be, ID id )
245 assert( be != NULL );
246 assert( slapMode & SLAP_TOOL_MODE );
247 assert( data.data != NULL );
249 DBT2bv( &data, &bv );
251 #ifdef SLAP_ZONE_ALLOC
252 /* FIXME: will add ctx later */
253 rc = entry_decode( &bv, &e, NULL );
255 rc = entry_decode( &bv, &e );
258 if( rc == LDAP_SUCCESS ) {
262 if ( slapMode & SLAP_TOOL_READONLY ) {
263 EntryInfo *ei = NULL;
269 op.o_tmpmemctx = NULL;
270 op.o_tmpmfuncs = &ch_mfuncs;
272 rc = bdb_cache_find_parent( &op, NULL, cursor->locker, id, &ei );
273 if ( rc == LDAP_SUCCESS ) {
274 bdb_cache_entryinfo_unlock( ei );
286 static int bdb_tool_next_id(
293 struct berval dn = e->e_name;
294 struct berval ndn = e->e_nname;
295 struct berval pdn, npdn;
296 EntryInfo *ei = NULL, eidummy;
299 if (ndn.bv_len == 0) {
304 rc = bdb_cache_find_ndn( op, tid, &ndn, &ei );
305 if ( ei ) bdb_cache_entryinfo_unlock( ei );
306 if ( rc == DB_NOTFOUND ) {
307 if ( !be_issuffix( op->o_bd, &ndn ) ) {
309 dnParent( &dn, &pdn );
310 dnParent( &ndn, &npdn );
313 rc = bdb_tool_next_id( op, tid, e, text, 1 );
319 /* If parent didn't exist, it was created just now
320 * and its ID is now in e->e_id. Make sure the current
321 * entry gets added under the new parent ID.
323 if ( eid != e->e_id ) {
324 eidummy.bei_id = e->e_id;
328 rc = bdb_next_id( op->o_bd, tid, &e->e_id );
330 snprintf( text->bv_val, text->bv_len,
331 "next_id failed: %s (%d)",
332 db_strerror(rc), rc );
333 Debug( LDAP_DEBUG_ANY,
334 "=> bdb_tool_next_id: %s\n", text->bv_val, 0, 0 );
337 rc = bdb_dn2id_add( op, tid, ei, e );
339 snprintf( text->bv_val, text->bv_len,
340 "dn2id_add failed: %s (%d)",
341 db_strerror(rc), rc );
342 Debug( LDAP_DEBUG_ANY,
343 "=> bdb_tool_next_id: %s\n", text->bv_val, 0, 0 );
345 if ( nholes == nhmax - 1 ) {
346 if ( holes == hbuf ) {
347 holes = ch_malloc( nhmax * sizeof(dn_id) * 2 );
348 AC_MEMCPY( holes, hbuf, sizeof(hbuf) );
350 holes = ch_realloc( holes, nhmax * sizeof(dn_id) * 2 );
354 ber_dupbv( &holes[nholes].dn, &ndn );
355 holes[nholes++].id = e->e_id;
357 } else if ( !hole ) {
360 e->e_id = ei->bei_id;
362 for ( i=0; i<nholes; i++) {
363 if ( holes[i].id == e->e_id ) {
365 free(holes[i].dn.bv_val);
366 for (j=i;j<nholes;j++) holes[j] = holes[j+1];
370 } else if ( holes[i].id > e->e_id ) {
384 struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
386 if ( slapMode & SLAP_TOOL_QUICK ) {
391 ir = bdb_tool_index_rec;
392 memset(ir, 0, bdb->bi_nattrs * sizeof( IndexRec ));
394 for ( a = e->e_attrs; a != NULL; a = a->a_next ) {
395 rc = bdb_index_recset( bdb, a, a->a_desc->ad_type,
396 &a->a_desc->ad_tags, ir );
400 bdb_tool_ix_id = e->e_id;
402 ldap_pvt_thread_mutex_lock( &bdb_tool_index_mutex );
403 for ( i=1; i<slap_tool_thread_max; i++ )
404 bdb_tool_index_threads[i] = LDAP_BUSY;
405 ldap_pvt_thread_cond_broadcast( &bdb_tool_index_cond );
406 ldap_pvt_thread_mutex_unlock( &bdb_tool_index_mutex );
407 rc = bdb_index_recrun( op, bdb, ir, e->e_id, 0 );
410 for ( i=1; i<slap_tool_thread_max; i++ ) {
411 if ( bdb_tool_index_threads[i] == LDAP_BUSY ) {
412 ldap_pvt_thread_yield();
416 if ( bdb_tool_index_threads[i] )
417 return bdb_tool_index_threads[i];
421 return bdb_index_entry_add( op, txn, e );
425 ID bdb_tool_entry_put(
428 struct berval *text )
431 struct bdb_info *bdb = (struct bdb_info *) be->be_private;
436 assert( be != NULL );
437 assert( slapMode & SLAP_TOOL_MODE );
439 assert( text != NULL );
440 assert( text->bv_val != NULL );
441 assert( text->bv_val[0] == '\0' ); /* overconservative? */
443 Debug( LDAP_DEBUG_TRACE, "=> " LDAP_XSTRING(bdb_tool_entry_put)
444 "( %ld, \"%s\" )\n", (long) e->e_id, e->e_dn, 0 );
446 if (! (slapMode & SLAP_TOOL_QUICK)) {
447 rc = TXN_BEGIN( bdb->bi_dbenv, NULL, &tid,
448 bdb->bi_db_opflags );
450 snprintf( text->bv_val, text->bv_len,
451 "txn_begin failed: %s (%d)",
452 db_strerror(rc), rc );
453 Debug( LDAP_DEBUG_ANY,
454 "=> " LDAP_XSTRING(bdb_tool_entry_put) ": %s\n",
455 text->bv_val, 0, 0 );
462 op.o_tmpmemctx = NULL;
463 op.o_tmpmfuncs = &ch_mfuncs;
465 /* add dn2id indices */
466 rc = bdb_tool_next_id( &op, tid, e, text, 0 );
472 rc = bdb_id2entry_add( be, tid, e );
474 snprintf( text->bv_val, text->bv_len,
475 "id2entry_add failed: %s (%d)",
476 db_strerror(rc), rc );
477 Debug( LDAP_DEBUG_ANY,
478 "=> " LDAP_XSTRING(bdb_tool_entry_put) ": %s\n",
479 text->bv_val, 0, 0 );
483 if ( !bdb->bi_linear_index )
484 rc = bdb_tool_index_add( &op, tid, e );
486 snprintf( text->bv_val, text->bv_len,
487 "index_entry_add failed: %s (%d)",
488 db_strerror(rc), rc );
489 Debug( LDAP_DEBUG_ANY,
490 "=> " LDAP_XSTRING(bdb_tool_entry_put) ": %s\n",
491 text->bv_val, 0, 0 );
497 if ( !( slapMode & SLAP_TOOL_QUICK )) {
498 rc = TXN_COMMIT( tid, 0 );
500 snprintf( text->bv_val, text->bv_len,
501 "txn_commit failed: %s (%d)",
502 db_strerror(rc), rc );
503 Debug( LDAP_DEBUG_ANY,
504 "=> " LDAP_XSTRING(bdb_tool_entry_put) ": %s\n",
505 text->bv_val, 0, 0 );
511 if ( !( slapMode & SLAP_TOOL_QUICK )) {
513 snprintf( text->bv_val, text->bv_len,
514 "txn_aborted! %s (%d)",
515 db_strerror(rc), rc );
516 Debug( LDAP_DEBUG_ANY,
517 "=> " LDAP_XSTRING(bdb_tool_entry_put) ": %s\n",
518 text->bv_val, 0, 0 );
526 int bdb_tool_entry_reindex(
530 struct bdb_info *bi = (struct bdb_info *) be->be_private;
537 Debug( LDAP_DEBUG_ARGS,
538 "=> " LDAP_XSTRING(bdb_tool_entry_reindex) "( %ld )\n",
541 /* No indexes configured, nothing to do. Could return an
542 * error here to shortcut things.
548 /* Get the first attribute to index */
549 if (bi->bi_linear_index && !index_nattrs) {
550 index_nattrs = bi->bi_nattrs - 1;
554 e = bdb_tool_entry_get( be, id );
557 Debug( LDAP_DEBUG_ANY,
558 LDAP_XSTRING(bdb_tool_entry_reindex)
559 ": could not locate id=%ld\n",
564 if (! (slapMode & SLAP_TOOL_QUICK)) {
565 rc = TXN_BEGIN( bi->bi_dbenv, NULL, &tid, bi->bi_db_opflags );
567 Debug( LDAP_DEBUG_ANY,
568 "=> " LDAP_XSTRING(bdb_tool_entry_reindex) ": "
569 "txn_begin failed: %s (%d)\n",
570 db_strerror(rc), rc, 0 );
576 * just (re)add them for now
577 * assume that some other routine (not yet implemented)
578 * will zap index databases
582 Debug( LDAP_DEBUG_TRACE,
583 "=> " LDAP_XSTRING(bdb_tool_entry_reindex) "( %ld, \"%s\" )\n",
584 (long) id, e->e_dn, 0 );
588 op.o_tmpmemctx = NULL;
589 op.o_tmpmfuncs = &ch_mfuncs;
591 rc = bdb_tool_index_add( &op, tid, e );
595 if (! (slapMode & SLAP_TOOL_QUICK)) {
596 rc = TXN_COMMIT( tid, 0 );
598 Debug( LDAP_DEBUG_ANY,
599 "=> " LDAP_XSTRING(bdb_tool_entry_reindex)
600 ": txn_commit failed: %s (%d)\n",
601 db_strerror(rc), rc, 0 );
607 if (! (slapMode & SLAP_TOOL_QUICK)) {
609 Debug( LDAP_DEBUG_ANY,
610 "=> " LDAP_XSTRING(bdb_tool_entry_reindex)
611 ": txn_aborted! %s (%d)\n",
612 db_strerror(rc), rc, 0 );
616 bdb_entry_release( &op, e, 0 );
621 ID bdb_tool_entry_modify(
624 struct berval *text )
627 struct bdb_info *bdb = (struct bdb_info *) be->be_private;
632 assert( be != NULL );
633 assert( slapMode & SLAP_TOOL_MODE );
635 assert( text != NULL );
636 assert( text->bv_val != NULL );
637 assert( text->bv_val[0] == '\0' ); /* overconservative? */
639 assert ( e->e_id != NOID );
641 Debug( LDAP_DEBUG_TRACE,
642 "=> " LDAP_XSTRING(bdb_tool_entry_modify) "( %ld, \"%s\" )\n",
643 (long) e->e_id, e->e_dn, 0 );
645 if (! (slapMode & SLAP_TOOL_QUICK)) {
646 rc = TXN_BEGIN( bdb->bi_dbenv, NULL, &tid,
647 bdb->bi_db_opflags );
649 snprintf( text->bv_val, text->bv_len,
650 "txn_begin failed: %s (%d)",
651 db_strerror(rc), rc );
652 Debug( LDAP_DEBUG_ANY,
653 "=> " LDAP_XSTRING(bdb_tool_entry_modify) ": %s\n",
654 text->bv_val, 0, 0 );
661 op.o_tmpmemctx = NULL;
662 op.o_tmpmfuncs = &ch_mfuncs;
665 rc = bdb_id2entry_update( be, tid, e );
667 snprintf( text->bv_val, text->bv_len,
668 "id2entry_add failed: %s (%d)",
669 db_strerror(rc), rc );
670 Debug( LDAP_DEBUG_ANY,
671 "=> " LDAP_XSTRING(bdb_tool_entry_modify) ": %s\n",
672 text->bv_val, 0, 0 );
677 /* FIXME: this is bogus, we don't have the old values to delete
678 * from the index because the given entry has already been modified.
680 rc = bdb_index_entry_del( &op, tid, e );
682 snprintf( text->bv_val, text->bv_len,
683 "index_entry_del failed: %s (%d)",
684 db_strerror(rc), rc );
685 Debug( LDAP_DEBUG_ANY,
686 "=> " LDAP_XSTRING(bdb_tool_entry_modify) ": %s\n",
687 text->bv_val, 0, 0 );
692 rc = bdb_index_entry_add( &op, tid, e );
694 snprintf( text->bv_val, text->bv_len,
695 "index_entry_add failed: %s (%d)",
696 db_strerror(rc), rc );
697 Debug( LDAP_DEBUG_ANY,
698 "=> " LDAP_XSTRING(bdb_tool_entry_modify) ": %s\n",
699 text->bv_val, 0, 0 );
705 if (! (slapMode & SLAP_TOOL_QUICK)) {
706 rc = TXN_COMMIT( tid, 0 );
708 snprintf( text->bv_val, text->bv_len,
709 "txn_commit failed: %s (%d)",
710 db_strerror(rc), rc );
711 Debug( LDAP_DEBUG_ANY,
712 "=> " LDAP_XSTRING(bdb_tool_entry_modify) ": "
713 "%s\n", text->bv_val, 0, 0 );
719 if (! (slapMode & SLAP_TOOL_QUICK)) {
721 snprintf( text->bv_val, text->bv_len,
722 "txn_aborted! %s (%d)",
723 db_strerror(rc), rc );
724 Debug( LDAP_DEBUG_ANY,
725 "=> " LDAP_XSTRING(bdb_tool_entry_modify) ": %s\n",
726 text->bv_val, 0, 0 );
735 typedef struct bdb_tool_idl_cache {
738 int idls[BDB_IDL_DB_SIZE / IDBLOCK];
740 } bdb_tool_idl_cache;
743 bdb_tool_idl_cmp( const void *v1, const void *v2 )
745 const bdb_tool_idl_cache *c1 = v1, *c2 = v2;
748 if (( rc = c1->kstr.bv_len - c2->kstr.bv_len )) return rc;
749 return memcmp( c1->kstr.bv_val, c2->kstr.bv_val, c1->kstr.bv_len );
753 bdb_tool_idl_flush_one( void *v1, void *arg )
755 bdb_tool_idl_cache *ic = v1;
767 rc = db->cursor( db, NULL, &curs, 0 );
774 bv2DBT( &ic->kstr, &key );
776 data.size = data.ulen = sizeof( ID );
777 data.flags = DB_DBT_USERMEM;
780 rc = curs->c_get( curs, &key, &data, DB_SET );
781 /* If key already exists and we're writing a range... */
782 if ( rc == 0 && ic->count > BDB_IDL_DB_SIZE ) {
783 /* If it's not currently a range, must delete old info */
786 while ( curs->c_get( curs, &key, &data, DB_NEXT_DUP ) == 0 )
787 curs->c_del( curs, 0 );
790 /* Store range marker */
791 curs->c_put( curs, &key, &data, DB_KEYFIRST );
795 rc = curs->c_get( curs, &key, &data, DB_NEXT_DUP );
798 rc = curs->c_get( curs, &key, &data, DB_NEXT_DUP );
801 curs->c_del( curs, 0 );
803 BDB_ID2DISK( ic->last, &nid );
804 curs->c_put( curs, &key, &data, DB_KEYLAST );
806 } else if ( rc && rc != DB_NOTFOUND ) {
808 } else if ( ic->count > BDB_IDL_DB_SIZE ) {
809 /* range, didn't exist before */
811 rc = curs->c_put( curs, &key, &data, DB_KEYLAST );
813 BDB_ID2DISK( ic->first, &nid );
814 rc = curs->c_put( curs, &key, &data, DB_KEYLAST );
816 BDB_ID2DISK( ic->last, &nid );
817 rc = curs->c_put( curs, &key, &data, DB_KEYLAST );
826 /* Just a normal write */
828 for ( n=0; n<=ic->idn; n++ ) {
829 ID *ids = bdb_tool_idls + ic->idls[n];
834 end = ic->count & (IDBLOCK-1);
838 for ( i=0; i<end; i++ ) {
839 if ( !ids[i] ) continue;
840 BDB_ID2DISK( ids[i], &nid );
841 rc = curs->c_put( curs, &key, &data, DB_NODUPDATA );
843 if ( rc == DB_KEYEXIST ) {
858 curs->c_close( curs );
863 bdb_tool_idl_flush( BackendDB *be )
865 struct bdb_info *bdb = (struct bdb_info *) be->be_private;
870 for ( i=BDB_NDB; i < bdb->bi_ndatabases; i++ ) {
871 db = bdb->bi_databases[i]->bdi_db;
872 if ( !db->app_private ) continue;
873 rc = avl_apply( db->app_private, bdb_tool_idl_flush_one, db, -1,
875 avl_free( db->app_private, NULL );
876 db->app_private = NULL;
882 bdb->bi_idl_cache_size = 0;
883 bdb_tool_idl_next = 0;
888 int bdb_tool_idl_add(
895 struct bdb_info *bdb = (struct bdb_info *) be->be_private;
896 bdb_tool_idl_cache *ic, itmp;
901 if ( !bdb->bi_idl_cache_max_size )
902 return bdb_idl_insert_key( be, db, txn, key, id );
904 DBT2bv( key, &itmp.kstr );
907 root = db->app_private;
909 ic = avl_find( root, &itmp, bdb_tool_idl_cmp );
911 /* No entry yet, create one */
918 ic = ch_malloc( sizeof( bdb_tool_idl_cache ) + itmp.kstr.bv_len );
919 ic->kstr.bv_len = itmp.kstr.bv_len;
920 ic->kstr.bv_val = (char *)(ic+1);
921 AC_MEMCPY( ic->kstr.bv_val, itmp.kstr.bv_val, ic->kstr.bv_len );
925 avl_insert( &root, ic, bdb_tool_idl_cmp, avl_dup_error );
926 db->app_private = root;
928 /* load existing key count here */
929 rc = db->cursor( db, NULL, &curs, 0 );
932 data.ulen = sizeof( ID );
933 data.flags = DB_DBT_USERMEM;
935 rc = curs->c_get( curs, key, &data, DB_SET );
938 ic->count = BDB_IDL_DB_SIZE+1;
942 curs->c_count( curs, &count, 0 );
944 BDB_DISK2ID( &nid, &ic->first );
947 curs->c_close( curs );
949 /* are we a range already? */
950 if ( ic->count > BDB_IDL_DB_SIZE ) {
953 /* Are we at the limit, and converting to a range? */
954 } else if ( ic->count == BDB_IDL_DB_SIZE ) {
960 /* No free block, create that too */
961 if ( ic->idn == -1 || ( ic->count & (IDBLOCK-1)) == 0) {
962 ldap_pvt_thread_mutex_lock( &bdb->bi_idl_tree_lrulock );
963 bdb->bi_idl_cache_size++;
964 if ( bdb->bi_idl_cache_size > bdb->bi_idl_cache_max_size ) {
965 rc = bdb_tool_idl_flush( be );
966 ldap_pvt_thread_mutex_unlock( &bdb->bi_idl_tree_lrulock );
971 ic->idls[++ic->idn] = bdb_tool_idl_next;
972 ids = bdb_tool_idls + bdb_tool_idl_next;
973 bdb_tool_idl_next += IDBLOCK;
974 ldap_pvt_thread_mutex_unlock( &bdb->bi_idl_tree_lrulock );
976 memset( ids, 0, IDBLOCK * sizeof( ID ));
980 ids = bdb_tool_idls + ic->idls[ic->idn];
981 ids[ ic->count & (IDBLOCK-1) ] = id;
988 bdb_tool_index_task( void *ctx, void *ptr )
990 int base = *(int *)ptr;
994 ldap_pvt_thread_mutex_lock( &bdb_tool_index_mutex );
995 ldap_pvt_thread_cond_wait( &bdb_tool_index_cond,
996 &bdb_tool_index_mutex );
997 ldap_pvt_thread_mutex_unlock( &bdb_tool_index_mutex );
998 if ( slapd_shutdown )
1001 bdb_tool_index_threads[base] = bdb_index_recrun( bdb_tool_ix_op,
1002 bdb_tool_info, bdb_tool_index_rec, bdb_tool_ix_id, base );