From d19acb303c4ff90e48fd98ce2d7ba739ca9ea2db Mon Sep 17 00:00:00 2001
From: gbellato <gbellato@localhost>
Date: Wed, 18 Nov 2009 16:55:52 +0000
Subject: [PATCH] Fix for Issue 4300 : stop replication server cause OutOfMemoryError

---
 opends/src/server/org/opends/server/replication/plugin/PendingChanges.java |   52 +++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 51 insertions(+), 1 deletions(-)

diff --git a/opends/src/server/org/opends/server/replication/plugin/PendingChanges.java b/opends/src/server/org/opends/server/replication/plugin/PendingChanges.java
index ad1207d..72414a3 100644
--- a/opends/src/server/org/opends/server/replication/plugin/PendingChanges.java
+++ b/opends/src/server/org/opends/server/replication/plugin/PendingChanges.java
@@ -212,7 +212,14 @@
       {
         numSentUpdates++;
         LDAPUpdateMsg updateMsg = firstChange.getMsg();
-        domain.publish(updateMsg);
+        if (!recoveringOldChanges)
+        {
+          domain.publish(updateMsg);
+        }
+        else
+        {
+          domain.getServerState().update(updateMsg.getChangeNumber());
+        }
       }
       pendingChanges.remove(firstChangeNumber);
 
@@ -248,4 +255,47 @@
     _commit(changeNumber, msg);
     return _pushCommittedChanges();
   }
+
+  private boolean recoveringOldChanges = false;
+  /**
+   * Set the PendingChangesList structure in a mode where it is
+   * waiting for the RS to receive all the previous changes to
+   * be sent before starting to process the changes normally.
+   * In this mode, The Domain does not publish the changes from
+   * the pendingChanges because there are older changes that
+   * need to be published before.
+   *
+   * @param b The recovering status that must be set.
+   */
+  public void setRecovering(boolean b)
+  {
+    recoveringOldChanges = b;
+  }
+
+  /**
+   * Allows to update the recovery situation by comparing the ChangeNumber of
+   * the last change that was sent to the ReplicationServer with the
+   * ChangeNumber of the last operation that was taken out of the
+   * PendingChanges list.
+   * If he two match then the recovery is completed and normal procedure can
+   * restart. Otherwise the RSUpdate thread must continue to look for
+   * older changes and no changes can be committed from the pendingChanges list.
+   *
+   * @param recovered  The ChangeNumber of the last change that was published
+   *                   to the ReplicationServer.
+   *
+   * @return           A boolean indicating if the recovery is completed (false)
+   *                   or must continue (true).
+   */
+
+  public synchronized boolean RecoveryUntil(ChangeNumber recovered)
+  {
+    ChangeNumber lastLocalChange = domain.getLastLocalChange();
+
+    if ((recovered != null) && (recovered.newerOrEquals(lastLocalChange)))
+    {
+      recoveringOldChanges = false;
+    }
+    return recoveringOldChanges;
+  }
 }

--
Gitblit v1.10.0