From acfcc9e05552e3d2fe37f8d9b8ac0827a204ee3a Mon Sep 17 00:00:00 2001
From: Jean-Noel Rouvignac <jean-noel.rouvignac@forgerock.com>
Date: Mon, 21 Jul 2014 12:53:41 +0000
Subject: [PATCH] OPENDJ-1441 (CR-4037) Persistent searches on external changelog do not return changes for new replicas and new domains

---
 opends/src/server/org/opends/server/replication/server/changelog/je/CompositeDBCursor.java |   43 ++++++++++++++++++-------------------------
 1 files changed, 18 insertions(+), 25 deletions(-)

diff --git a/opends/src/server/org/opends/server/replication/server/changelog/je/CompositeDBCursor.java b/opends/src/server/org/opends/server/replication/server/changelog/je/CompositeDBCursor.java
index 38afd7d..ae54930 100644
--- a/opends/src/server/org/opends/server/replication/server/changelog/je/CompositeDBCursor.java
+++ b/opends/src/server/org/opends/server/replication/server/changelog/je/CompositeDBCursor.java
@@ -129,21 +129,31 @@
 
   private void removeNoLongerNeededCursors()
   {
-    for (Iterator<Entry<DBCursor<UpdateMsg>, Data>> iterator =
-        cursors.entrySet().iterator(); iterator.hasNext();)
+    for (final Iterator<Data> iter = removedCursorsIterator(); iter.hasNext();)
     {
-      final Entry<DBCursor<UpdateMsg>, Data> entry = iterator.next();
-      final Data data = entry.getValue();
-      if (isCursorNoLongerNeededFor(data))
+      final Data dataToFind = iter.next();
+      for (Iterator<Entry<DBCursor<UpdateMsg>, Data>> cursorIter =
+          cursors.entrySet().iterator(); cursorIter.hasNext();)
       {
-        entry.getKey().close();
-        iterator.remove();
-        cursorRemoved(data);
+        final Entry<DBCursor<UpdateMsg>, Data> entry = cursorIter.next();
+        if (dataToFind.equals(entry.getValue()))
+        {
+          entry.getKey().close();
+          cursorIter.remove();
+        }
       }
+      iter.remove();
     }
   }
 
   /**
+   * Returns an Iterator over the data associated to cursors that must be removed.
+   *
+   * @return an Iterator over the data associated to cursors that must be removed.
+   */
+  protected abstract Iterator<Data> removedCursorsIterator();
+
+  /**
    * Adds a cursor to this composite cursor. It first calls
    * {@link DBCursor#next()} to verify whether it is exhausted or not.
    *
@@ -191,23 +201,6 @@
   protected abstract void incorporateNewCursors() throws ChangelogException;
 
   /**
-   * Returns whether the cursor associated to the provided data should be removed.
-   *
-   * @param data the data associated to the cursor to be tested
-   * @return true if the cursor associated to the provided data should be removed,
-   *         false otherwise
-   */
-  protected abstract boolean isCursorNoLongerNeededFor(Data data);
-
-  /**
-   * Notifies that the cursor associated to the provided data has been removed.
-   *
-   * @param data
-   *          the data associated to the removed cursor
-   */
-  protected abstract void cursorRemoved(Data data);
-
-  /**
    * Returns the data associated to the cursor that returned the current record.
    *
    * @return the data associated to the cursor that returned the current record.

--
Gitblit v1.10.0