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

Jean-Noel Rouvignac
02.26.2013 07347aac048a14dc5fa1a5c1d02426230622051d
serviceId => baseDN (To make the code less confusing)
19 files modified
674 ■■■■ changed files
opends/src/server/org/opends/server/replication/common/MultiDomainServerState.java 51 ●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/replication/protocol/ECLUpdateMsg.java 58 ●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/replication/protocol/StartECLSessionMsg.java 36 ●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/replication/server/DataServerHandler.java 32 ●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/replication/server/DraftCNDB.java 8 ●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/replication/server/DraftCNData.java 26 ●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/replication/server/DraftCNDbHandler.java 36 ●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/replication/server/DraftCNDbIterator.java 14 ●●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/replication/server/ECLServerHandler.java 101 ●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/replication/server/ECLServerWriter.java 17 ●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/replication/server/MessageHandler.java 59 ●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/replication/server/ReplicationServer.java 32 ●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/replication/server/ReplicationServerHandler.java 20 ●●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/replication/server/ServerHandler.java 20 ●●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/replication/server/ServerReader.java 27 ●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/replication/server/ServerWriter.java 24 ●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/workflowelement/externalchangelog/ECLSearchOperation.java 24 ●●●●● patch | view | raw | blame | history
opends/tests/unit-tests-testng/src/server/org/opends/server/replication/protocol/SynchronizationMsgTest.java 51 ●●●● patch | view | raw | blame | history
opends/tests/unit-tests-testng/src/server/org/opends/server/replication/server/DraftCNDbHandlerTest.java 38 ●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/replication/common/MultiDomainServerState.java
@@ -23,15 +23,15 @@
 *
 *
 *      Copyright 2006-2009 Sun Microsystems, Inc.
 *      Portions Copyright 2011 ForgeRock AS
 *      Portions Copyright 2011-2013 ForgeRock AS
 */
package org.opends.server.replication.common;
import static org.opends.messages.ReplicationMessages.*;
import java.util.Iterator;
import java.util.Map;
import java.util.TreeMap;
import java.util.Iterator;
import org.opends.messages.Category;
import org.opends.messages.Message;
@@ -39,11 +39,13 @@
import org.opends.server.types.DirectoryException;
import org.opends.server.types.ResultCode;
/**
 * This object is used to store a list of ServerState object, one by
 * replication domain. Globally, it is the generalization of ServerState
 * (that applies to one domain) to a list of domains.
 * This object is used to store a list of ServerState object, one by replication
 * domain. Globally, it is the generalization of ServerState (that applies to
 * one domain) to a list of domains.
 * <p>
 * MultiDomainServerState is also known as "cookie" and is used with the
 * cookie-based changelog.
 */
public class MultiDomainServerState implements Iterable<String>
{
@@ -86,15 +88,15 @@
  }
  /**
   * Update the ServerState of the provided serviceId with the
   * Update the ServerState of the provided baseDN with the
   * replication change number provided.
   *
   * @param serviceId    The provided serviceId.
   * @param baseDN       The provided baseDN.
   * @param changeNumber The provided ChangeNumber.
   *
   * @return a boolean indicating if the update was meaningful.
   */
  public boolean update(String serviceId, ChangeNumber changeNumber)
  public boolean update(String baseDN, ChangeNumber changeNumber)
  {
    if (changeNumber == null)
      return false;
@@ -102,33 +104,30 @@
    synchronized(this)
    {
      int serverId =  changeNumber.getServerId();
      ServerState oldServerState = list.get(serviceId);
      ServerState oldServerState = list.get(baseDN);
      if (oldServerState == null)
        oldServerState = new ServerState();
      if (changeNumber.newer(oldServerState.getMaxChangeNumber(serverId)))
      {
        oldServerState.update(changeNumber);
        list.put(serviceId,oldServerState);
        list.put(baseDN, oldServerState);
        return true;
      }
      else
      {
        return false;
      }
      return false;
    }
  }
  /**
   * Update the ServerState of the provided serviceId with the
   * Update the ServerState of the provided baseDN with the
   * provided server state.
   *
   * @param serviceId    The provided serviceId.
   * @param baseDN       The provided baseDN.
   * @param serverState  The provided serverState.
   */
  public void update(String serviceId, ServerState serverState)
  public void update(String baseDN, ServerState serverState)
  {
    list.put(serviceId,serverState.duplicate());
    list.put(baseDN,serverState.duplicate());
  }
  /**
@@ -141,11 +140,10 @@
    String res = "";
    if ((list != null) && (!list.isEmpty()))
    {
      for (String serviceId  : list.keySet())
      for (String baseDN  : list.keySet())
      {
        ServerState ss = list.get(serviceId);
        res += serviceId + ":" + ss.toString();
        res += ";";
        ServerState ss = list.get(baseDN);
        res += baseDN + ":" + ss + ";";
      }
    }
    return res;
@@ -174,6 +172,7 @@
  /**
   * {@inheritDoc}
   */
  @Override
  public Iterator<String> iterator()
  {
    return list.keySet().iterator();
@@ -196,10 +195,10 @@
   */
  public boolean cover(MultiDomainServerState covered)
  {
    for (String serviceId : covered.list.keySet())
    for (String baseDN : covered.list.keySet())
    {
      ServerState state = list.get(serviceId);
      ServerState coveredState = covered.list.get(serviceId);
      ServerState state = list.get(baseDN);
      ServerState coveredState = covered.list.get(baseDN);
      if ((state==null)||(coveredState == null) || (!state.cover(coveredState)))
      {
        return false;
opends/src/server/org/opends/server/replication/protocol/ECLUpdateMsg.java
@@ -29,8 +29,9 @@
import java.io.UnsupportedEncodingException;
import java.util.zip.DataFormatException;
import org.opends.server.types.DirectoryException;
import org.opends.server.replication.common.MultiDomainServerState;
import org.opends.server.types.DirectoryException;
/**
 * Container for the ECL information sent from the ReplicationServer
@@ -38,31 +39,31 @@
 */
public class ECLUpdateMsg extends ReplicationMsg
{
  // The replication change returned.
  /** The replication change returned. */
  private final LDAPUpdateMsg updateMsg;
  // The serviceId (baseDN) of the domain to which applies the change.
  private final String serviceId;
  /** The baseDN of the domain to which applies the change. */
  private final String baseDN;
  // The value of the cookie updated with the current change
  /** The value of the cookie updated with the current change. */
  private MultiDomainServerState cookie;
  // The changenumber as specified by draft-good-ldap-changelog.
  /** The changeNumber as specified by draft-good-ldap-changelog. */
  private int draftChangeNumber;
  /**
   * Creates a new message.
   * @param update    The provided update.
   * @param updateMsg The provided update message.
   * @param cookie    The provided cookie value
   * @param serviceId The provided serviceId.
   * @param baseDN    The provided baseDN.
   * @param draftChangeNumber The provided draft change number.
   */
  public ECLUpdateMsg(LDAPUpdateMsg update, MultiDomainServerState cookie,
      String serviceId, int draftChangeNumber)
  public ECLUpdateMsg(LDAPUpdateMsg updateMsg, MultiDomainServerState cookie,
      String baseDN, int draftChangeNumber)
  {
    this.cookie = cookie;
    this.serviceId = serviceId;
    this.updateMsg = update;
    this.baseDN = baseDN;
    this.updateMsg = updateMsg;
    this.draftChangeNumber = draftChangeNumber;
  }
@@ -85,7 +86,7 @@
      if (in[0] != MSG_TYPE_ECL_UPDATE)
      {
        throw new DataFormatException("byte[] is not a valid " +
            this.getClass().getCanonicalName());
            getClass().getCanonicalName());
      }
      int pos = 1;
@@ -95,9 +96,9 @@
      this.cookie = new MultiDomainServerState(cookieStr);
      pos += length + 1;
      // Decode the serviceId
      // Decode the baseDN
      length = getNextLength(in, pos);
      this.serviceId = new String(in, pos, length, "UTF-8");
      this.baseDN = new String(in, pos, length, "UTF-8");
      pos += length + 1;
      // Decode the draft changeNumber
@@ -145,12 +146,13 @@
  }
  /**
   * Getter for the serviceId.
   * @return The serviceId.
   * Getter for the baseDN.
   *
   * @return The baseDN.
   */
  public  String getServiceId()
  public String getBaseDN()
  {
    return serviceId;
    return baseDN;
  }
  /**
@@ -172,7 +174,7 @@
    " updateMsg: " + updateMsg +
    " cookie: " + cookie +
    " draftChangeNumber: " + draftChangeNumber +
    " serviceId: " + serviceId + "]";
    " serviceId: " + baseDN + "]";
  }
  /**
@@ -182,14 +184,14 @@
  public byte[] getBytes(short protocolVersion)
      throws UnsupportedEncodingException
  {
    byte[] byteCookie    = String.valueOf(cookie).getBytes("UTF-8");
    byte[] byteServiceId = String.valueOf(serviceId).getBytes("UTF-8");
    byte[] byteCookie = String.valueOf(cookie).getBytes("UTF-8");
    byte[] byteBaseDN = String.valueOf(baseDN).getBytes("UTF-8");
    byte[] byteDraftChangeNumber =
      Integer.toString(draftChangeNumber).getBytes("UTF-8");
    byte[] byteUpdateMsg = updateMsg.getBytes(protocolVersion);
    int length = 1 + byteCookie.length +
                 1 + byteServiceId.length +
                 1 + byteBaseDN.length +
                 1 + byteDraftChangeNumber.length +
                 1 + byteUpdateMsg.length + 1;
@@ -199,16 +201,10 @@
    resultByteArray[0] = MSG_TYPE_ECL_UPDATE;
    int pos = 1;
    // Encode cookie
    // Encode all fields
    pos = addByteArray(byteCookie, resultByteArray, pos);
    // Encode serviceid
    pos = addByteArray(byteServiceId, resultByteArray, pos);
    /* Put the draftChangeNumber */
    pos = addByteArray(byteBaseDN, resultByteArray, pos);
    pos = addByteArray(byteDraftChangeNumber, resultByteArray, pos);
    // Encode msg
    pos = addByteArray(byteUpdateMsg, resultByteArray, pos);
    return resultByteArray;
opends/src/server/org/opends/server/replication/protocol/StartECLSessionMsg.java
@@ -37,7 +37,6 @@
import org.opends.server.replication.common.ChangeNumber;
import org.opends.server.util.StaticUtils;
/**
 * This class specifies the parameters of a search request on the ECL.
 * It is used as an interface between the requestor (plugin part)
@@ -115,7 +114,7 @@
  private String operationId = "";
  /** Excluded domains. */
  private Set<String> excludedServiceIDs = new HashSet<String>();
  private Set<String> excludedBaseDNs = new HashSet<String>();
  /**
   * Creates a new StartSessionMsg message from its encoded form.
@@ -189,7 +188,7 @@
      if (excludedDNsString.length()>0)
      {
        String[] excludedDNsStr = excludedDNsString.split(";");
        Collections.addAll(this.excludedServiceIDs, excludedDNsStr);
        Collections.addAll(this.excludedBaseDNs, excludedDNsStr);
      }
      pos += length + 1;
@@ -214,7 +213,7 @@
    changeNumber = new ChangeNumber(0,0,0);
    isPersistent = NON_PERSISTENT;
    operationId = "-1";
    excludedServiceIDs = new HashSet<String>();
    excludedBaseDNs = new HashSet<String>();
  }
  /**
@@ -223,8 +222,8 @@
  @Override
  public byte[] getBytes(short protocolVersion)
  {
    String excludedSIDsString =
        StaticUtils.collectionToString(excludedServiceIDs, ";");
    String excludedBaseDNsString =
        StaticUtils.collectionToString(excludedBaseDNs, ";");
    try
    {
@@ -243,7 +242,7 @@
      byte[] byteOperationId =
        String.valueOf(operationId).getBytes("UTF-8");
      byte[] byteExcludedDNs =
        String.valueOf(excludedSIDsString).getBytes("UTF-8");
        String.valueOf(excludedBaseDNsString).getBytes("UTF-8");
      int length =
        byteMode.length + 1 +
@@ -291,7 +290,7 @@
            " lastDraftChangeNumber="  + lastDraftChangeNumber +
            " generalizedState="       + crossDomainServerState +
            " operationId="            + operationId +
            " excludedDNs="            + excludedServiceIDs + "]";
            " excludedDNs="            + excludedBaseDNs + "]";
  }
  /**
@@ -403,7 +402,7 @@
  /**
   * Setter of the operation id.
   * @param operationId The provided opration id.
   * @param operationId The provided operation id.
   */
  public void setOperationId(String operationId)
  {
@@ -420,21 +419,24 @@
  }
  /**
   * Getter on the list of excluded ServiceIDs.
   * @return the list of excluded ServiceIDs.
   * Getter on the list of excluded baseDNs.
   *
   * @return the list of excluded baseDNs.
   */
  public Set<String> getExcludedServiceIDs()
  public Set<String> getExcludedBaseDNs()
  {
    return this.excludedServiceIDs;
    return this.excludedBaseDNs;
  }
  /**
   * Setter on the list of excluded ServiceIDs.
   * @param excludedServiceIDs the provided list of excluded ServiceIDs.
   * Setter on the list of excluded baseDNs.
   *
   * @param excludedBaseDNs
   *          the provided list of excluded baseDNs.
   */
  public void setExcludedDNs(Set<String> excludedServiceIDs)
  public void setExcludedDNs(Set<String> excludedBaseDNs)
  {
    this.excludedServiceIDs = excludedServiceIDs;
    this.excludedBaseDNs = excludedBaseDNs;
  }
}
opends/src/server/org/opends/server/replication/server/DataServerHandler.java
@@ -133,7 +133,7 @@
                "In RS " +
                replicationServerDomain.getReplicationServer().getServerId() +
                ". Closing connection to DS " + getServerId() +
                " for baseDn " + getServiceId() +
                " for baseDn " + getBaseDN() +
                " to force reconnection as new local" +
                " generationId and remote one match and DS is in bad gen id: " +
                newGenId);
@@ -171,7 +171,7 @@
            TRACER.debugInfo(
                "In RS " +
                replicationServerDomain.getReplicationServer().getServerId() +
                ". DS " + getServerId() + " for baseDn " + getServiceId() +
                ". DS " + getServerId() + " for baseDn " + getBaseDN() +
                " has already generation id " + newGenId +
            " so no ChangeStatusMsg sent to him.");
          }
@@ -193,7 +193,7 @@
      Message message = NOTE_BAD_GEN_ID_IN_FULL_UPDATE.get(
          Integer.toString(replicationServerDomain.
              getReplicationServer().getServerId()),
              getServiceId(),
              getBaseDN(),
              Integer.toString(serverId),
              Long.toString(generationId),
              Long.toString(newGenId));
@@ -205,7 +205,7 @@
    if (newStatus == ServerStatus.INVALID_STATUS)
    {
      Message msg = ERR_RS_CANNOT_CHANGE_STATUS.get(getServiceId(),
      Message msg = ERR_RS_CANNOT_CHANGE_STATUS.get(getBaseDN(),
          Integer.toString(serverId), status.toString(), event.toString());
      logError(msg);
      return;
@@ -221,7 +221,7 @@
          "In RS " +
          replicationServerDomain.getReplicationServer().getServerId() +
          " Sending change status for reset gen id to " + getServerId() +
          " for baseDn " + getServiceId() + ":\n" + csMsg);
          " for baseDn " + getBaseDN() + ":\n" + csMsg);
    }
    session.publish(csMsg);
@@ -243,7 +243,7 @@
    ServerStatus newStatus = StatusMachine.computeNewStatus(status, event);
    if (newStatus == ServerStatus.INVALID_STATUS)
    {
      Message msg = ERR_RS_CANNOT_CHANGE_STATUS.get(getServiceId(),
      Message msg = ERR_RS_CANNOT_CHANGE_STATUS.get(getBaseDN(),
          Integer.toString(serverId), status.toString(), event.toString());
      logError(msg);
      // Status analyzer must only change from NORMAL_STATUS to DEGRADED_STATUS
@@ -264,7 +264,7 @@
          "In RS " +
          replicationServerDomain.getReplicationServer().getServerId() +
          " Sending change status from status analyzer to " + getServerId() +
          " for baseDn " + getServiceId() + ":\n" + csMsg);
          " for baseDn " + getBaseDN() + ":\n" + csMsg);
    }
    session.publish(csMsg);
@@ -383,7 +383,7 @@
    if (event == StatusMachineEvent.INVALID_EVENT)
    {
      Message msg = ERR_RS_INVALID_NEW_STATUS.get(reqStatus.toString(),
          getServiceId(), Integer.toString(serverId));
          getBaseDN(), Integer.toString(serverId));
      logError(msg);
      return ServerStatus.INVALID_STATUS;
    }
@@ -392,7 +392,7 @@
    ServerStatus newStatus = StatusMachine.computeNewStatus(status, event);
    if (newStatus == ServerStatus.INVALID_STATUS)
    {
      Message msg = ERR_RS_CANNOT_CHANGE_STATUS.get(getServiceId(),
      Message msg = ERR_RS_CANNOT_CHANGE_STATUS.get(getBaseDN(),
          Integer.toString(serverId), status.toString(), event.toString());
      logError(msg);
      return ServerStatus.INVALID_STATUS;
@@ -421,7 +421,7 @@
    heartbeatInterval = serverStartMsg.getHeartbeatInterval();
    // generic stuff
    setServiceIdAndDomain(serverStartMsg.getBaseDn(), true);
    setBaseDNAndDomain(serverStartMsg.getBaseDn(), true);
    setInitialServerState(serverStartMsg.getServerState());
    setSendWindowSize(serverStartMsg.getWindowSize());
@@ -613,7 +613,7 @@
    {
      // Peer DS uses protocol < V4 : send it a ReplServerStartMsg
      startMsg = new ReplServerStartMsg(replicationServerId,
          replicationServerURL, getServiceId(), maxRcvWindow,
          replicationServerURL, getBaseDN(), maxRcvWindow,
          replicationServerDomain.getDbServerState(),
          localGenerationId, sslEncryption, getLocalGroupId(),
          replicationServerDomain.getReplicationServer()
@@ -623,7 +623,7 @@
    {
      // Peer DS uses protocol V4 : send it a ReplServerStartDSMsg
      startMsg = new ReplServerStartDSMsg(replicationServerId,
          replicationServerURL, getServiceId(), maxRcvWindow,
          replicationServerURL, getBaseDN(), maxRcvWindow,
          replicationServerDomain.getDbServerState(),
          localGenerationId, sslEncryption, getLocalGroupId(),
          replicationServerDomain.getReplicationServer()
@@ -707,7 +707,7 @@
    {
      Message message = ERR_RS_INVALID_INIT_STATUS.get(
          this.status.toString(),
          getServiceId(),
          getBaseDN(),
          Integer.toString(serverId));
      throw new DirectoryException(ResultCode.OTHER, message);
    }
@@ -735,21 +735,21 @@
      {
        Message message = WARN_BAD_GENERATION_ID_FROM_DS.get(
            serverId, session.getReadableRemoteAddress(),
            generationId, getServiceId(),
            generationId, getBaseDN(),
            getReplicationServerId(), localGenerationId);
        logError(message);
      }
    }
    else
    {
      // We are an empty Replicationserver
      // We are an empty ReplicationServer
      if ((generationId > 0) && (!getServerState().isEmpty()))
      {
        // If the LDAP server has already sent changes
        // it is not expected to connect to an empty RS
        Message message = WARN_BAD_GENERATION_ID_FROM_DS.get(
            serverId, session.getReadableRemoteAddress(),
            generationId, getServiceId(),
            generationId, getBaseDN(),
            getReplicationServerId(), localGenerationId);
        logError(message);
      }
opends/src/server/org/opends/server/replication/server/DraftCNDB.java
@@ -580,10 +580,10 @@
    }
    /**
     * Getter for the serviceID field of the current cursor.
     * @return The current serviceID.
     * Getter for the baseDN field of the current cursor.
     * @return The current baseDN.
     */
    public String currentServiceID()
    public String currentBaseDN()
    {
      if (isClosed)
      {
@@ -594,7 +594,7 @@
      {
        if (seqnumData != null)
        {
          return seqnumData.getServiceID();
          return seqnumData.getBaseDN();
        }
      }
      catch(Exception e)
opends/src/server/org/opends/server/replication/server/DraftCNData.java
@@ -27,7 +27,7 @@
 */
package org.opends.server.replication.server;
import static org.opends.server.util.StaticUtils.getBytes;
import static org.opends.server.util.StaticUtils.*;
import java.io.UnsupportedEncodingException;
@@ -45,21 +45,20 @@
  private static final long serialVersionUID = 1L;
  String value;
  String serviceID;
  ChangeNumber changeNumber;
  private String value;
  private String baseDN;
  private ChangeNumber changeNumber;
  /**
   * Creates a record to be stored in the DraftCNDB.
   * @param value The value (cookie).
   * @param serviceID The serviceID (domain DN).
   * @param baseDN The baseDN (domain DN).
   * @param changeNumber The replication change number.
   */
  public DraftCNData(String value,
                     String serviceID, ChangeNumber changeNumber)
  public DraftCNData(String value, String baseDN, ChangeNumber changeNumber)
  {
    String record = value
                   + FIELD_SEPARATOR + serviceID
                   + FIELD_SEPARATOR + baseDN
                   + FIELD_SEPARATOR + changeNumber;
    setData(getBytes(record));
  }
@@ -88,7 +87,7 @@
      String[] str = stringData.split(FIELD_SEPARATOR, 3);
      value = str[0];
      serviceID = str[1];
      baseDN = str[1];
      changeNumber = new ChangeNumber(str[2]);
    }
    catch (UnsupportedEncodingException e)
@@ -114,15 +113,15 @@
  /**
   * Getter for the service ID.
   * @return The serviceID..
   * @return The baseDN
   * @throws Exception when a problem occurs.
   */
  public String getServiceID()
  public String getBaseDN()
  throws Exception
  {
    if (value == null)
      this.decodeData(this.getData());
    return this.serviceID;
    return this.baseDN;
  }
  /**
@@ -142,6 +141,7 @@
   * Provide a string representation of these data.
   * @return the string representation of these data.
   */
  @Override
  public String toString()
  {
    StringBuilder buffer = new StringBuilder();
@@ -156,7 +156,7 @@
  public void toString(StringBuilder buffer)
  {
    buffer.append("DraftCNData : [value=").append(value);
    buffer.append("] [serviceID=").append(serviceID);
    buffer.append("] [serviceID=").append(baseDN);
    buffer.append("] [changeNumber=").append(changeNumber).append("]");
  }
}
opends/src/server/org/opends/server/replication/server/DraftCNDbHandler.java
@@ -133,20 +133,20 @@
   * than its maximum.
   * @param key The key for this record in the db.
   * @param value The associated value.
   * @param serviceID The associated serviceID.
   * @param baseDN The associated baseDN.
   * @param cn The associated replication change number.
   */
  public synchronized void add(int key, String value, String serviceID,
  public synchronized void add(int key, String value, String baseDN,
      ChangeNumber cn)
  {
    db.addEntry(key, value, serviceID, cn);
    db.addEntry(key, value, baseDN, cn);
    if (debugEnabled())
      TRACER.debugInfo(
          "In DraftCNDbhandler.add, added: "
        + " key=" + key
        + " value=" + value
        + " serviceID=" + serviceID
        + " baseDN=" + baseDN
        + " cn=" + cn);
  }
@@ -320,15 +320,15 @@
  /**
   * Clear the changes from this DB (from both memory cache and DB storage)
   * for the provided serviceID.
   * @param serviceIDToClear The serviceID for which we want to remove
   * for the provided baseDN.
   * @param baseDNToClear The baseDN for which we want to remove
   *         all records from the DraftCNDb - null means all.
   * @throws DatabaseException When an exception occurs while removing the
   * changes from the DB.
   * @throws Exception When an exception occurs while accessing a resource
   * from the DB.
   */
  public void clear(String serviceIDToClear)
  public void clear(String baseDNToClear)
      throws DatabaseException, Exception
  {
    // FIXME according to JE javadoc, this is a "fairly expensive operation"
@@ -361,17 +361,17 @@
          ChangeNumber cn = cursor.currentChangeNumber();
          // From the draftCNDb change record, get the domain and changeNumber
          String serviceID = cursor.currentServiceID();
          String baseDN = cursor.currentBaseDN();
          if ((serviceIDToClear != null)
              && (serviceIDToClear.equalsIgnoreCase(serviceID)))
          if ((baseDNToClear != null)
              && (baseDNToClear.equalsIgnoreCase(baseDN)))
          {
            cursor.delete();
            continue;
          }
          ReplicationServerDomain domain = replicationServer
              .getReplicationServerDomain(serviceID, false);
              .getReplicationServerDomain(baseDN, false);
          if (domain == null)
          {
@@ -405,7 +405,7 @@
            Map<String,ServerState> cnStartStates =
                MultiDomainServerState.splitGenStateToServerStates(
                        cursor.currentValue());
            cnVector = cnStartStates.get(serviceID);
            cnVector = cnStartStates.get(baseDN);
            if (debugEnabled())
              TRACER.debugInfo("DraftCNDBHandler:clear() - ChangeVector:" +
@@ -616,24 +616,24 @@
  }
  /**
   * Get the serviceID associated to a provided key.
   * Get the baseDN associated to a provided key.
   * @param key the provided key.
   * @return the serviceID, null when none.
   * @return the baseDN, null when none.
   */
  public String getServiceID(int key)
  public String getBaseDN(int key)
  {
    String sid = null;
    DraftCNDBCursor draftCNDBCursor = null;
    try
    {
      draftCNDBCursor = db.openReadCursor(key);
      sid = draftCNDBCursor.currentServiceID();
      sid = draftCNDBCursor.currentBaseDN();
    }
    catch(Exception e)
    {
      if (debugEnabled())
        TRACER.debugInfo("In DraftCNDbHandler.getServiceID, read: " +
          " key=" + key + " serviceID returned is null" +
        TRACER.debugInfo("In DraftCNDbHandler.getBaseDN(), read: " +
          " key=" + key + " baseDN returned is null" +
          " first=" + db.readFirstDraftCN() +
          " last=" + db.readLastDraftCN() +
          " count=" + db.count() +
opends/src/server/org/opends/server/replication/server/DraftCNDbIterator.java
@@ -23,15 +23,15 @@
 *
 *
 *      Copyright 2009 Sun Microsystems, Inc.
 *      Portions Copyright 2011 ForgeRock AS
 *      Portions Copyright 2011-2013 ForgeRock AS
 */
package org.opends.server.replication.server;
import static org.opends.server.loggers.debug.DebugLogger.getTracer;
import static org.opends.server.loggers.debug.DebugLogger.*;
import org.opends.server.loggers.debug.DebugTracer;
import org.opends.server.replication.common.ChangeNumber;
import org.opends.server.replication.server.DraftCNDB.*;
import org.opends.server.replication.server.DraftCNDB.DraftCNDBCursor;
import org.opends.server.types.DebugLogLevel;
import com.sleepycat.je.DatabaseException;
@@ -68,14 +68,15 @@
  }
  /**
   * Getter for the serviceID field.
   * Getter for the baseDN field.
   *
   * @return The service ID.
   */
  public String getServiceID()
  public String getBaseDN()
  {
    try
    {
      return this.draftCNDbCursor.currentServiceID();
      return this.draftCNDbCursor.currentBaseDN();
    }
    catch(Exception e)
    {
@@ -147,6 +148,7 @@
   * Release the cursor in case the iterator was badly used and releaseCursor
   * was never called.
   */
  @Override
  protected void finalize()
  {
    releaseCursor();
opends/src/server/org/opends/server/replication/server/ECLServerHandler.java
@@ -69,44 +69,44 @@
  /**
   * Specifies the last draft changer number (seqnum) requested.
   */
  public int lastDraftCN = 0;
  private int lastDraftCN = 0;
  /**
   * Specifies whether the draft change number (seqnum) db has been read until
   * its end.
   */
  public boolean isEndOfDraftCNReached = false;
  private boolean isEndOfDraftCNReached = false;
  /**
   * Specifies whether the current search has been requested to be persistent
   * or not.
   */
  public short isPersistent;
  private short isPersistent;
  /**
   * Specifies the current search phase : INIT or PERSISTENT.
   */
  public int searchPhase = INIT_PHASE;
  private int searchPhase = INIT_PHASE;
  /**
   * Specifies the cookie contained in the request, specifying where
   * to start serving the ECL.
   */
  public String startCookie;
  private String startCookie;
  /**
   * Specifies the value of the cookie before the change currently processed
   * is returned. It is updated with the change number of the change
   * currently processed (thus becoming the "current" cookie just
   * before the change is returned.
   */
  public MultiDomainServerState previousCookie =
  private MultiDomainServerState previousCookie =
    new MultiDomainServerState();
  /**
   * Specifies the excluded DNs (like cn=admin, ...).
   */
  public Set<String> excludedServiceIDs = new HashSet<String>();
  private Set<String> excludedBaseDNs = new HashSet<String>();
  /**
   * Eligible changeNumber - only changes older or equal to eligibleCN
   * are published in the ECL.
   */
  public ChangeNumber eligibleCN = null;
  private ChangeNumber eligibleCN = null;
  /**
   * Provides a string representation of this object.
@@ -136,19 +136,23 @@
   */
  private class DomainContext
  {
    ReplicationServerDomain rsd;
    private ReplicationServerDomain rsd;
    boolean active;              // active when there are still changes
    // supposed eligible for the ECL.
    /**
     * active when there are still changes supposed eligible for the ECL.
     */
    private boolean active;
    MessageHandler mh;           // the message handler from which are read
    // the changes for this domain
    /**
     * the message handler from which are reading the changes for this domain.
     */
    private MessageHandler mh;
    private UpdateMsg nextMsg;
    private UpdateMsg nextNonEligibleMsg;
    ServerState startState;
    ServerState currentState;
    ServerState stopState;
    long domainLatestTrimDate;
    private ServerState startState;
    private ServerState currentState;
    private ServerState stopState;
    private long domainLatestTrimDate;
    /**
     * {@inheritDoc}
@@ -166,14 +170,16 @@
     */
    public void toString(StringBuilder buffer)
    {
      buffer.append("[ [active=").append(active).append("] [rsd=")
          .append(rsd).append("] [nextMsg=").append(nextMsg).append("(")
      buffer.append("[ [active=").append(active)
          .append("] [rsd=").append(rsd)
          .append("] [nextMsg=").append(nextMsg).append("(")
          .append(nextMsg != null ?
          new Date(nextMsg.getChangeNumber().getTime()).toString():"")
          .append(")")
          .append("] [nextNonEligibleMsg=").append(nextNonEligibleMsg)
          .append("] [startState=").append(startState).append("] [stopState=")
          .append(stopState).append("] [currentState=").append(currentState)
          .append("] [startState=").append(startState)
          .append("] [stopState=").append(stopState)
          .append("] [currentState=").append(currentState)
          .append("]]");
    }
@@ -185,7 +191,7 @@
    private void getNextEligibleMessageForDomain(String opid)
    {
      if (debugEnabled())
        TRACER.debugInfo(" In ECLServerHandler, for " + mh.getServiceId() +
        TRACER.debugInfo(" In ECLServerHandler, for " + mh.getBaseDN() +
          " getNextEligibleMessageForDomain(" + opid+ ") "
          + "ctxt=" + toString());
@@ -202,7 +208,7 @@
                <= eligibleCN.getTime());
          if (debugEnabled())
            TRACER.debugInfo(" In ECLServerHandler, for " + mh.getServiceId() +
            TRACER.debugInfo(" In ECLServerHandler, for " + mh.getBaseDN() +
                " getNextEligibleMessageForDomain(" + opid+ ") "
              + " stored nonEligibleMsg " + nextNonEligibleMsg
              + " has now become eligible regarding "
@@ -232,10 +238,10 @@
              (newMsg.getChangeNumber().getTime() < domainLatestTrimDate));
          if (debugEnabled())
            TRACER.debugInfo(" In ECLServerHandler, for " + mh.getServiceId() +
            TRACER.debugInfo(" In ECLServerHandler, for " + mh.getBaseDN() +
                " getNextEligibleMessageForDomain(" + opid+ ") "
                + " got new message : "
                +  " serviceId=[" + mh.getServiceId()
                +  " serviceId=[" + mh.getBaseDN()
                + "] [newMsg=" + newMsg + "]" + dumpState());
          // in non blocking mode, return null when no more msg
@@ -245,7 +251,7 @@
                <= eligibleCN.getTime());
          if (debugEnabled())
              TRACER.debugInfo(" In ECLServerHandler, for " + mh.getServiceId()
              TRACER.debugInfo(" In ECLServerHandler, for " + mh.getBaseDN()
                + " getNextEligibleMessageForDomain(" + opid+ ") "
                + "newMsg isEligible=" + isEligible + " since "
                + "newMsg=[" + newMsg.getChangeNumber()
@@ -289,8 +295,10 @@
    }
  }
  // The global list of contexts by domain for the search currently processed.
  DomainContext[] domainCtxts = new DomainContext[0];
  /**
   * The global list of contexts by domain for the search currently processed.
   */
  private DomainContext[] domainCtxts = new DomainContext[0];
  private String clDomCtxtsToString(String msg)
  {
@@ -304,9 +312,9 @@
    return buffer.toString();
  }
  static int UNDEFINED_PHASE = 0;
  static int INIT_PHASE = 1;
  static int PERSISTENT_PHASE = 2;
  private static int UNDEFINED_PHASE = 0;
  private static int INIT_PHASE = 1;
  private static int PERSISTENT_PHASE = 2;
  /**
   * Starts this handler based on a start message received from remote server.
@@ -355,7 +363,7 @@
    {
      // Peer DS uses protocol < V4 : send it a ReplServerStartMsg
      startMsg = new ReplServerStartMsg(replicationServerId,
          replicationServerURL, getServiceId(), maxRcvWindow,
          replicationServerURL, getBaseDN(), maxRcvWindow,
          replicationServerDomain.getDbServerState(),
          localGenerationId, sslEncryption, getLocalGroupId(),
          replicationServerDomain.getReplicationServer()
@@ -365,7 +373,7 @@
    {
      // Peer DS uses protocol V4 : send it a ReplServerStartDSMsg
      startMsg = new ReplServerStartDSMsg(replicationServerId,
          replicationServerURL, getServiceId(), maxRcvWindow,
          replicationServerURL, getBaseDN(), maxRcvWindow,
          new ServerState(), localGenerationId, sslEncryption,
          getLocalGroupId(), 0, replicationServer.getWeight(), 0);
    }
@@ -395,14 +403,12 @@
        replicationServer, rcvWindowSize);
    try
    {
      setServiceIdAndDomain(ServerConstants.DN_EXTERNAL_CHANGELOG_ROOT, true);
      setBaseDNAndDomain(ServerConstants.DN_EXTERNAL_CHANGELOG_ROOT, true);
    }
    catch(DirectoryException de)
    {
      // no chance to have a bad domain set here
    }
  }
  /**
@@ -425,7 +431,7 @@
        replicationServer, 0);
    try
    {
      setServiceIdAndDomain(ServerConstants.DN_EXTERNAL_CHANGELOG_ROOT, true);
      setBaseDNAndDomain(ServerConstants.DN_EXTERNAL_CHANGELOG_ROOT, true);
    }
    catch(DirectoryException de)
    {
@@ -610,7 +616,7 @@
          // the operation) in order to have the first and possible last
          // DraftCN.
          int[] limits = replicationServer.getECLDraftCNLimits(
              eligibleCN, excludedServiceIDs);
              eligibleCN, excludedBaseDNs);
          // If the startDraftCN provided is lower than the first Draft CN in
          // the DB, let's use the lower limit.
@@ -732,7 +738,7 @@
            continue;
          // skip the excluded domains
          if (excludedServiceIDs.contains(rsd.getBaseDn()))
          if (excludedBaseDNs.contains(rsd.getBaseDn()))
          {
            // this is an excluded domain
            if (allowUnknownDomains)
@@ -826,10 +832,8 @@
          // Creates an unconnected SH for the domain
          MessageHandler mh = new MessageHandler(maxQueueSize,
              replicationServerURL, replicationServerId, replicationServer);
          // set initial state
          mh.setInitialServerState(newDomainCtxt.startState);
          // set serviceID and domain
          mh.setServiceIdAndDomain(rsd.getBaseDn(), false);
          mh.setBaseDNAndDomain(rsd.getBaseDn(), false);
          // register the unconnected into the domain
          rsd.registerHandler(mh);
          newDomainCtxt.mh = mh;
@@ -1011,7 +1015,7 @@
    String localString;
    localString = "External changelog Server ";
    if (this.serverId != 0)
      localString += serverId + " " + serverURL + " " + getServiceId()
      localString += serverId + " " + serverURL + " " + getBaseDN()
       + " " + this.getOperationId();
    else
      localString += this.getClass().getCanonicalName()+ " " + operationId;
@@ -1064,8 +1068,8 @@
          ERR_INVALID_COOKIE_SYNTAX.get());
    }
    excludedServiceIDs = startECLSessionMsg.getExcludedServiceIDs();
    replicationServer.disableEligibility(excludedServiceIDs);
    excludedBaseDNs = startECLSessionMsg.getExcludedBaseDNs();
    replicationServer.disableEligibility(excludedBaseDNs);
    eligibleCN = replicationServer.getEligibleCN();
    if (startECLSessionMsg.getECLRequestType()==
@@ -1327,7 +1331,7 @@
                // the next change from the DraftCN db
                ChangeNumber cnFromDraftCNDb = draftCNDbIter.getChangeNumber();
                String dnFromDraftCNDb = draftCNDbIter.getServiceID();
                String dnFromDraftCNDb = draftCNDbIter.getBaseDN();
                // are replogcn and DraftCNcn should be the same change ?
                int areCNEqual = cnFromChangelogDb.compareTo(cnFromDraftCNDb);
@@ -1395,7 +1399,7 @@
                        draftCNDb.add(
                            oldestChange.getDraftChangeNumber(),
                            previousCookie.toString(),
                            oldestChange.getServiceId(),
                            oldestChange.getBaseDN(),
                            oldestChange.getUpdateMsg().getChangeNumber());
                        break;
@@ -1528,7 +1532,7 @@
      // Update the current state
      previousCookie.update(
          oldestChange.getServiceId(),
          oldestChange.getBaseDN(),
          oldestChange.getUpdateMsg().getChangeNumber());
      // Set the current value of global state in the returned message
@@ -1566,7 +1570,6 @@
        writer = new ECLServerWriter(session,this,replicationServerDomain);
        writer.start();  // start suspended
      }
    }
    else
    {
opends/src/server/org/opends/server/replication/server/ECLServerWriter.java
@@ -26,11 +26,11 @@
 *      Portions copyright 2011-2013 ForgeRock AS
 */
package org.opends.server.replication.server;
import static org.opends.messages.ReplicationMessages.*;
import static org.opends.server.loggers.ErrorLogger.logError;
import static org.opends.server.loggers.debug.DebugLogger.debugEnabled;
import static org.opends.server.loggers.debug.DebugLogger.getTracer;
import static org.opends.server.util.StaticUtils.stackTraceToSingleLineString;
import static org.opends.server.loggers.ErrorLogger.*;
import static org.opends.server.loggers.debug.DebugLogger.*;
import static org.opends.server.util.StaticUtils.*;
import java.io.IOException;
import java.net.SocketException;
@@ -49,7 +49,6 @@
import org.opends.server.workflowelement.externalchangelog.ECLSearchOperation;
import org.opends.server.workflowelement.externalchangelog.ECLWorkflowElement;
/**
 * This class defines a server writer, which is used to send changes to a
 * directory server.
@@ -136,6 +135,7 @@
   * Loops waiting for changes from the ReplicationServerDomain and
   * forward them to the other servers
   */
  @Override
  public void run()
  {
    try
@@ -176,7 +176,7 @@
              handler.getReplicationServerId(),
              handler.getServerId(),
              session.getReadableRemoteAddress(),
              handler.getServiceId());
              handler.getBaseDN());
        }
        else
        {
@@ -184,7 +184,7 @@
              handler.getReplicationServerId(),
              handler.getServerId(),
              session.getReadableRemoteAddress(),
              handler.getServiceId());
              handler.getBaseDN());
        }
        logError(errMessage);
      }
@@ -194,8 +194,7 @@
      // An unexpected error happened.
      // Log an error and close the connection.
      Message errMessage = ERR_WRITER_UNEXPECTED_EXCEPTION
          .get(handler.toString() + " "
              + stackTraceToSingleLineString(e));
          .get(handler + " " + stackTraceToSingleLineString(e));
      logError(errMessage);
    }
    finally
opends/src/server/org/opends/server/replication/server/MessageHandler.java
@@ -27,7 +27,7 @@
 */
package org.opends.server.replication.server;
import static org.opends.messages.ReplicationMessages.ERR_RS_DN_DOES_NOT_MATCH;
import static org.opends.messages.ReplicationMessages.*;
import static org.opends.server.loggers.debug.DebugLogger.*;
import java.util.ArrayList;
@@ -44,11 +44,7 @@
import org.opends.server.replication.common.ChangeNumber;
import org.opends.server.replication.common.ServerState;
import org.opends.server.replication.protocol.UpdateMsg;
import org.opends.server.types.Attribute;
import org.opends.server.types.Attributes;
import org.opends.server.types.DirectoryException;
import org.opends.server.types.InitializationException;
import org.opends.server.types.ResultCode;
import org.opends.server.types.*;
/**
 * This class implements a buffering/producer/consumer mechanism of
@@ -90,7 +86,7 @@
   */
  protected int replicationServerId;
  /**
   * Specifies the related replication server domain based on serviceId(baseDn).
   * Specifies the related replication server domain based on baseDn.
   */
  protected ReplicationServerDomain replicationServerDomain = null;
  /**
@@ -118,9 +114,9 @@
   */
  private ServerState serverState;
  /**
   * Specifies the identifier of the service (usually the baseDn of the domain).
   * Specifies the baseDn of the domain.
   */
  private String serviceId = null;
  private String baseDN = null;
  /**
   * Specifies whether the consumer is still active or not.
   * If not active, the handler will not return any message.
@@ -208,9 +204,8 @@
  {
    if (replicationServerDomain==null)
    {
      replicationServerDomain =
        replicationServer.getReplicationServerDomain(
            serviceId, createIfNotExist, waitConnections);
      replicationServerDomain = replicationServer.getReplicationServerDomain(
            baseDN, createIfNotExist, waitConnections);
    }
    return replicationServerDomain;
  }
@@ -590,12 +585,13 @@
  }
  /**
   * Get the name of the serviceId (usually baseDn) for this handler.
   * @return The name of the serviceId.
   * Get the baseDN for this handler.
   *
   * @return The name of the baseDN.
   */
  protected String getServiceId()
  protected String getBaseDN()
  {
    return serviceId;
    return baseDN;
  }
  /**
@@ -650,32 +646,31 @@
  /**
   * Set the serviceId (usually baseDn) for this handler. Expected to be done
   * once and never changed during the handler life.
   * Set the baseDN for this handler. Expected to be done once and never changed
   * during the handler life.
   *
   * @param serviceId       The provided serviceId.
   * @param isDataServer    The handler is a dataServer
   *
   * @exception DirectoryException raised when a problem occurs.
   * @param baseDN
   *          The provided baseDN.
   * @param isDataServer
   *          The handler is a dataServer
   * @exception DirectoryException
   *              raised when a problem occurs.
   */
  protected void setServiceIdAndDomain(String serviceId, boolean isDataServer)
  protected void setBaseDNAndDomain(String baseDN, boolean isDataServer)
  throws DirectoryException
  {
    if (this.serviceId != null)
    if (this.baseDN != null)
    {
      if (!this.serviceId.equalsIgnoreCase(serviceId))
      if (!this.baseDN.equalsIgnoreCase(baseDN))
      {
        Message message = ERR_RS_DN_DOES_NOT_MATCH.get(
            this.serviceId,
            serviceId);
        throw new DirectoryException(ResultCode.OTHER,
            message, null);
        Message message = ERR_RS_DN_DOES_NOT_MATCH.get(this.baseDN, baseDN);
        throw new DirectoryException(ResultCode.OTHER, message, null);
      }
    }
    else
    {
      this.serviceId = serviceId;
      if (!serviceId.equalsIgnoreCase("cn=changelog"))
      this.baseDN = baseDN;
      if (!baseDN.equalsIgnoreCase("cn=changelog"))
        this.replicationServerDomain = getDomain(true, isDataServer);
    }
  }
opends/src/server/org/opends/server/replication/server/ReplicationServer.java
@@ -180,8 +180,8 @@
  private final Object connectThreadLock = new Object();
  private long domainTicket = 0L;
  /** ServiceIDs excluded for ECL. */
  private Collection<String> excludedServiceIDs = new ArrayList<String>();
  /** BaseDNs excluded for ECL. */
  private Collection<String> excludedBaseDNs = new ArrayList<String>();
  /**
   * The weight affected to the replication server.
@@ -1631,12 +1631,12 @@
  /**
   * Excluded a list of domain from eligibility computation.
   * @param excludedServiceIDs the provided list of serviceIDs excluded from
   * @param excludedBaseDNs the provided list of baseDNs excluded from
   *                          the computation of eligibleCN.
   */
  public void disableEligibility(Set<String> excludedServiceIDs)
  public void disableEligibility(Set<String> excludedBaseDNs)
  {
    this.excludedServiceIDs = excludedServiceIDs;
    this.excludedBaseDNs = excludedBaseDNs;
  }
  /**
@@ -1653,8 +1653,8 @@
    ChangeNumber eligibleCN = null;
    for (ReplicationServerDomain domain : getReplicationServerDomains())
    {
      if ((excludedServiceIDs != null) &&
          excludedServiceIDs.contains(domain.getBaseDn()))
      if ((excludedBaseDNs != null) &&
          excludedBaseDNs.contains(domain.getBaseDn()))
        continue;
      ChangeNumber domainEligibleCN = domain.getEligibleCN();
@@ -1769,12 +1769,12 @@
   *
   * @param  crossDomainEligibleCN The provided crossDomainEligibleCN used as
   *                               the upper limit for the lastDraftCN
   * @param  excludedServiceIDs  The serviceIDs that are excluded from the ECL.
   * @param  excludedBaseDNs       The baseDNs that are excluded from the ECL.
   * @return                       The first and last draftCN.
   * @throws DirectoryException    When it happens.
   */
  public int[] getECLDraftCNLimits(ChangeNumber crossDomainEligibleCN,
      Set<String> excludedServiceIDs) throws DirectoryException
      Set<String> excludedBaseDNs) throws DirectoryException
  {
    /* The content of the DraftCNdb depends on the SEARCH operations done before
     * requesting the DraftCN. If no operations, DraftCNdb is empty.
@@ -1830,13 +1830,13 @@
      changeNumberForLastSeqnum = draftCNDbH.getChangeNumber(lastDraftCN);
      // Get the domain associated with the current last DraftCN
      domainForLastSeqnum = draftCNDbH.getServiceID(lastDraftCN);
      domainForLastSeqnum = draftCNDbH.getBaseDN(lastDraftCN);
    }
    // Domain by domain
    for (ReplicationServerDomain rsd : getReplicationServerDomains())
    {
      if (excludedServiceIDs.contains(rsd.getBaseDn()))
      if (excludedBaseDNs.contains(rsd.getBaseDn()))
        continue;
      // for this domain, have the state in the replchangelog
@@ -1894,19 +1894,19 @@
  /**
   * Returns the last (newest) cookie value.
   * @param excludedServiceIDs The list of serviceIDs excluded from ECL.
   * @param excludedBaseDNs The list of baseDNs excluded from ECL.
   * @return the last cookie value.
   */
  public MultiDomainServerState getLastECLCookie(Set<String> excludedServiceIDs)
  public MultiDomainServerState getLastECLCookie(Set<String> excludedBaseDNs)
  {
    disableEligibility(excludedServiceIDs);
    disableEligibility(excludedBaseDNs);
    MultiDomainServerState result = new MultiDomainServerState();
    // Initialize start state for  all running domains with empty state
    for (ReplicationServerDomain rsd : getReplicationServerDomains())
    {
      if ((excludedServiceIDs != null)
          && (excludedServiceIDs.contains(rsd.getBaseDn())))
      if ((excludedBaseDNs != null)
          && (excludedBaseDNs.contains(rsd.getBaseDn())))
        continue;
      if (rsd.getDbServerState().isEmpty())
opends/src/server/org/opends/server/replication/server/ReplicationServerHandler.java
@@ -54,8 +54,8 @@
public class ReplicationServerHandler extends ServerHandler
{
  /*
   * Properties filled only if remote server is a RS
  /**
   * Properties filled only if remote server is a RS.
   */
  private String serverAddressURL;
  /**
@@ -87,7 +87,7 @@
      serverAddressURL =
        session.getRemoteAddress() + ":" + serverURL.substring(separator +
            1);
      setServiceIdAndDomain(inReplServerStartMsg.getBaseDn(), false);
      setBaseDNAndDomain(inReplServerStartMsg.getBaseDn(), false);
      setInitialServerState(inReplServerStartMsg.getServerState());
      setSendWindowSize(inReplServerStartMsg.getWindowSize());
      if (protocolVersion > ProtocolVersion.REPLICATION_PROTOCOL_V1)
@@ -117,7 +117,7 @@
  private ReplServerStartMsg sendStartToRemote() throws IOException
  {
    ReplServerStartMsg outReplServerStartMsg = new ReplServerStartMsg(
        replicationServerId, replicationServerURL, getServiceId(),
        replicationServerId, replicationServerURL, getBaseDN(),
        maxRcvWindow, replicationServerDomain.getDbServerState(),
        localGenerationId, sslEncryption,
        getLocalGroupId(), replicationServerDomain.getReplicationServer()
@@ -150,17 +150,17 @@
  /**
   * Connect the hosting RS to the RS represented by THIS handler
   * on an outgoing connection.
   * @param serviceId The serviceId (usually baseDn).
   * @param baseDN The baseDN
   * @param sslEncryption The sslEncryption requested to the remote RS.
   * @throws DirectoryException when an error occurs.
   */
  public void connect(String serviceId, boolean sslEncryption)
  public void connect(String baseDN, boolean sslEncryption)
  throws DirectoryException
  {
    // we are the initiator and decides of the encryption
    this.sslEncryption = sslEncryption;
    setServiceIdAndDomain(serviceId, false);
    setBaseDNAndDomain(baseDN, false);
    localGenerationId = replicationServerDomain.getGenerationId();
    oldGenerationId = localGenerationId;
@@ -315,7 +315,6 @@
   */
  public void startFromRemoteRS(ReplServerStartMsg inReplServerStartMsg)
  {
    //
    localGenerationId = -1;
    oldGenerationId = -100;
    try
@@ -581,7 +580,7 @@
           */
          Message message = WARN_BAD_GENERATION_ID_FROM_RS.get(
                  serverId, session.getReadableRemoteAddress(), generationId,
                  getServiceId(), getReplicationServerId(), localGenerationId);
                  getBaseDN(), getReplicationServerId(), localGenerationId);
          logError(message);
        }
      }
@@ -767,8 +766,7 @@
    ArrayList<Attribute> attributes = super.getMonitorData();
    // Add the specific RS ones
    attributes.add(Attributes.create("Replication-Server",
        serverURL));
    attributes.add(Attributes.create("Replication-Server", serverURL));
    MonitorData md = replicationServerDomain.getDomainMonitorData();
opends/src/server/org/opends/server/replication/server/ServerHandler.java
@@ -28,8 +28,8 @@
package org.opends.server.replication.server;
import static org.opends.messages.ReplicationMessages.*;
import static org.opends.server.loggers.ErrorLogger.logError;
import static org.opends.server.loggers.debug.DebugLogger.debugEnabled;
import static org.opends.server.loggers.ErrorLogger.*;
import static org.opends.server.loggers.debug.DebugLogger.*;
import java.io.IOException;
import java.util.ArrayList;
@@ -324,6 +324,7 @@
   * Set the shut down flag to true and returns the previous value of the flag.
   * @return The previous value of the shut down flag
   */
  @Override
  public boolean engageShutdown()
  {
    // Use thread safe boolean
@@ -571,6 +572,7 @@
   * Get the count of updates received from the server.
   * @return the count of update received from the server.
   */
  @Override
  public int getInCount()
  {
    return inCount;
@@ -591,7 +593,7 @@
    ArrayList<Attribute> attributes = super.getMonitorData();
    attributes.add(Attributes.create("server-id", String.valueOf(serverId)));
    attributes.add(Attributes.create("domain-name", getServiceId()));
    attributes.add(Attributes.create("domain-name", getBaseDN()));
    // Deprecated
    attributes.add(Attributes.create("max-waiting-changes", String
@@ -658,6 +660,7 @@
   * Get the count of updates sent to this server.
   * @return  The count of update sent to this server.
   */
  @Override
  public int getOutCount()
  {
    return outCount;
@@ -774,6 +777,7 @@
  /**
   * Increase the counter of update received from the server.
   */
  @Override
  public void incrementInCount()
  {
    inCount++;
@@ -782,6 +786,7 @@
  /**
   * Increase the counter of updates sent to the server.
   */
  @Override
  public void incrementOutCount()
  {
    outCount++;
@@ -894,13 +899,13 @@
      Random random = new Random();
      int randomTime = random.nextInt(6); // Random from 0 to 5
      // Wait at least 3 seconds + (0 to 5 seconds)
      long timeout = (long) (3000 + ( randomTime * 1000 ) );
      long timeout = 3000 + (randomTime * 1000);
      boolean noTimeout = replicationServerDomain.tryLock(timeout);
      if (!noTimeout)
      {
        // Timeout
        Message message = WARN_TIMEOUT_WHEN_CROSS_CONNECTION.get(
            getServiceId(),
            getBaseDN(),
            serverId,
            session.getReadableRemoteAddress(),
            replicationServerId);
@@ -952,7 +957,7 @@
      // while it is not, this means that some problem happened in the
      // window exchange procedure !
      // lets update the LDAP server with out current window size and hope
      // that everything will work better in the futur.
      // that everything will work better in the future.
      // TODO also log an error message.
      WindowMsg msg = new WindowMsg(rcvWindow);
      session.publish(msg);
@@ -1022,6 +1027,7 @@
  /**
   * Shutdown This ServerHandler.
   */
  @Override
  public void shutdown()
  {
    shutdownWriter();
@@ -1084,7 +1090,7 @@
    {
      try
      {
        acquired = sendWindow.tryAcquire((long) 500, TimeUnit.MILLISECONDS);
        acquired = sendWindow.tryAcquire(500, TimeUnit.MILLISECONDS);
        interrupted = false;
      } catch (InterruptedException e)
      {
opends/src/server/org/opends/server/replication/server/ServerReader.java
@@ -28,10 +28,9 @@
package org.opends.server.replication.server;
import static org.opends.messages.ReplicationMessages.*;
import static org.opends.server.loggers.ErrorLogger.logError;
import static org.opends.server.loggers.debug.DebugLogger.debugEnabled;
import static org.opends.server.loggers.debug.DebugLogger.getTracer;
import static org.opends.server.util.StaticUtils.stackTraceToSingleLineString;
import static org.opends.server.loggers.ErrorLogger.*;
import static org.opends.server.loggers.debug.DebugLogger.*;
import static org.opends.server.util.StaticUtils.*;
import java.io.IOException;
@@ -85,6 +84,7 @@
  /**
   * Create a loop that reads changes and hands them off to be processed.
   */
  @Override
  public void run()
  {
    Message errMessage = null;
@@ -141,7 +141,7 @@
                  logError(WARN_IGNORING_UPDATE_FROM_DS_BADGENID.get(
                      handler.getReplicationServerId(),
                      ((UpdateMsg) msg).getChangeNumber().toString(),
                      handler.getServiceId(), handler.getServerId(),
                      handler.getBaseDN(), handler.getServerId(),
                      session.getReadableRemoteAddress(),
                      handler.getGenerationId(),
                      referenceGenerationId));
@@ -149,7 +149,7 @@
                  logError(WARN_IGNORING_UPDATE_FROM_DS_FULLUP.get(
                      handler.getReplicationServerId(),
                      ((UpdateMsg) msg).getChangeNumber().toString(),
                      handler.getServiceId(), handler.getServerId(),
                      handler.getBaseDN(), handler.getServerId(),
                      session.getReadableRemoteAddress()));
                filtered = true;
              }
@@ -167,7 +167,7 @@
                    WARN_IGNORING_UPDATE_FROM_RS.get(
                        handler.getReplicationServerId(),
                        ((UpdateMsg) msg).getChangeNumber().toString(),
                        handler.getServiceId(),
                        handler.getBaseDN(),
                        handler.getServerId(),
                        session.getReadableRemoteAddress(),
                        handler.getGenerationId(),
@@ -237,7 +237,7 @@
            {
              errMessage =
                ERR_RECEIVED_CHANGE_STATUS_NOT_FROM_DS.get(
                    handler.getServiceId(),
                    handler.getBaseDN(),
                    Integer.toString(handler.getServerId()),
                    csMsg.toString());
              logError(errMessage);
@@ -269,8 +269,8 @@
          } else if (msg == null)
          {
            /*
             * The remote server has sent an unknown message,
             * close the conenction.
             * The remote server has sent an unknown message, close the
             * connection.
             */
            errMessage = NOTE_READER_NULL_MSG.get(handler.toString());
            logError(errMessage);
@@ -303,13 +303,13 @@
        {
          errMessage = ERR_DS_BADLY_DISCONNECTED.get(
              handler.getReplicationServerId(), handler.getServerId(),
              remoteAddress, handler.getServiceId());
              remoteAddress, handler.getBaseDN());
        }
        else
        {
          errMessage = ERR_RS_BADLY_DISCONNECTED.get(
              handler.getReplicationServerId(), handler.getServerId(),
              remoteAddress, handler.getServiceId());
              remoteAddress, handler.getBaseDN());
        }
        logError(errMessage);
      }
@@ -334,8 +334,7 @@
       */
      if (debugEnabled())
      {
        TRACER.debugInfo("In " + this.getName()
            + " closing the session");
        TRACER.debugInfo("In " + this.getName() + " closing the session");
      }
      session.close();
      handler.doStop();
opends/src/server/org/opends/server/replication/server/ServerWriter.java
@@ -26,17 +26,16 @@
 *      Portions Copyright 2011-2013 ForgeRock AS
 */
package org.opends.server.replication.server;
import org.opends.messages.Message;
import static org.opends.server.loggers.ErrorLogger.logError;
import static org.opends.server.loggers.debug.DebugLogger.debugEnabled;
import static org.opends.server.loggers.debug.DebugLogger.getTracer;
import static org.opends.server.util.StaticUtils.stackTraceToSingleLineString;
import static org.opends.messages.ReplicationMessages.*;
import static org.opends.server.loggers.ErrorLogger.*;
import static org.opends.server.loggers.debug.DebugLogger.*;
import static org.opends.server.util.StaticUtils.*;
import java.net.SocketException;
import java.util.NoSuchElementException;
import org.opends.messages.Message;
import org.opends.server.api.DirectoryThread;
import org.opends.server.loggers.debug.DebugTracer;
import org.opends.server.replication.common.ServerStatus;
@@ -94,6 +93,7 @@
   * Loops waiting for changes from the ReplicationServerDomain and forward them
   * to the other servers
   */
  @Override
  public void run()
  {
    Message errMessage = null;
@@ -138,7 +138,7 @@
              logError(WARN_IGNORING_UPDATE_TO_DS_BADGENID.get(
                  handler.getReplicationServerId(),
                  update.getChangeNumber().toString(),
                  handler.getServiceId(), handler.getServerId(),
                  handler.getBaseDN(), handler.getServerId(),
                  session.getReadableRemoteAddress(),
                  handler.getGenerationId(),
                  referenceGenerationId));
@@ -146,7 +146,7 @@
              logError(WARN_IGNORING_UPDATE_TO_DS_FULLUP.get(
                  handler.getReplicationServerId(),
                  update.getChangeNumber().toString(),
                  handler.getServiceId(), handler.getServerId(),
                  handler.getBaseDN(), handler.getServerId(),
                  session.getReadableRemoteAddress()));
            continue;
          }
@@ -165,7 +165,7 @@
                WARN_IGNORING_UPDATE_TO_RS.get(
                    handler.getReplicationServerId(),
                    update.getChangeNumber().toString(),
                    handler.getServiceId(),
                    handler.getBaseDN(),
                    handler.getServerId(),
                    session.getReadableRemoteAddress(),
                    handler.getGenerationId(),
@@ -204,13 +204,13 @@
      {
        errMessage = ERR_DS_BADLY_DISCONNECTED.get(
            handler.getReplicationServerId(), handler.getServerId(),
            session.getReadableRemoteAddress(), handler.getServiceId());
            session.getReadableRemoteAddress(), handler.getBaseDN());
      }
      else
      {
        errMessage = ERR_RS_BADLY_DISCONNECTED.get(
            handler.getReplicationServerId(), handler.getServerId(),
            session.getReadableRemoteAddress(), handler.getServiceId());
            session.getReadableRemoteAddress(), handler.getBaseDN());
      }
      logError(errMessage);
@@ -225,13 +225,13 @@
      {
        errMessage = ERR_DS_BADLY_DISCONNECTED.get(
            handler.getReplicationServerId(), handler.getServerId(),
            session.getReadableRemoteAddress(), handler.getServiceId());
            session.getReadableRemoteAddress(), handler.getBaseDN());
      }
      else
      {
        errMessage = ERR_RS_BADLY_DISCONNECTED.get(
            handler.getReplicationServerId(), handler.getServerId(),
            session.getReadableRemoteAddress(), handler.getServiceId());
            session.getReadableRemoteAddress(), handler.getBaseDN());
      }
      logError(errMessage);
    }
opends/src/server/org/opends/server/workflowelement/externalchangelog/ECLSearchOperation.java
@@ -86,7 +86,7 @@
          ServerConstants.OID_VLV_REQUEST_CONTROL));
  /** The set of objectclasses that will be used in ECL root entry. */
  private static final HashMap<ObjectClass, String>
  private static final Map<ObjectClass, String>
    CHANGELOG_ROOT_OBJECT_CLASSES = new LinkedHashMap<ObjectClass, String>(2);
  static
  {
@@ -98,7 +98,7 @@
  }
  /** The set of objectclasses that will be used in ECL entries. */
  private static final HashMap<ObjectClass, String>
  private static final Map<ObjectClass, String>
    CHANGELOG_ENTRY_OBJECT_CLASSES = new LinkedHashMap<ObjectClass, String>(2);
  static
  {
@@ -787,16 +787,15 @@
                + e.getMessage()));
      }
      ArrayList<RawAttribute> eclAttributes = addMsg.getEclIncludes();
      List<RawAttribute> eclAttributes = addMsg.getEclIncludes();
      clEntry = createChangelogEntry(eclmsg.getServiceId(), eclmsg
      clEntry = createChangelogEntry(eclmsg.getBaseDN(), eclmsg
          .getCookie().toString(), DN.decode(addMsg.getDn()),
          addMsg.getChangeNumber(), ldifChanges, // entry as created (in LDIF
                                                 // format)
          addMsg.getEntryUUID(),
          eclAttributes, // entry attributes
          eclmsg.getDraftChangeNumber(), "add", changeInitiatorsName);
    }
    else if (msg instanceof ModifyCommonMsg)
    {
@@ -857,7 +856,7 @@
      String changeType = (modifyMsg instanceof ModifyDNMsg) ? "modrdn"
          : "modify";
      clEntry = createChangelogEntry(eclmsg.getServiceId(), eclmsg
      clEntry = createChangelogEntry(eclmsg.getBaseDN(), eclmsg
          .getCookie().toString(), DN.decode(modifyMsg.getDn()),
          modifyMsg.getChangeNumber(), ldifChanges,
          modifyMsg.getEntryUUID(),
@@ -869,8 +868,7 @@
      {
        ModifyDNMsg modDNMsg = (ModifyDNMsg) modifyMsg;
        Attribute a = Attributes.create("newrdn",
            modDNMsg.getNewRDN());
        Attribute a = Attributes.create("newrdn", modDNMsg.getNewRDN());
        clEntry.addAttribute(a, null);
        if (modDNMsg.getNewSuperior() != null)
@@ -889,7 +887,7 @@
    {
      DeleteMsg delMsg = (DeleteMsg) msg;
      clEntry = createChangelogEntry(eclmsg.getServiceId(), eclmsg
      clEntry = createChangelogEntry(eclmsg.getBaseDN(), eclmsg
          .getCookie().toString(), DN.decode(delMsg.getDn()),
          delMsg.getChangeNumber(),
          null, // no changes
@@ -987,7 +985,7 @@
   * Create an ECL entry from a set of provided information. This is the part
   * of entry creation common to all types of msgs (ADD, DEL, MOD, MODDN).
   *
   * @param serviceID       The provided cookie value.
   * @param baseDN          The provided baseDN value.
   * @param cookie          The provided cookie value.
   * @param targetDN        The provided targetDN.
   * @param changeNumber    The provided replication changeNumber.
@@ -1002,7 +1000,7 @@
   *         When any error occurs.
   */
  private static Entry createChangelogEntry(
      String serviceID,
      String baseDN,
      String cookie,
      DN targetDN,
      ChangeNumber changeNumber,
@@ -1018,7 +1016,7 @@
    if (draftChangenumber == 0)
    {
      // Draft uncompat mode
      dnString = "replicationCSN=" + changeNumber + "," + serviceID + ","
      dnString = "replicationCSN=" + changeNumber + "," + baseDN + ","
          + ServerConstants.DN_EXTERNAL_CHANGELOG_ROOT;
    }
    else
@@ -1031,12 +1029,10 @@
    // Objectclass
    Map<AttributeType, List<Attribute>> uAttrs =
      new LinkedHashMap<AttributeType,List<Attribute>>();
    Map<AttributeType, List<Attribute>> operationalAttrs =
      new LinkedHashMap<AttributeType,List<Attribute>>();
    // Operational standard attributes
    addAttributeByType(ATTR_SUBSCHEMA_SUBENTRY_LC, ATTR_SUBSCHEMA_SUBENTRY_LC,
        ConfigConstants.DN_DEFAULT_SCHEMA_ROOT, uAttrs, operationalAttrs);
opends/tests/unit-tests-testng/src/server/org/opends/server/replication/protocol/SynchronizationMsgTest.java
@@ -50,10 +50,12 @@
import org.testng.annotations.BeforeClass;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
/**
 * Test the constructors, encoders and decoders of the replication protocol
 * PDUs classes (message classes)
 */
@SuppressWarnings("javadoc")
public class SynchronizationMsgTest extends ReplicationTestCase
{
  /**
@@ -92,12 +94,12 @@
    mods2.add(mod2);
    AttributeBuilder builder = new AttributeBuilder(type);
    List<Modification> mods3 = new ArrayList<Modification>();
    builder.add("string");
    builder.add("value");
    builder.add("again");
    Attribute attr3 = builder.toAttribute();
    Modification mod3 = new Modification(ModificationType.ADD, attr3);
    List<Modification> mods3 = new ArrayList<Modification>();
    mods3.add(mod3);
    List<Modification> mods4 = new ArrayList<Modification>();
@@ -745,7 +747,7 @@
    DeleteMsg delmsg = new DeleteMsg(op);
    int draftcn = 21;
    String serviceId = "serviceid";
    String baseDN = "dc=example,dc=com";
    // create a cookie
    MultiDomainServerState cookie =
@@ -754,26 +756,26 @@
          "o=test2:000001210b6f21e904b100000002 000001210b6f21e904b200000002;");
    // Constructor test
    ECLUpdateMsg msg1 = new ECLUpdateMsg(delmsg, cookie, serviceId, draftcn);
    ECLUpdateMsg msg1 = new ECLUpdateMsg(delmsg, cookie, baseDN, draftcn);
    assertTrue(msg1.getCookie().equalsTo(cookie));
    assertTrue(msg1.getServiceId().equalsIgnoreCase(serviceId));
    assertTrue((msg1.getDraftChangeNumber()==draftcn));
    assertTrue(msg1.getBaseDN().equalsIgnoreCase(baseDN));
    assertEquals(msg1.getDraftChangeNumber(), draftcn);
    DeleteMsg delmsg2 = (DeleteMsg)msg1.getUpdateMsg();
    assertTrue(delmsg.compareTo(delmsg2)==0);
    assertEquals(delmsg.compareTo(delmsg2), 0);
    // Constructor test (with byte[])
    ECLUpdateMsg msg2 = new ECLUpdateMsg(msg1.getBytes(getCurrentVersion()));
    assertTrue(msg2.getCookie().equalsTo(msg2.getCookie()));
    assertTrue(msg2.getCookie().equalsTo(cookie));
    assertTrue(msg2.getServiceId().equalsIgnoreCase(msg1.getServiceId()));
    assertTrue(msg2.getServiceId().equalsIgnoreCase(serviceId));
    assertTrue(msg2.getDraftChangeNumber()==(msg1.getDraftChangeNumber()));
    assertTrue(msg2.getDraftChangeNumber()==draftcn);
    assertTrue(msg2.getBaseDN().equalsIgnoreCase(msg1.getBaseDN()));
    assertTrue(msg2.getBaseDN().equalsIgnoreCase(baseDN));
    assertEquals(msg2.getDraftChangeNumber(), msg1.getDraftChangeNumber());
    assertEquals(msg2.getDraftChangeNumber(), draftcn);
    DeleteMsg delmsg1 = (DeleteMsg)msg1.getUpdateMsg();
    delmsg2 = (DeleteMsg)msg2.getUpdateMsg();
    assertTrue(delmsg2.compareTo(delmsg)==0);
    assertTrue(delmsg2.compareTo(delmsg1)==0);
    assertEquals(delmsg2.compareTo(delmsg), 0);
    assertEquals(delmsg2.compareTo(delmsg1), 0);
  }
  @DataProvider(name="createServerStartData")
@@ -921,7 +923,7 @@
  public void stopMsgTest() throws Exception
  {
    StopMsg msg = new StopMsg();
    StopMsg newMsg = new StopMsg(msg.getBytes(getCurrentVersion()));
    new StopMsg(msg.getBytes(getCurrentVersion()));
  }
  /**
@@ -1406,6 +1408,7 @@
    assertEquals(msg.getGenerationId(), newMsg.getGenerationId());
    assertTrue(msg.getGroupId() == newMsg.getGroupId());
  }
  /**
   * Test StartSessionMsg encoding and decoding.
   */
@@ -1431,9 +1434,9 @@
    msg.setLastDraftChangeNumber(lastDraftChangeNumber);
    msg.setECLRequestType(mode);
    msg.setOperationId(myopid);
    Set<String> dns = new HashSet<String>();
    String dn1 = "cn=admin data";
    String dn2 = "cn=config";
    Set<String> dns = new HashSet<String>();
    dns.add(dn1);
    dns.add(dn2);
    msg.setExcludedDNs(dns);
@@ -1441,16 +1444,17 @@
    StartECLSessionMsg newMsg = new StartECLSessionMsg(msg.getBytes(getCurrentVersion()));
    // test equality between the two copies
    assertEquals(msg.getChangeNumber(), newMsg.getChangeNumber());
    assertTrue(msg.isPersistent() == newMsg.isPersistent());
    assertTrue(msg.getFirstDraftChangeNumber() == newMsg.getFirstDraftChangeNumber());
    assertEquals(msg.isPersistent(), newMsg.isPersistent());
    assertEquals(msg.getFirstDraftChangeNumber(), newMsg
        .getFirstDraftChangeNumber());
    assertEquals(msg.getECLRequestType(), newMsg.getECLRequestType());
    assertEquals(msg.getLastDraftChangeNumber(), newMsg.getLastDraftChangeNumber());
    assertTrue(
        msg.getCrossDomainServerState().equalsIgnoreCase(newMsg.getCrossDomainServerState()));
    assertTrue(
        msg.getOperationId().equalsIgnoreCase(newMsg.getOperationId()));
    Set<String> dns2 = newMsg.getExcludedServiceIDs();
    assertTrue(dns2.size()==2);
    Set<String> dns2 = newMsg.getExcludedBaseDNs();
    assertEquals(dns2.size(), 2);
    boolean dn1found=false,dn2found=false;
    for (String dn : dns2)
    {
@@ -1461,7 +1465,7 @@
    assertTrue(dn2found);
  }
  int perfRep = 100000;
  private int perfRep = 100000;
  @Test(enabled=false,dataProvider = "createAddData")
@@ -1473,7 +1477,6 @@
    long createmsgfromop = 0;
    long encodemsg = 0;
    long getbytes = 0;
    long alld = 0;
    long setentryattr = 0;
    long buildnew = 0;
    long t1,t2,t3,t31,t4,t5,t6 = 0;
@@ -1537,8 +1540,6 @@
      new AddMsg(bytes);
      t6 = System.nanoTime();
      buildnew += (t6 - t5);
      alld += (t6 - t1);
    }
    System.out.println(
@@ -1571,7 +1572,6 @@
    long createmsgfromop = 0;
    long encodemsg = 0;
    long getbytes = 0;
    long alld = 0;
    long setentryattr = 0;
    long buildnew = 0;
    long t1,t2,t3,t31,t4,t5,t6 = 0;
@@ -1617,8 +1617,6 @@
      new ModifyMsg(bytes);
      t6 = System.nanoTime();
      buildnew += (t6 - t5);
      alld += (t6 - t1);
    }
    System.out.println(
@@ -1651,7 +1649,6 @@
    long createmsgfromop = 0;
    long encodemsg = 0;
    long getbytes = 0;
    long alld = 0;
    long setentryattr = 0;
    long buildnew = 0;
    long t1,t2,t3,t31,t4,t5,t6 = 0;
@@ -1693,8 +1690,6 @@
      new DeleteMsg(bytes);
      t6 = System.nanoTime();
      buildnew += (t6 - t5);
      alld += (t6 - t1);
    }
    System.out.println(
opends/tests/unit-tests-testng/src/server/org/opends/server/replication/server/DraftCNDbHandlerTest.java
@@ -23,13 +23,11 @@
 *
 *
 *      Copyright 2009-2010 Sun Microsystems, Inc.
 *      Portions Copyright 2011 ForgeRock AS
 *      Portions Copyright 2011-2013 ForgeRock AS
 */
package org.opends.server.replication.server;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertTrue;
import static org.testng.Assert.*;
import java.io.File;
import java.net.ServerSocket;
@@ -107,9 +105,9 @@
      String value2 = "value2";
      String value3 = "value3";
      String serviceID1 = "serviceID1";
      String serviceID2 = "serviceID2";
      String serviceID3 = "serviceID3";
      String baseDN1 = "baseDN1";
      String baseDN2 = "baseDN2";
      String baseDN3 = "baseDN3";
      ChangeNumberGenerator gen = new ChangeNumberGenerator( 1, 0);
      ChangeNumber changeNumber1 = gen.newChangeNumber();
@@ -117,9 +115,9 @@
      ChangeNumber changeNumber3 = gen.newChangeNumber();
      // Add records
      handler.add(sn1, value1, serviceID1, changeNumber1);
      handler.add(sn2, value2, serviceID2, changeNumber2);
      handler.add(sn3, value3, serviceID3, changeNumber3);
      handler.add(sn1, value1, baseDN1, changeNumber1);
      handler.add(sn2, value2, baseDN2, changeNumber2);
      handler.add(sn3, value3, baseDN3, changeNumber3);
      // The ChangeNumber should not get purged
      int firstkey = handler.getFirstKey();
@@ -130,20 +128,20 @@
      try
      {
        assertEquals(dbc.currentChangeNumber(), changeNumber1);
        assertEquals(dbc.currentServiceID(), serviceID1);
        assertEquals(dbc.currentBaseDN(), baseDN1);
        assertEquals(dbc.currentValue(), value1);
        assertTrue(dbc.toString().length() != 0);
        assertTrue(dbc.next());
        assertEquals(dbc.currentChangeNumber(), changeNumber2);
        assertEquals(dbc.currentServiceID(), serviceID2);
        assertEquals(dbc.currentBaseDN(), baseDN2);
        assertEquals(dbc.currentValue(), value2);
        assertTrue(dbc.next());
        assertEquals(dbc.currentChangeNumber(), changeNumber3);
        assertEquals(dbc.currentServiceID(), serviceID3);
        assertEquals(dbc.currentBaseDN(), baseDN3);
        assertEquals(dbc.currentValue(), value3);
        assertFalse(dbc.next());
@@ -238,9 +236,9 @@
      String value2 = "value2";
      String value3 = "value3";
      String serviceID1 = "serviceID1";
      String serviceID2 = "serviceID2";
      String serviceID3 = "serviceID3";
      String baseDN1 = "baseDN1";
      String baseDN2 = "baseDN2";
      String baseDN3 = "baseDN3";
      ChangeNumberGenerator gen = new ChangeNumberGenerator( 1, 0);
      ChangeNumber changeNumber1 = gen.newChangeNumber();
@@ -248,9 +246,9 @@
      ChangeNumber changeNumber3 = gen.newChangeNumber();
      // Add records
      handler.add(sn1, value1, serviceID1, changeNumber1);
      handler.add(sn2, value2, serviceID2, changeNumber2);
      handler.add(sn3, value3, serviceID3, changeNumber3);
      handler.add(sn1, value1, baseDN1, changeNumber1);
      handler.add(sn2, value2, baseDN2, changeNumber2);
      handler.add(sn3, value3, baseDN3, changeNumber3);
      Thread.sleep(500);
      // Checks
@@ -308,7 +306,7 @@
      // Check the db is cleared.
      assertEquals(handler.getFirstKey(), 0);
      assertEquals(handler.getLastKey(), 0);
      assertTrue(handler.count()==0);
      assertEquals(handler.count(), 0);
    } finally
    {