From e4f80a3325b8ca06ad3823113b2e30054e471062 Mon Sep 17 00:00:00 2001
From: Jean-Noel Rouvignac <jean-noel.rouvignac@forgerock.com>
Date: Thu, 11 Jun 2015 10:20:09 +0000
Subject: [PATCH] OPENDJ-2106 (CR-7228) Entry is not replicated on second instance in 2 RS topology

---
 opendj-server-legacy/src/main/java/org/opends/server/replication/server/ServerHandler.java |   67 ++++++++++++++-------------------
 1 files changed, 29 insertions(+), 38 deletions(-)

diff --git a/opendj-server-legacy/src/main/java/org/opends/server/replication/server/ServerHandler.java b/opendj-server-legacy/src/main/java/org/opends/server/replication/server/ServerHandler.java
index 21eb5fb..6656852 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/replication/server/ServerHandler.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/replication/server/ServerHandler.java
@@ -31,7 +31,6 @@
 import java.io.IOException;
 import java.util.List;
 import java.util.Random;
-import java.util.Set;
 import java.util.concurrent.Semaphore;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicInteger;
@@ -603,15 +602,6 @@
 
   /**
    * Increment the number of updates sent to the server in assured safe data
-   * mode.
-   */
-  private void incrementAssuredSdSentUpdates()
-  {
-    assuredSdSentUpdates++;
-  }
-
-  /**
-   * Increment the number of updates sent to the server in assured safe data
    * mode that timed out.
    */
   public void incrementAssuredSdSentUpdatesTimeout()
@@ -639,15 +629,6 @@
 
   /**
    * Increment the number of updates sent to the server in assured safe read
-   * mode.
-   */
-  private void incrementAssuredSrSentUpdates()
-  {
-    assuredSrSentUpdates++;
-  }
-
-  /**
-   * Increment the number of updates sent to the server in assured safe read
    * mode that timed out.
    */
   public void incrementAssuredSrSentUpdatesTimeout()
@@ -942,17 +923,31 @@
    * Select the next update that must be sent to the server managed by this
    * ServerHandler.
    *
-   * @param connectedReplicaIds
-   *          Ids of replicas to accept when returning a message.
    * @return the next update that must be sent to the server managed by this
    *         ServerHandler.
    */
-  public UpdateMsg take(Set<Integer> connectedReplicaIds)
+  public UpdateMsg take()
   {
-    boolean interrupted = true;
-    UpdateMsg msg = getNextMessage(connectedReplicaIds, true); // synchronous:block until msg
+    final UpdateMsg msg = getNextMessage(serverId);
 
+    acquirePermitInSendWindow();
+
+    if (msg != null)
+    {
+      incrementOutCount();
+      if (msg.isAssured())
+      {
+        incrementAssuredStats(msg);
+      }
+      return msg;
+    }
+    return null;
+  }
+
+  private void acquirePermitInSendWindow()
+  {
     boolean acquired = false;
+    boolean interrupted = true;
     do
     {
       try
@@ -964,22 +959,18 @@
         // loop until not interrupted
       }
     } while ((interrupted || !acquired) && !shutdownWriter);
-    if (msg != null)
-    {
-      incrementOutCount();
+  }
 
-      if (msg.isAssured())
-      {
-        if (msg.getAssuredMode() == AssuredMode.SAFE_READ_MODE)
-        {
-          incrementAssuredSrSentUpdates();
-        } else if (!isDataServer())
-        {
-          incrementAssuredSdSentUpdates();
-        }
-      }
+  private void incrementAssuredStats(final UpdateMsg msg)
+  {
+    if (msg.getAssuredMode() == AssuredMode.SAFE_READ_MODE)
+    {
+      assuredSrSentUpdates++;
     }
-    return msg;
+    else if (!isDataServer())
+    {
+      assuredSdSentUpdates++;
+    }
   }
 
   /**

--
Gitblit v1.10.0