opends/src/server/org/opends/server/messages/ReplicationMessages.java
@@ -415,12 +415,20 @@ CATEGORY_MASK_SYNC | SEVERITY_MASK_SEVERE_ERROR | 58; /** * Eception durin rename of a conflicting entry. * Exception during rename of a conflicting entry. */ public static final int MSGID_EXCEPTION_RENAME_CONFLICT_ENTRY = CATEGORY_MASK_SYNC | SEVERITY_MASK_SEVERE_ERROR | 59; /** * The JVM does not support UTF8. This is required to serialize * the changes and store them in the database. */ public static final int MSGID_CHANGELOG_UNSUPPORTED_UTF8_ENCODING = CATEGORY_MASK_SYNC | SEVERITY_MASK_SEVERE_ERROR | 60; /** * Register the messages from this class in the core server. * */ @@ -575,5 +583,9 @@ "An error happened trying the rename a conflicting entry : "); registerMessage(MSGID_EXCEPTION_RENAME_CONFLICT_ENTRY, "An Exception happened when trying the rename a conflicting entry : "); registerMessage(MSGID_CHANGELOG_UNSUPPORTED_UTF8_ENCODING, "The JVM does not support UTF-8. This is required to be able to " + "encode the changes in the database. " + "This replication server will now shutdown"); } } opends/src/server/org/opends/server/replication/common/ChangeNumberGenerator.java
@@ -81,7 +81,6 @@ */ public ChangeNumber newChangeNumber() { /* TODO : we probably don't need a time stamp with a 1 msec accuracy */ long curTime = TimeThread.getTime(); synchronized(this) opends/src/server/org/opends/server/replication/protocol/AddMsg.java
@@ -211,48 +211,43 @@ /** * Get the byte[] representation of this Message. * * @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. */ @Override public byte[] getBytes() public byte[] getBytes() throws UnsupportedEncodingException { try int length = encodedAttributes.length; byte[] byteParentId = null; if (parentUniqueId != null) { int length = encodedAttributes.length; byte[] byteParentId = null; if (parentUniqueId != null) { byteParentId = parentUniqueId.getBytes("UTF-8"); length += byteParentId.length + 1; } else { length += 1; } /* encode the header in a byte[] large enough to also contain the mods */ byte [] resultByteArray = encodeHeader(MSG_TYPE_ADD_REQUEST, length); int pos = resultByteArray.length - length; if (byteParentId != null) pos = addByteArray(byteParentId, resultByteArray, pos); else resultByteArray[pos++] = 0; /* put the attributes */ for (int i=0; i<encodedAttributes.length; i++,pos++) { resultByteArray[pos] = encodedAttributes[i]; } return resultByteArray; } catch (UnsupportedEncodingException e) { // this can not happen as only UTF-8 is used and it is always // going to be supported by the jvm // TODO : should log an error return null; byteParentId = parentUniqueId.getBytes("UTF-8"); length += byteParentId.length + 1; } else { length += 1; } /* encode the header in a byte[] large enough to also contain the mods */ byte [] resultByteArray = encodeHeader(MSG_TYPE_ADD_REQUEST, length); int pos = resultByteArray.length - length; if (byteParentId != null) pos = addByteArray(byteParentId, resultByteArray, pos); else resultByteArray[pos++] = 0; /* put the attributes */ for (int i=0; i<encodedAttributes.length; i++,pos++) { resultByteArray[pos] = encodedAttributes[i]; } return resultByteArray; } /** opends/src/server/org/opends/server/replication/protocol/DeleteMsg.java
@@ -103,18 +103,14 @@ * Get the byte array representation of this Message. * * @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. */ @Override public byte[] getBytes() public byte[] getBytes() throws UnsupportedEncodingException { try { return encodeHeader(MSG_TYPE_DELETE_REQUEST, 0); } catch (UnsupportedEncodingException e) { // should never happen : TODO : log error properly return null; } return encodeHeader(MSG_TYPE_DELETE_REQUEST, 0); } /** opends/src/server/org/opends/server/replication/protocol/ModifyDNMsg.java
@@ -167,68 +167,64 @@ * Get the byte array representation of this Message. * * @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. */ @Override public byte[] getBytes() public byte[] getBytes() throws UnsupportedEncodingException { try byte[] byteNewRdn = newRDN.getBytes("UTF-8"); byte[] byteNewSuperior = null; byte[] byteNewSuperiorId = null; // calculate the length necessary to encode the parameters int length = byteNewRdn.length + 1 + 1; if (newSuperior != null) { byte[] byteNewRdn = newRDN.getBytes("UTF-8"); byte[] byteNewSuperior = null; byte[] byteNewSuperiorId = null; // calculate the length necessary to encode the parameters int length = byteNewRdn.length + 1 + 1; if (newSuperior != null) { byteNewSuperior = newSuperior.getBytes("UTF-8"); length += byteNewSuperior.length + 1; } else length += 1; if (newSuperiorId != null) { byteNewSuperiorId = newSuperiorId.getBytes("UTF-8"); length += byteNewSuperiorId.length + 1; } else length += 1; byte[] resultByteArray = encodeHeader(MSG_TYPE_MODIFYDN_REQUEST, length); int pos = resultByteArray.length - length; /* put the new RDN and a terminating 0 */ pos = addByteArray(byteNewRdn, resultByteArray, pos); /* put the newsuperior and a terminating 0 */ if (newSuperior != null) { pos = addByteArray(byteNewSuperior, resultByteArray, pos); } else resultByteArray[pos++] = 0; /* put the newsuperiorId and a terminating 0 */ if (newSuperiorId != null) { pos = addByteArray(byteNewSuperiorId, resultByteArray, pos); } else resultByteArray[pos++] = 0; /* put the deleteoldrdn flag */ if (deleteOldRdn) resultByteArray[pos++] = 1; else resultByteArray[pos++] = 0; return resultByteArray; } catch (UnsupportedEncodingException e) { // should never happen : TODO : log error byteNewSuperior = newSuperior.getBytes("UTF-8"); length += byteNewSuperior.length + 1; } return null; else length += 1; if (newSuperiorId != null) { byteNewSuperiorId = newSuperiorId.getBytes("UTF-8"); length += byteNewSuperiorId.length + 1; } else length += 1; byte[] resultByteArray = encodeHeader(MSG_TYPE_MODIFYDN_REQUEST, length); int pos = resultByteArray.length - length; /* put the new RDN and a terminating 0 */ pos = addByteArray(byteNewRdn, resultByteArray, pos); /* put the newsuperior and a terminating 0 */ if (newSuperior != null) { pos = addByteArray(byteNewSuperior, resultByteArray, pos); } else resultByteArray[pos++] = 0; /* put the newsuperiorId and a terminating 0 */ if (newSuperiorId != null) { pos = addByteArray(byteNewSuperiorId, resultByteArray, pos); } else resultByteArray[pos++] = 0; /* put the deleteoldrdn flag */ if (deleteOldRdn) resultByteArray[pos++] = 1; else resultByteArray[pos++] = 0; return resultByteArray; } /** opends/src/server/org/opends/server/replication/protocol/ModifyMsg.java
@@ -108,20 +108,16 @@ * Get the byte array representation of this Message. * * @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. */ @Override public byte[] getBytes() public byte[] getBytes() throws UnsupportedEncodingException { if (encodedMsg == null) { try { encode(); } catch (UnsupportedEncodingException e) { // should never happens : TODO : log some error return null; } encode(); } return encodedMsg; } opends/src/server/org/opends/server/replication/protocol/ReplicationMessage.java
@@ -74,8 +74,10 @@ * MSG_TYPE_ERROR * * @return the byte[] 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(); public abstract byte[] getBytes() throws UnsupportedEncodingException; /** opends/src/server/org/opends/server/replication/protocol/SocketSession.java
@@ -42,10 +42,6 @@ * This class Implement a protocol session using a basic socket and relying on * the innate encoding/decoding capabilities of the ReplicationMessage * by using the getBytes() and generateMsg() methods of those classes. * * TODO : should have some versioning in the packets so that * the futur versions can evolve while still * being able to understand the older versions. */ public class SocketSession implements ProtocolSession { opends/src/server/org/opends/server/replication/server/ReplicationDB.java
@@ -125,6 +125,25 @@ logError(ErrorLogCategory.SYNCHRONIZATION, ErrorLogSeverity.SEVERE_ERROR, message, msgID); if (txn != null) { try { txn.abort(); } catch (DatabaseException e1) { // can't do much more. The ReplicationServer is shuting down. } } replicationServer.shutdown(); } catch (UnsupportedEncodingException e) { int msgID = MSGID_CHANGELOG_UNSUPPORTED_UTF8_ENCODING; String message = getMessage(msgID) + stackTraceToSingleLineString(e); logError(ErrorLogCategory.SYNCHRONIZATION, ErrorLogSeverity.SEVERE_ERROR, message, msgID); replicationServer.shutdown(); if (txn != null) { @@ -136,6 +155,7 @@ // can't do much more. The ReplicationServer is shuting down. } } replicationServer.shutdown(); } } opends/src/server/org/opends/server/replication/server/ReplicationData.java
@@ -26,6 +26,8 @@ */ package org.opends.server.replication.server; import java.io.UnsupportedEncodingException; import com.sleepycat.je.DatabaseEntry; import org.opends.server.replication.protocol.ReplicationMessage; @@ -39,17 +41,25 @@ { /** * Creates a new ReplicationData object from an UpdateMessage. * * @param change the UpdateMessage used to create the ReplicationData. * * @throws UnsupportedEncodingException When the encoding of the message * failed because the UTF-8 encoding is not supported. */ public ReplicationData(UpdateMessage change) throws UnsupportedEncodingException { this.setData(change.getBytes()); } /** * Generate an UpdateMessage from its byte[] form. * * @param data The DatabaseEntry used to generate the UpdateMessage. * @return The generated change. * * @return The generated change. * * @throws Exception When the data was not a valid Update Message. */ public static UpdateMessage generateChange(byte[] data) opends/tests/unit-tests-testng/src/server/org/opends/server/replication/protocol/SynchronizationMsgTest.java
@@ -31,6 +31,7 @@ import static org.testng.Assert.assertFalse; import static org.testng.Assert.assertTrue; import java.io.UnsupportedEncodingException; import java.util.ArrayList; import java.util.HashMap; import java.util.LinkedHashSet; @@ -642,8 +643,11 @@ /** * Test PendingChange * @throws UnsupportedEncodingException */ private void testPendingChange(ChangeNumber cn, Operation op, ReplicationMessage msg) private void testPendingChange( ChangeNumber cn, Operation op, ReplicationMessage msg) throws UnsupportedEncodingException { if (! (msg instanceof UpdateMessage)) { opends/tests/unit-tests-testng/src/server/org/opends/server/replication/server/ReplicationServerTest.java
@@ -471,7 +471,8 @@ server.stop(); for (int i =0; i< CLIENT_THREADS; i++) { clientBroker[i].stop(); if (clientBroker[i] != null) clientBroker[i].stop(); } } }