Commit d1e874c6 authored by Ondřej Kuzník's avatar Ondřej Kuzník Committed by Quanah Gibson-Mount
Browse files

ITS#8768 Introduce delcsn into our syncrepl cookies

parent eae2dfde
...@@ -36,7 +36,8 @@ slap_compose_sync_cookie( ...@@ -36,7 +36,8 @@ slap_compose_sync_cookie(
struct berval *cookie, struct berval *cookie,
BerVarray csn, BerVarray csn,
int rid, int rid,
int sid ) int sid,
struct berval *delcsn )
{ {
int len, numcsn = 0; int len, numcsn = 0;
...@@ -65,6 +66,8 @@ slap_compose_sync_cookie( ...@@ -65,6 +66,8 @@ slap_compose_sync_cookie(
len = 0; len = 0;
for ( i=0; i<numcsn; i++) for ( i=0; i<numcsn; i++)
len += csn[i].bv_len + 1; len += csn[i].bv_len + 1;
if ( delcsn && !BER_BVISEMPTY(delcsn) )
len += STRLENOF(",delcsn=") + delcsn->bv_len;
len += STRLENOF("rid=123,csn="); len += STRLENOF("rid=123,csn=");
if ( sid >= 0 ) if ( sid >= 0 )
...@@ -83,6 +86,10 @@ slap_compose_sync_cookie( ...@@ -83,6 +86,10 @@ slap_compose_sync_cookie(
*ptr++ = ';'; *ptr++ = ';';
} }
ptr--; ptr--;
if ( delcsn && !BER_BVISEMPTY(delcsn) ) {
ptr = lutil_strcopy( ptr, ",delcsn=" );
ptr = lutil_strncopy( ptr, delcsn->bv_val, delcsn->bv_len );
}
*ptr = '\0'; *ptr = '\0';
cookie->bv_len = ptr - cookie->bv_val; cookie->bv_len = ptr - cookie->bv_val;
} }
...@@ -112,6 +119,11 @@ slap_sync_cookie_free( ...@@ -112,6 +119,11 @@ slap_sync_cookie_free(
BER_BVZERO( &cookie->octet_str ); BER_BVZERO( &cookie->octet_str );
} }
if ( !BER_BVISNULL( &cookie->delcsn )) {
ch_free( cookie->delcsn.bv_val );
BER_BVZERO( &cookie->delcsn );
}
if ( free_cookie ) { if ( free_cookie ) {
ch_free( cookie ); ch_free( cookie );
} }
...@@ -273,6 +285,7 @@ slap_parse_sync_cookie( ...@@ -273,6 +285,7 @@ slap_parse_sync_cookie(
cookie->ctxcsn = NULL; cookie->ctxcsn = NULL;
cookie->sids = NULL; cookie->sids = NULL;
cookie->numcsns = 0; cookie->numcsns = 0;
BER_BVZERO( &cookie->delcsn );
end = cookie->octet_str.bv_val + cookie->octet_str.bv_len; end = cookie->octet_str.bv_val + cookie->octet_str.bv_len;
...@@ -359,6 +372,49 @@ slap_parse_sync_cookie( ...@@ -359,6 +372,49 @@ slap_parse_sync_cookie(
} }
continue; continue;
} }
if ( !strncmp( next, "delcsn=", STRLENOF("delcsn=") )) {
struct berval stamp;
next += STRLENOF("delcsn=");
while ( next < end ) {
csn_str = next;
csn_ptr = strchr( csn_str, '#' );
if ( !csn_ptr || csn_ptr > end )
break;
/* ad will be NULL when called from main. we just
* want to parse the rid then. But we still iterate
* through the string to find the end.
*/
cval = strchr( csn_ptr, ';' );
if ( !cval )
cval = strchr(csn_ptr, ',' );
if ( cval )
stamp.bv_len = cval - csn_str;
else
stamp.bv_len = end - csn_str;
if ( ad ) {
struct berval bv;
stamp.bv_val = csn_str;
if ( ad->ad_type->sat_syntax->ssyn_validate(
ad->ad_type->sat_syntax, &stamp ) != LDAP_SUCCESS )
break;
if ( ad->ad_type->sat_equality->smr_normalize(
SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX,
ad->ad_type->sat_syntax,
ad->ad_type->sat_equality,
&stamp, &bv, memctx ) != LDAP_SUCCESS )
break;
cookie->delcsn = bv;
}
if ( cval ) {
next = cval + 1;
} else {
next = end;
}
break;
}
continue;
}
next++; next++;
} }
if ( cookie->numcsns ) { if ( cookie->numcsns ) {
...@@ -411,6 +467,7 @@ slap_init_sync_cookie_ctxcsn( ...@@ -411,6 +467,7 @@ slap_init_sync_cookie_ctxcsn(
value_add_one( &cookie->ctxcsn, &ctxcsn ); value_add_one( &cookie->ctxcsn, &ctxcsn );
cookie->numcsns = 1; cookie->numcsns = 1;
cookie->sid = -1; cookie->sid = -1;
BER_BVZERO( &cookie->delcsn );
return 0; return 0;
} }
...@@ -455,6 +512,10 @@ slap_dup_sync_cookie( ...@@ -455,6 +512,10 @@ slap_dup_sync_cookie(
new->sids[i] = src->sids[i]; new->sids[i] = src->sids[i];
} }
if ( !BER_BVISNULL( &src->delcsn )) {
ber_dupbv( &new->delcsn, &src->delcsn );
}
if ( !BER_BVISNULL( &src->octet_str )) { if ( !BER_BVISNULL( &src->octet_str )) {
ber_dupbv( &new->octet_str, &src->octet_str ); ber_dupbv( &new->octet_str, &src->octet_str );
} }
......
...@@ -887,7 +887,8 @@ syncprov_sendresp( Operation *op, resinfo *ri, syncops *so, int mode ) ...@@ -887,7 +887,8 @@ syncprov_sendresp( Operation *op, resinfo *ri, syncops *so, int mode )
rs.sr_flags = REP_CTRLS_MUSTBEFREED; rs.sr_flags = REP_CTRLS_MUSTBEFREED;
csns[0] = ri->ri_csn; csns[0] = ri->ri_csn;
BER_BVZERO( &csns[1] ); BER_BVZERO( &csns[1] );
slap_compose_sync_cookie( op, &cookie, csns, so->s_rid, slap_serverID ? slap_serverID : -1 ); slap_compose_sync_cookie( op, &cookie, csns, so->s_rid,
slap_serverID ? slap_serverID : -1, NULL );
#ifdef LDAP_DEBUG #ifdef LDAP_DEBUG
if ( so->s_sid > 0 ) { if ( so->s_sid > 0 ) {
...@@ -1139,7 +1140,7 @@ syncprov_qresp( opcookie *opc, syncops *so, int mode ) ...@@ -1139,7 +1140,7 @@ syncprov_qresp( opcookie *opc, syncops *so, int mode )
syncprov_info_t *si = opc->son->on_bi.bi_private; syncprov_info_t *si = opc->son->on_bi.bi_private;
slap_compose_sync_cookie( NULL, &ri->ri_cookie, si->si_ctxcsn, slap_compose_sync_cookie( NULL, &ri->ri_cookie, si->si_ctxcsn,
so->s_rid, slap_serverID ? slap_serverID : -1); so->s_rid, slap_serverID ? slap_serverID : -1, NULL );
} }
Debug( LDAP_DEBUG_SYNC, "%s syncprov_qresp: " Debug( LDAP_DEBUG_SYNC, "%s syncprov_qresp: "
"set up a new syncres mode=%d csn=%s\n", "set up a new syncres mode=%d csn=%s\n",
...@@ -1899,7 +1900,7 @@ syncprov_playlog( Operation *op, SlapReply *rs, sessionlog *sl, ...@@ -1899,7 +1900,7 @@ syncprov_playlog( Operation *op, SlapReply *rs, sessionlog *sl,
if ( delcsn[0].bv_len ) { if ( delcsn[0].bv_len ) {
slap_compose_sync_cookie( op, &cookie, delcsn, srs->sr_state.rid, slap_compose_sync_cookie( op, &cookie, delcsn, srs->sr_state.rid,
slap_serverID ? slap_serverID : -1 ); slap_serverID ? slap_serverID : -1, delcsn );
Debug( LDAP_DEBUG_SYNC, "%s syncprov_playlog: cookie=%s\n", Debug( LDAP_DEBUG_SYNC, "%s syncprov_playlog: cookie=%s\n",
op->o_log_prefix, cookie.bv_val ); op->o_log_prefix, cookie.bv_val );
...@@ -2537,7 +2538,8 @@ syncprov_search_response( Operation *op, SlapReply *rs ) ...@@ -2537,7 +2538,8 @@ syncprov_search_response( Operation *op, SlapReply *rs )
/* If we're in delta-sync mode, always send a cookie */ /* If we're in delta-sync mode, always send a cookie */
if ( si->si_nopres && si->si_usehint && a ) { if ( si->si_nopres && si->si_usehint && a ) {
struct berval cookie; struct berval cookie;
slap_compose_sync_cookie( op, &cookie, a->a_nvals, srs->sr_state.rid, slap_serverID ? slap_serverID : -1 ); slap_compose_sync_cookie( op, &cookie, a->a_nvals, srs->sr_state.rid,
slap_serverID ? slap_serverID : -1, NULL );
rs->sr_err = syncprov_state_ctrl( op, rs, rs->sr_entry, rs->sr_err = syncprov_state_ctrl( op, rs, rs->sr_entry,
LDAP_SYNC_ADD, rs->sr_ctrls, 0, 1, &cookie ); LDAP_SYNC_ADD, rs->sr_ctrls, 0, 1, &cookie );
op->o_tmpfree( cookie.bv_val, op->o_tmpmemctx ); op->o_tmpfree( cookie.bv_val, op->o_tmpmemctx );
...@@ -2551,7 +2553,8 @@ syncprov_search_response( Operation *op, SlapReply *rs ) ...@@ -2551,7 +2553,8 @@ syncprov_search_response( Operation *op, SlapReply *rs )
if ( ( ss->ss_flags & SS_CHANGED ) && if ( ( ss->ss_flags & SS_CHANGED ) &&
ss->ss_ctxcsn && !BER_BVISNULL( &ss->ss_ctxcsn[0] )) { ss->ss_ctxcsn && !BER_BVISNULL( &ss->ss_ctxcsn[0] )) {
slap_compose_sync_cookie( op, &cookie, ss->ss_ctxcsn, slap_compose_sync_cookie( op, &cookie, ss->ss_ctxcsn,
srs->sr_state.rid, slap_serverID ? slap_serverID : -1 ); srs->sr_state.rid,
slap_serverID ? slap_serverID : -1, NULL );
Debug( LDAP_DEBUG_SYNC, "%s syncprov_search_response: cookie=%s\n", Debug( LDAP_DEBUG_SYNC, "%s syncprov_search_response: cookie=%s\n",
op->o_log_prefix, cookie.bv_val ); op->o_log_prefix, cookie.bv_val );
......
...@@ -1188,7 +1188,7 @@ LDAP_SLAPD_V (char *) slap_known_controls[]; ...@@ -1188,7 +1188,7 @@ LDAP_SLAPD_V (char *) slap_known_controls[];
* ldapsync.c * ldapsync.c
*/ */
LDAP_SLAPD_F (void) slap_compose_sync_cookie LDAP_P(( LDAP_SLAPD_F (void) slap_compose_sync_cookie LDAP_P((
Operation *, struct berval *, BerVarray, int, int )); Operation *, struct berval *, BerVarray, int, int, struct berval * ));
LDAP_SLAPD_F (void) slap_sync_cookie_free LDAP_P(( LDAP_SLAPD_F (void) slap_sync_cookie_free LDAP_P((
struct sync_cookie *, int free_cookie )); struct sync_cookie *, int free_cookie ));
LDAP_SLAPD_F (int) slap_parse_csn_sid LDAP_P(( LDAP_SLAPD_F (int) slap_parse_csn_sid LDAP_P((
......
...@@ -1769,6 +1769,7 @@ struct sync_cookie { ...@@ -1769,6 +1769,7 @@ struct sync_cookie {
int numcsns; int numcsns;
int rid; int rid;
struct berval octet_str; struct berval octet_str;
struct berval delcsn;
int sid; int sid;
LDAP_STAILQ_ENTRY(sync_cookie) sc_next; LDAP_STAILQ_ENTRY(sync_cookie) sc_next;
}; };
......
...@@ -764,7 +764,7 @@ check_syncprov( ...@@ -764,7 +764,7 @@ check_syncprov(
ch_free( si->si_syncCookie.octet_str.bv_val ); ch_free( si->si_syncCookie.octet_str.bv_val );
slap_compose_sync_cookie( NULL, &si->si_syncCookie.octet_str, slap_compose_sync_cookie( NULL, &si->si_syncCookie.octet_str,
si->si_syncCookie.ctxcsn, si->si_syncCookie.rid, si->si_syncCookie.ctxcsn, si->si_syncCookie.rid,
si->si_syncCookie.sid ); si->si_syncCookie.sid, NULL );
ch_free( si->si_syncCookie.sids ); ch_free( si->si_syncCookie.sids );
slap_reparse_sync_cookie( &si->si_syncCookie, op->o_tmpmemctx ); slap_reparse_sync_cookie( &si->si_syncCookie, op->o_tmpmemctx );
} }
...@@ -927,7 +927,7 @@ do_syncrep1( ...@@ -927,7 +927,7 @@ do_syncrep1(
ch_free( si->si_syncCookie.octet_str.bv_val ); ch_free( si->si_syncCookie.octet_str.bv_val );
slap_compose_sync_cookie( NULL, &si->si_syncCookie.octet_str, slap_compose_sync_cookie( NULL, &si->si_syncCookie.octet_str,
si->si_syncCookie.ctxcsn, si->si_syncCookie.rid, si->si_syncCookie.ctxcsn, si->si_syncCookie.rid,
si->si_syncCookie.sid ); si->si_syncCookie.sid, NULL );
} else { } else {
/* ITS#6367: recreate the cookie so it has our SID, not our peer's */ /* ITS#6367: recreate the cookie so it has our SID, not our peer's */
ch_free( si->si_syncCookie.octet_str.bv_val ); ch_free( si->si_syncCookie.octet_str.bv_val );
...@@ -937,7 +937,7 @@ do_syncrep1( ...@@ -937,7 +937,7 @@ do_syncrep1(
if ( BER_BVISNULL( &si->si_syncCookie.octet_str )) if ( BER_BVISNULL( &si->si_syncCookie.octet_str ))
slap_compose_sync_cookie( NULL, &si->si_syncCookie.octet_str, slap_compose_sync_cookie( NULL, &si->si_syncCookie.octet_str,
si->si_syncCookie.ctxcsn, si->si_syncCookie.rid, si->si_syncCookie.ctxcsn, si->si_syncCookie.rid,
si->si_syncCookie.sid ); si->si_syncCookie.sid, NULL );
} }
} }
...@@ -1852,7 +1852,7 @@ reload: ...@@ -1852,7 +1852,7 @@ reload:
if ( BER_BVISNULL( &si->si_syncCookie.octet_str )) if ( BER_BVISNULL( &si->si_syncCookie.octet_str ))
slap_compose_sync_cookie( NULL, &si->si_syncCookie.octet_str, slap_compose_sync_cookie( NULL, &si->si_syncCookie.octet_str,
si->si_syncCookie.ctxcsn, si->si_syncCookie.rid, si->si_syncCookie.ctxcsn, si->si_syncCookie.rid,
si->si_syncCookie.sid ); si->si_syncCookie.sid, NULL );
rc = ldap_sync_search( si, op->o_tmpmemctx ); rc = ldap_sync_search( si, op->o_tmpmemctx );
goto reload; goto reload;
} }
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment