X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=servers%2Fslapd%2Fsyncrepl.c;h=f10c36b600e72370bfcbf9ce80bfd6d659047fc3;hb=7fe91339dfd08d6c4168c8493f5c1f0faca6ba54;hp=d99af0ef2ef67b2ba2fc931ba9a8fa06278e4f17;hpb=686ceac31f1c4f2d7f59362ea830d650a9ca4bcd;p=openldap diff --git a/servers/slapd/syncrepl.c b/servers/slapd/syncrepl.c index d99af0ef2e..f10c36b600 100644 --- a/servers/slapd/syncrepl.c +++ b/servers/slapd/syncrepl.c @@ -1037,6 +1037,17 @@ do_syncrep2( "LDAP_RES_INTERMEDIATE", "NEW_COOKIE" ); ber_scanf( ber, "tm", &tag, &cookie ); + Debug( LDAP_DEBUG_SYNC, + "do_syncrep2: %s NEW_COOKIE: %s\n", + si->si_ridtxt, + cookie.bv_val, 0); + if ( !BER_BVISNULL( &cookie ) ) { + ch_free( syncCookie.octet_str.bv_val ); + ber_dupbv( &syncCookie.octet_str, &cookie ); + } + if (!BER_BVISNULL( &syncCookie.octet_str ) ) { + slap_parse_sync_cookie( &syncCookie, NULL ); + } break; case LDAP_TAG_SYNC_REFRESH_DELETE: case LDAP_TAG_SYNC_REFRESH_PRESENT: @@ -1149,6 +1160,7 @@ do_syncrep2( if ( match < 0 ) { if ( si->si_refreshPresent == 1 && + si_tag != LDAP_TAG_SYNC_NEW_COOKIE && syncCookie_req.numcsns == syncCookie.numcsns ) { syncrepl_del_nonpresent( op, si, NULL, &syncCookie, m ); @@ -2875,12 +2887,11 @@ syncrepl_updateCookie( { Backend *be = op->o_bd; Modifications mod; - struct berval first = BER_BVNULL; #ifdef CHECK_CSN Syntax *syn = slap_schema.si_ad_contextCSN->ad_type->sat_syntax; #endif - int rc, i, j; + int rc, i, j, csn_changed = 0; ber_len_t len; slap_callback cb = { NULL }; @@ -2922,13 +2933,7 @@ syncrepl_updateCookie( if ( memcmp( syncCookie->ctxcsn[i].bv_val, si->si_cookieState->cs_vals[j].bv_val, len ) > 0 ) { mod.sml_values[j] = syncCookie->ctxcsn[i]; - if ( BER_BVISNULL( &first ) ) { - first = syncCookie->ctxcsn[i]; - - } else if ( memcmp( syncCookie->ctxcsn[i].bv_val, first.bv_val, first.bv_len ) > 0 ) - { - first = syncCookie->ctxcsn[i]; - } + csn_changed = 1; } break; } @@ -2938,23 +2943,16 @@ syncrepl_updateCookie( ( mod.sml_numvals+2 )*sizeof(struct berval), op->o_tmpmemctx ); mod.sml_values[mod.sml_numvals++] = syncCookie->ctxcsn[i]; BER_BVZERO( &mod.sml_values[mod.sml_numvals] ); - if ( BER_BVISNULL( &first ) ) { - first = syncCookie->ctxcsn[i]; - } else if ( memcmp( syncCookie->ctxcsn[i].bv_val, first.bv_val, first.bv_len ) > 0 ) - { - first = syncCookie->ctxcsn[i]; - } + csn_changed = 1; } } /* Should never happen, ITS#5065 */ - if ( BER_BVISNULL( &first )) { + if ( !csn_changed ) { ldap_pvt_thread_mutex_unlock( &si->si_cookieState->cs_mutex ); op->o_tmpfree( mod.sml_values, op->o_tmpmemctx ); return 0; } op->o_bd = si->si_wbe; - slap_queue_csn( op, &first ); - op->o_tag = LDAP_REQ_MODIFY; cb.sc_response = null_callback; @@ -4325,13 +4323,22 @@ add_syncrepl( BER_BVISNULL( &si->si_bindconf.sb_uri ) ? "(null)" : si->si_bindconf.sb_uri.bv_val, 0, 0 ); if ( c->be->be_syncinfo ) { + syncinfo_t *sip; + si->si_cookieState = c->be->be_syncinfo->si_cookieState; + + // 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 { si->si_cookieState = ch_calloc( 1, sizeof( cookie_state )); ldap_pvt_thread_mutex_init( &si->si_cookieState->cs_mutex ); + + c->be->be_syncinfo = si; } - si->si_next = c->be->be_syncinfo; - c->be->be_syncinfo = si; + + si->si_next = NULL; + return 0; } }