From 003531d1be38a2abd2b875452da1a752273576a2 Mon Sep 17 00:00:00 2001
From: gbellato <gbellato@localhost>
Date: Thu, 14 Jun 2007 15:46:00 +0000
Subject: [PATCH] cleanup : suppress a few TODO comments by throwing exception and logging proper error message in case of unlikely failures.
---
opends/src/server/org/opends/server/messages/ReplicationMessages.java | 14 ++
opends/src/server/org/opends/server/replication/protocol/ReplicationMessage.java | 4
opends/src/server/org/opends/server/replication/protocol/SocketSession.java | 4
opends/src/server/org/opends/server/replication/protocol/AddMsg.java | 67 ++++++-------
opends/tests/unit-tests-testng/src/server/org/opends/server/replication/protocol/SynchronizationMsgTest.java | 6 +
opends/tests/unit-tests-testng/src/server/org/opends/server/replication/server/ReplicationServerTest.java | 3
opends/src/server/org/opends/server/replication/protocol/DeleteMsg.java | 14 +-
opends/src/server/org/opends/server/replication/protocol/ModifyMsg.java | 14 +-
opends/src/server/org/opends/server/replication/common/ChangeNumberGenerator.java | 1
opends/src/server/org/opends/server/replication/server/ReplicationDB.java | 20 ++++
opends/src/server/org/opends/server/replication/protocol/ModifyDNMsg.java | 110 ++++++++++-----------
opends/src/server/org/opends/server/replication/server/ReplicationData.java | 12 ++
12 files changed, 148 insertions(+), 121 deletions(-)
diff --git a/opends/src/server/org/opends/server/messages/ReplicationMessages.java b/opends/src/server/org/opends/server/messages/ReplicationMessages.java
index 85f2e53..bd671fe 100644
--- a/opends/src/server/org/opends/server/messages/ReplicationMessages.java
+++ b/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");
}
}
diff --git a/opends/src/server/org/opends/server/replication/common/ChangeNumberGenerator.java b/opends/src/server/org/opends/server/replication/common/ChangeNumberGenerator.java
index 85eb36d..7a1ce2e 100644
--- a/opends/src/server/org/opends/server/replication/common/ChangeNumberGenerator.java
+++ b/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)
diff --git a/opends/src/server/org/opends/server/replication/protocol/AddMsg.java b/opends/src/server/org/opends/server/replication/protocol/AddMsg.java
index 5979842..299bcfa 100644
--- a/opends/src/server/org/opends/server/replication/protocol/AddMsg.java
+++ b/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;
}
/**
diff --git a/opends/src/server/org/opends/server/replication/protocol/DeleteMsg.java b/opends/src/server/org/opends/server/replication/protocol/DeleteMsg.java
index 0669ab6..cea0321 100644
--- a/opends/src/server/org/opends/server/replication/protocol/DeleteMsg.java
+++ b/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);
}
/**
diff --git a/opends/src/server/org/opends/server/replication/protocol/ModifyDNMsg.java b/opends/src/server/org/opends/server/replication/protocol/ModifyDNMsg.java
index 7a3ebd3..b4f9935 100644
--- a/opends/src/server/org/opends/server/replication/protocol/ModifyDNMsg.java
+++ b/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;
}
/**
diff --git a/opends/src/server/org/opends/server/replication/protocol/ModifyMsg.java b/opends/src/server/org/opends/server/replication/protocol/ModifyMsg.java
index a8f1214..aff4180 100644
--- a/opends/src/server/org/opends/server/replication/protocol/ModifyMsg.java
+++ b/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;
}
diff --git a/opends/src/server/org/opends/server/replication/protocol/ReplicationMessage.java b/opends/src/server/org/opends/server/replication/protocol/ReplicationMessage.java
index f4a8ecf..3cd873d 100644
--- a/opends/src/server/org/opends/server/replication/protocol/ReplicationMessage.java
+++ b/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;
/**
diff --git a/opends/src/server/org/opends/server/replication/protocol/SocketSession.java b/opends/src/server/org/opends/server/replication/protocol/SocketSession.java
index 7d0a90f..d71a0d2 100644
--- a/opends/src/server/org/opends/server/replication/protocol/SocketSession.java
+++ b/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
{
diff --git a/opends/src/server/org/opends/server/replication/server/ReplicationDB.java b/opends/src/server/org/opends/server/replication/server/ReplicationDB.java
index 0206294..c8116e1 100644
--- a/opends/src/server/org/opends/server/replication/server/ReplicationDB.java
+++ b/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();
}
}
diff --git a/opends/src/server/org/opends/server/replication/server/ReplicationData.java b/opends/src/server/org/opends/server/replication/server/ReplicationData.java
index cb9985d..5e49dc2 100644
--- a/opends/src/server/org/opends/server/replication/server/ReplicationData.java
+++ b/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)
diff --git a/opends/tests/unit-tests-testng/src/server/org/opends/server/replication/protocol/SynchronizationMsgTest.java b/opends/tests/unit-tests-testng/src/server/org/opends/server/replication/protocol/SynchronizationMsgTest.java
index d3a5557..f51c762 100644
--- a/opends/tests/unit-tests-testng/src/server/org/opends/server/replication/protocol/SynchronizationMsgTest.java
+++ b/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))
{
diff --git a/opends/tests/unit-tests-testng/src/server/org/opends/server/replication/server/ReplicationServerTest.java b/opends/tests/unit-tests-testng/src/server/org/opends/server/replication/server/ReplicationServerTest.java
index c54021c..b1a1eb2 100644
--- a/opends/tests/unit-tests-testng/src/server/org/opends/server/replication/server/ReplicationServerTest.java
+++ b/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();
}
}
}
--
Gitblit v1.10.0