From 0eab55fa49863935bbc81242b7e13fa550fedc6d Mon Sep 17 00:00:00 2001
From: gbellato <gbellato@localhost>
Date: Tue, 25 Sep 2007 07:29:24 +0000
Subject: [PATCH] some replication hardening :  - fix some race conditions in namingConflict test  - add some cleanup at the end of ReplicationServerDynamicConfTest and    IsolationTest  - don't use anymore 2 statics in the replication code that could cause    problem when in-core restart are done.  - improve the shutdown by making sure that all threads are done    before returning

---
 opends/src/server/org/opends/server/replication/plugin/ReplicationDomain.java |   58 ++++++++++++++++++++++++++++++++++++++++++++--------------
 1 files changed, 44 insertions(+), 14 deletions(-)

diff --git a/opends/src/server/org/opends/server/replication/plugin/ReplicationDomain.java b/opends/src/server/org/opends/server/replication/plugin/ReplicationDomain.java
index 1f178ab..38149a0 100644
--- a/opends/src/server/org/opends/server/replication/plugin/ReplicationDomain.java
+++ b/opends/src/server/org/opends/server/replication/plugin/ReplicationDomain.java
@@ -245,6 +245,12 @@
   private DN configDn;
 
   /**
+   * A boolean indicating if the thread used to save the persistentServerState
+   * is terminated.
+   */
+  private boolean done = false;
+
+  /**
    * This class contain the context related to an import or export
    * launched on the domain.
    */
@@ -1207,6 +1213,8 @@
       { }
     }
     state.save();
+
+    done = true;
   }
 
   /**
@@ -1216,12 +1224,18 @@
    */
   private void createListeners()
   {
-    synchroThreads.clear();
-    for (int i=0; i<listenerThreadNumber; i++)
+    synchronized (synchroThreads)
     {
-      ListenerThread myThread = new ListenerThread(this);
-      myThread.start();
-      synchroThreads.add(myThread);
+      if (!shutdown)
+      {
+        synchroThreads.clear();
+        for (int i=0; i<listenerThreadNumber; i++)
+        {
+          ListenerThread myThread = new ListenerThread(this);
+          myThread.start();
+          synchroThreads.add(myThread);
+        }
+      }
     }
   }
 
@@ -1230,14 +1244,18 @@
    */
   public void shutdown()
   {
-    // stop the listener threads
-    for (ListenerThread thread : synchroThreads)
-    {
-      thread.shutdown();
-    }
-
     // stop the flush thread
     shutdown = true;
+
+    synchronized (synchroThreads)
+    {
+      // stop the listener threads
+      for (ListenerThread thread : synchroThreads)
+      {
+        thread.shutdown();
+      }
+    }
+
     synchronized (this)
     {
       this.notify();
@@ -1253,7 +1271,19 @@
     //  wait for the listener thread to stop
     for (ListenerThread thread : synchroThreads)
     {
-      thread.shutdown();
+      thread.waitForShutdown();
+    }
+
+    // wait for completion of the persistentServerState thread.
+    try
+    {
+      while (!done)
+      {
+        Thread.sleep(50);
+      }
+    } catch (InterruptedException e)
+    {
+      // stop waiting when interrupted.
     }
   }
 
@@ -2249,7 +2279,7 @@
    */
   public long computeGenerationId() throws DirectoryException
   {
-    Backend backend = this.retrievesBackend(baseDN);
+    Backend backend = retrievesBackend(baseDN);
     long bec = backend.getEntryCount();
     this.acquireIEContext();
     ieContext.checksumOutput = true;
@@ -3049,7 +3079,7 @@
     LDIFImportConfig importConfig = null;
     DirectoryException de = null;
 
-    Backend backend = this.retrievesBackend(baseDN);
+    Backend backend = retrievesBackend(baseDN);
 
     if (!backend.supportsLDIFImport())
     {

--
Gitblit v1.10.0