From 07608669c09feb6964c2e25e98cb378d220e16bf Mon Sep 17 00:00:00 2001
From: gbellato <gbellato@localhost>
Date: Mon, 15 Jun 2009 07:19:18 +0000
Subject: [PATCH] Fix for 4052 : Ghost adds in Replication Server   The clear procedure of the Replication Server was failing if several clear are done consecutively. The cause of the failure is that the dnHandler were not shutdown properly at this time. The first clear therefore seemed successful but was leaving some open DBhandler  that was causing later clear to fail. 

---
 opends/src/server/org/opends/server/replication/server/ReplicationServerDomain.java |   36 ++++++++++++++++++++++++++++++------
 1 files changed, 30 insertions(+), 6 deletions(-)

diff --git a/opends/src/server/org/opends/server/replication/server/ReplicationServerDomain.java b/opends/src/server/org/opends/server/replication/server/ReplicationServerDomain.java
index e37f6a6..184d2ef 100644
--- a/opends/src/server/org/opends/server/replication/server/ReplicationServerDomain.java
+++ b/opends/src/server/org/opends/server/replication/server/ReplicationServerDomain.java
@@ -1058,7 +1058,7 @@
             unregisterServerHandler(handler);
             handler.shutdown();
 
-            // Check if generation id has to be resetted
+            // Check if generation id has to be reset
             mayResetGenerationId();
             // Warn our DSs that a RS or DS has quit (does not use this
             // handler as already removed from list)
@@ -1083,7 +1083,7 @@
             unregisterServerHandler(handler);
             handler.shutdown();
 
-            // Check if generation id has to be resetted
+            // Check if generation id has to be reset
             mayResetGenerationId();
             // Update the remote replication servers with our list
             // of connected LDAP servers
@@ -1233,7 +1233,7 @@
       (!this.generationIdSavedStatus) &&
       (generationId != -1))
     {
-      setGenerationId(-1, false);
+      changeGenerationId(-1, false);
     }
   }
 
@@ -1710,6 +1710,14 @@
 
     stopAllServers();
 
+    stopDbHandlers();
+  }
+
+  /**
+   * Stop the dbHandlers .
+   */
+  private void stopDbHandlers()
+  {
     // Shutdown the dbHandlers
     synchronized (sourceDbHandlers)
     {
@@ -1924,14 +1932,30 @@
     return generationIdSavedStatus;
   }
 
+
+  /**
+   * Initialize the value of the generationID for this ReplicationServerDomain.
+   * This method is intended to be used for initialization at startup and
+   * simply stores the new value without any additional processing.
+   * For example it does not clear the change-log DBs
+   *
+   * @param generationId The new value of generationId.
+   */
+  synchronized public void initGenerationID(long generationId)
+  {
+    this.generationId = generationId;
+    this.generationIdSavedStatus = true;
+  }
+
   /**
    * Sets the provided value as the new in memory generationId.
+   * Also clear the changelog databases.
    *
    * @param generationId The new value of generationId.
    * @param savedStatus  The saved status of the generationId.
    * @return The old generation id
    */
-  synchronized public long setGenerationId(long generationId,
+  synchronized public long changeGenerationId(long generationId,
     boolean savedStatus)
   {
     long oldGenerationId = this.generationId;
@@ -1980,7 +2004,7 @@
 
     if (newGenId != this.generationId)
     {
-      setGenerationId(newGenId, false);
+      changeGenerationId(newGenId, false);
     }
     else
     {
@@ -2184,7 +2208,7 @@
           logError(mb.toMessage());
         }
       }
-      sourceDbHandlers.clear();
+      stopDbHandlers();
 
       if (debugEnabled())
         TRACER.debugInfo(

--
Gitblit v1.10.0