From a3f218b56d16d995c63ab7eef13a84818c6f2be7 Mon Sep 17 00:00:00 2001
From: Matthew Swift <matthew.swift@forgerock.com>
Date: Fri, 10 Jun 2011 14:34:10 +0000
Subject: [PATCH] Partial fix for OPENDJ-194: Minor improvements to change log content and configuration
---
opendj-sdk/opends/src/server/org/opends/server/replication/protocol/ModifyMsg.java | 6 +
opendj-sdk/opends/src/server/org/opends/server/replication/protocol/StartSessionMsg.java | 40 ++++++++----
opendj-sdk/opends/src/server/org/opends/server/replication/protocol/LDAPUpdateMsg.java | 17 ++---
opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/replication/plugin/TopologyViewTest.java | 5 +
opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/replication/protocol/ProtocolCompatibilityTest.java | 6 +-
opendj-sdk/opends/src/server/org/opends/server/replication/protocol/DeleteMsg.java | 6 +
opendj-sdk/opends/src/server/org/opends/server/replication/protocol/TopologyMsg.java | 44 +++++++++-----
opendj-sdk/opends/src/server/org/opends/server/replication/protocol/AddMsg.java | 6 +
opendj-sdk/opends/src/server/org/opends/server/replication/protocol/ProtocolVersion.java | 11 +++
opendj-sdk/opends/src/server/org/opends/server/replication/protocol/ModifyDNMsg.java | 6 +
10 files changed, 93 insertions(+), 54 deletions(-)
diff --git a/opendj-sdk/opends/src/server/org/opends/server/replication/protocol/AddMsg.java b/opendj-sdk/opends/src/server/org/opends/server/replication/protocol/AddMsg.java
index 0f4f479..611ff45 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/replication/protocol/AddMsg.java
+++ b/opendj-sdk/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)
diff --git a/opendj-sdk/opends/src/server/org/opends/server/replication/protocol/DeleteMsg.java b/opendj-sdk/opends/src/server/org/opends/server/replication/protocol/DeleteMsg.java
index 7e8c1cf..9a1c734 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/replication/protocol/DeleteMsg.java
+++ b/opendj-sdk/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);
diff --git a/opendj-sdk/opends/src/server/org/opends/server/replication/protocol/LDAPUpdateMsg.java b/opendj-sdk/opends/src/server/org/opends/server/replication/protocol/LDAPUpdateMsg.java
index b6e75c3..7bac025 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/replication/protocol/LDAPUpdateMsg.java
+++ b/opendj-sdk/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;
/**
diff --git a/opendj-sdk/opends/src/server/org/opends/server/replication/protocol/ModifyDNMsg.java b/opendj-sdk/opends/src/server/org/opends/server/replication/protocol/ModifyDNMsg.java
index 8232018..6f0e669 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/replication/protocol/ModifyDNMsg.java
+++ b/opendj-sdk/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;
diff --git a/opendj-sdk/opends/src/server/org/opends/server/replication/protocol/ModifyMsg.java b/opendj-sdk/opends/src/server/org/opends/server/replication/protocol/ModifyMsg.java
index f15df16..daae6dc 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/replication/protocol/ModifyMsg.java
+++ b/opendj-sdk/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);
diff --git a/opendj-sdk/opends/src/server/org/opends/server/replication/protocol/ProtocolVersion.java b/opendj-sdk/opends/src/server/org/opends/server/replication/protocol/ProtocolVersion.java
index 3b6912e..2c95416 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/replication/protocol/ProtocolVersion.java
+++ b/opendj-sdk/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;
}
/**
diff --git a/opendj-sdk/opends/src/server/org/opends/server/replication/protocol/StartSessionMsg.java b/opendj-sdk/opends/src/server/org/opends/server/replication/protocol/StartSessionMsg.java
index 39aa36e..f456025 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/replication/protocol/StartSessionMsg.java
+++ b/opendj-sdk/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);
}
}
diff --git a/opendj-sdk/opends/src/server/org/opends/server/replication/protocol/TopologyMsg.java b/opendj-sdk/opends/src/server/org/opends/server/replication/protocol/TopologyMsg.java
index 4288497..16be10e 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/replication/protocol/TopologyMsg.java
+++ b/opendj-sdk/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);
}
}
diff --git a/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/replication/plugin/TopologyViewTest.java b/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/replication/plugin/TopologyViewTest.java
index 735f221..295a834 100644
--- a/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/replication/plugin/TopologyViewTest.java
+++ b/opendj-sdk/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);
diff --git a/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/replication/protocol/ProtocolCompatibilityTest.java b/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/replication/protocol/ProtocolCompatibilityTest.java
index 9e17bc9..9793eea 100644
--- a/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/replication/protocol/ProtocolCompatibilityTest.java
+++ b/opendj-sdk/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);
}
--
Gitblit v1.10.0