From: Howard Chu Date: Thu, 13 Mar 2008 05:18:28 +0000 (+0000) Subject: In mirrormode, also ask syncprov for initial cookie. It may have been X-Git-Tag: OPENLDAP_REL_ENG_2_4_9~20^2~97 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=af80427965c2baf4dab8e077c0539c378625b07b;p=openldap In mirrormode, also ask syncprov for initial cookie. It may have been cached from a recent update. --- diff --git a/servers/slapd/syncrepl.c b/servers/slapd/syncrepl.c index 0ae6cb63b2..0ac5ca389b 100644 --- a/servers/slapd/syncrepl.c +++ b/servers/slapd/syncrepl.c @@ -432,6 +432,34 @@ ldap_sync_search( return rc; } +static int +ask_syncprov( Operation *op, syncinfo_t *si, Attribute *a ) +{ + AttributeName at[2]; + Entry e = {0}; + SlapReply rs = {0}; + + /* Look for contextCSN from syncprov overlay. If + * there's no overlay, this will be a no-op. That means + * this is a pure consumer, so local changes will not be + * allowed, and all changes will already be reflected in + * the cookieState. + */ + a->a_desc = slap_schema.si_ad_contextCSN; + e.e_attrs = a; + e.e_name = si->si_wbe->be_suffix[0]; + e.e_nname = si->si_wbe->be_nsuffix[0]; + rs.sr_entry = &e; + rs.sr_flags = REP_ENTRY_MODIFIABLE; + at[0].an_name = a->a_desc->ad_cname; + at[0].an_desc = a->a_desc; + BER_BVZERO( &at[1].an_name ); + op->o_req_dn = e.e_name; + op->o_req_ndn = e.e_nname; + + return backend_operational( op, &rs ); +} + static int do_syncrep1( Operation *op, @@ -468,16 +496,16 @@ do_syncrep1( ldap_set_option( si->si_ld, LDAP_OPT_TIMELIMIT, &si->si_tlimit ); + si->si_syncCookie.rid = si->si_rid; + si->si_syncCookie.sid = SLAP_SINGLE_SHADOW( si->si_be ) ? -1 : + slap_serverID; + /* We've just started up, or the remote server hasn't sent us * any meaningful state. */ if ( BER_BVISNULL( &si->si_syncCookie.octet_str ) ) { int i; - si->si_syncCookie.rid = si->si_rid; - si->si_syncCookie.sid = SLAP_SINGLE_SHADOW( si->si_be ) ? -1 : - slap_serverID; - LDAP_STAILQ_FOREACH( sc, &slap_sync_cookie, sc_next ) { if ( si->si_rid == sc->rid ) { cmdline_cookie_found = 1; @@ -499,22 +527,25 @@ do_syncrep1( ldap_pvt_thread_mutex_lock( &si->si_cookieState->cs_mutex ); if ( !si->si_cookieState->cs_num ) { /* get contextCSN shadow replica from database */ - BerVarray csn = NULL; + Attribute a = {0}; void *ctx = op->o_tmpmemctx; - op->o_req_ndn = op->o_bd->be_nsuffix[0]; - op->o_req_dn = op->o_req_ndn; - - /* try to read stored contextCSN */ - op->o_tmpmemctx = NULL; - backend_attribute( op, NULL, &op->o_req_ndn, - slap_schema.si_ad_contextCSN, &csn, ACL_READ ); - op->o_tmpmemctx = ctx; - if ( csn ) { - si->si_cookieState->cs_vals = csn; - for (i=0; !BER_BVISNULL( &csn[i] ); i++); - si->si_cookieState->cs_num = i; - si->si_cookieState->cs_sids = slap_parse_csn_sids( csn, i, NULL ); + rc = ask_syncprov( op, si, &a ); + if ( rc || !a.a_vals ) { + /* try to read stored contextCSN */ + op->o_tmpmemctx = NULL; + backend_attribute( op, NULL, &op->o_req_ndn, + slap_schema.si_ad_contextCSN, &a.a_vals, ACL_READ ); + op->o_tmpmemctx = ctx; + if ( a.a_vals ) { + for (i=0; !BER_BVISNULL( &a.a_vals[i] ); i++); + a.a_numvals = i; + } + } + if ( a.a_vals ) { + si->si_cookieState->cs_vals = a.a_vals; + si->si_cookieState->cs_num = a.a_numvals; + si->si_cookieState->cs_sids = slap_parse_csn_sids( a.a_vals, a.a_numvals, NULL ); } } if ( si->si_cookieState->cs_num ) { @@ -538,10 +569,7 @@ do_syncrep1( si->si_syncCookie.ctxcsn, si->si_syncCookie.rid, si->si_syncCookie.sid ); } else { - AttributeName at[2]; Attribute a = {0}; - Entry e = {0}; - SlapReply rs = {0}; int i, j, changed = 0; /* Look for contextCSN from syncprov overlay. If @@ -550,20 +578,8 @@ do_syncrep1( * allowed, and all changes will already be reflected in * the cookieState. */ - a.a_desc = slap_schema.si_ad_contextCSN; - e.e_attrs = &a; - e.e_name = si->si_wbe->be_suffix[0]; - e.e_nname = si->si_wbe->be_nsuffix[0]; - rs.sr_entry = &e; - rs.sr_flags = REP_ENTRY_MODIFIABLE; - at[0].an_name = a.a_desc->ad_cname; - at[0].an_desc = a.a_desc; - BER_BVZERO( &at[1].an_name ); - op->o_req_dn = e.e_name; - op->o_req_ndn = e.e_nname; - ldap_pvt_thread_mutex_lock( &si->si_cookieState->cs_mutex ); - rc = backend_operational( op, &rs ); + rc = ask_syncprov( op, si, &a ); if ( rc == LDAP_SUCCESS && a.a_vals ) { int num = a.a_numvals; /* check for differences */ @@ -624,7 +640,7 @@ do_syncrep1( ch_free( si->si_syncCookie.octet_str.bv_val ); slap_compose_sync_cookie( NULL, &si->si_syncCookie.octet_str, si->si_syncCookie.ctxcsn, si->si_syncCookie.rid, - SLAP_SINGLE_SHADOW( si->si_be ) ? -1 : slap_serverID ); + si->si_syncCookie.sid ); } } ldap_pvt_thread_mutex_unlock( &si->si_cookieState->cs_mutex );