From a215fdea668ca74dd2b9f45a6e2b0b435bd40e5b Mon Sep 17 00:00:00 2001 From: Pierangelo Masarati Date: Thu, 5 May 2005 17:34:11 +0000 Subject: [PATCH] a bit more reworking and streamline; the change to the LAST_CONN test seems to eliminate the last LDAP_BUSY problems on the only machine that was showing it yet; please test --- servers/slapd/back-meta/back-meta.h | 3 -- servers/slapd/back-meta/bind.c | 51 ++++++++++++++++++++--------- servers/slapd/back-meta/compare.c | 19 ++++++----- servers/slapd/back-meta/conn.c | 46 +++++++++++++------------- servers/slapd/back-meta/init.c | 11 +++++-- servers/slapd/back-meta/search.c | 13 +++++--- 6 files changed, 87 insertions(+), 56 deletions(-) diff --git a/servers/slapd/back-meta/back-meta.h b/servers/slapd/back-meta/back-meta.h index f3d3a84a94..620bb93e14 100644 --- a/servers/slapd/back-meta/back-meta.h +++ b/servers/slapd/back-meta/back-meta.h @@ -162,7 +162,6 @@ typedef struct metasingleconn_t { int msc_candidate; #define META_NOT_CANDIDATE ((ber_tag_t)0) #define META_CANDIDATE ((ber_tag_t)1) -#define META_LAST_CONN ((ber_tag_t)(-1)) LDAP *msc_ld; struct berval msc_bound_ndn; @@ -175,8 +174,6 @@ typedef struct metasingleconn_t { struct metainfo_t *msc_info; } metasingleconn_t; -#define META_LAST(msc) ((msc)->msc_candidate == META_LAST_CONN) - typedef struct metaconn_t { struct slap_conn *mc_conn; ldap_pvt_thread_mutex_t mc_mutex; diff --git a/servers/slapd/back-meta/bind.c b/servers/slapd/back-meta/bind.c index 88bbf72a69..120959699f 100644 --- a/servers/slapd/back-meta/bind.c +++ b/servers/slapd/back-meta/bind.c @@ -431,6 +431,9 @@ retry:; } break; } + + } else { + rc = slap_map_api2result( rs ); } rs->sr_err = rc; @@ -453,13 +456,16 @@ meta_back_dobind( { metainfo_t *mi = ( metainfo_t * )op->o_bd->be_private; - metasingleconn_t *msc; int bound = 0, i; SlapReply *candidates = meta_back_candidates_get( op ); ldap_pvt_thread_mutex_lock( &mc->mc_mutex ); + Debug( LDAP_DEBUG_TRACE, + "%s meta_back_dobind: conn=%ld\n", + op->o_log_prefix, mc->mc_conn->c_connid, 0 ); + /* * all the targets are bound as pseudoroot */ @@ -468,22 +474,29 @@ meta_back_dobind( goto done; } - for ( i = 0, msc = &mc->mc_conns[ 0 ]; !META_LAST( msc ); ++i, ++msc ) { - metatarget_t *mt = &mi->mi_targets[ i ]; - int rc; + for ( i = 0; i < mi->mi_ntargets; i++ ) { + metatarget_t *mt = &mi->mi_targets[ i ]; + metasingleconn_t *msc = &mc->mc_conns[ i ]; + int rc; /* - * Not a candidate or something wrong with this target ... + * Not a candidate */ - if ( msc->msc_ld == NULL ) { + if ( candidates[ i ].sr_tag != META_CANDIDATE ) { continue; } + assert( msc->msc_ld != NULL ); + /* * If the target is already bound it is skipped */ if ( msc->msc_bound == META_BOUND && mc->mc_auth_target == i ) { ++bound; + + Debug( LDAP_DEBUG_TRACE, "%s meta_back_dobind[%d]: " + "authcTarget\n", + op->o_log_prefix, i, 0 ); continue; } @@ -504,13 +517,13 @@ meta_back_dobind( * so better clear the handle */ candidates[ i ].sr_tag = META_NOT_CANDIDATE; -#if 0 - ( void )meta_clear_one_candidate( msc ); -#endif continue; } /* else */ - candidates[ i ].sr_tag = META_CANDIDATE; + Debug( LDAP_DEBUG_TRACE, "%s meta_back_dobind[%d]: " + "(anonymous)\n", + op->o_log_prefix, i, 0 ); + msc->msc_bound = META_ANONYMOUS; ++bound; } @@ -518,7 +531,11 @@ meta_back_dobind( done:; ldap_pvt_thread_mutex_unlock( &mc->mc_mutex ); - if ( bound == 0 && sendok & LDAP_BACK_SENDERR ) { + Debug( LDAP_DEBUG_TRACE, + "%s meta_back_dobind: conn=%ld bound=%d\n", + op->o_log_prefix, mc->mc_conn->c_connid, bound ); + + if ( bound == 0 && ( sendok & LDAP_BACK_SENDERR ) ) { if ( rs->sr_err == LDAP_SUCCESS ) { rs->sr_err = LDAP_BUSY; } @@ -559,16 +576,17 @@ meta_back_op_result( SlapReply *rs, int candidate ) { + metainfo_t *mi = ( metainfo_t * )op->o_bd->be_private; + int i, rerr = LDAP_SUCCESS; - metasingleconn_t *msc; char *rmsg = NULL; char *rmatch = NULL; int free_rmsg = 0, free_rmatch = 0; if ( candidate != META_TARGET_NONE ) { - msc = &mc->mc_conns[ candidate ]; + metasingleconn_t *msc = &mc->mc_conns[ candidate ]; rs->sr_err = LDAP_SUCCESS; @@ -602,9 +620,10 @@ meta_back_op_result( } } else { - for ( i = 0, msc = &mc->mc_conns[ 0 ]; !META_LAST( msc ); ++i, ++msc ) { - char *msg = NULL; - char *match = NULL; + for ( i = 0; i < mi->mi_ntargets; i++ ) { + metasingleconn_t *msc = &mc->mc_conns[ i ]; + char *msg = NULL; + char *match = NULL; rs->sr_err = LDAP_SUCCESS; diff --git a/servers/slapd/back-meta/compare.c b/servers/slapd/back-meta/compare.c index e447f7a8d1..77701d154e 100644 --- a/servers/slapd/back-meta/compare.c +++ b/servers/slapd/back-meta/compare.c @@ -36,7 +36,6 @@ meta_back_compare( Operation *op, SlapReply *rs ) { metainfo_t *mi = ( metainfo_t * )op->o_bd->be_private; metaconn_t *mc; - metasingleconn_t *msc; char *match = NULL, *err = NULL; struct berval mmatch = BER_BVNULL; @@ -69,10 +68,11 @@ meta_back_compare( Operation *op, SlapReply *rs ) dc.rs = rs; dc.ctx = "compareDN"; - for ( i = 0, msc = &mc->mc_conns[ 0 ]; !META_LAST( msc ); ++i, ++msc ) { - struct berval mdn = BER_BVNULL; - struct berval mapped_attr = op->orc_ava->aa_desc->ad_cname; - struct berval mapped_value = op->orc_ava->aa_value; + for ( i = 0; i < mi->mi_ntargets; i++ ) { + metasingleconn_t *msc = &mc->mc_conns[ i ]; + struct berval mdn = BER_BVNULL; + struct berval mapped_attr = op->orc_ava->aa_desc->ad_cname; + struct berval mapped_value = op->orc_ava->aa_value; if ( candidates[ i ].sr_tag != META_CANDIDATE ) { msgid[ i ] = -1; @@ -171,10 +171,11 @@ meta_back_compare( Operation *op, SlapReply *rs ) /* * FIXME: should we check for abandon? */ - for ( i = 0, msc = &mc->mc_conns[ 0 ]; !META_LAST( msc ); msc++, i++ ) { - int lrc; - LDAPMessage *res = NULL; - struct timeval tv = { 0 }; + for ( i = 0; i < mi->mi_ntargets; i++ ) { + metasingleconn_t *msc = &mc->mc_conns[ i ]; + int lrc; + LDAPMessage *res = NULL; + struct timeval tv = { 0 }; tv.tv_sec = 0; tv.tv_usec = 0; diff --git a/servers/slapd/back-meta/conn.c b/servers/slapd/back-meta/conn.c index 138b820068..587bd15d98 100644 --- a/servers/slapd/back-meta/conn.c +++ b/servers/slapd/back-meta/conn.c @@ -125,28 +125,25 @@ metaconn_alloc( { metainfo_t *mi = ( metainfo_t * )op->o_bd->be_private; metaconn_t *mc; - int ntargets = mi->mi_ntargets; + int i, ntargets = mi->mi_ntargets; assert( ntargets > 0 ); /* malloc once only; leave an extra one for one-past-end */ mc = ( metaconn_t * )ch_malloc( sizeof( metaconn_t ) - + sizeof( metasingleconn_t ) * ( ntargets + 1 ) ); + + sizeof( metasingleconn_t ) * ntargets ); if ( mc == NULL ) { return NULL; } mc->mc_conns = ( metasingleconn_t * )&mc[ 1 ]; - /* FIXME: needed by META_LAST() */ - mc->mc_conns[ ntargets ].msc_candidate = META_LAST_CONN; - - for ( ; ntargets-- > 0; ) { - mc->mc_conns[ ntargets ].msc_ld = NULL; - BER_BVZERO( &mc->mc_conns[ ntargets ].msc_bound_ndn ); - BER_BVZERO( &mc->mc_conns[ ntargets ].msc_cred ); - mc->mc_conns[ ntargets ].msc_bound = META_UNBOUND; - mc->mc_conns[ ntargets ].msc_info = mi; + for ( i = 0; i < ntargets; i++ ) { + mc->mc_conns[ i ].msc_ld = NULL; + BER_BVZERO( &mc->mc_conns[ i ].msc_bound_ndn ); + BER_BVZERO( &mc->mc_conns[ i ].msc_cred ); + mc->mc_conns[ i ].msc_bound = META_UNBOUND; + mc->mc_conns[ i ].msc_info = mi; } mc->mc_auth_target = META_BOUND_NONE; @@ -595,7 +592,9 @@ meta_back_getconn( int cached = META_TARGET_NONE, i = META_TARGET_NONE, err = LDAP_SUCCESS, - new_conn = 0; + new_conn = 0, + ncandidates = 0; + meta_op_type op_type = META_OP_REQUIRE_SINGLE; int parent = 0, @@ -674,6 +673,7 @@ meta_back_getconn( &mc->mc_conns[ i ], sendok ); if ( lerr == LDAP_SUCCESS ) { candidates[ i ].sr_tag = META_CANDIDATE; + ncandidates++; } else { @@ -735,7 +735,7 @@ meta_back_getconn( return NULL; } - Debug( LDAP_DEBUG_CACHE, + Debug( LDAP_DEBUG_TRACE, "==>meta_back_getconn: got target %d for ndn=\"%s\" from cache\n", i, op->o_req_ndn.bv_val, 0 ); @@ -767,6 +767,7 @@ meta_back_getconn( &mc->mc_conns[ i ], sendok ); if ( err == LDAP_SUCCESS ) { candidates[ i ].sr_tag = META_CANDIDATE; + ncandidates++; } else { @@ -792,8 +793,6 @@ meta_back_getconn( */ } else { - int ncandidates = 0; - /* Looks like we didn't get a bind. Open a new session... */ if ( !mc ) { mc = metaconn_alloc( op ); @@ -818,6 +817,9 @@ meta_back_getconn( candidates[ i ].sr_tag = META_CANDIDATE; ncandidates++; + Debug( LDAP_DEBUG_TRACE, "%s: meta_back_init_one_conn(%d)\n", + op->o_log_prefix, i, 0 ); + } else { /* @@ -887,13 +889,13 @@ done:; */ if ( err == 0 ) { Debug( LDAP_DEBUG_TRACE, - "%s meta_back_getconn: conn %ld inserted\n", - op->o_log_prefix, mc->mc_conn->c_connid, 0 ); + "%s meta_back_getconn: candidates=%d conn=%ld inserted\n", + op->o_log_prefix, ncandidates, mc->mc_conn->c_connid ); } else { - Debug( LDAP_DEBUG_TRACE, - "%s meta_back_getconn: conn %ld insert failed\n", - op->o_log_prefix, mc->mc_conn->c_connid, 0 ); + Debug( LDAP_DEBUG_ANY, + "%s meta_back_getconn: candidates=%d conn=%ld insert failed\n", + op->o_log_prefix, ncandidates, mc->mc_conn->c_connid ); rs->sr_err = LDAP_OTHER; rs->sr_text = "Internal server error"; @@ -907,8 +909,8 @@ done:; } else { Debug( LDAP_DEBUG_TRACE, - "%s meta_back_getconn: conn %ld fetched\n", - op->o_log_prefix, mc->mc_conn->c_connid, 0 ); + "%s meta_back_getconn: candidates=%d conn=%ld fetched\n", + op->o_log_prefix, ncandidates, mc->mc_conn->c_connid ); } return mc; diff --git a/servers/slapd/back-meta/init.c b/servers/slapd/back-meta/init.c index 305bf901b9..336f001713 100644 --- a/servers/slapd/back-meta/init.c +++ b/servers/slapd/back-meta/init.c @@ -128,17 +128,24 @@ conn_free( void *v_mc ) { metaconn_t *mc = v_mc; - metasingleconn_t *msc; + int i, ntargets; assert( mc->mc_conns != NULL ); - for ( msc = &mc->mc_conns[ 0 ]; !META_LAST( msc ); msc++ ) { + /* at least one must be present... */ + ntargets = mc->mc_conns[ 0 ].msc_info->mi_ntargets; + + for ( i = 0; i < ntargets; i++ ) { + metasingleconn_t *msc = &mc->mc_conns[ i ]; + if ( msc->msc_ld != NULL ) { ldap_unbind_ext_s( msc->msc_ld, NULL, NULL ); } + if ( !BER_BVISNULL( &msc->msc_bound_ndn ) ) { ber_memfree( msc->msc_bound_ndn.bv_val ); } + if ( !BER_BVISNULL( &msc->msc_cred ) ) { /* destroy sensitive data */ memset( msc->msc_cred.bv_val, 0, msc->msc_cred.bv_len ); diff --git a/servers/slapd/back-meta/search.c b/servers/slapd/back-meta/search.c index dca47acb14..42e7cb993a 100644 --- a/servers/slapd/back-meta/search.c +++ b/servers/slapd/back-meta/search.c @@ -220,7 +220,6 @@ meta_back_search( Operation *op, SlapReply *rs ) { metainfo_t *mi = ( metainfo_t * )op->o_bd->be_private; metaconn_t *mc; - metasingleconn_t *msc; struct timeval tv = { 0, 0 }; LDAPMessage *res = NULL, *e; int rc = 0, sres = LDAP_SUCCESS; @@ -249,7 +248,9 @@ meta_back_search( Operation *op, SlapReply *rs ) /* * Inits searches */ - for ( i = 0, msc = &mc->mc_conns[ 0 ]; !META_LAST( msc ); ++i, ++msc ) { + for ( i = 0; i < mi->mi_ntargets; i++ ) { + metasingleconn_t *msc = &mc->mc_conns[ i ]; + candidates[ i ].sr_msgid = -1; if ( candidates[ i ].sr_tag != META_CANDIDATE ) { @@ -319,7 +320,9 @@ meta_back_search( Operation *op, SlapReply *rs ) for ( rc = 0; ncandidates > 0; ) { int gotit = 0, doabandon = 0; - for ( i = 0, msc = &mc->mc_conns[ 0 ]; !META_LAST( msc ); msc++, i++ ) { + for ( i = 0; i < mi->mi_ntargets; i++ ) { + metasingleconn_t *msc = &mc->mc_conns[ i ]; + if ( candidates[ i ].sr_msgid == -1 ) { continue; } @@ -607,7 +610,9 @@ really_bad:; /* check for abandon */ if ( op->o_abandon || doabandon ) { - for ( i = 0, msc = mc->mc_conns; !META_LAST( msc ); msc++, i++ ) { + for ( i = 0; i < mi->mi_ntargets; i++ ) { + metasingleconn_t *msc = &mc->mc_conns[ i ]; + if ( candidates[ i ].sr_msgid != -1 ) { ldap_abandon_ext( msc->msc_ld, candidates[ i ].sr_msgid, -- 2.39.5