From aea0892feca2fd3d56c9c810debed6d22389454e Mon Sep 17 00:00:00 2001
From: Jean-Noel Rouvignac <jean-noel.rouvignac@forgerock.com>
Date: Fri, 11 Jul 2014 09:54:43 +0000
Subject: [PATCH] OPENDJ-1453 (CR-3938) Replica offline messages should be synced with updates

---
 opendj3-server-dev/src/server/org/opends/server/replication/server/ServerWriter.java |   20 +++++++++++++++-----
 1 files changed, 15 insertions(+), 5 deletions(-)

diff --git a/opendj3-server-dev/src/server/org/opends/server/replication/server/ServerWriter.java b/opendj3-server-dev/src/server/org/opends/server/replication/server/ServerWriter.java
index b071f99..343e2d5 100644
--- a/opendj3-server-dev/src/server/org/opends/server/replication/server/ServerWriter.java
+++ b/opendj3-server-dev/src/server/org/opends/server/replication/server/ServerWriter.java
@@ -32,8 +32,10 @@
 import org.opends.server.api.DirectoryThread;
 import org.forgerock.i18n.slf4j.LocalizedLogger;
 import org.opends.server.replication.common.ServerStatus;
+import org.opends.server.replication.protocol.ReplicaOfflineMsg;
 import org.opends.server.replication.protocol.Session;
 import org.opends.server.replication.protocol.UpdateMsg;
+import org.opends.server.replication.service.DSRSShutdownSync;
 
 import static org.opends.messages.ReplicationMessages.*;
 import static org.opends.server.replication.common.ServerStatus.*;
@@ -50,8 +52,7 @@
   private final Session session;
   private final ServerHandler handler;
   private final ReplicationServerDomain replicationServerDomain;
-
-
+  private final DSRSShutdownSync dsrsShutdownSync;
 
   /**
    * Create a ServerWriter. Then ServerWriter then waits on the ServerHandler
@@ -63,9 +64,11 @@
    *          handler for which the ServerWriter is created.
    * @param replicationServerDomain
    *          The ReplicationServerDomain of this ServerWriter.
+   * @param dsrsShutdownSync Synchronization object for shutdown of combined DS/RS instances.
    */
   public ServerWriter(Session session, ServerHandler handler,
-      ReplicationServerDomain replicationServerDomain)
+      ReplicationServerDomain replicationServerDomain,
+      DSRSShutdownSync dsrsShutdownSync)
   {
     // Session may be null for ECLServerWriter.
     super("Replication server RS(" + handler.getReplicationServerId()
@@ -75,6 +78,7 @@
     this.session = session;
     this.handler = handler;
     this.replicationServerDomain = replicationServerDomain;
+    this.dsrsShutdownSync = dsrsShutdownSync;
   }
 
   /**
@@ -93,7 +97,9 @@
     LocalizableMessage errMessage = null;
     try
     {
-      while (true)
+      boolean shutdown = false;
+      while (!shutdown
+          || !dsrsShutdownSync.canShutdown(replicationServerDomain.getBaseDN()))
       {
         final UpdateMsg updateMsg = replicationServerDomain.take(this.handler);
         if (updateMsg == null)
@@ -101,12 +107,16 @@
           // this connection is closing
           errMessage = LocalizableMessage.raw(
            "Connection closure: null update returned by domain.");
-          return;
+          shutdown = true;
         }
         else if (!isUpdateMsgFiltered(updateMsg))
         {
           // Publish the update to the remote server using a protocol version it supports
           session.publish(updateMsg);
+          if (updateMsg instanceof ReplicaOfflineMsg)
+          {
+            dsrsShutdownSync.replicaOfflineMsgForwarded(replicationServerDomain.getBaseDN());
+          }
         }
       }
     }

--
Gitblit v1.10.0