From b5acb25ee2ad9bf8b166b9de1a34e6aab6ea23b7 Mon Sep 17 00:00:00 2001
From: gbellato <gbellato@localhost>
Date: Fri, 01 Sep 2006 12:04:47 +0000
Subject: [PATCH] issue 604 : solve the naming conflict that might happen when several masters are used there are 3 main parts in this commit : - attach the replication context in an OperationContext - if operation replay fails then fix the problem  - in the pre-op checks for conflict and cause failure if necessary most of the time there should be no conflict and the operation should be processed normally

---
 opends/src/server/org/opends/server/synchronization/DeleteMsg.java |   91 ++++++++-------------------------------------
 1 files changed, 17 insertions(+), 74 deletions(-)

diff --git a/opends/src/server/org/opends/server/synchronization/DeleteMsg.java b/opends/src/server/org/opends/server/synchronization/DeleteMsg.java
index 3e7388f..3fec9b3 100644
--- a/opends/src/server/org/opends/server/synchronization/DeleteMsg.java
+++ b/opends/src/server/org/opends/server/synchronization/DeleteMsg.java
@@ -26,7 +26,7 @@
  */
 package org.opends.server.synchronization;
 
-import static org.opends.server.synchronization.SynchMessages.SYNCHRONIZATION;
+import static org.opends.server.synchronization.OperationContext.*;
 
 import java.io.UnsupportedEncodingException;
 import java.util.zip.DataFormatException;
@@ -41,7 +41,6 @@
  */
 public class DeleteMsg extends UpdateMessage
 {
-  private String dn;
   private static final long serialVersionUID = -4905520652801395185L;
 
   /**
@@ -50,8 +49,8 @@
    */
   public DeleteMsg(DeleteOperation op)
   {
-    dn = op.getRawEntryDN().stringValue();
-    changeNumber = (ChangeNumber) op.getAttachment(SYNCHRONIZATION);
+    super((OperationContext) op.getAttachment(SYNCHROCONTEXT),
+           op.getRawEntryDN().stringValue());
   }
 
   /**
@@ -59,55 +58,29 @@
    *
    * @param in The byte[] from which the operation must be read.
    * @throws DataFormatException The input byte[] is not a valid AddMsg
+   * @throws UnsupportedEncodingException  If UTF8 is not supported by the jvm
    */
-  public DeleteMsg(byte[] in) throws DataFormatException
+  public DeleteMsg(byte[] in) throws DataFormatException,
+                                     UnsupportedEncodingException
   {
-    /* first byte is the type */
-    if (in[0] != MSG_TYPE_DELETE_REQUEST)
-      throw new DataFormatException("byte[] is not a valid delete msg");
-    int pos = 1;
-
-    /* read the dn
-     * first calculate the length then construct the string
-     */
-    int length = 0;
-    int offset = pos;
-    while (in[pos++] != 0)
-    {
-      if (pos > in.length)
-        throw new DataFormatException("byte[] is not a valid delete msg");
-      length++;
-    }
-    try
-    {
-      dn = new String(in, offset, length, "UTF-8");
-
-      /* read the changeNumber
-       * it is always 24 characters long
-       */
-      String changenumberStr = new String(in, pos, 24, "UTF-8");
-      changeNumber = new ChangeNumber(changenumberStr);
-    } catch (UnsupportedEncodingException e)
-    {
-      throw new DataFormatException("UTF-8 is not supported by this jvm.");
-    }
+    super(in);
+    decodeHeader(MSG_TYPE_DELETE_REQUEST, in);
   }
 
 
   /**
-   * Create an Operation from a delete Message.
-   *
-   * @param connection the connection
-   * @return the Operation from which the message was received
+   * {@inheritDoc}
    */
   @Override
-  public Operation createOperation(InternalClientConnection connection)
+  public Operation createOperation(InternalClientConnection connection,
+      String newDn)
   {
     DeleteOperation del =  new DeleteOperation(connection,
                                InternalClientConnection.nextOperationID(),
                                InternalClientConnection.nextMessageID(), null,
-                               new ASN1OctetString(dn));
-    del.setAttachment(SYNCHRONIZATION, getChangeNumber());
+                               new ASN1OctetString(newDn));
+    DeleteContext ctx = new DeleteContext(getChangeNumber(), getUniqueId());
+    del.setAttachment(SYNCHROCONTEXT, ctx);
     return del;
   }
 
@@ -119,44 +92,14 @@
   @Override
   public byte[] getBytes()
   {
-    byte[] byteDn;
     try
     {
-      byteDn = dn.getBytes("UTF-8");
-
-      /* The Delete message is stored in the form :
-       * <operation type><dn><changenumber>
-       * the length of result byte array is therefore :
-       *   1 + dn length + 1 + 24
-       */
-      int length = 1 + byteDn.length + 1  + 24;
-      byte[] resultByteArray = new byte[length];
-      int pos = 1;
-
-      /* put the type of the operation */
-      resultByteArray[0] = MSG_TYPE_DELETE_REQUEST;
-
-      /* put the DN and a terminating 0 */
-      for (int i = 0; i< byteDn.length; i++,pos++)
-      {
-        resultByteArray[pos] = byteDn[i];
-      }
-      resultByteArray[pos++] = 0;
-
-      /* put the ChangeNumber */
-      byte[] changeNumberByte =
-                      this.getChangeNumber().toString().getBytes("UTF-8");
-      for (int i=0; i<24; i++,pos++)
-      {
-        resultByteArray[pos] = changeNumberByte[i];
-      }
-
-      return resultByteArray;
+      return encodeHeader(MSG_TYPE_DELETE_REQUEST, 0);
     } catch (UnsupportedEncodingException e)
     {
       // should never happen : TODO : log error properly
+      return null;
     }
-    return null;
   }
 
   /**
@@ -165,6 +108,6 @@
   @Override
   public String toString()
   {
-    return ("DEL " + dn + " " + getChangeNumber());
+    return ("DEL " + getDn() + " " + getChangeNumber());
   }
 }

--
Gitblit v1.10.0