From 3fde23013fcd5ff31f01b580a7e3e23080e5caad Mon Sep 17 00:00:00 2001
From: ludovicp <ludovicp@localhost>
Date: Thu, 27 May 2010 13:08:02 +0000
Subject: [PATCH] fix issue #4529 - The conflict resolution code was not correctly handling the case when two mods (one add and one del) are done in the same modify operation. This code contains unit tests case for this problem and fix the conflict resolution code.

---
 opends/src/server/org/opends/server/replication/plugin/AttrInfoMultiple.java |   19 +++++++++++++------
 1 files changed, 13 insertions(+), 6 deletions(-)

diff --git a/opends/src/server/org/opends/server/replication/plugin/AttrInfoMultiple.java b/opends/src/server/org/opends/server/replication/plugin/AttrInfoMultiple.java
index a65d036..d78bef1 100644
--- a/opends/src/server/org/opends/server/replication/plugin/AttrInfoMultiple.java
+++ b/opends/src/server/org/opends/server/replication/plugin/AttrInfoMultiple.java
@@ -22,7 +22,7 @@
  * CDDL HEADER END
  *
  *
- *      Copyright 2006-2008 Sun Microsystems, Inc.
+ *      Copyright 2006-2010 Sun Microsystems, Inc.
  */
 package org.opends.server.replication.plugin;
 
@@ -465,6 +465,7 @@
       for (AttributeValue val : modAttr)
       {
         Boolean deleteIt = true;  // true if the delete must be done
+        Boolean addedInCurrentOp = false;
 
         /* update historical information */
         ValueInfo valInfo = new ValueInfo(val, null, changeNumber);
@@ -473,8 +474,14 @@
         {
           /* this value already exist in the historical information */
           ValueInfo oldValInfo  = valuesInfo.get(index);
-          if (changeNumber.newer(oldValInfo.getValueDeleteTime()) &&
-              changeNumber.newer(oldValInfo.getValueUpdateTime()))
+          if (changeNumber.equals(oldValInfo.getValueUpdateTime()))
+          {
+            // This value was added earlier in the same operation
+            // we need to keep the delete.
+            addedInCurrentOp = true;
+          }
+          if (changeNumber.newerOrEquals(oldValInfo.getValueDeleteTime()) &&
+              changeNumber.newerOrEquals(oldValInfo.getValueUpdateTime()))
           {
             valuesInfo.remove(index);
             valuesInfo.add(valInfo);
@@ -494,8 +501,8 @@
          * MOD to make sure the delete is going to succeed
          */
         if (!deleteIt
-            || !modifiedEntry.hasValue(modAttr.getAttributeType(), modAttr
-                .getOptions(), val))
+            || (!modifiedEntry.hasValue(modAttr.getAttributeType(), modAttr
+                .getOptions(), val) && ! addedInCurrentOp))
         {
           // this value was already deleted before and therefore
           // this should not be replayed.
@@ -587,7 +594,7 @@
           /* this value is marked as a deleted value
            * check if this mod is more recent the this delete
            */
-          if (changeNumber.newer(oldValueInfo.getValueDeleteTime()))
+          if (changeNumber.newerOrEquals(oldValueInfo.getValueDeleteTime()))
           {
             /* this add is more recent,
              * remove the old delete historical information

--
Gitblit v1.10.0