From a5c5efbf8ca56c059709953f7fedb647dadaed06 Mon Sep 17 00:00:00 2001
From: ludovicp <ludovicp@localhost>
Date: Thu, 27 May 2010 15:28:09 +0000
Subject: [PATCH] Fix for issues #3395 and #3998. The changes improves the replica initialization protocol, especially flow control and handling connection outage.

---
 opends/src/server/org/opends/server/tasks/InitializeTask.java |   37 +++++++++++++++++--------------------
 1 files changed, 17 insertions(+), 20 deletions(-)

diff --git a/opends/src/server/org/opends/server/tasks/InitializeTask.java b/opends/src/server/org/opends/server/tasks/InitializeTask.java
index f74b684..d0a77c2 100644
--- a/opends/src/server/org/opends/server/tasks/InitializeTask.java
+++ b/opends/src/server/org/opends/server/tasks/InitializeTask.java
@@ -22,7 +22,7 @@
  * CDDL HEADER END
  *
  *
- *      Copyright 2006-2009 Sun Microsystems, Inc.
+ *      Copyright 2006-2010 Sun Microsystems, Inc.
  */
 package org.opends.server.tasks;
 import org.opends.server.replication.plugin.LDAPReplicationDomain;
@@ -76,7 +76,7 @@
   // completed
   long left = 0;
 
-  private Message initTaskError = null;
+  private Message taskCompletionError = null;
 
   /**
    * {@inheritDoc}
@@ -139,8 +139,8 @@
   {
     if (debugEnabled())
     {
-      TRACER.debugInfo("InitializeTask is starting domain: %s source:%d",
-                domain.getServiceID(), source);
+      TRACER.debugInfo("[IE] InitializeTask is starting on domain: %s "
+          + " from source:%d", domain.getServiceID(), source);
     }
     initState = getTaskState();
     try
@@ -163,20 +163,23 @@
       replaceAttributeValue(ATTR_TASK_INITIALIZE_LEFT, String.valueOf(left));
       replaceAttributeValue(
           ATTR_TASK_INITIALIZE_DONE, String.valueOf(total-left));
+
+      // Error raised at completion time
+      if (taskCompletionError != null)
+        logError(taskCompletionError);
+
     }
     catch(InterruptedException ie) {}
     catch(DirectoryException de)
     {
+      // Error raised at submission time
       logError(de.getMessageObject());
       initState = TaskState.STOPPED_BY_ERROR;
     }
 
-    if (initTaskError != null)
-      logError(initTaskError);
-
     if (debugEnabled())
     {
-      TRACER.debugInfo("InitializeTask is ending with state:%s",
+      TRACER.debugInfo("[IE] InitializeTask is ending with state:%s",
           initState.toString());
     }
     return initState;
@@ -190,28 +193,22 @@
    */
   public void updateTaskCompletionState(DirectoryException de)
   {
+    initState =  TaskState.STOPPED_BY_ERROR;
     try
     {
-      if (de != null)
-      {
-        initTaskError = de.getMessageObject();
-      }
       if (de == null)
         initState =  TaskState.COMPLETED_SUCCESSFULLY;
       else
-        initState =  TaskState.STOPPED_BY_ERROR;
-
-      if (debugEnabled())
-      {
-        TRACER.debugInfo("InitializeTask/setState: %s", initState);
-      }
+        taskCompletionError = de.getMessageObject();
+    }
+    finally
+    {
+      // Wake up runTask method waiting for completion
       synchronized (initState)
       {
         initState.notify();
       }
     }
-    catch(Exception e)
-    {}
   }
 
 

--
Gitblit v1.10.0