mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

Matthew Swift
31.07.2013 627cd94899c0bedc90d0248f72b1b224d9209028
Additional fix for OPENDJ-875: Use of hostnames in replication protocol causes failover problems

* fix unit test regression introduced by previous commit. RS candidate filtering was too aggressive and assumed that there would only be one RS per JVM, which is not the case in the unit tests

* also use a thread safe set implementation for the local RS ports in order to avoid potential race conditions in unit tests (this may be the cause of occasional RS load balancing unit test failures).

2 files modified
25 ■■■■ changed files
opends/src/server/org/opends/server/replication/server/ReplicationServer.java 6 ●●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/replication/service/ReplicationBroker.java 19 ●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/replication/server/ReplicationServer.java
@@ -43,6 +43,7 @@
import java.io.StringReader;
import java.net.*;
import java.util.*;
import java.util.concurrent.CopyOnWriteArraySet;
import org.opends.messages.Category;
import org.opends.messages.Message;
@@ -165,8 +166,9 @@
  private ECLWorkflowElement eclwe;
  private WorkflowImpl externalChangeLogWorkflowImpl = null;
  // FIXME: why is this a set of ports? Do we claim to support multiple ports?
  private static HashSet<Integer> localPorts = new HashSet<Integer>();
  // This is required for unit testing, so that we can keep track of all the
  // replication servers which are running in the VM.
  private static Set<Integer> localPorts = new CopyOnWriteArraySet<Integer>();
  // Monitors for synchronizing domain creation with the connect thread.
  private final Object domainTicketLock = new Object();
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.
          }
        }
      }