From 2cf4412179a4ca8610d7fbb2108040377290bf82 Mon Sep 17 00:00:00 2001
From: Jean-Noel Rouvignac <jean-noel.rouvignac@forgerock.com>
Date: Fri, 06 Jun 2014 13:12:34 +0000
Subject: [PATCH] OPENDJ-1453 (CR-3697) Change time heart beat change numbers should be synced with updates

---
 opends/src/server/org/opends/server/replication/plugin/RemotePendingChanges.java |   93 +++++++++++++++++++++++-----------------------
 1 files changed, 47 insertions(+), 46 deletions(-)

diff --git a/opends/src/server/org/opends/server/replication/plugin/RemotePendingChanges.java b/opends/src/server/org/opends/server/replication/plugin/RemotePendingChanges.java
index 52c79ca..9d2b2d2 100644
--- a/opends/src/server/org/opends/server/replication/plugin/RemotePendingChanges.java
+++ b/opends/src/server/org/opends/server/replication/plugin/RemotePendingChanges.java
@@ -22,7 +22,7 @@
  *
  *
  *      Copyright 2007-2009 Sun Microsystems, Inc.
- *      Portions Copyright 2013 ForgeRock AS.
+ *      Portions Copyright 2013-2014 ForgeRock AS.
  */
 package org.opends.server.replication.plugin;
 
@@ -48,7 +48,7 @@
  *
  * One of this object is instantiated for each ReplicationDomain.
  */
-public final class RemotePendingChanges
+final class RemotePendingChanges
 {
   /**
    * A map used to store the pending changes.
@@ -124,7 +124,7 @@
     CSN firstCSN = pendingChanges.firstKey();
     PendingChange firstChange = pendingChanges.get(firstCSN);
 
-    while ((firstChange != null) && firstChange.isCommitted())
+    while (firstChange != null && firstChange.isCommitted())
     {
       state.update(firstCSN);
       pendingChanges.remove(firstCSN);
@@ -196,17 +196,19 @@
   public synchronized boolean checkDependencies(AddOperation op)
   {
     boolean hasDependencies = false;
-    DN targetDn = op.getEntryDN();
-    CSN csn = OperationContext.getCSN(op);
-    PendingChange change = pendingChanges.get(csn);
+    final DN targetDN = op.getEntryDN();
+    final CSN csn = OperationContext.getCSN(op);
+    final PendingChange change = pendingChanges.get(csn);
     if (change == null)
+    {
       return false;
+    }
 
     for (PendingChange pendingChange : pendingChanges.values())
     {
       if (pendingChange.getCSN().isOlderThan(csn))
       {
-        LDAPUpdateMsg pendingMsg = pendingChange.getMsg();
+        final LDAPUpdateMsg pendingMsg = pendingChange.getMsg();
         if (pendingMsg != null)
         {
           if (pendingMsg instanceof DeleteMsg)
@@ -215,7 +217,7 @@
              * Check is the operation to be run is a deleteOperation on the
              * same DN.
              */
-            if (pendingChange.getTargetDN().equals(targetDn))
+            if (pendingMsg.getDN().equals(targetDN))
             {
               hasDependencies = true;
               addDependency(change, pendingChange);
@@ -227,7 +229,7 @@
              * Check if the operation to be run is an addOperation on a
              * parent of the current AddOperation.
              */
-            if (pendingChange.getTargetDN().isAncestorOf(targetDn))
+            if (pendingMsg.getDN().isAncestorOf(targetDN))
             {
               hasDependencies = true;
               addDependency(change, pendingChange);
@@ -240,15 +242,15 @@
              * the same target DN as the ADD DN
              * or a ModifyDnOperation with new DN equals to the ADD DN parent
              */
-            if (pendingChange.getTargetDN().equals(targetDn))
+            if (pendingMsg.getDN().equals(targetDN))
             {
               hasDependencies = true;
               addDependency(change, pendingChange);
             }
             else
             {
-              ModifyDNMsg pendingModDn = (ModifyDNMsg) pendingChange.getMsg();
-              if (pendingModDn.newDNIsParent(targetDn))
+              final ModifyDNMsg pendingModDn = (ModifyDNMsg) pendingMsg;
+              if (pendingModDn.newDNIsParent(targetDN))
               {
                 hasDependencies = true;
                 addDependency(change, pendingChange);
@@ -286,30 +288,26 @@
   public synchronized boolean checkDependencies(ModifyOperation op)
   {
     boolean hasDependencies = false;
-    DN targetDn = op.getEntryDN();
-    CSN csn = OperationContext.getCSN(op);
-    PendingChange change = pendingChanges.get(csn);
+    final DN targetDN = op.getEntryDN();
+    final CSN csn = OperationContext.getCSN(op);
+    final PendingChange change = pendingChanges.get(csn);
     if (change == null)
+    {
       return false;
+    }
 
     for (PendingChange pendingChange : pendingChanges.values())
     {
       if (pendingChange.getCSN().isOlderThan(csn))
       {
-        LDAPUpdateMsg pendingMsg = pendingChange.getMsg();
-        if (pendingMsg != null)
+        final LDAPUpdateMsg pendingMsg = pendingChange.getMsg();
+        if (pendingMsg instanceof AddMsg)
         {
-          if (pendingMsg instanceof AddMsg)
+          // Check if the operation to be run is an addOperation on a same DN.
+          if (pendingMsg.getDN().equals(targetDN))
           {
-            /*
-             * Check if the operation to be run is an addOperation on a
-             * same DN.
-             */
-            if (pendingChange.getTargetDN().equals(targetDn))
-            {
-              hasDependencies = true;
-              addDependency(change, pendingChange);
-            }
+            hasDependencies = true;
+            addDependency(change, pendingChange);
           }
         }
       }
@@ -342,29 +340,30 @@
    *
    * @return A boolean indicating if this operation has some dependencies.
    */
-  public synchronized boolean checkDependencies(ModifyDNMsg msg)
+  private synchronized boolean checkDependencies(ModifyDNMsg msg)
   {
     boolean hasDependencies = false;
-    CSN csn = msg.getCSN();
-    PendingChange change = pendingChanges.get(csn);
+    final CSN csn = msg.getCSN();
+    final PendingChange change = pendingChanges.get(csn);
     if (change == null)
+    {
       return false;
+    }
 
-    DN targetDn = change.getTargetDN();
-
+    final DN targetDN = change.getMsg().getDN();
 
     for (PendingChange pendingChange : pendingChanges.values())
     {
       if (pendingChange.getCSN().isOlderThan(csn))
       {
-        LDAPUpdateMsg pendingMsg = pendingChange.getMsg();
+        final LDAPUpdateMsg pendingMsg = pendingChange.getMsg();
         if (pendingMsg != null)
         {
           if (pendingMsg instanceof DeleteMsg)
           {
             // Check if the target of the Delete is the same
             // as the new DN of this ModifyDN
-            if (msg.newDNIsEqual(pendingChange.getTargetDN()))
+            if (msg.newDNIsEqual(pendingMsg.getDN()))
             {
               hasDependencies = true;
               addDependency(change, pendingChange);
@@ -374,14 +373,14 @@
           {
             // Check if the Add Operation was done on the new parent of
             // the MODDN  operation
-            if (msg.newParentIsEqual(pendingChange.getTargetDN()))
+            if (msg.newParentIsEqual(pendingMsg.getDN()))
             {
               hasDependencies = true;
               addDependency(change, pendingChange);
             }
             // Check if the AddOperation was done on the same DN as the
             // target DN of the MODDN operation
-            if (pendingChange.getTargetDN().equals(targetDn))
+            if (pendingMsg.getDN().equals(targetDN))
             {
               hasDependencies = true;
               addDependency(change, pendingChange);
@@ -391,7 +390,7 @@
           {
             // Check if the ModifyDNOperation was done from the new DN of
             // the MODDN operation
-            if (msg.newDNIsEqual(pendingChange.getTargetDN()))
+            if (msg.newDNIsEqual(pendingMsg.getDN()))
             {
               hasDependencies = true;
               addDependency(change, pendingChange);
@@ -431,17 +430,19 @@
   public synchronized boolean checkDependencies(DeleteOperation op)
   {
     boolean hasDependencies = false;
-    DN targetDn = op.getEntryDN();
-    CSN csn = OperationContext.getCSN(op);
-    PendingChange change = pendingChanges.get(csn);
+    final DN targetDN = op.getEntryDN();
+    final CSN csn = OperationContext.getCSN(op);
+    final PendingChange change = pendingChanges.get(csn);
     if (change == null)
+    {
       return false;
+    }
 
     for (PendingChange pendingChange : pendingChanges.values())
     {
       if (pendingChange.getCSN().isOlderThan(csn))
       {
-        LDAPUpdateMsg pendingMsg = pendingChange.getMsg();
+        final LDAPUpdateMsg pendingMsg = pendingChange.getMsg();
         if (pendingMsg != null)
         {
           if (pendingMsg instanceof DeleteMsg)
@@ -450,7 +451,7 @@
              * Check if the operation to be run is a deleteOperation on a
              * children of the current DeleteOperation.
              */
-            if (pendingChange.getTargetDN().isDescendantOf(targetDn))
+            if (pendingMsg.getDN().isDescendantOf(targetDN))
             {
               hasDependencies = true;
               addDependency(change, pendingChange);
@@ -462,7 +463,7 @@
              * Check if the operation to be run is an addOperation on a
              * parent of the current DeleteOperation.
              */
-            if (pendingChange.getTargetDN().equals(targetDn))
+            if (pendingMsg.getDN().equals(targetDN))
             {
               hasDependencies = true;
               addDependency(change, pendingChange);
@@ -470,13 +471,13 @@
           }
           else if (pendingMsg instanceof ModifyDNMsg)
           {
-            ModifyDNMsg pendingModDn = (ModifyDNMsg) pendingChange.getMsg();
+            final ModifyDNMsg pendingModDn = (ModifyDNMsg) pendingMsg;
             /*
              * Check if the operation to be run is an ModifyDNOperation
              * on a children of the current DeleteOperation
              */
-            if ((pendingChange.getTargetDN().isDescendantOf(targetDn)) ||
-                (pendingModDn.newDNIsParent(targetDn)))
+            if (pendingMsg.getDN().isDescendantOf(targetDN)
+                || pendingModDn.newDNIsParent(targetDN))
             {
               hasDependencies = true;
               addDependency(change, pendingChange);

--
Gitblit v1.10.0