From 627cd94899c0bedc90d0248f72b1b224d9209028 Mon Sep 17 00:00:00 2001
From: Matthew Swift <matthew.swift@forgerock.com>
Date: Fri, 31 May 2013 09:07:14 +0000
Subject: [PATCH] Additional fix for OPENDJ-875: Use of hostnames in replication protocol causes failover problems

---
 opends/src/server/org/opends/server/replication/service/ReplicationBroker.java |   19 ++++++++++++++++---
 1 files changed, 16 insertions(+), 3 deletions(-)

diff --git a/opends/src/server/org/opends/server/replication/service/ReplicationBroker.java b/opends/src/server/org/opends/server/replication/service/ReplicationBroker.java
index bc1b1de..3307e31 100644
--- a/opends/src/server/org/opends/server/replication/service/ReplicationBroker.java
+++ b/opends/src/server/org/opends/server/replication/service/ReplicationBroker.java
@@ -1819,6 +1819,11 @@
   private static Map<Integer, ReplicationServerInfo> filterServersOnSameHost(
       Map<Integer, ReplicationServerInfo> bestServers)
   {
+    /*
+     * Initially look for all servers on the same host. If we find one in the
+     * same VM, then narrow the search.
+     */
+    boolean filterServersInSameVM = false;
     Map<Integer, ReplicationServerInfo> result =
         new HashMap<Integer, ReplicationServerInfo>();
     for (Integer rsId : bestServers.keySet())
@@ -1835,13 +1840,21 @@
           if (isLocalReplicationServerPort(port))
           {
             // An RS in the same VM will always have priority.
-            result.clear();
+            if (!filterServersInSameVM)
+            {
+              // Narrow the search to only include servers in this VM.
+              result.clear();
+              filterServersInSameVM = true;
+            }
             result.put(rsId, replicationServerInfo);
-            break;
+          }
+          else if (!filterServersInSameVM)
+          {
+            result.put(rsId, replicationServerInfo);
           }
           else
           {
-            result.put(rsId, replicationServerInfo);
+            // Skip: we have found some RSs in the same VM, but this RS is not.
           }
         }
       }

--
Gitblit v1.10.0