]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/overlays/syncprov.c
fix length
[openldap] / servers / slapd / overlays / syncprov.c
index 5c9cff1317342113c90e63b20a72a6eb90ab5d79..835ed240d7de0a8912d49e2a2cf878ebf1fbf3a9 100644 (file)
@@ -393,9 +393,6 @@ static struct berval generic_filterstr = BER_BVC("(objectclass=*)");
 static int
 syncprov_findbase( Operation *op, fbase_cookie *fc )
 {
-       opcookie *opc = op->o_callback->sc_private;
-       slap_overinst *on = opc->son;
-
        /* Use basic parameters from syncrepl search, but use
         * current op's threadctx / tmpmemctx
         */
@@ -630,7 +627,7 @@ again:
                cf.f_av_value = si->si_ctxcsn[maxid];
                fop.ors_filterstr.bv_len = snprintf( buf, sizeof( buf ),
                        "(entryCSN>=%s)", cf.f_av_value.bv_val );
-               if ( fop.ors_filterstr.bv_len < 0 || fop.ors_filterstr.bv_len >= sizeof( buf ) ) {
+               if ( fop.ors_filterstr.bv_len >= sizeof( buf ) ) {
                        return LDAP_OTHER;
                }
                fop.ors_attrsonly = 0;
@@ -667,7 +664,7 @@ again:
                        fop.ors_filterstr.bv_len = snprintf( buf, sizeof( buf ),
                                "(entryCSN<=%s)", cf.f_av_value.bv_val );
                }
-               if ( fop.ors_filterstr.bv_len < 0 || fop.ors_filterstr.bv_len >= sizeof( buf ) ) {
+               if ( fop.ors_filterstr.bv_len >= sizeof( buf ) ) {
                        return LDAP_OTHER;
                }
                fop.ors_attrsonly = 1;
@@ -911,6 +908,10 @@ syncprov_qplay( Operation *op, struct re_s *rtask )
        } else {
                /* bail out on any error */
                ldap_pvt_runqueue_remove( &slapd_rq, rtask );
+
+               /* Prevent duplicate remove */
+               if ( so->s_qtask == rtask )
+                       so->s_qtask = NULL;
        }
        ldap_pvt_thread_mutex_unlock( &slapd_rq.rq_mutex );
        ldap_pvt_thread_mutex_unlock( &so->s_mutex );
@@ -1603,12 +1604,12 @@ syncprov_op_response( Operation *op, SlapReply *rs )
        {
                struct berval maxcsn = BER_BVNULL;
                char cbuf[LDAP_LUTIL_CSNSTR_BUFSIZE];
-               int do_check = 0, have_psearches;
+               int do_check = 0, have_psearches, foundit;
 
                /* Update our context CSN */
                cbuf[0] = '\0';
                ldap_pvt_thread_rdwr_wlock( &si->si_csn_rwlock );
-               slap_get_commit_csn( op, &maxcsn );
+               slap_get_commit_csn( op, &maxcsn, &foundit );
                if ( BER_BVISNULL( &maxcsn ) && SLAP_GLUE_SUBORDINATE( op->o_bd )) {
                        /* syncrepl queues the CSN values in the db where
                         * it is configured , not where the changes are made.
@@ -1617,7 +1618,7 @@ syncprov_op_response( Operation *op, SlapReply *rs )
                         */
                        BackendDB *be = op->o_bd;
                        op->o_bd = select_backend( &be->be_nsuffix[0], 1);
-                       slap_get_commit_csn( op, &maxcsn );
+                       slap_get_commit_csn( op, &maxcsn, &foundit );
                        op->o_bd = be;
                }
                if ( !BER_BVISNULL( &maxcsn ) ) {
@@ -1640,15 +1641,14 @@ syncprov_op_response( Operation *op, SlapReply *rs )
                                        sizeof(int));
                                si->si_sids[i] = sid;
                        }
-               } else {
+               } else if ( !foundit ) {
                        /* internal ops that aren't meant to be replicated */
                        ldap_pvt_thread_rdwr_wunlock( &si->si_csn_rwlock );
                        return SLAP_CB_CONTINUE;
                }
 
                /* Don't do any processing for consumer contextCSN updates */
-               if ( SLAP_SYNC_SHADOW( op->o_bd ) && 
-                       op->o_msgid == SLAP_SYNC_UPDATE_MSGID ) {
+               if ( op->o_dont_replicate ) {
                        ldap_pvt_thread_rdwr_wunlock( &si->si_csn_rwlock );
                        return SLAP_CB_CONTINUE;
                }
@@ -1677,8 +1677,11 @@ syncprov_op_response( Operation *op, SlapReply *rs )
                        ldap_pvt_thread_rdwr_runlock( &si->si_csn_rwlock );
                }
 
-               opc->sctxcsn.bv_len = maxcsn.bv_len;
-               opc->sctxcsn.bv_val = cbuf;
+               /* only update consumer ctx if this is the greatest csn */
+               if ( bvmatch( &maxcsn, &op->o_csn )) {
+                       opc->sctxcsn.bv_len = maxcsn.bv_len;
+                       opc->sctxcsn.bv_val = cbuf;
+               }
 
                /* Handle any persistent searches */
                ldap_pvt_thread_mutex_lock( &si->si_ops_mutex );
@@ -2535,7 +2538,7 @@ sp_cf_gen(ConfigArgs *c)
                                struct berval bv;
                                bv.bv_len = snprintf( c->cr_msg, sizeof( c->cr_msg ),
                                        "%d %d", si->si_chkops, si->si_chktime );
-                               if ( bv.bv_len < 0 || bv.bv_len >= sizeof( c->cr_msg ) ) {
+                               if ( bv.bv_len >= sizeof( c->cr_msg ) ) {
                                        rc = 1;
                                } else {
                                        bv.bv_val = c->cr_msg;
@@ -2729,7 +2732,7 @@ syncprov_db_open(
                        si->si_sids = slap_parse_csn_sids( si->si_ctxcsn, a->a_numvals, NULL );
                }
                overlay_entry_release_ov( op, e, 0, on );
-               if ( si->si_ctxcsn ) {
+               if ( si->si_ctxcsn && !SLAP_DBCLEAN( be )) {
                        op->o_req_dn = be->be_suffix[0];
                        op->o_req_ndn = be->be_nsuffix[0];
                        op->ors_scope = LDAP_SCOPE_SUBTREE;