From c6c3de416bcc406346299a860905c9e71870a4ab Mon Sep 17 00:00:00 2001
From: gbellato <gbellato@localhost>
Date: Mon, 27 Aug 2007 11:58:47 +0000
Subject: [PATCH] complement for issue 2097 : total update fails sending a Message to ReplicationCache

---
 opends/src/server/org/opends/server/replication/plugin/ReplicationDomain.java |   50 ++++++++++++++++++++++++++++++++++----------------
 1 files changed, 34 insertions(+), 16 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 5ed95cb..05233d3 100644
--- a/opends/src/server/org/opends/server/replication/plugin/ReplicationDomain.java
+++ b/opends/src/server/org/opends/server/replication/plugin/ReplicationDomain.java
@@ -799,9 +799,10 @@
 
     if (update == null)
     {
-      synchronized (broker)
+      while (update == null)
       {
-        while (update == null)
+        InitializeRequestMessage initMsg = null;
+        synchronized (broker)
         {
           ReplicationMessage msg;
           try
@@ -822,32 +823,27 @@
             {
               // Another server requests us to provide entries
               // for a total update
-              InitializeRequestMessage initMsg = (InitializeRequestMessage) msg;
-              try
-              {
-                initializeTarget(initMsg.getsenderID(), initMsg.getsenderID(),
-                                 null);
-              }
-              catch(DirectoryException de)
-              {
-                // An error message has been sent to the peer
-                // Nothing more to do locally
-              }
+              initMsg = (InitializeRequestMessage) msg;
             }
             else if (msg instanceof InitializeTargetMessage)
             {
               // Another server is exporting its entries to us
-              InitializeTargetMessage initMsg = (InitializeTargetMessage) msg;
+              InitializeTargetMessage importMsg = (InitializeTargetMessage) msg;
 
               try
               {
-                importBackend(initMsg);
+                // This must be done while we are still holding the
+                // broker lock because we are now going to receive a
+                // bunch of entries from the remote server and we
+                // want the import thread to catch them and
+                // not the ListenerThread.
+                importBackend(importMsg);
               }
               catch(DirectoryException de)
               {
                 // Return an error message to notify the sender
                 ErrorMessage errorMsg =
-                  new ErrorMessage(initMsg.getsenderID(),
+                  new ErrorMessage(importMsg.getsenderID(),
                                    de.getMessageObject());
                 MessageBuilder mb = new MessageBuilder();
                 mb.append(de.getMessageObject());
@@ -880,6 +876,28 @@
             // just retry
           }
         }
+        // Test if we have received and export request message and
+        // if that's the case handle it now.
+        // This must be done outside of the portion of code protected
+        // by the broker lock so that we keep receiveing update
+        // when we are doing and export and so that a possible
+        // closure of the socket happening when we are publishing the
+        // entries to the remote can be handled by the other
+        // ListenerThread when they call this method and therefore the
+        // broker.receive() method.
+        if (initMsg != null)
+        {
+          try
+          {
+            initializeTarget(initMsg.getsenderID(), initMsg.getsenderID(),
+                null);
+          }
+          catch(DirectoryException de)
+          {
+            // An error message has been sent to the peer
+            // Nothing more to do locally
+          }
+        }
       }
     }
     return update;

--
Gitblit v1.10.0