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

gbellato
03.47.2006 840c825261ce76e69fbffe437861b40984d30d35
At startup time, each changelog server establish a connection with each other
changelog server.

At regular time each changelog server checks if it knows some changelog
servers with whom it is not connected and if necessary tries to open a connection
to this server.

This check is based on the hostname of the server.
When a changelog server uses DHCP this hostname is not always the same on
all the servers and this can result in tentative to open duplicate connections
which then result in spurious errors message.

In the long term, the changelog servers will use a discovery process and
this will be a good opportunity to discover the server ID of each other changelog
server and this will be a much better way to check for missing connections.

In the short term I've modified the code to use the IP address instead of the
hostname as an identifier for the remote changelog servers.

This should work fine with DHCP.
6 files modified
72 ■■■■ changed files
opendj-sdk/opends/src/server/org/opends/server/changelog/Changelog.java 33 ●●●●● patch | view | raw | blame | history
opendj-sdk/opends/src/server/org/opends/server/changelog/ChangelogCache.java 2 ●●● patch | view | raw | blame | history
opendj-sdk/opends/src/server/org/opends/server/changelog/ProtocolSession.java 7 ●●●●● patch | view | raw | blame | history
opendj-sdk/opends/src/server/org/opends/server/changelog/SerializingProtocolSession.java 8 ●●●●● patch | view | raw | blame | history
opendj-sdk/opends/src/server/org/opends/server/changelog/ServerHandler.java 14 ●●●●● patch | view | raw | blame | history
opendj-sdk/opends/src/server/org/opends/server/changelog/SocketSession.java 8 ●●●●● patch | view | raw | blame | history
opendj-sdk/opends/src/server/org/opends/server/changelog/Changelog.java
@@ -89,7 +89,6 @@
  private static HashMap<DN, ChangelogCache> baseDNs =
          new HashMap<DN, ChangelogCache>();
  private String localhostname = "null";
  private String localURL = "null";
  private static boolean shutdown = false;
  private short changelogServerId;
@@ -207,17 +206,27 @@
     */
    StringConfigAttribute changelogServer =
      (StringConfigAttribute) config.getConfigAttribute(changelogStub);
    if (changelogServer == null)
    {
      changelogServers = new ArrayList<String>();
    }
    else
    if (changelogServer != null)
    {
      changelogServers = changelogServer.activeValues();
      for (String serverURL : changelogServer.activeValues())
      {
        String[] splitStrings = serverURL.split(":");
        try
        {
          changelogServers.add(
              InetAddress.getByName(splitStrings[0]).getHostAddress()
              + ":" + splitStrings[1]);
        } catch (UnknownHostException e)
        {
          throw new ConfigException(MSGID_UNKNOWN_HOSTNAME,
              e.getLocalizedMessage());
        }
      }
    }
    configAttributes.add(changelogServer);
    initialize(changelogServerId, changelogPort, changelogServers);
    initialize(changelogServerId, changelogPort);
    configDn = config.getDN();
    DirectoryServer.registerConfigurableComponent(this);
@@ -384,12 +393,9 @@
   *
   * @param  changelogId       The unique identifier for this changelog.
   * @param  changelogPort     The port on which the changelog should listen.
   * @param  changelogServers  The set of changelog servers that have been
   *                           defined.
   *
   */
  private void initialize(short changelogId, int changelogPort,
                         List<String> changelogServers)
  private void initialize(short changelogId, int changelogPort)
  {
    try
    {
@@ -408,9 +414,10 @@
      /*
       * Open changelog socket
       */
      localhostname = InetAddress.getLocalHost().getHostName();
      String localhostname = InetAddress.getLocalHost().getHostName();
      String localAdddress = InetAddress.getLocalHost().getHostAddress();
      serverURL = localhostname + ":" + String.valueOf(changelogPort);
      localURL = localhostname + ":" + String.valueOf(changelogPort);
      localURL = localAdddress + ":" + String.valueOf(changelogPort);
      listenSocket = new ServerSocket(changelogPort);
      /*
opendj-sdk/opends/src/server/org/opends/server/changelog/ChangelogCache.java
@@ -359,7 +359,7 @@
    for (ServerHandler handler : changelogServers.values())
    {
      mySet.add(handler.getServerURL());
      mySet.add(handler.getServerAddressURL());
    }
    return mySet;
opendj-sdk/opends/src/server/org/opends/server/changelog/ProtocolSession.java
@@ -83,4 +83,11 @@
  public abstract SynchronizationMessage receive()
                  throws IOException, ClassNotFoundException,
                         DataFormatException;
  /**
   * Retrieve the IP address of the remote server.
   *
   * @return The IP address of the remote server.
   */
  public abstract String getRemoteAddress();
}
opendj-sdk/opends/src/server/org/opends/server/changelog/SerializingProtocolSession.java
@@ -103,4 +103,12 @@
    }
    return (SynchronizationMessage) socketInput.readObject();
  }
  /**
   * {@inheritDoc}
   */
  public String getRemoteAddress()
  {
    return socket.getInetAddress().getHostAddress();
  }
}
opendj-sdk/opends/src/server/org/opends/server/changelog/ServerHandler.java
@@ -92,6 +92,7 @@
  private boolean active = true;
  private ServerWriter writer = null;
  private DN baseDn = null;
  private String serverAddressURL;
  private static Map<ChangeNumber, ChangelogAckMessageList>
   changelogsWaitingAcks = new HashMap<ChangeNumber, ChangelogAckMessageList>();
@@ -188,6 +189,8 @@
        ChangelogStartMessage receivedMsg = (ChangelogStartMessage) msg;
        serverId = receivedMsg.getServerId();
        serverURL = receivedMsg.getServerURL();
        String[] splittedURL = serverURL.split(":");
        serverAddressURL = session.getRemoteAddress() + ":" + splittedURL[1];
        serverIsLDAPserver = false;
        this.baseDn = receivedMsg.getBaseDn();
        if (baseDn == null)
@@ -262,6 +265,17 @@
  }
  /**
   * Retrieves the Address URL for this server handler.
   *
   * @return  The Address URL for this server handler,
   *          in the form of an IP address and port separated by a colon.
   */
  public String getServerAddressURL()
  {
    return serverAddressURL;
  }
  /**
   * Retrieves the URL for this server handler.
   *
   * @return  The URL for this server handler, in the form of an address and
opendj-sdk/opends/src/server/org/opends/server/changelog/SocketSession.java
@@ -120,4 +120,12 @@
                            + totalLength + " bytes.");
    }
  }
  /**
   * {@inheritDoc}
   */
  public String getRemoteAddress()
  {
    return socket.getInetAddress().getHostAddress();
  }
}