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

Matthew Swift
10.34.2011 459796336f95d56450c970b87575f22c871b4604
Partial fix for OPENDJ-194: Minor improvements to change log content and configuration

Bump replication protocol version to v5.
10 files modified
147 ■■■■■ changed files
opends/src/server/org/opends/server/replication/protocol/AddMsg.java 6 ●●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/replication/protocol/DeleteMsg.java 6 ●●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/replication/protocol/LDAPUpdateMsg.java 17 ●●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/replication/protocol/ModifyDNMsg.java 6 ●●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/replication/protocol/ModifyMsg.java 6 ●●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/replication/protocol/ProtocolVersion.java 11 ●●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/replication/protocol/StartSessionMsg.java 40 ●●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/replication/protocol/TopologyMsg.java 44 ●●●●● patch | view | raw | blame | history
opends/tests/unit-tests-testng/src/server/org/opends/server/replication/plugin/TopologyViewTest.java 5 ●●●●● patch | view | raw | blame | history
opends/tests/unit-tests-testng/src/server/org/opends/server/replication/protocol/ProtocolCompatibilityTest.java 6 ●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/replication/protocol/AddMsg.java
@@ -23,6 +23,7 @@
 *
 *
 *      Copyright 2006-2010 Sun Microsystems, Inc.
 *      Portions Copyright 2011 ForgeRock AS
 */
package org.opends.server.replication.protocol;
@@ -273,7 +274,8 @@
   * {@inheritDoc}
   */
  @Override
  public byte[] getBytes_V4() throws UnsupportedEncodingException
  public byte[] getBytes_V45(short reqProtocolVersion)
      throws UnsupportedEncodingException
  {
    // Put together the different encoded pieces
    int bodyLength = 0;
@@ -303,7 +305,7 @@
    /* encode the header in a byte[] large enough to also contain the mods */
    byte [] encodedMsg = encodeHeader(MSG_TYPE_ADD, bodyLength,
        ProtocolVersion.REPLICATION_PROTOCOL_V4);
        reqProtocolVersion);
    int pos = encodedMsg.length - bodyLength;
    if (byteParentId != null)
opends/src/server/org/opends/server/replication/protocol/DeleteMsg.java
@@ -23,6 +23,7 @@
 *
 *
 *      Copyright 2006-2010 Sun Microsystems, Inc.
 *      Portions Copyright 2011 ForgeRock AS
 */
package org.opends.server.replication.protocol;
@@ -154,7 +155,8 @@
   * {@inheritDoc}
   */
  @Override
  public byte[] getBytes_V4() throws UnsupportedEncodingException
  public byte[] getBytes_V45(short reqProtocolVersion)
      throws UnsupportedEncodingException
  {
    // Put together the different encoded pieces
    int bodyLength = 0;
@@ -179,7 +181,7 @@
    /* encode the header in a byte[] large enough to also contain the mods */
    byte [] encodedMsg = encodeHeader(MSG_TYPE_DELETE, bodyLength,
        ProtocolVersion.REPLICATION_PROTOCOL_V4);
        reqProtocolVersion);
    int pos = encodedMsg.length - bodyLength;
    if (byteInitiatorsName != null)
      pos = addByteArray(byteInitiatorsName, encodedMsg, pos);
opends/src/server/org/opends/server/replication/protocol/LDAPUpdateMsg.java
@@ -352,12 +352,7 @@
  throws UnsupportedEncodingException
  {
    // Encode in the current protocol version
    if (bytes == null)
    {
      // this is the current version of the protocol
      bytes = getBytes_V4();
    }
    return bytes;
    return getBytes(ProtocolVersion.getCurrentVersion());
  }
  /**
@@ -381,7 +376,7 @@
      if (bytes == null)
      {
        // this is the current version of the protocol
        bytes = getBytes_V4();
        bytes = getBytes_V45(reqProtocolVersion);
      }
      return bytes;
    }
@@ -411,15 +406,17 @@
  /**
   * Get the byte array representation of this Message. This uses the version
   * 4 of the replication protocol (used for compatibility purpose).
   * Get the byte array representation of this Message. This uses the provided
   * version number which must be version 4 or newer.
   * @param reqProtocolVersion TODO
   *
   * @return The byte array representation of this Message.
   *
   * @throws UnsupportedEncodingException  When the encoding of the message
   *         failed because the UTF-8 encoding is not supported.
   */
  public abstract byte[] getBytes_V4() throws UnsupportedEncodingException;
  public abstract byte[] getBytes_V45(short reqProtocolVersion)
      throws UnsupportedEncodingException;
  /**
opends/src/server/org/opends/server/replication/protocol/ModifyDNMsg.java
@@ -23,6 +23,7 @@
 *
 *
 *      Copyright 2006-2010 Sun Microsystems, Inc.
 *      Portions Copyright 2011 ForgeRock AS
 */
package org.opends.server.replication.protocol;
@@ -327,7 +328,8 @@
  /**
   * {@inheritDoc}
   */
  public byte[] getBytes_V4() throws UnsupportedEncodingException
  public byte[] getBytes_V45(short reqProtocolVersion)
      throws UnsupportedEncodingException
  {
    int bodyLength = 0;
    byte[] byteNewSuperior = null;
@@ -366,7 +368,7 @@
    /* encode the header in a byte[] large enough to also contain mods.. */
    byte[] encodedMsg = encodeHeader(MSG_TYPE_MODIFYDN, bodyLength,
        ProtocolVersion.REPLICATION_PROTOCOL_V4);
        reqProtocolVersion);
    int pos = encodedMsg.length - bodyLength;
opends/src/server/org/opends/server/replication/protocol/ModifyMsg.java
@@ -23,6 +23,7 @@
 *
 *
 *      Copyright 2006-2010 Sun Microsystems, Inc.
 *      Portions Copyright 2011 ForgeRock AS
 */
package org.opends.server.replication.protocol;
@@ -255,7 +256,8 @@
  /**
   * {@inheritDoc}
   */
  public byte[] getBytes_V4() throws UnsupportedEncodingException
  public byte[] getBytes_V45(short reqProtocolVersion)
      throws UnsupportedEncodingException
  {
    int bodyLength = 0;
    byte[] byteModsLen =
@@ -270,7 +272,7 @@
    /* encode the header in a byte[] large enough to also contain the mods */
    byte [] encodedMsg = encodeHeader(MSG_TYPE_MODIFY, bodyLength,
        ProtocolVersion.REPLICATION_PROTOCOL_V4);
        reqProtocolVersion);
    int pos = encodedMsg.length - bodyLength;
    pos = addByteArray(byteModsLen, encodedMsg, pos);
opends/src/server/org/opends/server/replication/protocol/ProtocolVersion.java
@@ -23,6 +23,7 @@
 *
 *
 *      Copyright 2006-2010 Sun Microsystems, Inc.
 *      Portions Copyright 2011 ForgeRock AS
 */
package org.opends.server.replication.protocol;
@@ -66,6 +67,14 @@
  public static final short REPLICATION_PROTOCOL_V4 = 4;
  /**
   * The constant for the 5th version of the replication protocol.
   * - Add support for wild-cards in change log included attributes
   * - Add support for specifying additional included attributes for deletes
   * - See OPENDJ-194.
   */
  public static final short REPLICATION_PROTOCOL_V5 = 5;
  /**
   * The replication protocol version used by the instance of RS/DS in this VM.
   */
  private static short currentVersion = -1;
@@ -100,7 +109,7 @@
   */
  public static void resetCurrentVersion()
  {
    currentVersion = REPLICATION_PROTOCOL_V4;
    currentVersion = REPLICATION_PROTOCOL_V5;
  }
  /**
opends/src/server/org/opends/server/replication/protocol/StartSessionMsg.java
@@ -98,7 +98,7 @@
    }
    else
    {
      decode_V4(in, version);
      decode_V45(in, version);
    }
  }
@@ -191,7 +191,7 @@
    }
    else
    {
      return getBytes_V4(protocolVersion);
      return getBytes_V45(protocolVersion);
    }
  }
@@ -208,11 +208,11 @@
    }
    else
    {
      return getBytes_V4(reqProtocolVersion);
      return getBytes_V45(reqProtocolVersion);
    }
  }
  private byte[] getBytes_V4(short version)
  private byte[] getBytes_V45(short version)
  {
    try
    {
@@ -237,12 +237,15 @@
      }
      writer.writeEndSequence();
      writer.writeStartSequence();
      for (String attrDef : eclIncludesForDeletes)
      if (version >= ProtocolVersion.REPLICATION_PROTOCOL_V5)
      {
        writer.writeOctetString(attrDef);
        writer.writeStartSequence();
        for (String attrDef : eclIncludesForDeletes)
        {
          writer.writeOctetString(attrDef);
        }
        writer.writeEndSequence();
      }
      writer.writeEndSequence();
      return byteBuilder.toByteArray();
    }
@@ -302,7 +305,7 @@
  // Msg decoding
  // ============
  private void decode_V4(byte[] in, short version)
  private void decode_V45(byte[] in, short version)
  throws DataFormatException
  {
    ByteSequenceReader reader = ByteString.wrap(in).asReader();
@@ -341,16 +344,25 @@
      }
      asn1Reader.readEndSequence();
      asn1Reader.readStartSequence();
      while (asn1Reader.hasNextElement())
      if (version >= ProtocolVersion.REPLICATION_PROTOCOL_V5)
      {
        String s = asn1Reader.readOctetStringAsString();
        this.eclIncludesForDeletes.add(s);
        asn1Reader.readStartSequence();
        while (asn1Reader.hasNextElement())
        {
          String s = asn1Reader.readOctetStringAsString();
          this.eclIncludesForDeletes.add(s);
        }
        asn1Reader.readEndSequence();
      }
      asn1Reader.readEndSequence();
      else
      {
        // Default to using the same set of attributes for deletes.
        this.eclIncludesForDeletes.addAll(eclIncludes);
      }
    }
    catch (Exception e)
    {
      throw new RuntimeException(e);
    }
  }
opends/src/server/org/opends/server/replication/protocol/TopologyMsg.java
@@ -167,16 +167,24 @@
            nRead++;
          }
          nAttrs = in[pos++];
          nRead = 0;
          /* Read attrs until expected number read */
          while ((nRead != nAttrs) && (pos < in.length))
          if (version >= ProtocolVersion.REPLICATION_PROTOCOL_V5)
          {
            length = getNextLength(in, pos);
            String attr = new String(in, pos, length, "UTF-8");
            delattrs.add(attr);
            pos += length + 1;
            nRead++;
            nAttrs = in[pos++];
            nRead = 0;
            /* Read attrs until expected number read */
            while ((nRead != nAttrs) && (pos < in.length))
            {
              length = getNextLength(in, pos);
              String attr = new String(in, pos, length, "UTF-8");
              delattrs.add(attr);
              pos += length + 1;
              nRead++;
            }
          }
          else
          {
            // Default to using the same set of attributes for deletes.
            delattrs.addAll(attrs);
          }
          /* Read Protocol version */
@@ -360,12 +368,15 @@
            oStream.write(0);
          }
          Set<String> delattrs = dsInfo.getEclIncludesForDeletes();
          oStream.write(delattrs.size());
          for (String attr : delattrs)
          if (version >= ProtocolVersion.REPLICATION_PROTOCOL_V5)
          {
            oStream.write(attr.getBytes("UTF-8"));
            oStream.write(0);
            Set<String> delattrs = dsInfo.getEclIncludesForDeletes();
            oStream.write(delattrs.size());
            for (String attr : delattrs)
            {
              oStream.write(attr.getBytes("UTF-8"));
              oStream.write(0);
            }
          }
          oStream.write(dsInfo.getProtocolVersion());
@@ -403,10 +414,11 @@
      }
      return oStream.toByteArray();
    } catch (IOException e)
    }
    catch (IOException e)
    {
      // never happens
      return null;
      throw new RuntimeException(e);
    }
  }
opends/tests/unit-tests-testng/src/server/org/opends/server/replication/plugin/TopologyViewTest.java
@@ -59,6 +59,7 @@
import org.opends.server.replication.common.DSInfo;
import org.opends.server.replication.common.RSInfo;
import org.opends.server.replication.common.ServerStatus;
import org.opends.server.replication.protocol.ProtocolVersion;
import org.opends.server.replication.server.ReplServerFakeConfiguration;
import org.opends.server.replication.server.ReplicationServer;
import org.opends.server.types.DN;
@@ -866,7 +867,7 @@
    int assuredSdLevel = -100;
    SortedSet<String> refUrls = null;
    Set<String> eclIncludes = new HashSet<String>();
    short protocolVersion = 4;
    short protocolVersion = ProtocolVersion.getCurrentVersion();
    switch (dsId)
      {
@@ -1123,7 +1124,7 @@
     List<String> refUrls = rd.getRefUrls();
     Set<String> eclInclude = rd.getEclIncludes();
     Set<String> eclIncludeForDeletes = rd.getEclIncludesForDeletes();
     short protocolVersion = 4;
     short protocolVersion = ProtocolVersion.getCurrentVersion();
     DSInfo dsInfo = new DSInfo(dsId, rsId, TEST_DN_WITH_ROOT_ENTRY_GENID, status, assuredFlag, assuredMode,
       safeDataLevel, groupId, refUrls, eclInclude, eclIncludeForDeletes, protocolVersion);
     dsList.add(dsInfo);
opends/tests/unit-tests-testng/src/server/org/opends/server/replication/protocol/ProtocolCompatibilityTest.java
@@ -75,7 +75,7 @@
 */
public class ProtocolCompatibilityTest extends ReplicationTestCase {
  short REPLICATION_PROTOCOL_VLAST = ProtocolVersion.REPLICATION_PROTOCOL_V4;
  short REPLICATION_PROTOCOL_VLAST = ProtocolVersion.REPLICATION_PROTOCOL_V5;
  /**
   * Set up the environment for performing the tests in this Class.
   *
@@ -946,7 +946,7 @@
  public Object[][] createOldServerStartData()
  {
    return new Object[][] {
        {"140431323438001f6f3d74657374003136006675726f6e0030003000" +
        {"140531323438001f6f3d74657374003136006675726f6e0030003000" +
          "300030003130300031303000747275650032363300303030303030303030303030303034" +
          "623031303730303030303030350000",
          16, "o=test", (byte) 31,}
@@ -965,7 +965,7 @@
    assertEquals(msg.getBaseDn(), dn);
    assertEquals(msg.getGroupId(), groupId);
    // We use V4 here because these PDU have not changed since 2.0.
    BigInteger bi = new BigInteger(msg.getBytes(ProtocolVersion.REPLICATION_PROTOCOL_V4));
    BigInteger bi = new BigInteger(msg.getBytes(ProtocolVersion.REPLICATION_PROTOCOL_V5));
    assertEquals(bi.toString(16), oldPdu);
  }