time_t si_chklast; /* time of last checkpoint */
Avlnode *si_mods; /* entries being modified */
sessionlog *si_logs;
- ldap_pvt_thread_mutex_t si_csn_mutex;
+ ldap_pvt_thread_rdwr_t si_csn_rwlock;
ldap_pvt_thread_mutex_t si_ops_mutex;
ldap_pvt_thread_mutex_t si_mods_mutex;
char si_ctxcsnbuf[LDAP_LUTIL_CSNSTR_BUFSIZE];
}
static void
-syncprov_checkpoint( Operation *op, SlapReply *rs, slap_overinst *on,
- struct berval *csn )
+syncprov_checkpoint( Operation *op, SlapReply *rs, slap_overinst *on )
{
+ syncprov_info_t *si = on->on_bi.bi_private;
Modifications mod;
Operation opm;
SlapReply rsm = { 0 };
slap_callback cb = {0};
/* If ctxcsn is empty, delete it */
- if ( BER_BVISEMPTY( csn )) {
+ if ( BER_BVISEMPTY( &si->si_ctxcsn )) {
mod.sml_values = NULL;
} else {
mod.sml_values = bv;
bv[1].bv_val = NULL;
- bv[0] = *csn;
+ bv[0] = si->si_ctxcsn;
}
mod.sml_nvalues = NULL;
mod.sml_desc = slap_schema.si_ad_contextCSN;
* and everything else at the end. Do this first so we can
* unlock the list mutex.
*/
- Debug( LDAP_DEBUG_SYNC, "srs csn %s\n", srs-> sr_state.ctxcsn.bv_val, 0, 0 );
+ Debug( LDAP_DEBUG_SYNC, "srs csn %s\n", srs->sr_state.ctxcsn.bv_val, 0, 0 );
for ( se=sl->sl_head; se; se=se->se_next ) {
- Debug( LDAP_DEBUG_SYNC, "log csn %s\n", se-> se_csn.bv_val,
-0, 0 );
- ndel = ber_bvcmp( &se->se_csn, &srs->sr_state.ctxcsn );
- if ( ndel <= 0 ) {
- Debug( LDAP_DEBUG_SYNC, "cmp %d, too old\n", ndel,
-0, 0 );
- continue;
- }
- ndel = ber_bvcmp( &se->se_csn, ctxcsn );
- if ( ndel > 0 ) {
- Debug( LDAP_DEBUG_SYNC, "cmp %d, too new\n", ndel,
-0, 0 );
- break;
- }
+ Debug( LDAP_DEBUG_SYNC, "log csn %s\n", se->se_csn.bv_val, 0, 0 );
+ ndel = ber_bvcmp( &se->se_csn, &srs->sr_state.ctxcsn );
+ if ( ndel <= 0 ) {
+ Debug( LDAP_DEBUG_SYNC, "cmp %d, too old\n", ndel, 0, 0 );
+ continue;
+ }
+ ndel = ber_bvcmp( &se->se_csn, ctxcsn );
+ if ( ndel > 0 ) {
+ Debug( LDAP_DEBUG_SYNC, "cmp %d, too new\n", ndel, 0, 0 );
+ break;
+ }
if ( se->se_tag == LDAP_REQ_DELETE ) {
j = i;
i++;
{
struct berval maxcsn = BER_BVNULL;
char cbuf[LDAP_LUTIL_CSNSTR_BUFSIZE];
- int do_check = 0;
+ int do_check=0;
/* Update our context CSN */
cbuf[0] = '\0';
- ldap_pvt_thread_mutex_lock( &si->si_csn_mutex );
+ ldap_pvt_thread_rdwr_wlock( &si->si_csn_rwlock );
slap_get_commit_csn( op, &maxcsn );
if ( !BER_BVISNULL( &maxcsn ) ) {
strcpy( cbuf, maxcsn.bv_val );
/* Don't do any processing for consumer contextCSN updates */
if ( SLAP_SYNC_SHADOW( op->o_bd ) &&
op->o_msgid == SLAP_SYNC_UPDATE_MSGID ) {
- ldap_pvt_thread_mutex_unlock( &si->si_csn_mutex );
+ ldap_pvt_thread_rdwr_wunlock( &si->si_csn_rwlock );
return SLAP_CB_CONTINUE;
}
si->si_chklast = op->o_time;
}
}
- ldap_pvt_thread_mutex_unlock( &si->si_csn_mutex );
-
- opc->sctxcsn.bv_len = maxcsn.bv_len;
- opc->sctxcsn.bv_val = cbuf;
+ ldap_pvt_thread_rdwr_wunlock( &si->si_csn_rwlock );
if ( do_check ) {
- syncprov_checkpoint( op, rs, on, &opc->sctxcsn );
+ ldap_pvt_thread_rdwr_rlock( &si->si_csn_rwlock );
+ syncprov_checkpoint( op, rs, on );
+ ldap_pvt_thread_rdwr_runlock( &si->si_csn_rwlock );
}
+ opc->sctxcsn.bv_len = maxcsn.bv_len;
+ opc->sctxcsn.bv_val = cbuf;
+
/* Handle any persistent searches */
if ( si->si_ops ) {
switch(op->o_tag) {
a.a_vals = bv;
a.a_nvals = a.a_vals;
- ldap_pvt_thread_mutex_lock( &si->si_csn_mutex );
+ ldap_pvt_thread_rdwr_rlock( &si->si_csn_rwlock );
rs->sr_err = access_allowed( op, &e, op->oq_compare.rs_ava->aa_desc,
&op->oq_compare.rs_ava->aa_value, ACL_COMPARE, NULL );
return_results:;
- ldap_pvt_thread_mutex_unlock( &si->si_csn_mutex );
+ ldap_pvt_thread_rdwr_runlock( &si->si_csn_rwlock );
send_ldap_result( op, rs );
}
/* snapshot the ctxcsn */
- ldap_pvt_thread_mutex_lock( &si->si_csn_mutex );
+ ldap_pvt_thread_rdwr_rlock( &si->si_csn_rwlock );
strcpy( csnbuf, si->si_ctxcsnbuf );
ctxcsn.bv_len = si->si_ctxcsn.bv_len;
- ldap_pvt_thread_mutex_unlock( &si->si_csn_mutex );
+ ldap_pvt_thread_rdwr_runlock( &si->si_csn_rwlock );
ctxcsn.bv_val = csnbuf;
/* If we have a cookie, handle the PRESENT lookups */
*ap = a;
}
- ldap_pvt_thread_mutex_lock( &si->si_csn_mutex );
+ ldap_pvt_thread_rdwr_rlock( &si->si_csn_rwlock );
if ( !ap ) {
strcpy( a->a_vals[0].bv_val, si->si_ctxcsnbuf );
} else {
ber_dupbv( &a->a_vals[0], &si->si_ctxcsn );
}
- ldap_pvt_thread_mutex_unlock( &si->si_csn_mutex );
+ ldap_pvt_thread_rdwr_runlock( &si->si_csn_rwlock );
}
}
return SLAP_CB_CONTINUE;
op->o_bd = be;
op->o_dn = be->be_rootdn;
op->o_ndn = be->be_rootndn;
- syncprov_checkpoint( op, &rs, on, &si->si_ctxcsn );
+ syncprov_checkpoint( op, &rs, on );
}
return 0;
si = ch_calloc(1, sizeof(syncprov_info_t));
on->on_bi.bi_private = si;
- ldap_pvt_thread_mutex_init( &si->si_csn_mutex );
+ ldap_pvt_thread_rdwr_init( &si->si_csn_rwlock );
ldap_pvt_thread_mutex_init( &si->si_ops_mutex );
ldap_pvt_thread_mutex_init( &si->si_mods_mutex );
si->si_ctxcsn.bv_val = si->si_ctxcsnbuf;
}
ldap_pvt_thread_mutex_destroy( &si->si_mods_mutex );
ldap_pvt_thread_mutex_destroy( &si->si_ops_mutex );
- ldap_pvt_thread_mutex_destroy( &si->si_csn_mutex );
+ ldap_pvt_thread_rdwr_destroy( &si->si_csn_rwlock );
ch_free( si );
}