X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=servers%2Fslapd%2Fback-bdb%2Ftools.c;h=167f3c7e5e2b46d198a5e2114a5cba5933a87cf3;hb=0af1940f3fb59fe57b2281ef253fe1341c505c2c;hp=9dbb549afcf68ca3c8db22b67835d36fa9cc6f3b;hpb=8f7fbfe60ac1918e1fd6eb2ceea9c20119e18a49;p=openldap diff --git a/servers/slapd/back-bdb/tools.c b/servers/slapd/back-bdb/tools.c index 9dbb549afc..167f3c7e5e 100644 --- a/servers/slapd/back-bdb/tools.c +++ b/servers/slapd/back-bdb/tools.c @@ -2,7 +2,7 @@ /* $OpenLDAP$ */ /* This work is part of OpenLDAP Software . * - * Copyright 2000-2005 The OpenLDAP Foundation. + * Copyright 2000-2006 The OpenLDAP Foundation. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -64,13 +64,12 @@ static bdb_tool_idl_cache_entry *bdb_tool_idl_free_list; static ID bdb_tool_ix_id; static Operation *bdb_tool_ix_op; -static volatile int *bdb_tool_index_threads; +static int *bdb_tool_index_threads, bdb_tool_index_tcount; static void *bdb_tool_index_rec; static struct bdb_info *bdb_tool_info; static ldap_pvt_thread_mutex_t bdb_tool_index_mutex; static ldap_pvt_thread_cond_t bdb_tool_index_cond; -static int bdb_tool_ix_rec( int base ); static void * bdb_tool_index_task( void *ctx, void *ptr ); int bdb_tool_entry_open( @@ -94,19 +93,20 @@ int bdb_tool_entry_open( } /* Set up for threaded slapindex */ - if (( slapMode & (SLAP_TOOL_QUICK|SLAP_TOOL_READONLY)) == SLAP_TOOL_QUICK) { + if (( slapMode & (SLAP_TOOL_QUICK|SLAP_TOOL_READONLY)) == SLAP_TOOL_QUICK + && bdb->bi_nattrs ) { if ( !bdb_tool_info ) { int i; ldap_pvt_thread_mutex_init( &bdb_tool_index_mutex ); ldap_pvt_thread_cond_init( &bdb_tool_index_cond ); bdb_tool_index_threads = ch_malloc( slap_tool_thread_max * sizeof( int )); bdb_tool_index_rec = ch_malloc( bdb->bi_nattrs * sizeof( IndexRec )); + bdb_tool_index_tcount = slap_tool_thread_max - 1; for (i=1; ibe_private; - if ( bdb_tool_info ) { slapd_shutdown = 1; ldap_pvt_thread_mutex_lock( &bdb_tool_index_mutex ); + bdb_tool_index_tcount = slap_tool_thread_max - 1; ldap_pvt_thread_cond_broadcast( &bdb_tool_index_cond ); ldap_pvt_thread_mutex_unlock( &bdb_tool_index_mutex ); } @@ -409,8 +408,15 @@ bdb_tool_index_add( bdb_tool_ix_id = e->e_id; bdb_tool_ix_op = op; ldap_pvt_thread_mutex_lock( &bdb_tool_index_mutex ); + /* Wait for all threads to be ready */ + while ( bdb_tool_index_tcount ) { + ldap_pvt_thread_mutex_unlock( &bdb_tool_index_mutex ); + ldap_pvt_thread_yield(); + ldap_pvt_thread_mutex_lock( &bdb_tool_index_mutex ); + } for ( i=1; ie_id, 0 ); @@ -477,11 +483,11 @@ ID bdb_tool_entry_put( goto done; } - /* id2entry index */ - rc = bdb_id2entry_add( be, tid, e ); + if ( !bdb->bi_linear_index ) + rc = bdb_tool_index_add( &op, tid, e ); if( rc != 0 ) { snprintf( text->bv_val, text->bv_len, - "id2entry_add failed: %s (%d)", + "index_entry_add failed: %s (%d)", db_strerror(rc), rc ); Debug( LDAP_DEBUG_ANY, "=> " LDAP_XSTRING(bdb_tool_entry_put) ": %s\n", @@ -489,11 +495,11 @@ ID bdb_tool_entry_put( goto done; } - if ( !bdb->bi_linear_index ) - rc = bdb_tool_index_add( &op, tid, e ); + /* id2entry index */ + rc = bdb_id2entry_add( be, tid, e ); if( rc != 0 ) { snprintf( text->bv_val, text->bv_len, - "index_entry_add failed: %s (%d)", + "id2entry_add failed: %s (%d)", db_strerror(rc), rc ); Debug( LDAP_DEBUG_ANY, "=> " LDAP_XSTRING(bdb_tool_entry_put) ": %s\n", @@ -682,33 +688,6 @@ ID bdb_tool_entry_modify( goto done; } -#if 0 - /* FIXME: this is bogus, we don't have the old values to delete - * from the index because the given entry has already been modified. - */ - rc = bdb_index_entry_del( &op, tid, e ); - if( rc != 0 ) { - snprintf( text->bv_val, text->bv_len, - "index_entry_del failed: %s (%d)", - db_strerror(rc), rc ); - Debug( LDAP_DEBUG_ANY, - "=> " LDAP_XSTRING(bdb_tool_entry_modify) ": %s\n", - text->bv_val, 0, 0 ); - goto done; - } -#endif - - rc = bdb_index_entry_add( &op, tid, e ); - if( rc != 0 ) { - snprintf( text->bv_val, text->bv_len, - "index_entry_add failed: %s (%d)", - db_strerror(rc), rc ); - Debug( LDAP_DEBUG_ANY, - "=> " LDAP_XSTRING(bdb_tool_entry_modify) ": %s\n", - text->bv_val, 0, 0 ); - goto done; - } - done: if( rc == 0 ) { if (! (slapMode & SLAP_TOOL_QUICK)) { @@ -1035,6 +1014,7 @@ bdb_tool_index_task( void *ctx, void *ptr ) free( ptr ); while ( 1 ) { ldap_pvt_thread_mutex_lock( &bdb_tool_index_mutex ); + bdb_tool_index_tcount--; ldap_pvt_thread_cond_wait( &bdb_tool_index_cond, &bdb_tool_index_mutex ); ldap_pvt_thread_mutex_unlock( &bdb_tool_index_mutex );