From a2c3fde785f4dcab651ee75492a95d3f6c07a853 Mon Sep 17 00:00:00 2001
From: Jean-Noel Rouvignac <jean-noel.rouvignac@forgerock.com>
Date: Mon, 09 Dec 2013 16:10:36 +0000
Subject: [PATCH] OPENDJ-1106 fractional-replication: adding entry on a replica as DM should not exit with RC 50

---
 opends/src/server/org/opends/server/workflowelement/localbackend/LocalBackendAddOperation.java |   68 +++++++++++++++------------------
 1 files changed, 31 insertions(+), 37 deletions(-)

diff --git a/opends/src/server/org/opends/server/workflowelement/localbackend/LocalBackendAddOperation.java b/opends/src/server/org/opends/server/workflowelement/localbackend/LocalBackendAddOperation.java
index 76f71eb..e3202b4 100644
--- a/opends/src/server/org/opends/server/workflowelement/localbackend/LocalBackendAddOperation.java
+++ b/opends/src/server/org/opends/server/workflowelement/localbackend/LocalBackendAddOperation.java
@@ -275,8 +275,9 @@
       entryLock = LockManager.lockWrite(entryDN);
       if (entryLock == null)
       {
-        setResultCodeAndMessageNoInfoDisclosure(entryDN, ResultCode.BUSY,
-            ERR_ADD_CANNOT_LOCK_ENTRY.get(String.valueOf(entryDN)));
+        setResultCode(ResultCode.BUSY);
+        appendErrorMessage(ERR_ADD_CANNOT_LOCK_ENTRY.get(
+            String.valueOf(entryDN)));
         return;
       }
 
@@ -291,8 +292,8 @@
               provider.handleConflictResolution(this);
           if (!result.continueProcessing())
           {
-            setResultCodeAndMessageNoInfoDisclosure(entryDN,
-                result.getResultCode(), result.getErrorMessage());
+            setResultCode(result.getResultCode());
+            appendErrorMessage(result.getErrorMessage());
             setMatchedDN(result.getMatchedDN());
             setReferralURLs(result.getReferralURLs());
             return;
@@ -640,47 +641,40 @@
    * @throws  DirectoryException  If a problem occurs while attempting to
    *                              acquire the lock.
    */
-  private Lock lockParent(DN parentDN)
-          throws DirectoryException
+  private Lock lockParent(DN parentDN) throws DirectoryException
   {
-    Lock parentLock = null;
-
-    if (parentDN == null)
+    if (parentDN != null)
     {
-      // Either this entry is a suffix or doesn't belong in the directory.
-      if (DirectoryServer.isNamingContext(entryDN))
+      final Lock parentLock = LockManager.lockRead(parentDN);
+      if (parentLock == null)
       {
-        // This is fine.  This entry is one of the configured suffixes.
-        parentLock = null;
+        throw newDirectoryException(parentDN, ResultCode.BUSY,
+            ERR_ADD_CANNOT_LOCK_PARENT.get(
+                String.valueOf(entryDN),
+                String.valueOf(parentDN)));
       }
-      else if (entryDN.isNullDN())
-      {
-        // This is not fine.  The root DSE cannot be added.
-        throw new DirectoryException(ResultCode.UNWILLING_TO_PERFORM,
-                                     ERR_ADD_CANNOT_ADD_ROOT_DSE.get());
-      }
-      else
-      {
-        // The entry doesn't have a parent but isn't a suffix.  This is not
-        // allowed.
-        throw new DirectoryException(ResultCode.NO_SUCH_OBJECT,
-                                     ERR_ADD_ENTRY_NOT_SUFFIX.get(
-                                          String.valueOf(entryDN)));
-      }
+      return parentLock;
+    }
+
+    // Either this entry is a suffix or doesn't belong in the directory.
+    if (DirectoryServer.isNamingContext(entryDN))
+    {
+      // This is fine.  This entry is one of the configured suffixes.
+      return null;
+    }
+    else if (entryDN.isNullDN())
+    {
+      // This is not fine.  The root DSE cannot be added.
+      throw new DirectoryException(ResultCode.UNWILLING_TO_PERFORM,
+          ERR_ADD_CANNOT_ADD_ROOT_DSE.get());
     }
     else
     {
-      parentLock = LockManager.lockRead(parentDN);
-      if (parentLock == null)
-      {
-        throw newDirectoryException(entryDN, ResultCode.BUSY,
-                                     ERR_ADD_CANNOT_LOCK_PARENT.get(
-                                          String.valueOf(entryDN),
-                                          String.valueOf(parentDN)));
-      }
+      // The entry doesn't have a parent but isn't a suffix.  This is not
+      // allowed.
+      throw new DirectoryException(ResultCode.NO_SUCH_OBJECT,
+          ERR_ADD_ENTRY_NOT_SUFFIX.get(String.valueOf(entryDN)));
     }
-
-    return parentLock;
   }
 
 

--
Gitblit v1.10.0