From 9795721f7ada1b86cac35f30dc0cb3372cd5ae1b Mon Sep 17 00:00:00 2001 From: Pierangelo Masarati Date: Wed, 11 Jan 2006 19:33:44 +0000 Subject: [PATCH] improve back-meta retry capabilities (ITS#4328) --- servers/slapd/back-meta/back-meta.h | 17 ++++++++++++++--- servers/slapd/back-meta/bind.c | 20 ++++++++++---------- servers/slapd/back-meta/conn.c | 29 +++++++++++++++++++++++------ 3 files changed, 47 insertions(+), 19 deletions(-) diff --git a/servers/slapd/back-meta/back-meta.h b/servers/slapd/back-meta/back-meta.h index 4f27415c37..a667e86567 100644 --- a/servers/slapd/back-meta/back-meta.h +++ b/servers/slapd/back-meta/back-meta.h @@ -301,12 +301,15 @@ meta_back_release_conn( metaconn_t *mc ); extern int -meta_back_retry( +meta_back_retry_lock( Operation *op, SlapReply *rs, metaconn_t *mc, int candidate, - ldap_back_send_t sendok ); + ldap_back_send_t sendok, + int dolock ); +#define meta_back_retry(op, rs, mc, candidate, sendok) \ + meta_back_retry_lock((op), (rs), (mc), (candidate), (sendok), 1) extern void meta_back_conn_free( @@ -322,6 +325,14 @@ meta_back_init_one_conn( int ispriv, ldap_back_send_t sendok ); +extern int +meta_back_single_bind( + Operation *op, + SlapReply *rs, + metaconn_t *mc, + int candidate, + int massage ); + extern int meta_back_dobind( Operation *op, @@ -329,7 +340,7 @@ meta_back_dobind( metaconn_t *mc, ldap_back_send_t sendok ); -int +extern int meta_back_single_dobind( Operation *op, SlapReply *rs, diff --git a/servers/slapd/back-meta/bind.c b/servers/slapd/back-meta/bind.c index 32389a75c1..36e12ba0fc 100644 --- a/servers/slapd/back-meta/bind.c +++ b/servers/slapd/back-meta/bind.c @@ -41,14 +41,6 @@ static LDAP_REBIND_PROC meta_back_default_rebind; */ LDAP_REBIND_PROC *meta_back_rebind_f = meta_back_default_rebind; -static int -meta_back_single_bind( - Operation *op, - SlapReply *rs, - metaconn_t *mc, - int candidate, - int massage ); - int meta_back_bind( Operation *op, SlapReply *rs ) { @@ -272,7 +264,7 @@ retry_lock:; * * attempts to perform a bind with creds */ -static int +int meta_back_single_bind( Operation *op, SlapReply *rs, @@ -648,7 +640,7 @@ meta_back_dobind( for ( i = 0; i < mi->mi_ntargets; i++ ) { metatarget_t *mt = &mi->mi_targets[ i ]; metasingleconn_t *msc = &mc->mc_conns[ i ]; - int rc; + int rc, do_retry = 1; char *rootdn = NULL; /* @@ -668,6 +660,7 @@ meta_back_dobind( continue; } +retry:; if ( isroot && !BER_BVISNULL( &mi->mi_targets[ i ].mt_pseudorootdn ) ) { Operation op2 = *op; @@ -690,6 +683,13 @@ meta_back_dobind( if ( rc != LDAP_SUCCESS ) { char buf[ SLAP_TEXT_BUFLEN ]; + if ( rc == LDAP_UNAVAILABLE && do_retry ) { + do_retry = 0; + if ( meta_back_retry_lock( op, rs, mc, i, LDAP_BACK_DONTSEND, 0 ) ) { + goto retry; + } + } + snprintf( buf, sizeof( buf ), "meta_back_dobind[%d]: (%s) err=%d.", i, rootdn ? rootdn : "anonymous", rc ); diff --git a/servers/slapd/back-meta/conn.c b/servers/slapd/back-meta/conn.c index 08fcbea92c..cd5bad958a 100644 --- a/servers/slapd/back-meta/conn.c +++ b/servers/slapd/back-meta/conn.c @@ -444,17 +444,18 @@ error_return:; } /* - * meta_back_retry + * meta_back_retry_lock * * Retries one connection */ int -meta_back_retry( +meta_back_retry_lock( Operation *op, SlapReply *rs, metaconn_t *mc, int candidate, - ldap_back_send_t sendok ) + ldap_back_send_t sendok, + int dolock ) { metainfo_t *mi = ( metainfo_t * )op->o_bd->be_private; metatarget_t *mt = &mi->mi_targets[ candidate ]; @@ -469,7 +470,7 @@ retry_lock:; if ( mc->mc_refcnt == 1 ) { char buf[ SLAP_TEXT_BUFLEN ]; - while ( ldap_pvt_thread_mutex_trylock( &mc->mc_mutex ) ) { + while ( dolock && ldap_pvt_thread_mutex_trylock( &mc->mc_mutex ) ) { ldap_pvt_thread_mutex_unlock( &mi->mi_conninfo.lai_mutex ); ldap_pvt_thread_yield(); goto retry_lock; @@ -494,11 +495,27 @@ retry_lock:; LDAP_BACK_CONN_ISPRIV( mc ), sendok ); if ( rc == LDAP_SUCCESS ) { - rc = meta_back_single_dobind( op, rs, mc, candidate, + if ( be_isroot( op ) && !BER_BVISNULL( &mi->mi_targets[ candidate ].mt_pseudorootdn ) ) + { + Operation op2 = *op; + + op2.o_tag = LDAP_REQ_BIND; + op2.o_req_dn = mi->mi_targets[ candidate ].mt_pseudorootdn; + op2.o_req_ndn = mi->mi_targets[ candidate ].mt_pseudorootdn; + op2.orb_cred = mi->mi_targets[ candidate ].mt_pseudorootpw; + op2.orb_method = LDAP_AUTH_SIMPLE; + + rc = meta_back_single_bind( &op2, rs, mc, candidate, 0 ); + + } else { + rc = meta_back_single_dobind( op, rs, mc, candidate, sendok, mt->mt_nretries, 0 ); + } } - ldap_pvt_thread_mutex_unlock( &mc->mc_mutex ); + if ( dolock ) { + ldap_pvt_thread_mutex_unlock( &mc->mc_mutex ); + } } if ( rc != LDAP_SUCCESS ) { -- 2.39.5