From 4aeaf5775f4edc7af87aa33058ae3db25d27f9a9 Mon Sep 17 00:00:00 2001
From: Jean-Noël Rouvignac <jean-noel.rouvignac@forgerock.com>
Date: Thu, 23 Jun 2016 13:59:36 +0000
Subject: [PATCH] OPENDJ-3149 Upgrade 3.0.0 -> 4.0.0: Error in logs after upgrading a replication topology

---
 opendj-server-legacy/src/main/java/org/opends/server/backends/SchemaBackend.java     |   42 +++++++++++++++++++++++++++++++++++++++---
 opendj-server-legacy/src/main/java/org/opends/server/tools/upgrade/UpgradeTasks.java |    4 +++-
 2 files changed, 42 insertions(+), 4 deletions(-)

diff --git a/opendj-server-legacy/src/main/java/org/opends/server/backends/SchemaBackend.java b/opendj-server-legacy/src/main/java/org/opends/server/backends/SchemaBackend.java
index 2953dbb..7f8a556 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/backends/SchemaBackend.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/backends/SchemaBackend.java
@@ -800,7 +800,7 @@
       for (ByteString v : a)
       {
         AttributeType type = newSchema.parseAttributeType(v.toString());
-        removeAttributeType(type, newSchema, modifiedSchemaFiles);
+        removeAttributeType(type, newSchema, mods, pos, modifiedSchemaFiles);
       }
     }
     else if (at.equals(objectClassesType))
@@ -1108,8 +1108,8 @@
    *                              the provided attribute type from the server
    *                              schema.
    */
-  private void removeAttributeType(AttributeType attributeType, Schema schema, Set<String> modifiedSchemaFiles)
-          throws DirectoryException
+  private void removeAttributeType(AttributeType attributeType, Schema schema, List<Modification> modifications,
+      int currentPosition, Set<String> modifiedSchemaFiles) throws DirectoryException
   {
     // See if the specified attribute type is actually defined in the server
     // schema.  If not, then fail.
@@ -1121,6 +1121,42 @@
       throw new DirectoryException(ResultCode.UNWILLING_TO_PERFORM, message);
     }
 
+    // See if there is another modification later to add the attribute type back
+    // into the schema. If so, then it's a replace and we should ignore the
+    // remove because adding it back will handle the replace.
+    for (int i = currentPosition + 1; i < modifications.size(); i++)
+    {
+      Modification m = modifications.get(i);
+      Attribute a = m.getAttribute();
+
+      if (m.getModificationType() != ModificationType.ADD
+          || !a.getAttributeDescription().getAttributeType().equals(attributeTypesType))
+      {
+        continue;
+      }
+
+      for (ByteString v : a)
+      {
+        String oid;
+        try
+        {
+          oid = Schema.parseOID(v.toString(), ERR_PARSING_ATTRIBUTE_TYPE_OID);
+        }
+        catch (DirectoryException de)
+        {
+          logger.traceException(de);
+          throw de;
+        }
+
+        if (attributeType.getOID().equals(oid))
+        {
+          // We found a match where the attribute type is added back later,
+          // so we don't need to do anything else here.
+          return;
+        }
+      }
+    }
+
     // Make sure that the attribute type isn't used as the superior type for
     // any other attributes.
     for (AttributeType at : schema.getAttributeTypes())
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/tools/upgrade/UpgradeTasks.java b/opendj-server-legacy/src/main/java/org/opends/server/tools/upgrade/UpgradeTasks.java
index a04d8cc..0a5a90c 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/tools/upgrade/UpgradeTasks.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/tools/upgrade/UpgradeTasks.java
@@ -25,6 +25,7 @@
 import static org.opends.messages.ToolMessages.*;
 import static org.opends.server.tools.upgrade.FileManager.copy;
 import static org.opends.server.tools.upgrade.UpgradeUtils.*;
+import static org.opends.server.types.Schema.*;
 import static org.opends.server.util.StaticUtils.*;
 
 import java.io.BufferedWriter;
@@ -1431,11 +1432,12 @@
 
         if (!configCsvCharAT.isPlaceHolder() && concatenatedCsvCharAT.isPlaceHolder())
         {
+          final String csvCharAttrTypeDefinition = configCsvCharAT.toString().trim();
           try (BufferedWriter writer = Files.newBufferedWriter(concatenatedSchemaFile.toPath(), UTF_8, APPEND))
           {
             writer.append(CoreSchema.getAttributeTypesAttributeType().getNameOrOID());
             writer.append(": ");
-            writer.append(configCsvCharAT.toString().trim());
+            writer.append(addSchemaFileToElementDefinitionIfAbsent(csvCharAttrTypeDefinition, "02-config.ldif"));
             writer.newLine();
           }
           catch (IOException e)

--
Gitblit v1.10.0