]> git.ipfire.org Git - thirdparty/openldap.git/commitdiff
ITS#9342 delta-sync ignore add of already existing entry
authorHoward Chu <hyc@openldap.org>
Thu, 1 Oct 2020 13:26:48 +0000 (14:26 +0100)
committerQuanah Gibson-Mount <quanah@openldap.org>
Thu, 1 Oct 2020 15:00:10 +0000 (15:00 +0000)
if the entryCSN is older. Previous patch breaks if writes are
received out of order, e.g. during a refresh.

servers/slapd/syncrepl.c

index 9f2d57c9d5625a78c0fa4991c94a751b58ddbfbe..7741a9d59db6a1475eed431e36e3da05e36031b3 100644 (file)
@@ -2603,29 +2603,20 @@ syncrepl_message_to_op(
                                "mods2entry (%s)\n",
                                        si->si_ridtxt, text, 0 );
                        } else {
-                               rc = CV_CSN_OK;
-                               if ( do_lock ) {
-                                       /* do_lock is only true because we didn't get a cookieCSN and
-                                        * therefore didn't already lock the pending list. See if the
-                                        * entryCSN is fresh enough. Ignore this op if too old.
-                                        */
+                               rc = op->o_bd->be_add( op, &rs );
+                               Debug( LDAP_DEBUG_SYNC,
+                                       "syncrepl_message_to_op: %s be_add %s (%d)\n",
+                                       si->si_ridtxt, op->o_req_dn.bv_val, rc );
+                               do_graduate = 0;
+                               if ( rc == LDAP_ALREADY_EXISTS ) {
                                        Attribute *a = attr_find( e->e_attrs, slap_schema.si_ad_entryCSN );
-                                       if ( a ) {
-                                               int sid = slap_parse_csn_sid( &a->a_nvals[0] );
-                                               ldap_pvt_thread_mutex_lock( &si->si_cookieState->cs_mutex );
-                                               rc = check_csn_age( si, &op->o_req_dn, &a->a_nvals[0],
-                                                       sid, (cookie_vals *)&si->si_cookieState->cs_vals, NULL );
-                                               ldap_pvt_thread_mutex_unlock( &si->si_cookieState->cs_mutex );
-                                       }
-                               }
-                               if ( rc == CV_CSN_OLD ) {
-                                       rc = LDAP_SUCCESS;
-                               } else {
-                                       rc = op->o_bd->be_add( op, &rs );
-                                       Debug( LDAP_DEBUG_SYNC,
-                                               "syncrepl_message_to_op: %s be_add %s (%d)\n",
-                                               si->si_ridtxt, op->o_req_dn.bv_val, rc );
-                                       do_graduate = 0;
+                                       struct berval *vals;
+                                       if ( a && backend_attribute( op, NULL, &op->o_req_ndn,
+                                               slap_schema.si_ad_entryCSN, &vals, ACL_READ ) == LDAP_SUCCESS ) {
+                                               if ( ber_bvcmp( &vals[0], &a->a_vals[0] ) >= 0 )
+                                                       rc = LDAP_SUCCESS;
+                                               ber_bvarray_free_x( vals, op->o_tmpmemctx );
+                                       }
                                }
                        }
                        if ( e == op->ora_e )