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

Matthew Swift
31.25.2013 5a872b4517410def8b08290ebd0645b053be4e32
Fix for OPENDJ-875: Use of hostnames in replication protocol causes failover problems

* Set the RS URL by first checking the list of configured replication servers to see if any correspond to the local host / port. If a match is found then it is used, otherwise we fall back to the old mechanism which was to perform a name lookup of /etc/hostname.
2 files modified
60 ■■■■■ changed files
opends/src/server/org/opends/server/replication/server/ReplicationServer.java 44 ●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/replication/server/ReplicationServerDomain.java 16 ●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/replication/server/ReplicationServer.java
@@ -537,11 +537,7 @@
      dbEnv = new ReplicationDbEnv(getFileForPath(dbDirname).getAbsolutePath(),
          this);
      /*
       * Open replicationServer socket
       */
      String localhostname = InetAddress.getLocalHost().getHostName();
      serverURL = localhostname + ":" + String.valueOf(replicationPort);
      setServerURL();
      listenSocket = new ServerSocket();
      listenSocket.bind(new InetSocketAddress(replicationPort));
@@ -1038,8 +1034,7 @@
        stopListen = false;
        replicationPort = newPort;
        String localhostname = InetAddress.getLocalHost().getHostName();
        serverURL = localhostname + ":" + String.valueOf(replicationPort);
        setServerURL();
        listenSocket = new ServerSocket();
        listenSocket.bind(new InetSocketAddress(replicationPort));
@@ -1151,6 +1146,41 @@
    return new ConfigChangeResult(ResultCode.SUCCESS, false);
  }
  /*
   * Try and set a sensible URL for this replication server. Since we are
   * listening on all addresses there are a couple of potential candidates: 1) a
   * matching server url in the replication server's configuration, 2) hostname
   * local address.
   */
  private void setServerURL() throws UnknownHostException
  {
    /*
     * First try the set of configured replication servers to see if one of them
     * is this replication server (this should always be the case).
     */
    for (String rs : replicationServers)
    {
      /*
       * No need validate the string format because the admin framework has
       * already done it.
       */
      final int index = rs.lastIndexOf(":");
      final String hostname = rs.substring(0, index);
      final int port = Integer.parseInt(rs.substring(index + 1));
      if (port == replicationPort && isLocalAddress(hostname))
      {
        serverURL = rs;
        return;
      }
    }
    /*
     * Fall-back to the machine hostname.
     */
    serverURL = InetAddress.getLocalHost().getHostName() + ":"
        + replicationPort;
  }
  /**
   * Broadcast a configuration change that just happened to the whole topology
   * by sending a TopologyMsg to every entity in the topology.
opends/src/server/org/opends/server/replication/server/ReplicationServerDomain.java
@@ -34,7 +34,6 @@
import static org.opends.server.util.StaticUtils.stackTraceToSingleLineString;
import java.io.IOException;
import java.net.InetAddress;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentLinkedQueue;
@@ -3017,18 +3016,9 @@
  @Override
  public String getMonitorInstanceName()
  {
    String hostname = "unknown";
    try
    {
      hostname = InetAddress.getLocalHost().getHostName();
    }
    catch (Exception e) {}
    return "Replication Server "
           + replicationServer.getReplicationPort() + " "
           + hostname
           + " " + replicationServer.getServerId()
           + ",cn=" + baseDn.replace(',', '_').replace('=', '_')
           + ",cn=replication";
    return "Replication server RS(" + replicationServer.getServerId() + ") "
        + replicationServer.getServerURL() + ",cn="
        + baseDn.replace(',', '_').replace('=', '_') + ",cn=Replication";
  }
  /**