Partial fix for OPENDJ-194: Minor improvements to change log content and configuration
Bump replication protocol version to v5.
| | |
| | | * |
| | | * |
| | | * Copyright 2006-2010 Sun Microsystems, Inc. |
| | | * Portions Copyright 2011 ForgeRock AS |
| | | */ |
| | | package org.opends.server.replication.protocol; |
| | | |
| | |
| | | * {@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; |
| | |
| | | |
| | | /* 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) |
| | |
| | | * |
| | | * |
| | | * Copyright 2006-2010 Sun Microsystems, Inc. |
| | | * Portions Copyright 2011 ForgeRock AS |
| | | */ |
| | | package org.opends.server.replication.protocol; |
| | | |
| | |
| | | * {@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; |
| | |
| | | |
| | | /* 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); |
| | |
| | | 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()); |
| | | } |
| | | |
| | | /** |
| | |
| | | if (bytes == null) |
| | | { |
| | | // this is the current version of the protocol |
| | | bytes = getBytes_V4(); |
| | | bytes = getBytes_V45(reqProtocolVersion); |
| | | } |
| | | return bytes; |
| | | } |
| | |
| | | |
| | | |
| | | /** |
| | | * 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; |
| | | |
| | | |
| | | /** |
| | |
| | | * |
| | | * |
| | | * Copyright 2006-2010 Sun Microsystems, Inc. |
| | | * Portions Copyright 2011 ForgeRock AS |
| | | */ |
| | | package org.opends.server.replication.protocol; |
| | | |
| | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | public byte[] getBytes_V4() throws UnsupportedEncodingException |
| | | public byte[] getBytes_V45(short reqProtocolVersion) |
| | | throws UnsupportedEncodingException |
| | | { |
| | | int bodyLength = 0; |
| | | byte[] byteNewSuperior = null; |
| | |
| | | |
| | | /* 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; |
| | | |
| | |
| | | * |
| | | * |
| | | * Copyright 2006-2010 Sun Microsystems, Inc. |
| | | * Portions Copyright 2011 ForgeRock AS |
| | | */ |
| | | package org.opends.server.replication.protocol; |
| | | |
| | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | public byte[] getBytes_V4() throws UnsupportedEncodingException |
| | | public byte[] getBytes_V45(short reqProtocolVersion) |
| | | throws UnsupportedEncodingException |
| | | { |
| | | int bodyLength = 0; |
| | | byte[] byteModsLen = |
| | |
| | | |
| | | /* 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); |
| | |
| | | * |
| | | * |
| | | * Copyright 2006-2010 Sun Microsystems, Inc. |
| | | * Portions Copyright 2011 ForgeRock AS |
| | | */ |
| | | package org.opends.server.replication.protocol; |
| | | |
| | |
| | | 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; |
| | |
| | | */ |
| | | public static void resetCurrentVersion() |
| | | { |
| | | currentVersion = REPLICATION_PROTOCOL_V4; |
| | | currentVersion = REPLICATION_PROTOCOL_V5; |
| | | } |
| | | |
| | | /** |
| | |
| | | } |
| | | else |
| | | { |
| | | decode_V4(in, version); |
| | | decode_V45(in, version); |
| | | } |
| | | } |
| | | |
| | |
| | | } |
| | | else |
| | | { |
| | | return getBytes_V4(protocolVersion); |
| | | return getBytes_V45(protocolVersion); |
| | | } |
| | | } |
| | | |
| | |
| | | } |
| | | else |
| | | { |
| | | return getBytes_V4(reqProtocolVersion); |
| | | return getBytes_V45(reqProtocolVersion); |
| | | } |
| | | } |
| | | |
| | | private byte[] getBytes_V4(short version) |
| | | private byte[] getBytes_V45(short version) |
| | | { |
| | | try |
| | | { |
| | |
| | | } |
| | | 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(); |
| | | } |
| | |
| | | // 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(); |
| | |
| | | } |
| | | 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); |
| | | } |
| | | } |
| | | |
| | |
| | | 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 */ |
| | |
| | | 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()); |
| | |
| | | } |
| | | |
| | | return oStream.toByteArray(); |
| | | } catch (IOException e) |
| | | } |
| | | catch (IOException e) |
| | | { |
| | | // never happens |
| | | return null; |
| | | throw new RuntimeException(e); |
| | | } |
| | | |
| | | } |
| | |
| | | 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; |
| | |
| | | int assuredSdLevel = -100; |
| | | SortedSet<String> refUrls = null; |
| | | Set<String> eclIncludes = new HashSet<String>(); |
| | | short protocolVersion = 4; |
| | | short protocolVersion = ProtocolVersion.getCurrentVersion(); |
| | | |
| | | switch (dsId) |
| | | { |
| | |
| | | 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); |
| | |
| | | */ |
| | | 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. |
| | | * |
| | |
| | | public Object[][] createOldServerStartData() |
| | | { |
| | | return new Object[][] { |
| | | {"140431323438001f6f3d74657374003136006675726f6e0030003000" + |
| | | {"140531323438001f6f3d74657374003136006675726f6e0030003000" + |
| | | "300030003130300031303000747275650032363300303030303030303030303030303034" + |
| | | "623031303730303030303030350000", |
| | | 16, "o=test", (byte) 31,} |
| | |
| | | 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); |
| | | } |
| | | |