X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=servers%2Fslapd%2Fsyncrepl.c;h=07e9dd78577fb08c33b472ac2a67a339204a7b06;hb=861441fcf7661e6a13dfe236537dd318a58492d1;hp=2033100e37c26f6ecc4a162a8a9be126d6b34e08;hpb=c6da723a91f234daea133ef9b5a63faf4885fae6;p=openldap diff --git a/servers/slapd/syncrepl.c b/servers/slapd/syncrepl.c index 2033100e37..07e9dd7857 100644 --- a/servers/slapd/syncrepl.c +++ b/servers/slapd/syncrepl.c @@ -41,6 +41,7 @@ typedef struct cookie_state { ldap_pvt_thread_mutex_t cs_mutex; int cs_num; int cs_age; + int cs_ref; struct berval *cs_vals; int *cs_sids; } cookie_state; @@ -1255,11 +1256,13 @@ do_syncrepl( int rc = LDAP_SUCCESS; int dostop = 0; ber_socket_t s; - int i, defer = 1, fail = 0; + int i, defer = 1, fail = 0, freeinfo = 0; Backend *be; if ( si == NULL ) return NULL; + if ( slapd_shutdown ) + return NULL; Debug( LDAP_DEBUG_TRACE, "=>do_syncrepl %s\n", si->si_ridtxt, 0, 0 ); @@ -1271,6 +1274,10 @@ do_syncrepl( ldap_pvt_thread_yield(); } + if ( si->si_ctype < 1 ) { + goto deleted; + } + switch( abs( si->si_type ) ) { case LDAP_SYNC_REFRESH_ONLY: case LDAP_SYNC_REFRESH_AND_PERSIST: @@ -1296,10 +1303,6 @@ do_syncrepl( connection_fake_init( &conn, &opbuf, ctx ); op = &opbuf.ob_op; - /* use global malloc for now */ - op->o_tmpmemctx = NULL; - op->o_tmpmfuncs = &ch_mfuncs; - op->o_managedsait = SLAP_CONTROL_NONCRITICAL; be = si->si_be; @@ -1358,8 +1361,13 @@ reload: goto reload; } +deleted: /* We got deleted while running on cn=config */ - if ( !si->si_ctype ) { + if ( si->si_ctype < 1 ) { + if ( si->si_ctype == -1 ) { + si->si_ctype = 0; + freeinfo = 1; + } if ( si->si_conn ) dostop = 1; rc = -1; @@ -1426,7 +1434,7 @@ reload: break; } - if ( !si->si_ctype + if ( si->si_ctype < 1 || !si->si_retrynum || si->si_retrynum[i] == RETRYNUM_TAIL ) { if ( si->si_re ) { ldap_pvt_runqueue_remove( &slapd_rq, rtask ); @@ -1463,10 +1471,8 @@ reload: } /* Do final delete cleanup */ - if ( !si->si_ctype ) { - cookie_state *cs = si->si_cookieState; - syncinfo_free( si, ( !be->be_syncinfo || - be->be_syncinfo->si_cookieState != cs )); + if ( freeinfo ) { + syncinfo_free( si, 0 ); } return NULL; } @@ -1621,7 +1627,16 @@ syncrepl_message_to_op( if ( !ber_bvstrcasecmp( &bv, &ls->ls_dn ) ) { bdn = bvals[0]; - dnPrettyNormal( NULL, &bdn, &dn, &ndn, op->o_tmpmemctx ); + rc = dnPrettyNormal( NULL, &bdn, &dn, &ndn, op->o_tmpmemctx ); + if ( rc != LDAP_SUCCESS ) { + Debug( LDAP_DEBUG_ANY, + "syncrepl_message_to_op: %s " + "dn \"%s\" normalization failed (%d)", + si->si_ridtxt, bdn.bv_val, rc ); + rc = -1; + ch_free( bvals ); + goto done; + } ber_dupbv( &op->o_req_dn, &dn ); ber_dupbv( &op->o_req_ndn, &ndn ); slap_sl_free( ndn.bv_val, op->o_tmpmemctx ); @@ -1853,7 +1868,21 @@ syncrepl_message_to_entry( return -1; } - dnPrettyNormal( NULL, &bdn, &dn, &ndn, op->o_tmpmemctx ); + rc = dnPrettyNormal( NULL, &bdn, &dn, &ndn, op->o_tmpmemctx ); + if ( rc != LDAP_SUCCESS ) { + /* One of the things that could happen is that the schema + * is not lined-up; this could result in unknown attributes. + * A value non conformant to the syntax should be unlikely, + * except when replicating between different versions + * of the software, or when syntax validation bugs are fixed + */ + Debug( LDAP_DEBUG_ANY, + "syncrepl_message_to_entry: " + "%s dn \"%s\" normalization failed (%d)", + si->si_ridtxt, bdn.bv_val, rc ); + return rc; + } + ber_dupbv( &op->o_req_dn, &dn ); ber_dupbv( &op->o_req_ndn, &ndn ); slap_sl_free( ndn.bv_val, op->o_tmpmemctx ); @@ -3599,12 +3628,6 @@ syncinfo_free( syncinfo_t *sie, int free_all ) Debug( LDAP_DEBUG_TRACE, "syncinfo_free: %s\n", sie->si_ridtxt, 0, 0 ); - if ( free_all && sie->si_cookieState ) { - ch_free( sie->si_cookieState->cs_sids ); - ber_bvarray_free( sie->si_cookieState->cs_vals ); - ldap_pvt_thread_mutex_destroy( &sie->si_cookieState->cs_mutex ); - ch_free( sie->si_cookieState ); - } do { si_next = sie->si_next; @@ -3616,20 +3639,21 @@ syncinfo_free( syncinfo_t *sie, int free_all ) ldap_unbind_ext( sie->si_ld, NULL, NULL ); } - /* re-fetch it, in case it was already removed */ - ldap_pvt_thread_mutex_lock( &slapd_rq.rq_mutex ); - sie->si_re = ldap_pvt_runqueue_find( &slapd_rq, do_syncrepl, sie ); if ( sie->si_re ) { - if ( ldap_pvt_runqueue_isrunning( &slapd_rq, sie->si_re ) ) - ldap_pvt_runqueue_stoptask( &slapd_rq, sie->si_re ); - ldap_pvt_runqueue_remove( &slapd_rq, sie->si_re ); + struct re_s *re = sie->si_re; + sie->si_re = NULL; + + ldap_pvt_thread_mutex_lock( &slapd_rq.rq_mutex ); + if ( ldap_pvt_runqueue_isrunning( &slapd_rq, re ) ) + ldap_pvt_runqueue_stoptask( &slapd_rq, re ); + ldap_pvt_runqueue_remove( &slapd_rq, re ); + ldap_pvt_thread_mutex_unlock( &slapd_rq.rq_mutex ); } - - ldap_pvt_thread_mutex_unlock( &slapd_rq.rq_mutex ); - ldap_pvt_thread_mutex_destroy( &sie->si_mutex ); - + + ldap_pvt_thread_mutex_destroy( &sie->si_mutex ); + bindconf_free( &sie->si_bindconf ); - + if ( sie->si_filterstr.bv_val ) { ch_free( sie->si_filterstr.bv_val ); } @@ -3705,6 +3729,13 @@ syncinfo_free( syncinfo_t *sie, int free_all ) } ch_free( npe ); } + sie->si_cookieState->cs_ref--; + if ( !sie->si_cookieState->cs_ref ) { + ch_free( sie->si_cookieState->cs_sids ); + ber_bvarray_free( sie->si_cookieState->cs_vals ); + ldap_pvt_thread_mutex_destroy( &sie->si_cookieState->cs_mutex ); + ch_free( sie->si_cookieState ); + } ch_free( sie ); sie = si_next; } while ( free_all && si_next ); @@ -4374,7 +4405,7 @@ add_syncrepl( si->si_cookieState = c->be->be_syncinfo->si_cookieState; - // add new syncrepl to end of list (same order as when deleting) + /* add new syncrepl to end of list (same order as when deleting) */ for ( sip = c->be->be_syncinfo; sip->si_next; sip = sip->si_next ); sip->si_next = si; } else { @@ -4383,6 +4414,7 @@ add_syncrepl( c->be->be_syncinfo = si; } + si->si_cookieState->cs_ref++; si->si_next = NULL; @@ -4581,13 +4613,11 @@ syncrepl_config( ConfigArgs *c ) } return 1; } else if ( c->op == LDAP_MOD_DELETE ) { - cookie_state *cs = NULL; int isrunning = 0; if ( c->be->be_syncinfo ) { syncinfo_t *si, **sip; int i; - cs = c->be->be_syncinfo->si_cookieState; for ( sip = &c->be->be_syncinfo, i=0; *sip; i++ ) { si = *sip; if ( c->valx == -1 || i == c->valx ) { @@ -4600,15 +4630,20 @@ syncrepl_config( ConfigArgs *c ) if ( ldap_pvt_thread_mutex_trylock( &si->si_mutex )) { isrunning = 1; } else { + if ( si->si_conn ) { + /* If there's a persistent connection, it may + * already have a thread queued. We know it's + * not active, so it must be pending and we + * can simply cancel it now. + */ + ldap_pvt_thread_pool_retract( &connection_pool, + si->si_re->routine, si->si_re ); + } ldap_pvt_thread_mutex_unlock( &si->si_mutex ); } - if ( si->si_conn ) { - connection_client_stop( si->si_conn ); - si->si_conn = NULL; - } } - if ( si->si_re && isrunning ) { - si->si_ctype = 0; + if ( isrunning ) { + si->si_ctype = -1; si->si_next = NULL; } else { syncinfo_free( si, 0 ); @@ -4622,12 +4657,6 @@ syncrepl_config( ConfigArgs *c ) } if ( !c->be->be_syncinfo ) { SLAP_DBFLAGS( c->be ) &= ~SLAP_DBFLAG_SHADOW_MASK; - if ( cs && !isrunning ) { - ch_free( cs->cs_sids ); - ber_bvarray_free( cs->cs_vals ); - ldap_pvt_thread_mutex_destroy( &cs->cs_mutex ); - ch_free( cs ); - } } return 0; }