Elimination of entry- and cache-level locking in back-bdb2.

Slight adaption of concurrency-test to enable even more writers/readers.
This commit is contained in:
Kurt Spanier 1999-02-17 11:13:22 +00:00
parent a3c9bec0c5
commit ac4cb22f1c
11 changed files with 92 additions and 77 deletions

View file

@ -28,17 +28,17 @@ bdb2i_back_add_internal(
Debug(LDAP_DEBUG_ARGS, "==> bdb2i_back_add: %s\n", e->e_dn, 0, 0); Debug(LDAP_DEBUG_ARGS, "==> bdb2i_back_add: %s\n", e->e_dn, 0, 0);
/* nobody else can add until we lock our parent */ /* nobody else can add until we lock our parent */
ldap_pvt_thread_mutex_lock(&li->li_add_mutex); /* DDD ldap_pvt_thread_mutex_lock(&li->li_add_mutex); */
if ( ( bdb2i_dn2id( be, e->e_ndn ) ) != NOID ) { if ( ( bdb2i_dn2id( be, e->e_ndn ) ) != NOID ) {
ldap_pvt_thread_mutex_unlock(&li->li_add_mutex); /* DDD ldap_pvt_thread_mutex_unlock(&li->li_add_mutex); */
entry_free( e ); entry_free( e );
send_ldap_result( conn, op, LDAP_ALREADY_EXISTS, "", "" ); send_ldap_result( conn, op, LDAP_ALREADY_EXISTS, "", "" );
return( -1 ); return( -1 );
} }
if ( global_schemacheck && oc_schema_check( e ) != 0 ) { if ( global_schemacheck && oc_schema_check( e ) != 0 ) {
ldap_pvt_thread_mutex_unlock(&li->li_add_mutex); /* DDD ldap_pvt_thread_mutex_unlock(&li->li_add_mutex); */
Debug( LDAP_DEBUG_TRACE, "entry failed schema check\n", Debug( LDAP_DEBUG_TRACE, "entry failed schema check\n",
0, 0, 0 ); 0, 0, 0 );
@ -60,7 +60,7 @@ bdb2i_back_add_internal(
/* get parent with writer lock */ /* get parent with writer lock */
if ( (p = bdb2i_dn2entry_w( be, pdn, &matched )) == NULL ) { if ( (p = bdb2i_dn2entry_w( be, pdn, &matched )) == NULL ) {
ldap_pvt_thread_mutex_unlock(&li->li_add_mutex); /* DDD ldap_pvt_thread_mutex_unlock(&li->li_add_mutex); */
Debug( LDAP_DEBUG_TRACE, "parent does not exist\n", 0, Debug( LDAP_DEBUG_TRACE, "parent does not exist\n", 0,
0, 0 ); 0, 0 );
send_ldap_result( conn, op, LDAP_NO_SUCH_OBJECT, send_ldap_result( conn, op, LDAP_NO_SUCH_OBJECT,
@ -76,7 +76,7 @@ bdb2i_back_add_internal(
} }
/* don't need the add lock anymore */ /* don't need the add lock anymore */
ldap_pvt_thread_mutex_unlock(&li->li_add_mutex); /* DDD ldap_pvt_thread_mutex_unlock(&li->li_add_mutex); */
free(pdn); free(pdn);
@ -102,7 +102,7 @@ bdb2i_back_add_internal(
} else { } else {
/* no parent, must be adding entry to root */ /* no parent, must be adding entry to root */
if ( ! be_isroot( be, op->o_ndn ) ) { if ( ! be_isroot( be, op->o_ndn ) ) {
ldap_pvt_thread_mutex_unlock(&li->li_add_mutex); /* DDD ldap_pvt_thread_mutex_unlock(&li->li_add_mutex); */
Debug( LDAP_DEBUG_TRACE, "no parent & not root\n", 0, Debug( LDAP_DEBUG_TRACE, "no parent & not root\n", 0,
0, 0 ); 0, 0 );
send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS, send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
@ -116,9 +116,9 @@ bdb2i_back_add_internal(
* no parent, acquire the root write lock * no parent, acquire the root write lock
* and release the add lock. * and release the add lock.
*/ */
ldap_pvt_thread_mutex_lock(&li->li_root_mutex); /* DDD ldap_pvt_thread_mutex_lock(&li->li_root_mutex); */
rootlock = 1; rootlock = 1;
ldap_pvt_thread_mutex_unlock(&li->li_add_mutex); /* DDD ldap_pvt_thread_mutex_unlock(&li->li_add_mutex); */
} }
e->e_id = bdb2i_next_id( be ); e->e_id = bdb2i_next_id( be );
@ -136,7 +136,7 @@ bdb2i_back_add_internal(
if ( rootlock ) { if ( rootlock ) {
/* release root lock */ /* release root lock */
ldap_pvt_thread_mutex_unlock(&li->li_root_mutex); /* DDD ldap_pvt_thread_mutex_unlock(&li->li_root_mutex); */
} }
Debug( LDAP_DEBUG_ANY, "cache_add_entry_lock failed\n", 0, 0, Debug( LDAP_DEBUG_ANY, "cache_add_entry_lock failed\n", 0, 0,
@ -216,7 +216,7 @@ return_results:;
if ( rootlock ) { if ( rootlock ) {
/* release root lock */ /* release root lock */
ldap_pvt_thread_mutex_unlock(&li->li_root_mutex); /* DDD ldap_pvt_thread_mutex_unlock(&li->li_root_mutex); */
} }
/* free entry and writer lock */ /* free entry and writer lock */

View file

@ -79,7 +79,7 @@ struct cache {
Avlnode *c_idtree; Avlnode *c_idtree;
Entry *c_lruhead; /* lru - add accessed entries here */ Entry *c_lruhead; /* lru - add accessed entries here */
Entry *c_lrutail; /* lru - rem lru entries from here */ Entry *c_lrutail; /* lru - rem lru entries from here */
ldap_pvt_thread_mutex_t c_mutex; /* DDD ldap_pvt_thread_mutex_t c_mutex; */
}; };
#define CACHE_READ_LOCK 1 #define CACHE_READ_LOCK 1
@ -182,9 +182,9 @@ struct ldbminfo {
ID li_nextid_wrote; ID li_nextid_wrote;
#endif #endif
char *li_nextid_file; char *li_nextid_file;
ldap_pvt_thread_mutex_t li_root_mutex; /* DDD ldap_pvt_thread_mutex_t li_root_mutex; */
ldap_pvt_thread_mutex_t li_add_mutex; /* DDD ldap_pvt_thread_mutex_t li_add_mutex; */
ldap_pvt_thread_mutex_t li_nextid_mutex; /* DDD ldap_pvt_thread_mutex_t li_nextid_mutex; */
int li_mode; int li_mode;
char *li_directory; char *li_directory;
struct cache li_cache; struct cache li_cache;

View file

@ -102,11 +102,11 @@ cache_entry_private_init( Entry*e )
e->e_private = ch_calloc(1, sizeof(struct ldbm_entry_info)); e->e_private = ch_calloc(1, sizeof(struct ldbm_entry_info));
if( cache_entry_rdwr_init( e ) != 0 ) { /* DDD if( cache_entry_rdwr_init( e ) != 0 ) { */
free( LEI(e) ); /* DDD free( LEI(e) ); */
e->e_private = NULL; /* DDD e->e_private = NULL; */
return 1; /* DDD return 1; */
} /* DDD } */
return 0; return 0;
} }
@ -120,7 +120,7 @@ cache_entry_private_destroy( Entry*e )
assert( e->e_private ); assert( e->e_private );
#endif #endif
cache_entry_rdwr_destroy( e ); /* DDD cache_entry_rdwr_destroy( e ); */
free( e->e_private ); free( e->e_private );
e->e_private = NULL; e->e_private = NULL;
@ -131,13 +131,13 @@ void
bdb2i_cache_return_entry_rw( struct cache *cache, Entry *e, int rw ) bdb2i_cache_return_entry_rw( struct cache *cache, Entry *e, int rw )
{ {
/* set cache mutex */ /* set cache mutex */
ldap_pvt_thread_mutex_lock( &cache->c_mutex ); /* DDD ldap_pvt_thread_mutex_lock( &cache->c_mutex ); */
#ifdef LDAP_DEBUG #ifdef LDAP_DEBUG
assert( e->e_private ); assert( e->e_private );
#endif #endif
cache_entry_rdwr_unlock(e, rw); /* DDD cache_entry_rdwr_unlock(e, rw); */
LEI(e)->lei_refcnt--; LEI(e)->lei_refcnt--;
@ -170,7 +170,7 @@ bdb2i_cache_return_entry_rw( struct cache *cache, Entry *e, int rw )
} }
/* free cache mutex */ /* free cache mutex */
ldap_pvt_thread_mutex_unlock( &cache->c_mutex ); /* DDD ldap_pvt_thread_mutex_unlock( &cache->c_mutex ); */
} }
#define LRU_DELETE( cache, e ) { \ #define LRU_DELETE( cache, e ) { \
@ -215,7 +215,7 @@ bdb2i_cache_add_entry_rw(
Entry *ee; Entry *ee;
/* set cache mutex */ /* set cache mutex */
ldap_pvt_thread_mutex_lock( &cache->c_mutex ); /* DDD ldap_pvt_thread_mutex_lock( &cache->c_mutex ); */
#ifdef LDAP_DEBUG #ifdef LDAP_DEBUG
assert( e->e_private == NULL ); assert( e->e_private == NULL );
@ -238,7 +238,7 @@ bdb2i_cache_add_entry_rw(
cache_entry_private_destroy(e); cache_entry_private_destroy(e);
/* free cache mutex */ /* free cache mutex */
ldap_pvt_thread_mutex_unlock( &cache->c_mutex ); /* DDD ldap_pvt_thread_mutex_unlock( &cache->c_mutex ); */
return( 1 ); return( 1 );
} }
@ -261,11 +261,11 @@ bdb2i_cache_add_entry_rw(
cache_entry_private_destroy(e); cache_entry_private_destroy(e);
/* free cache mutex */ /* free cache mutex */
ldap_pvt_thread_mutex_unlock( &cache->c_mutex ); /* DDD ldap_pvt_thread_mutex_unlock( &cache->c_mutex ); */
return( -1 ); return( -1 );
} }
cache_entry_rdwr_lock( e, rw ); /* DDD cache_entry_rdwr_lock( e, rw ); */
/* put the entry into 'CREATING' state */ /* put the entry into 'CREATING' state */
/* will be marked after when entry is returned */ /* will be marked after when entry is returned */
@ -311,7 +311,7 @@ bdb2i_cache_add_entry_rw(
} }
/* free cache mutex */ /* free cache mutex */
ldap_pvt_thread_mutex_unlock( &cache->c_mutex ); /* DDD ldap_pvt_thread_mutex_unlock( &cache->c_mutex ); */
return( 0 ); return( 0 );
} }
@ -331,7 +331,7 @@ bdb2i_cache_update_entry(
Entry *ee; Entry *ee;
/* set cache mutex */ /* set cache mutex */
ldap_pvt_thread_mutex_lock( &cache->c_mutex ); /* DDD ldap_pvt_thread_mutex_lock( &cache->c_mutex ); */
#ifdef LDAP_DEBUG #ifdef LDAP_DEBUG
assert( e->e_private ); assert( e->e_private );
@ -345,7 +345,7 @@ bdb2i_cache_update_entry(
e->e_id, e->e_dn, 0 ); e->e_id, e->e_dn, 0 );
/* free cache mutex */ /* free cache mutex */
ldap_pvt_thread_mutex_unlock( &cache->c_mutex ); /* DDD ldap_pvt_thread_mutex_unlock( &cache->c_mutex ); */
return( 1 ); return( 1 );
} }
@ -366,7 +366,7 @@ bdb2i_cache_update_entry(
} }
/* free cache mutex */ /* free cache mutex */
ldap_pvt_thread_mutex_unlock( &cache->c_mutex ); /* DDD ldap_pvt_thread_mutex_unlock( &cache->c_mutex ); */
return( -1 ); return( -1 );
} }
@ -413,7 +413,7 @@ bdb2i_cache_update_entry(
} }
/* free cache mutex */ /* free cache mutex */
ldap_pvt_thread_mutex_unlock( &cache->c_mutex ); /* DDD ldap_pvt_thread_mutex_unlock( &cache->c_mutex ); */
return( 0 ); return( 0 );
} }
@ -433,7 +433,7 @@ bdb2i_cache_find_entry_dn2id(
ID id; ID id;
/* set cache mutex */ /* set cache mutex */
ldap_pvt_thread_mutex_lock( &cache->c_mutex ); /* DDD ldap_pvt_thread_mutex_lock( &cache->c_mutex ); */
e.e_dn = dn; e.e_dn = dn;
e.e_ndn = dn_normalize_case( ch_strdup( dn ) ); e.e_ndn = dn_normalize_case( ch_strdup( dn ) );
@ -464,7 +464,7 @@ bdb2i_cache_find_entry_dn2id(
dn, ep->e_id, LEI(ep)->lei_state); dn, ep->e_id, LEI(ep)->lei_state);
/* free cache mutex */ /* free cache mutex */
ldap_pvt_thread_mutex_unlock( &cache->c_mutex ); /* DDD ldap_pvt_thread_mutex_unlock( &cache->c_mutex ); */
return( NOID ); return( NOID );
} }
@ -480,7 +480,7 @@ bdb2i_cache_find_entry_dn2id(
id = ep->e_id; id = ep->e_id;
/* free cache mutex */ /* free cache mutex */
ldap_pvt_thread_mutex_unlock( &cache->c_mutex ); /* DDD ldap_pvt_thread_mutex_unlock( &cache->c_mutex ); */
return( id ); return( id );
} }
@ -488,7 +488,7 @@ bdb2i_cache_find_entry_dn2id(
free(e.e_ndn); free(e.e_ndn);
/* free cache mutex */ /* free cache mutex */
ldap_pvt_thread_mutex_unlock( &cache->c_mutex ); /* DDD ldap_pvt_thread_mutex_unlock( &cache->c_mutex ); */
return( NOID ); return( NOID );
} }
@ -511,7 +511,7 @@ bdb2i_cache_find_entry_id(
try_again: try_again:
/* set cache mutex */ /* set cache mutex */
ldap_pvt_thread_mutex_lock( &cache->c_mutex ); /* DDD ldap_pvt_thread_mutex_lock( &cache->c_mutex ); */
if ( (ep = (Entry *) avl_find( cache->c_idtree, (caddr_t) &e, if ( (ep = (Entry *) avl_find( cache->c_idtree, (caddr_t) &e,
entry_id_cmp )) != NULL ) entry_id_cmp )) != NULL )
@ -532,7 +532,7 @@ try_again:
id, ep->e_id, LEI(ep)->lei_state); id, ep->e_id, LEI(ep)->lei_state);
/* free cache mutex */ /* free cache mutex */
ldap_pvt_thread_mutex_unlock( &cache->c_mutex ); /* DDD ldap_pvt_thread_mutex_unlock( &cache->c_mutex ); */
return( NULL ); return( NULL );
} }
@ -541,17 +541,17 @@ try_again:
id, rw ? "w" : "r", ep->e_dn); id, rw ? "w" : "r", ep->e_dn);
/* acquire reader lock */ /* acquire reader lock */
if ( cache_entry_rdwr_trylock(ep, rw) == LDAP_PVT_THREAD_EBUSY ) { /* DDD if ( cache_entry_rdwr_trylock(ep, rw) == LDAP_PVT_THREAD_EBUSY ) { */
/* could not acquire entry lock... /* could not acquire entry lock...
* owner cannot free as we have the cache locked. * owner cannot free as we have the cache locked.
* so, unlock the cache, yield, and try again. * so, unlock the cache, yield, and try again.
*/ */
/* free cache mutex */ /* free cache mutex */
ldap_pvt_thread_mutex_unlock( &cache->c_mutex ); /* DDD ldap_pvt_thread_mutex_unlock( &cache->c_mutex ); */
ldap_pvt_thread_yield(); /* DDD ldap_pvt_thread_yield(); */
goto try_again; /* DDD goto try_again; */
} /* DDD } */
/* lru */ /* lru */
LRU_DELETE( cache, ep ); LRU_DELETE( cache, ep );
@ -560,13 +560,13 @@ try_again:
LEI(ep)->lei_refcnt++; LEI(ep)->lei_refcnt++;
/* free cache mutex */ /* free cache mutex */
ldap_pvt_thread_mutex_unlock( &cache->c_mutex ); /* DDD ldap_pvt_thread_mutex_unlock( &cache->c_mutex ); */
return( ep ); return( ep );
} }
/* free cache mutex */ /* free cache mutex */
ldap_pvt_thread_mutex_unlock( &cache->c_mutex ); /* DDD ldap_pvt_thread_mutex_unlock( &cache->c_mutex ); */
return( NULL ); return( NULL );
} }
@ -591,7 +591,7 @@ bdb2i_cache_delete_entry(
int rc; int rc;
/* set cache mutex */ /* set cache mutex */
ldap_pvt_thread_mutex_lock( &cache->c_mutex ); /* DDD ldap_pvt_thread_mutex_lock( &cache->c_mutex ); */
#ifdef LDAP_DEBUG #ifdef LDAP_DEBUG
assert( e->e_private ); assert( e->e_private );
@ -603,7 +603,7 @@ bdb2i_cache_delete_entry(
rc = cache_delete_entry_internal( cache, e ); rc = cache_delete_entry_internal( cache, e );
/* free cache mutex */ /* free cache mutex */
ldap_pvt_thread_mutex_unlock( &cache->c_mutex ); /* DDD ldap_pvt_thread_mutex_unlock( &cache->c_mutex ); */
return( rc ); return( rc );
} }

View file

@ -94,7 +94,7 @@ bdb2i_back_delete_internal(
goto return_results; goto return_results;
} }
ldap_pvt_thread_mutex_lock(&li->li_root_mutex); /* DDD ldap_pvt_thread_mutex_lock(&li->li_root_mutex); */
rootlock = 1; rootlock = 1;
} }
@ -138,7 +138,7 @@ return_results:;
if ( rootlock ) { if ( rootlock ) {
/* release root lock */ /* release root lock */
ldap_pvt_thread_mutex_unlock(&li->li_root_mutex); /* DDD ldap_pvt_thread_mutex_unlock(&li->li_root_mutex); */
} }
/* free entry and writer lock */ /* free entry and writer lock */

View file

@ -173,10 +173,10 @@ bdb2i_back_db_init_internal(
free( argv[ 1 ] ); free( argv[ 1 ] );
/* initialize various mutex locks & condition variables */ /* initialize various mutex locks & condition variables */
ldap_pvt_thread_mutex_init( &li->li_root_mutex ); /* DDD ldap_pvt_thread_mutex_init( &li->li_root_mutex ); */
ldap_pvt_thread_mutex_init( &li->li_add_mutex ); /* DDD ldap_pvt_thread_mutex_init( &li->li_add_mutex ); */
ldap_pvt_thread_mutex_init( &li->li_cache.c_mutex ); /* DDD ldap_pvt_thread_mutex_init( &li->li_cache.c_mutex ); */
ldap_pvt_thread_mutex_init( &li->li_nextid_mutex ); /* DDD ldap_pvt_thread_mutex_init( &li->li_nextid_mutex ); */
/* initialize the TP file head */ /* initialize the TP file head */
if ( bdb2i_txn_head_init( &li->li_txn_head ) != 0 ) if ( bdb2i_txn_head_init( &li->li_txn_head ) != 0 )

View file

@ -107,7 +107,7 @@ bdb2i_back_modrdn_internal(
goto return_results; goto return_results;
} }
ldap_pvt_thread_mutex_lock(&li->li_root_mutex); /* DDD ldap_pvt_thread_mutex_lock(&li->li_root_mutex); */
rootlock = 1; rootlock = 1;
new_dn = ch_strdup( newrdn ); new_dn = ch_strdup( newrdn );
@ -182,7 +182,7 @@ return_results:
if ( rootlock ) { if ( rootlock ) {
/* release root writer lock */ /* release root writer lock */
ldap_pvt_thread_mutex_unlock(&li->li_root_mutex); /* DDD ldap_pvt_thread_mutex_unlock(&li->li_root_mutex); */
} }
/* free entry and writer lock */ /* free entry and writer lock */

View file

@ -98,7 +98,7 @@ bdb2i_next_id( BackendDB *be )
struct ldbminfo *li = (struct ldbminfo *) be->be_private; struct ldbminfo *li = (struct ldbminfo *) be->be_private;
ID id; ID id;
ldap_pvt_thread_mutex_lock( &li->li_nextid_mutex ); /* DDD ldap_pvt_thread_mutex_lock( &li->li_nextid_mutex ); */
/* first time in here since startup - try to read the nexid */ /* first time in here since startup - try to read the nexid */
if ( li->li_nextid == NOID ) { if ( li->li_nextid == NOID ) {
@ -124,7 +124,7 @@ bdb2i_next_id( BackendDB *be )
(void) next_id_write( be, li->li_nextid ); (void) next_id_write( be, li->li_nextid );
#endif #endif
ldap_pvt_thread_mutex_unlock( &li->li_nextid_mutex ); /* DDD ldap_pvt_thread_mutex_unlock( &li->li_nextid_mutex ); */
return( id ); return( id );
} }
@ -134,10 +134,10 @@ bdb2i_next_id_return( BackendDB *be, ID id )
#ifdef SLAPD_NEXTID_RETURN #ifdef SLAPD_NEXTID_RETURN
struct ldbminfo *li = (struct ldbminfo *) be->be_private; struct ldbminfo *li = (struct ldbminfo *) be->be_private;
ldap_pvt_thread_mutex_lock( &li->li_nextid_mutex ); /* DDD ldap_pvt_thread_mutex_lock( &li->li_nextid_mutex ); */
if ( id != li->li_nextid - 1 ) { if ( id != li->li_nextid - 1 ) {
ldap_pvt_thread_mutex_unlock( &li->li_nextid_mutex ); /* DDD ldap_pvt_thread_mutex_unlock( &li->li_nextid_mutex ); */
return; return;
} }
@ -147,7 +147,7 @@ bdb2i_next_id_return( BackendDB *be, ID id )
(void) next_id_write( be, li->li_nextid ); (void) next_id_write( be, li->li_nextid );
#endif #endif
ldap_pvt_thread_mutex_unlock( &li->li_nextid_mutex ); /* DDD ldap_pvt_thread_mutex_unlock( &li->li_nextid_mutex ); */
#endif #endif
} }
@ -157,7 +157,7 @@ bdb2i_next_id_get( BackendDB *be )
struct ldbminfo *li = (struct ldbminfo *) be->be_private; struct ldbminfo *li = (struct ldbminfo *) be->be_private;
ID id; ID id;
ldap_pvt_thread_mutex_lock( &li->li_nextid_mutex ); /* DDD ldap_pvt_thread_mutex_lock( &li->li_nextid_mutex ); */
/* first time in here since startup - try to read the nexid */ /* first time in here since startup - try to read the nexid */
if ( li->li_nextid == NOID ) { if ( li->li_nextid == NOID ) {
@ -174,7 +174,7 @@ bdb2i_next_id_get( BackendDB *be )
id = li->li_nextid; id = li->li_nextid;
ldap_pvt_thread_mutex_unlock( &li->li_nextid_mutex ); /* DDD ldap_pvt_thread_mutex_unlock( &li->li_nextid_mutex ); */
return( id ); return( id );
} }

View file

@ -35,7 +35,7 @@ echo "Waiting 5 seconds for slapd to start..."
sleep 5 sleep 5
echo "Using tester for concurrent server access..." echo "Using tester for concurrent server access..."
$SLAPDTESTER -b "$BASEDN" -d "$DATADIR" -h localhost -p $PORT -D "$MANAGERDN" -w $PASSWD -l 100 $SLAPDTESTER -b "$BASEDN" -d "$DATADIR" -h localhost -p $PORT -D "$MANAGERDN" -w $PASSWD -l 50
RC=$? RC=$?
if [ $RC != 0 ]; then if [ $RC != 0 ]; then

View file

@ -232,6 +232,7 @@ do_addel(
{ {
LDAP *ld; LDAP *ld;
int i; int i;
pid_t pid = getpid();
if (( ld = ldap_init( host, port )) == NULL ) { if (( ld = ldap_init( host, port )) == NULL ) {
perror( "ldap_init" ); perror( "ldap_init" );
@ -245,7 +246,8 @@ do_addel(
} }
fprintf( stderr, "Add/Delete(%d): entry=\"%s\".\n", maxloop, entry ); fprintf( stderr, "PID=%ld - Add/Delete(%d): entry=\"%s\".\n",
pid, maxloop, entry );
for ( i = 0; i < maxloop; i++ ) { for ( i = 0; i < maxloop; i++ ) {
@ -270,6 +272,8 @@ do_addel(
} }
fprintf( stderr, " PID=%ld - Add/Delete done.\n", pid );
ldap_unbind( ld ); ldap_unbind( ld );
} }

View file

@ -70,7 +70,7 @@ main( int argc, char **argv )
} }
do_read( host, port, entry, loops ); do_read( host, port, entry, ( 4 * loops ));
exit( 0 ); exit( 0 );
} }
@ -83,6 +83,7 @@ do_read( char *host, int port, char *entry, int maxloop )
int i; int i;
char *attrs[] = { "cn", "sn", NULL }; char *attrs[] = { "cn", "sn", NULL };
char *filter = "(objectclass=*)"; char *filter = "(objectclass=*)";
pid_t pid = getpid();
if (( ld = ldap_init( host, port )) == NULL ) { if (( ld = ldap_init( host, port )) == NULL ) {
perror( "ldap_init" ); perror( "ldap_init" );
@ -95,22 +96,27 @@ do_read( char *host, int port, char *entry, int maxloop )
} }
fprintf( stderr, "Read(%d): entry=\"%s\".\n", maxloop, entry ); fprintf( stderr, "PID=%ld - Read(%d): entry=\"%s\".\n",
pid, maxloop, entry );
for ( i = 0; i < maxloop; i++ ) { for ( i = 0; i < maxloop; i++ ) {
LDAPMessage *res; LDAPMessage *res;
int rc;
if ( ldap_search_s( ld, entry, LDAP_SCOPE_BASE, if (( rc = ldap_search_s( ld, entry, LDAP_SCOPE_BASE,
filter, attrs, 0, &res ) != LDAP_SUCCESS ) { filter, attrs, 0, &res )) != LDAP_SUCCESS ) {
ldap_perror( ld, "ldap_read" ); ldap_perror( ld, "ldap_read" );
break; if ( rc != LDAP_NO_SUCH_OBJECT ) break;
continue;
} }
ldap_msgfree( res ); ldap_msgfree( res );
} }
fprintf( stderr, " PID=%ld - Read done.\n", pid );
ldap_unbind( ld ); ldap_unbind( ld );
} }

View file

@ -75,7 +75,7 @@ main( int argc, char **argv )
} }
do_search( host, port, sbase, filter, loops ); do_search( host, port, sbase, filter, ( 4 * loops ));
exit( 0 ); exit( 0 );
} }
@ -87,6 +87,7 @@ do_search( char *host, int port, char *sbase, char *filter, int maxloop )
LDAP *ld; LDAP *ld;
int i; int i;
char *attrs[] = { "cn", "sn", NULL }; char *attrs[] = { "cn", "sn", NULL };
pid_t pid = getpid();
if (( ld = ldap_init( host, port )) == NULL ) { if (( ld = ldap_init( host, port )) == NULL ) {
perror( "ldap_init" ); perror( "ldap_init" );
@ -99,23 +100,27 @@ do_search( char *host, int port, char *sbase, char *filter, int maxloop )
} }
fprintf( stderr, "Search(%d): base=\"%s\", filter=\"%s\".\n", fprintf( stderr, "PID=%ld - Search(%d): base=\"%s\", filter=\"%s\".\n",
maxloop, sbase, filter ); pid, maxloop, sbase, filter );
for ( i = 0; i < maxloop; i++ ) { for ( i = 0; i < maxloop; i++ ) {
LDAPMessage *res; LDAPMessage *res;
int rc;
if ( ldap_search_s( ld, sbase, LDAP_SCOPE_SUBTREE, if (( rc = ldap_search_s( ld, sbase, LDAP_SCOPE_SUBTREE,
filter, attrs, 0, &res ) != LDAP_SUCCESS ) { filter, attrs, 0, &res )) != LDAP_SUCCESS ) {
ldap_perror( ld, "ldap_search" ); ldap_perror( ld, "ldap_search" );
break; if ( rc != LDAP_NO_SUCH_OBJECT ) break;
continue;
} }
ldap_msgfree( res ); ldap_msgfree( res );
} }
fprintf( stderr, " PID=%ld - Search done.\n", pid );
ldap_unbind( ld ); ldap_unbind( ld );
} }