1 /* tools.c - tools for slap tools */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2000-2008 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 #ifdef BDB_TOOL_IDL_CACHING
42 #define bdb_tool_idl_cmp BDB_SYMBOL(tool_idl_cmp)
43 #define bdb_tool_idl_flush_one BDB_SYMBOL(tool_idl_flush_one)
44 #define bdb_tool_idl_flush BDB_SYMBOL(tool_idl_flush)
46 static int bdb_tool_idl_flush( BackendDB *be );
50 typedef struct bdb_tool_idl_cache_entry {
51 struct bdb_tool_idl_cache_entry *next;
53 } bdb_tool_idl_cache_entry;
55 typedef struct bdb_tool_idl_cache {
57 bdb_tool_idl_cache_entry *head, *tail;
62 static bdb_tool_idl_cache_entry *bdb_tool_idl_free_list;
63 #endif /* BDB_TOOL_IDL_CACHING */
65 static ID bdb_tool_ix_id;
66 static Operation *bdb_tool_ix_op;
67 static int *bdb_tool_index_threads, bdb_tool_index_tcount;
68 static void *bdb_tool_index_rec;
69 static struct bdb_info *bdb_tool_info;
70 static ldap_pvt_thread_mutex_t bdb_tool_index_mutex;
71 static ldap_pvt_thread_cond_t bdb_tool_index_cond;
73 static void * bdb_tool_index_task( void *ctx, void *ptr );
75 int bdb_tool_entry_open(
76 BackendDB *be, int mode )
78 struct bdb_info *bdb = (struct bdb_info *) be->be_private;
80 /* initialize key and data thangs */
83 key.flags = DB_DBT_REALLOC;
84 data.flags = DB_DBT_REALLOC;
87 int rc = bdb->bi_id2entry->bdi_db->cursor(
88 bdb->bi_id2entry->bdi_db, NULL, &cursor,
95 /* Set up for threaded slapindex */
96 if (( slapMode & (SLAP_TOOL_QUICK|SLAP_TOOL_READONLY)) == SLAP_TOOL_QUICK
98 if ( !bdb_tool_info ) {
100 ldap_pvt_thread_mutex_init( &bdb_tool_index_mutex );
101 ldap_pvt_thread_cond_init( &bdb_tool_index_cond );
102 bdb_tool_index_threads = ch_malloc( slap_tool_thread_max * sizeof( int ));
103 bdb_tool_index_rec = ch_malloc( bdb->bi_nattrs * sizeof( IndexRec ));
104 bdb_tool_index_tcount = slap_tool_thread_max - 1;
105 for (i=1; i<slap_tool_thread_max; i++) {
106 int *ptr = ch_malloc( sizeof( int ));
108 ldap_pvt_thread_pool_submit( &connection_pool,
109 bdb_tool_index_task, ptr );
118 int bdb_tool_entry_close(
121 if ( bdb_tool_info ) {
123 ldap_pvt_thread_mutex_lock( &bdb_tool_index_mutex );
124 bdb_tool_index_tcount = slap_tool_thread_max - 1;
125 ldap_pvt_thread_cond_broadcast( &bdb_tool_index_cond );
126 ldap_pvt_thread_mutex_unlock( &bdb_tool_index_mutex );
134 ch_free( data.data );
139 cursor->c_close( cursor );
143 #ifdef BDB_TOOL_IDL_CACHING
144 bdb_tool_idl_flush( be );
149 fprintf( stderr, "Error, entries missing!\n");
150 for (i=0; i<nholes; i++) {
151 fprintf(stderr, " entry %ld: %s\n",
152 holes[i].id, holes[i].dn.bv_val);
160 ID bdb_tool_entry_next(
165 struct bdb_info *bdb = (struct bdb_info *) be->be_private;
167 assert( be != NULL );
168 assert( slapMode & SLAP_TOOL_MODE );
169 assert( bdb != NULL );
171 rc = cursor->c_get( cursor, &key, &data, DB_NEXT );
174 /* If we're doing linear indexing and there are more attrs to
175 * index, and we're at the end of the database, start over.
177 if ( index_nattrs && rc == DB_NOTFOUND ) {
178 /* optional - do a checkpoint here? */
179 bdb_attr_info_free( bdb->bi_attrs[0] );
180 bdb->bi_attrs[0] = bdb->bi_attrs[index_nattrs];
182 rc = cursor->c_get( cursor, &key, &data, DB_FIRST );
191 if( data.data == NULL ) {
195 BDB_DISK2ID( key.data, &id );
199 ID bdb_tool_dn2id_get(
206 EntryInfo *ei = NULL;
209 if ( BER_BVISEMPTY(dn) )
214 op.o_tmpmemctx = NULL;
215 op.o_tmpmfuncs = &ch_mfuncs;
217 rc = bdb_cache_find_ndn( &op, 0, dn, &ei );
218 if ( ei ) bdb_cache_entryinfo_unlock( ei );
219 if ( rc == DB_NOTFOUND )
225 int bdb_tool_id2entry_get(
234 BDB_ID2DISK( id, &nid );
235 key.ulen = key.size = sizeof(ID);
236 key.flags = DB_DBT_USERMEM;
239 rc = cursor->c_get( cursor, &key, &data, DB_SET );
241 *e = bdb_tool_entry_get( be, id );
250 Entry* bdb_tool_entry_get( BackendDB *be, ID id )
256 assert( be != NULL );
257 assert( slapMode & SLAP_TOOL_MODE );
258 assert( data.data != NULL );
260 DBT2bv( &data, &bv );
262 #ifdef SLAP_ZONE_ALLOC
263 /* FIXME: will add ctx later */
264 rc = entry_decode( &bv, &e, NULL );
266 rc = entry_decode( &bv, &e );
269 if( rc == LDAP_SUCCESS ) {
273 if ( slapMode & SLAP_TOOL_READONLY ) {
274 EntryInfo *ei = NULL;
280 op.o_tmpmemctx = NULL;
281 op.o_tmpmfuncs = &ch_mfuncs;
283 rc = bdb_cache_find_parent( &op, cursor->locker, id, &ei );
284 if ( rc == LDAP_SUCCESS ) {
285 bdb_cache_entryinfo_unlock( ei );
297 static int bdb_tool_next_id(
304 struct berval dn = e->e_name;
305 struct berval ndn = e->e_nname;
306 struct berval pdn, npdn;
307 EntryInfo *ei = NULL, eidummy;
310 if (ndn.bv_len == 0) {
315 rc = bdb_cache_find_ndn( op, tid ? TXN_ID( tid ) : 0, &ndn, &ei );
316 if ( ei ) bdb_cache_entryinfo_unlock( ei );
317 if ( rc == DB_NOTFOUND ) {
318 if ( !be_issuffix( op->o_bd, &ndn ) ) {
320 dnParent( &dn, &pdn );
321 dnParent( &ndn, &npdn );
324 rc = bdb_tool_next_id( op, tid, e, text, 1 );
330 /* If parent didn't exist, it was created just now
331 * and its ID is now in e->e_id. Make sure the current
332 * entry gets added under the new parent ID.
334 if ( eid != e->e_id ) {
335 eidummy.bei_id = e->e_id;
339 rc = bdb_next_id( op->o_bd, tid, &e->e_id );
341 snprintf( text->bv_val, text->bv_len,
342 "next_id failed: %s (%d)",
343 db_strerror(rc), rc );
344 Debug( LDAP_DEBUG_ANY,
345 "=> bdb_tool_next_id: %s\n", text->bv_val, 0, 0 );
348 rc = bdb_dn2id_add( op, tid, ei, e );
350 snprintf( text->bv_val, text->bv_len,
351 "dn2id_add failed: %s (%d)",
352 db_strerror(rc), rc );
353 Debug( LDAP_DEBUG_ANY,
354 "=> bdb_tool_next_id: %s\n", text->bv_val, 0, 0 );
356 if ( nholes == nhmax - 1 ) {
357 if ( holes == hbuf ) {
358 holes = ch_malloc( nhmax * sizeof(dn_id) * 2 );
359 AC_MEMCPY( holes, hbuf, sizeof(hbuf) );
361 holes = ch_realloc( holes, nhmax * sizeof(dn_id) * 2 );
365 ber_dupbv( &holes[nholes].dn, &ndn );
366 holes[nholes++].id = e->e_id;
368 } else if ( !hole ) {
371 e->e_id = ei->bei_id;
373 for ( i=0; i<nholes; i++) {
374 if ( holes[i].id == e->e_id ) {
376 free(holes[i].dn.bv_val);
377 for (j=i;j<nholes;j++) holes[j] = holes[j+1];
381 } else if ( holes[i].id > e->e_id ) {
395 struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
400 if ( slapMode & SLAP_TOOL_QUICK ) {
405 ir = bdb_tool_index_rec;
406 memset(ir, 0, bdb->bi_nattrs * sizeof( IndexRec ));
408 for ( a = e->e_attrs; a != NULL; a = a->a_next ) {
409 rc = bdb_index_recset( bdb, a, a->a_desc->ad_type,
410 &a->a_desc->ad_tags, ir );
414 bdb_tool_ix_id = e->e_id;
416 ldap_pvt_thread_mutex_lock( &bdb_tool_index_mutex );
417 /* Wait for all threads to be ready */
418 while ( bdb_tool_index_tcount ) {
419 ldap_pvt_thread_mutex_unlock( &bdb_tool_index_mutex );
420 ldap_pvt_thread_yield();
421 ldap_pvt_thread_mutex_lock( &bdb_tool_index_mutex );
423 for ( i=1; i<slap_tool_thread_max; i++ )
424 bdb_tool_index_threads[i] = LDAP_BUSY;
425 bdb_tool_index_tcount = slap_tool_thread_max - 1;
426 ldap_pvt_thread_cond_broadcast( &bdb_tool_index_cond );
427 ldap_pvt_thread_mutex_unlock( &bdb_tool_index_mutex );
428 rc = bdb_index_recrun( op, bdb, ir, e->e_id, 0 );
431 for ( i=1; i<slap_tool_thread_max; i++ ) {
432 if ( bdb_tool_index_threads[i] == LDAP_BUSY ) {
433 ldap_pvt_thread_yield();
437 if ( bdb_tool_index_threads[i] )
438 return bdb_tool_index_threads[i];
442 return bdb_index_entry_add( op, txn, e );
446 ID bdb_tool_entry_put(
449 struct berval *text )
452 struct bdb_info *bdb = (struct bdb_info *) be->be_private;
457 assert( be != NULL );
458 assert( slapMode & SLAP_TOOL_MODE );
460 assert( text != NULL );
461 assert( text->bv_val != NULL );
462 assert( text->bv_val[0] == '\0' ); /* overconservative? */
464 Debug( LDAP_DEBUG_TRACE, "=> " LDAP_XSTRING(bdb_tool_entry_put)
465 "( %ld, \"%s\" )\n", (long) e->e_id, e->e_dn, 0 );
467 if (! (slapMode & SLAP_TOOL_QUICK)) {
468 rc = TXN_BEGIN( bdb->bi_dbenv, NULL, &tid,
469 bdb->bi_db_opflags );
471 snprintf( text->bv_val, text->bv_len,
472 "txn_begin failed: %s (%d)",
473 db_strerror(rc), rc );
474 Debug( LDAP_DEBUG_ANY,
475 "=> " LDAP_XSTRING(bdb_tool_entry_put) ": %s\n",
476 text->bv_val, 0, 0 );
483 op.o_tmpmemctx = NULL;
484 op.o_tmpmfuncs = &ch_mfuncs;
486 /* add dn2id indices */
487 rc = bdb_tool_next_id( &op, tid, e, text, 0 );
492 if ( !bdb->bi_linear_index )
493 rc = bdb_tool_index_add( &op, tid, e );
495 snprintf( text->bv_val, text->bv_len,
496 "index_entry_add failed: %s (%d)",
497 db_strerror(rc), rc );
498 Debug( LDAP_DEBUG_ANY,
499 "=> " LDAP_XSTRING(bdb_tool_entry_put) ": %s\n",
500 text->bv_val, 0, 0 );
505 rc = bdb_id2entry_add( be, tid, e );
507 snprintf( text->bv_val, text->bv_len,
508 "id2entry_add failed: %s (%d)",
509 db_strerror(rc), rc );
510 Debug( LDAP_DEBUG_ANY,
511 "=> " LDAP_XSTRING(bdb_tool_entry_put) ": %s\n",
512 text->bv_val, 0, 0 );
518 if ( !( slapMode & SLAP_TOOL_QUICK )) {
519 rc = TXN_COMMIT( tid, 0 );
521 snprintf( text->bv_val, text->bv_len,
522 "txn_commit failed: %s (%d)",
523 db_strerror(rc), rc );
524 Debug( LDAP_DEBUG_ANY,
525 "=> " LDAP_XSTRING(bdb_tool_entry_put) ": %s\n",
526 text->bv_val, 0, 0 );
532 if ( !( slapMode & SLAP_TOOL_QUICK )) {
534 snprintf( text->bv_val, text->bv_len,
535 "txn_aborted! %s (%d)",
536 db_strerror(rc), rc );
537 Debug( LDAP_DEBUG_ANY,
538 "=> " LDAP_XSTRING(bdb_tool_entry_put) ": %s\n",
539 text->bv_val, 0, 0 );
547 int bdb_tool_entry_reindex(
551 struct bdb_info *bi = (struct bdb_info *) be->be_private;
558 Debug( LDAP_DEBUG_ARGS,
559 "=> " LDAP_XSTRING(bdb_tool_entry_reindex) "( %ld )\n",
562 /* No indexes configured, nothing to do. Could return an
563 * error here to shortcut things.
569 /* Get the first attribute to index */
570 if (bi->bi_linear_index && !index_nattrs) {
571 index_nattrs = bi->bi_nattrs - 1;
575 e = bdb_tool_entry_get( be, id );
578 Debug( LDAP_DEBUG_ANY,
579 LDAP_XSTRING(bdb_tool_entry_reindex)
580 ": could not locate id=%ld\n",
585 if (! (slapMode & SLAP_TOOL_QUICK)) {
586 rc = TXN_BEGIN( bi->bi_dbenv, NULL, &tid, bi->bi_db_opflags );
588 Debug( LDAP_DEBUG_ANY,
589 "=> " LDAP_XSTRING(bdb_tool_entry_reindex) ": "
590 "txn_begin failed: %s (%d)\n",
591 db_strerror(rc), rc, 0 );
597 * just (re)add them for now
598 * assume that some other routine (not yet implemented)
599 * will zap index databases
603 Debug( LDAP_DEBUG_TRACE,
604 "=> " LDAP_XSTRING(bdb_tool_entry_reindex) "( %ld, \"%s\" )\n",
605 (long) id, e->e_dn, 0 );
609 op.o_tmpmemctx = NULL;
610 op.o_tmpmfuncs = &ch_mfuncs;
612 rc = bdb_tool_index_add( &op, tid, e );
616 if (! (slapMode & SLAP_TOOL_QUICK)) {
617 rc = TXN_COMMIT( tid, 0 );
619 Debug( LDAP_DEBUG_ANY,
620 "=> " LDAP_XSTRING(bdb_tool_entry_reindex)
621 ": txn_commit failed: %s (%d)\n",
622 db_strerror(rc), rc, 0 );
628 if (! (slapMode & SLAP_TOOL_QUICK)) {
630 Debug( LDAP_DEBUG_ANY,
631 "=> " LDAP_XSTRING(bdb_tool_entry_reindex)
632 ": txn_aborted! %s (%d)\n",
633 db_strerror(rc), rc, 0 );
637 bdb_entry_release( &op, e, 0 );
642 ID bdb_tool_entry_modify(
645 struct berval *text )
648 struct bdb_info *bdb = (struct bdb_info *) be->be_private;
653 assert( be != NULL );
654 assert( slapMode & SLAP_TOOL_MODE );
656 assert( text != NULL );
657 assert( text->bv_val != NULL );
658 assert( text->bv_val[0] == '\0' ); /* overconservative? */
660 assert ( e->e_id != NOID );
662 Debug( LDAP_DEBUG_TRACE,
663 "=> " LDAP_XSTRING(bdb_tool_entry_modify) "( %ld, \"%s\" )\n",
664 (long) e->e_id, e->e_dn, 0 );
666 if (! (slapMode & SLAP_TOOL_QUICK)) {
668 cursor->c_close( cursor );
671 rc = TXN_BEGIN( bdb->bi_dbenv, NULL, &tid,
672 bdb->bi_db_opflags );
674 snprintf( text->bv_val, text->bv_len,
675 "txn_begin failed: %s (%d)",
676 db_strerror(rc), rc );
677 Debug( LDAP_DEBUG_ANY,
678 "=> " LDAP_XSTRING(bdb_tool_entry_modify) ": %s\n",
679 text->bv_val, 0, 0 );
686 op.o_tmpmemctx = NULL;
687 op.o_tmpmfuncs = &ch_mfuncs;
690 rc = bdb_id2entry_update( be, tid, e );
692 snprintf( text->bv_val, text->bv_len,
693 "id2entry_add failed: %s (%d)",
694 db_strerror(rc), rc );
695 Debug( LDAP_DEBUG_ANY,
696 "=> " LDAP_XSTRING(bdb_tool_entry_modify) ": %s\n",
697 text->bv_val, 0, 0 );
703 if (! (slapMode & SLAP_TOOL_QUICK)) {
704 rc = TXN_COMMIT( tid, 0 );
706 snprintf( text->bv_val, text->bv_len,
707 "txn_commit failed: %s (%d)",
708 db_strerror(rc), rc );
709 Debug( LDAP_DEBUG_ANY,
710 "=> " LDAP_XSTRING(bdb_tool_entry_modify) ": "
711 "%s\n", text->bv_val, 0, 0 );
717 if (! (slapMode & SLAP_TOOL_QUICK)) {
719 snprintf( text->bv_val, text->bv_len,
720 "txn_aborted! %s (%d)",
721 db_strerror(rc), rc );
722 Debug( LDAP_DEBUG_ANY,
723 "=> " LDAP_XSTRING(bdb_tool_entry_modify) ": %s\n",
724 text->bv_val, 0, 0 );
732 #ifdef BDB_TOOL_IDL_CACHING
734 bdb_tool_idl_cmp( const void *v1, const void *v2 )
736 const bdb_tool_idl_cache *c1 = v1, *c2 = v2;
739 if (( rc = c1->kstr.bv_len - c2->kstr.bv_len )) return rc;
740 return memcmp( c1->kstr.bv_val, c2->kstr.bv_val, c1->kstr.bv_len );
744 bdb_tool_idl_flush_one( void *v1, void *arg )
746 bdb_tool_idl_cache *ic = v1;
748 struct bdb_info *bdb = bdb_tool_info;
749 bdb_tool_idl_cache_entry *ice;
755 /* Freshly allocated, ignore it */
756 if ( !ic->head && ic->count <= BDB_IDL_DB_SIZE ) {
760 rc = db->cursor( db, NULL, &curs, 0 );
767 bv2DBT( &ic->kstr, &key );
769 data.size = data.ulen = sizeof( ID );
770 data.flags = DB_DBT_USERMEM;
773 rc = curs->c_get( curs, &key, &data, DB_SET );
774 /* If key already exists and we're writing a range... */
775 if ( rc == 0 && ic->count > BDB_IDL_DB_SIZE ) {
776 /* If it's not currently a range, must delete old info */
779 while ( curs->c_get( curs, &key, &data, DB_NEXT_DUP ) == 0 )
780 curs->c_del( curs, 0 );
783 /* Store range marker */
784 curs->c_put( curs, &key, &data, DB_KEYFIRST );
788 rc = curs->c_get( curs, &key, &data, DB_NEXT_DUP );
791 rc = curs->c_get( curs, &key, &data, DB_NEXT_DUP );
794 curs->c_del( curs, 0 );
796 BDB_ID2DISK( ic->last, &nid );
797 curs->c_put( curs, &key, &data, DB_KEYLAST );
799 } else if ( rc && rc != DB_NOTFOUND ) {
801 } else if ( ic->count > BDB_IDL_DB_SIZE ) {
802 /* range, didn't exist before */
804 rc = curs->c_put( curs, &key, &data, DB_KEYLAST );
806 BDB_ID2DISK( ic->first, &nid );
807 rc = curs->c_put( curs, &key, &data, DB_KEYLAST );
809 BDB_ID2DISK( ic->last, &nid );
810 rc = curs->c_put( curs, &key, &data, DB_KEYLAST );
819 /* Just a normal write */
821 for ( ice = ic->head, n=0; ice; ice = ice->next, n++ ) {
826 end = ic->count & (IDBLOCK-1);
830 for ( i=0; i<end; i++ ) {
831 if ( !ice->ids[i] ) continue;
832 BDB_ID2DISK( ice->ids[i], &nid );
833 rc = curs->c_put( curs, &key, &data, DB_NODUPDATA );
835 if ( rc == DB_KEYEXIST ) {
849 ldap_pvt_thread_mutex_lock( &bdb->bi_idl_tree_lrulock );
850 ic->tail->next = bdb_tool_idl_free_list;
851 bdb_tool_idl_free_list = ic->head;
852 bdb->bi_idl_cache_size -= n;
853 ldap_pvt_thread_mutex_unlock( &bdb->bi_idl_tree_lrulock );
856 if ( ic != db->app_private ) {
859 ic->head = ic->tail = NULL;
861 curs->c_close( curs );
866 bdb_tool_idl_flush_db( DB *db, bdb_tool_idl_cache *ic )
868 Avlnode *root = db->app_private;
871 db->app_private = ic;
872 rc = avl_apply( root, bdb_tool_idl_flush_one, db, -1, AVL_INORDER );
873 avl_free( root, NULL );
874 db->app_private = NULL;
881 bdb_tool_idl_flush( BackendDB *be )
883 struct bdb_info *bdb = (struct bdb_info *) be->be_private;
888 for ( i=BDB_NDB; i < bdb->bi_ndatabases; i++ ) {
889 db = bdb->bi_databases[i]->bdi_db;
890 if ( !db->app_private ) continue;
891 rc = bdb_tool_idl_flush_db( db, NULL );
896 bdb->bi_idl_cache_size = 0;
901 int bdb_tool_idl_add(
908 struct bdb_info *bdb = (struct bdb_info *) be->be_private;
909 bdb_tool_idl_cache *ic, itmp;
910 bdb_tool_idl_cache_entry *ice;
913 if ( !bdb->bi_idl_cache_max_size )
914 return bdb_idl_insert_key( be, db, txn, key, id );
916 DBT2bv( key, &itmp.kstr );
918 ic = avl_find( (Avlnode *)db->app_private, &itmp, bdb_tool_idl_cmp );
920 /* No entry yet, create one */
927 ic = ch_malloc( sizeof( bdb_tool_idl_cache ) + itmp.kstr.bv_len );
928 ic->kstr.bv_len = itmp.kstr.bv_len;
929 ic->kstr.bv_val = (char *)(ic+1);
930 AC_MEMCPY( ic->kstr.bv_val, itmp.kstr.bv_val, ic->kstr.bv_len );
931 ic->head = ic->tail = NULL;
934 avl_insert( (Avlnode **)&db->app_private, ic, bdb_tool_idl_cmp,
937 /* load existing key count here */
938 rc = db->cursor( db, NULL, &curs, 0 );
941 data.ulen = sizeof( ID );
942 data.flags = DB_DBT_USERMEM;
944 rc = curs->c_get( curs, key, &data, DB_SET );
947 ic->count = BDB_IDL_DB_SIZE+1;
951 curs->c_count( curs, &count, 0 );
953 BDB_DISK2ID( &nid, &ic->first );
956 curs->c_close( curs );
958 /* are we a range already? */
959 if ( ic->count > BDB_IDL_DB_SIZE ) {
962 /* Are we at the limit, and converting to a range? */
963 } else if ( ic->count == BDB_IDL_DB_SIZE ) {
965 for ( ice = ic->head, n=0; ice; ice = ice->next, n++ )
968 ldap_pvt_thread_mutex_lock( &bdb->bi_idl_tree_lrulock );
969 ic->tail->next = bdb_tool_idl_free_list;
970 bdb_tool_idl_free_list = ic->head;
971 bdb->bi_idl_cache_size -= n;
972 ldap_pvt_thread_mutex_unlock( &bdb->bi_idl_tree_lrulock );
974 ic->head = ic->tail = NULL;
979 /* No free block, create that too */
980 if ( !ic->tail || ( ic->count & (IDBLOCK-1)) == 0) {
982 ldap_pvt_thread_mutex_lock( &bdb->bi_idl_tree_lrulock );
983 if ( bdb->bi_idl_cache_size >= bdb->bi_idl_cache_max_size ) {
984 ldap_pvt_thread_mutex_unlock( &bdb->bi_idl_tree_lrulock );
985 rc = bdb_tool_idl_flush_db( db, ic );
988 avl_insert( (Avlnode **)&db->app_private, ic, bdb_tool_idl_cmp,
990 ldap_pvt_thread_mutex_lock( &bdb->bi_idl_tree_lrulock );
992 bdb->bi_idl_cache_size++;
993 if ( bdb_tool_idl_free_list ) {
994 ice = bdb_tool_idl_free_list;
995 bdb_tool_idl_free_list = ice->next;
997 ldap_pvt_thread_mutex_unlock( &bdb->bi_idl_tree_lrulock );
999 ice = ch_malloc( sizeof( bdb_tool_idl_cache_entry ));
1001 memset( ice, 0, sizeof( *ice ));
1005 ic->tail->next = ice;
1012 ice->ids[ ic->count & (IDBLOCK-1) ] = id;
1020 bdb_tool_index_task( void *ctx, void *ptr )
1022 int base = *(int *)ptr;
1026 ldap_pvt_thread_mutex_lock( &bdb_tool_index_mutex );
1027 bdb_tool_index_tcount--;
1028 ldap_pvt_thread_cond_wait( &bdb_tool_index_cond,
1029 &bdb_tool_index_mutex );
1030 ldap_pvt_thread_mutex_unlock( &bdb_tool_index_mutex );
1031 if ( slapd_shutdown )
1034 bdb_tool_index_threads[base] = bdb_index_recrun( bdb_tool_ix_op,
1035 bdb_tool_info, bdb_tool_index_rec, bdb_tool_ix_id, base );