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

gbellato
14.46.2007 003531d1be38a2abd2b875452da1a752273576a2
cleanup : suppress a few TODO comments by throwing exception
and logging proper error message in case of unlikely failures.
12 files modified
111 ■■■■■ changed files
opends/src/server/org/opends/server/messages/ReplicationMessages.java 14 ●●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/replication/common/ChangeNumberGenerator.java 1 ●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/replication/protocol/AddMsg.java 15 ●●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/replication/protocol/DeleteMsg.java 12 ●●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/replication/protocol/ModifyDNMsg.java 12 ●●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/replication/protocol/ModifyMsg.java 12 ●●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/replication/protocol/ReplicationMessage.java 4 ●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/replication/protocol/SocketSession.java 4 ●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/replication/server/ReplicationDB.java 20 ●●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/replication/server/ReplicationData.java 10 ●●●●● patch | view | raw | blame | history
opends/tests/unit-tests-testng/src/server/org/opends/server/replication/protocol/SynchronizationMsgTest.java 6 ●●●● patch | view | raw | blame | history
opends/tests/unit-tests-testng/src/server/org/opends/server/replication/server/ReplicationServerTest.java 1 ●●●● patch | view | raw | blame | history
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,12 +211,14 @@
  /**
   * 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()
  {
    try
  public byte[] getBytes() throws UnsupportedEncodingException
    {
      int length = encodedAttributes.length;
      byte[] byteParentId = null;
@@ -246,13 +248,6 @@
        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;
    }
  }
  /**
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()
  {
    try
  public byte[] getBytes() throws UnsupportedEncodingException
    {
      return encodeHeader(MSG_TYPE_DELETE_REQUEST, 0);
    } catch (UnsupportedEncodingException e)
    {
      // should never happen : TODO : log error properly
      return null;
    }
  }
  /**
opends/src/server/org/opends/server/replication/protocol/ModifyDNMsg.java
@@ -167,11 +167,12 @@
   * 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()
  {
    try
  public byte[] getBytes() throws UnsupportedEncodingException
    {
      byte[] byteNewRdn = newRDN.getBytes("UTF-8");
      byte[] byteNewSuperior = null;
@@ -224,11 +225,6 @@
        resultByteArray[pos++] = 0;
      return resultByteArray;
    } catch (UnsupportedEncodingException e)
    {
      // should never happen : TODO : log error
    }
    return null;
  }
  /**
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;
      }
    }
    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.
   *
   * @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,6 +471,7 @@
        server.stop();
      for (int i =0; i< CLIENT_THREADS; i++)
      {
        if (clientBroker[i] != null)
        clientBroker[i].stop();
      }
    }