]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/overlays/syncprov.c
Update copyright for next release
[openldap] / servers / slapd / overlays / syncprov.c
index db113f042be0ff142df37556fb467e8ef86027f3..d7c857b6bae578b040ab509fd131bd9d0de28f7b 100644 (file)
@@ -2,7 +2,7 @@
 /* syncprov.c - syncrepl provider */
 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
  *
- * Copyright 2004-2008 The OpenLDAP Foundation.
+ * Copyright 2004-2009 The OpenLDAP Foundation.
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -908,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 );
@@ -1255,6 +1259,12 @@ syncprov_matchops( Operation *op, opcookie *opc, int saveit )
                        /* send DELETE */
                        syncprov_qresp( opc, ss, LDAP_SYNC_DELETE );
                }
+               if ( !saveit && found ) {
+                       /* Decrement s_inuse, was incremented when called
+                        * with saveit == TRUE
+                        */
+                       syncprov_free_syncop( ss );
+               }
        }
        ldap_pvt_thread_mutex_unlock( &si->si_ops_mutex );
 
@@ -1600,12 +1610,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.
@@ -1614,7 +1624,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 ) ) {
@@ -1637,15 +1647,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;
                }
@@ -1674,8 +1683,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 );
@@ -2726,7 +2738,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;