From 6286028b47778ec3a01a6c99f6c094ef4bc4698f Mon Sep 17 00:00:00 2001
From: gbellato <gbellato@localhost>
Date: Mon, 10 Aug 2009 08:29:48 +0000
Subject: [PATCH] Fix for 4169 : Ability to disable generation of historical information and 4170 : Replication should not generate HistoricalCsnOrdering index for replayed operation

---
 opendj-sdk/opends/src/server/org/opends/server/replication/plugin/LDAPReplicationDomain.java                 |   18 ++++++++
 opendj-sdk/opends/src/server/org/opends/server/replication/plugin/HistoricalCsnOrderingMatchingRule.java     |    6 ++
 opendj-sdk/opends/src/admin/defn/org/opends/server/admin/std/ReplicationDomainConfiguration.xml              |   47 +++++++++++++++++------
 opendj-sdk/opends/src/server/org/opends/server/replication/plugin/MultimasterReplication.java                |   16 ++++++++
 opendj-sdk/opends/src/admin/defn/org/opends/server/admin/std/ReplicationServerConfiguration.xml              |    6 +-
 opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/replication/plugin/DomainFakeCfg.java |    5 ++
 opendj-sdk/opends/resource/schema/02-config.ldif                                                             |    9 ++++
 7 files changed, 89 insertions(+), 18 deletions(-)

diff --git a/opendj-sdk/opends/resource/schema/02-config.ldif b/opendj-sdk/opends/resource/schema/02-config.ldif
index a883e0b..cce5b1b 100644
--- a/opendj-sdk/opends/resource/schema/02-config.ldif
+++ b/opendj-sdk/opends/resource/schema/02-config.ldif
@@ -2410,6 +2410,12 @@
   SYNTAX 1.3.6.1.4.1.1466.115.121.1.15
   USAGE directoryOperation
   X-ORIGIN 'OpenDS Directory Server' )
+  
+attributeTypes: ( 1.3.6.1.4.1.26027.1.1.592
+  NAME 'ds-cfg-solve-conflicts'
+  SYNTAX 1.3.6.1.4.1.1466.115.121.1.15
+  USAGE directoryOperation
+  X-ORIGIN 'OpenDS Directory Server' )
 objectClasses: ( 1.3.6.1.4.1.26027.1.2.1
   NAME 'ds-cfg-access-control-handler'
   SUP top
@@ -2969,7 +2975,8 @@
         ds-cfg-group-id $
         ds-cfg-referrals-url $
         ds-cfg-fractional-exclude $
-        ds-cfg-fractional-include)
+        ds-cfg-fractional-include $
+        ds-cfg-solve-conflicts )
   X-ORIGIN 'OpenDS Directory Server' )
 objectClasses: ( 1.3.6.1.4.1.26027.1.2.58
   NAME 'ds-cfg-length-based-password-validator'
diff --git a/opendj-sdk/opends/src/admin/defn/org/opends/server/admin/std/ReplicationDomainConfiguration.xml b/opendj-sdk/opends/src/admin/defn/org/opends/server/admin/std/ReplicationDomainConfiguration.xml
index 8930324..49450f0 100644
--- a/opendj-sdk/opends/src/admin/defn/org/opends/server/admin/std/ReplicationDomainConfiguration.xml
+++ b/opendj-sdk/opends/src/admin/defn/org/opends/server/admin/std/ReplicationDomainConfiguration.xml
@@ -108,7 +108,7 @@
       </ldap:attribute>
     </adm:profile>
   </adm:property>
-  <adm:property name="window-size" advanced="true">
+  <adm:property name="window-size">
     <adm:synopsis>
       Specifies the window size that the Directory Server will use when
       communicating with Replication Servers.
@@ -127,7 +127,7 @@
       </ldap:attribute>
     </adm:profile>
   </adm:property>
-  <adm:property name="heartbeat-interval" advanced="true">
+  <adm:property name="heartbeat-interval">
     <adm:synopsis>
       Specifies the heart-beat interval that the Directory Server will
       use when communicating with Replication Servers.
@@ -193,7 +193,7 @@
       </ldap:attribute>
     </adm:profile>
   </adm:property>
-  <adm:property name="assured-type" mandatory="false" advanced="true">
+  <adm:property name="assured-type" mandatory="false">
     <adm:synopsis>
       Defines the assured replication mode of the replicated domain.
     </adm:synopsis>
@@ -243,7 +243,7 @@
       </ldap:attribute>
     </adm:profile>
   </adm:property>
-  <adm:property name="assured-sd-level" mandatory="false" advanced="true">
+  <adm:property name="assured-sd-level" mandatory="false">
     <adm:synopsis>
       The level of acknowledgment for Safe Data assured sub mode.
     </adm:synopsis>
@@ -267,7 +267,7 @@
       </ldap:attribute>
     </adm:profile>
   </adm:property>
-  <adm:property name="assured-timeout" mandatory="false" advanced="true">
+  <adm:property name="assured-timeout" mandatory="false">
     <adm:synopsis>
       The timeout value when waiting for assured replication acknowledgments.
     </adm:synopsis>
@@ -290,7 +290,7 @@
       </ldap:attribute>
     </adm:profile>
   </adm:property>
-  <adm:property name="group-id" mandatory="false" advanced="true">
+  <adm:property name="group-id" mandatory="false">
     <adm:synopsis>
       The group ID associated with this replicated domain.
     </adm:synopsis>
@@ -314,8 +314,7 @@
       </ldap:attribute>
     </adm:profile>
   </adm:property>
-  <adm:property name="referrals-url" multi-valued="true" mandatory="false"
-  advanced="true">
+  <adm:property name="referrals-url" multi-valued="true" mandatory="false">
     <adm:synopsis>
       The URLs other LDAP servers should use to refer to the local server.
     </adm:synopsis>
@@ -345,8 +344,7 @@
       </ldap:attribute>
     </adm:profile>
   </adm:property>
-  <adm:property name="fractional-include" multi-valued="true" mandatory="false"
-  advanced="true">
+  <adm:property name="fractional-include" multi-valued="true" mandatory="false">
     <adm:synopsis>
       Allows to include some attributes to replicate to this server.
     </adm:synopsis>
@@ -392,8 +390,7 @@
       </ldap:attribute>
     </adm:profile>
   </adm:property>
-  <adm:property name="fractional-exclude" multi-valued="true" mandatory="false"
-  advanced="true">
+  <adm:property name="fractional-exclude" multi-valued="true" mandatory="false">
     <adm:synopsis>
       Allows to exclude some attributes to replicate to this server.
     </adm:synopsis>
@@ -440,4 +437,30 @@
       </ldap:attribute>
     </adm:profile>
   </adm:property>
+  <adm:property name="solve-conflicts" advanced="true">
+    <adm:synopsis>
+      Indicates if this server solves conflict.
+    </adm:synopsis>
+    <adm:description>
+      This boolean indicates if this domain keeps the historical information
+      necessary to solve conflicts.
+      When set to false the server will not maintain historical information 
+      and will therefore not be able to solve conflict. This should therefore
+      be done only if the replication is used in a single master type 
+      of deployment.
+    </adm:description>
+    <adm:default-behavior>
+      <adm:defined>
+        <adm:value>true</adm:value>
+      </adm:defined>
+    </adm:default-behavior>
+    <adm:syntax>
+      <adm:boolean />
+    </adm:syntax>
+    <adm:profile name="ldap">
+      <ldap:attribute>
+        <ldap:name>ds-cfg-solve-conflicts</ldap:name>
+      </ldap:attribute>
+    </adm:profile>
+  </adm:property>
 </adm:managed-object>
diff --git a/opendj-sdk/opends/src/admin/defn/org/opends/server/admin/std/ReplicationServerConfiguration.xml b/opendj-sdk/opends/src/admin/defn/org/opends/server/admin/std/ReplicationServerConfiguration.xml
index 6b2b3fc..812bad9 100644
--- a/opendj-sdk/opends/src/admin/defn/org/opends/server/admin/std/ReplicationServerConfiguration.xml
+++ b/opendj-sdk/opends/src/admin/defn/org/opends/server/admin/std/ReplicationServerConfiguration.xml
@@ -23,7 +23,7 @@
   ! CDDL HEADER END
   !
   !
-  !      Copyright 2007-2008 Sun Microsystems, Inc.
+  !      Copyright 2007-2009 Sun Microsystems, Inc.
   ! -->
 <adm:managed-object name="replication-server"
   plural-name="replication-servers"
@@ -93,7 +93,7 @@
       </ldap:attribute>
     </adm:profile>
   </adm:property>
-  <adm:property name="window-size" advanced="true">
+  <adm:property name="window-size">
     <adm:synopsis>
       Specifies the window size that the
       <adm:user-friendly-name />
@@ -154,7 +154,7 @@
       </ldap:attribute>
     </adm:profile>
   </adm:property>
-  <adm:property name="replication-purge-delay" advanced="true">
+  <adm:property name="replication-purge-delay">
     <adm:synopsis>
       The time (in seconds) after which the
       <adm:user-friendly-name />
diff --git a/opendj-sdk/opends/src/server/org/opends/server/replication/plugin/HistoricalCsnOrderingMatchingRule.java b/opendj-sdk/opends/src/server/org/opends/server/replication/plugin/HistoricalCsnOrderingMatchingRule.java
index cdad536..0fd77ee 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/replication/plugin/HistoricalCsnOrderingMatchingRule.java
+++ b/opendj-sdk/opends/src/server/org/opends/server/replication/plugin/HistoricalCsnOrderingMatchingRule.java
@@ -136,6 +136,7 @@
   @Override
   public ByteString normalizeValue(ByteSequence value)
   {
+
     String[] token = value.toString().split(":", 3);
 
     /* Change the format of the value to index and start
@@ -148,7 +149,10 @@
     String serverId = token[1].substring(16,20);
     String seqNumber = token[1].substring(20, 28);
 
-    return ByteString.valueOf(serverId + timestamp + seqNumber);
+    if (MultimasterReplication.isLocalServerId(Short.parseShort(serverId, 16)))
+      return ByteString.valueOf(serverId + timestamp + seqNumber);
+    else
+      return (ByteString.valueOf("0"));
   }
 
   /**
diff --git a/opendj-sdk/opends/src/server/org/opends/server/replication/plugin/LDAPReplicationDomain.java b/opendj-sdk/opends/src/server/org/opends/server/replication/plugin/LDAPReplicationDomain.java
index ae42a49..c598a8b 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/replication/plugin/LDAPReplicationDomain.java
+++ b/opendj-sdk/opends/src/server/org/opends/server/replication/plugin/LDAPReplicationDomain.java
@@ -492,7 +492,7 @@
     }
     else
     {
-      solveConflictFlag = true;
+      solveConflictFlag = configuration.isSolveConflicts();
     }
 
     Backend backend = retrievesBackend(baseDn);
@@ -4369,6 +4369,22 @@
     // Read fractional configuration and reconnect if needed
     readFractionalConfig(configuration, true);
 
+    /*
+     * Modify conflicts are solved for all suffixes but the schema suffix
+     * because we don't want to store extra information in the schema
+     * ldif files.
+     * This has no negative impact because the changes on schema should
+     * not produce conflicts.
+     */
+    if (baseDn.compareTo(DirectoryServer.getSchemaDN()) == 0)
+    {
+      solveConflictFlag = false;
+    }
+    else
+    {
+      solveConflictFlag = configuration.isSolveConflicts();
+    }
+
     return new ConfigChangeResult(ResultCode.SUCCESS, false);
   }
 
diff --git a/opendj-sdk/opends/src/server/org/opends/server/replication/plugin/MultimasterReplication.java b/opendj-sdk/opends/src/server/org/opends/server/replication/plugin/MultimasterReplication.java
index 68031e7..5f78d8c 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/replication/plugin/MultimasterReplication.java
+++ b/opendj-sdk/opends/src/server/org/opends/server/replication/plugin/MultimasterReplication.java
@@ -836,4 +836,20 @@
     return privateDNs;
   }
 
+  /**
+   * Checks if a given serverID is used by a local Replication Domain.
+   *
+   * @param serverId   The serverID that should be checked.
+   * @return           true if the serverID is local, false otherwise.
+   */
+  public static boolean isLocalServerId(Short serverId)
+  {
+    for (LDAPReplicationDomain domain : domains.values())
+    {
+      if (domain.getServerId() == serverId)
+        return true;
+    }
+    return false;
+  }
+
 }
diff --git a/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/replication/plugin/DomainFakeCfg.java b/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/replication/plugin/DomainFakeCfg.java
index 6f2ffbf..a6c6d04 100644
--- a/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/replication/plugin/DomainFakeCfg.java
+++ b/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/replication/plugin/DomainFakeCfg.java
@@ -343,4 +343,9 @@
   {
     return fractionalIncludes;
   }
+
+  public boolean isSolveConflicts()
+  {
+    return true;
+  }
 }

--
Gitblit v1.10.0