From 111c22a17e3ab4bdca9052891a810f5ab7cea6b6 Mon Sep 17 00:00:00 2001
From: pgamba <pgamba@localhost>
Date: Wed, 19 Mar 2008 10:33:45 +0000
Subject: [PATCH] The following changes fix a bug in the clearing of the replication server db that make the clearing sometimes fail silently . Particularly Berkeley DB requires to close the db and any reference to the  db handle released before to truncate the db. That requires to lock the db when it is closed/cleared with a limited impact on the performances in the other cases. A RW lock is added on the db : every thread using  the db takes/releases the READ lock before /after usage. That still allow these threads to run concurrently and prevent a big impact on performances.  Every thread closing the db  (shutdown or clear) takes/releases the WRITE lock before/after the closure.

---
 opends/src/server/org/opends/server/replication/server/ReplicationBackend.java |   54 +++++++++++++++++++++++++++++++++++++-----------------
 1 files changed, 37 insertions(+), 17 deletions(-)

diff --git a/opends/src/server/org/opends/server/replication/server/ReplicationBackend.java b/opends/src/server/org/opends/server/replication/server/ReplicationBackend.java
index 1209d93..49a34b4 100644
--- a/opends/src/server/org/opends/server/replication/server/ReplicationBackend.java
+++ b/opends/src/server/org/opends/server/replication/server/ReplicationBackend.java
@@ -136,7 +136,7 @@
    */
   private static final DebugTracer TRACER = getTracer();
 
-  private static final String EXPORT_BASE_DN = "dc=replicationChanges";
+  private static final String BASE_DN = "dc=replicationchanges";
 
   // The base DNs for this backend.
   private DN[] baseDNs;
@@ -545,7 +545,7 @@
         ReplicationServerDomain rc = rsdi.next();
 
         // Skip containers that are not covered by the include branches.
-        baseDN = DN.decode(rc.getBaseDn().toString() + "," + EXPORT_BASE_DN);
+        baseDN = DN.decode(rc.getBaseDn().toString() + "," + BASE_DN);
 
         if (includeBranches == null || includeBranches.isEmpty())
         {
@@ -662,7 +662,7 @@
     try
     {
       AddChangeRecordEntry changeRecord =
-        new AddChangeRecordEntry(DN.decode(EXPORT_BASE_DN),
+        new AddChangeRecordEntry(DN.decode(BASE_DN),
                                attributes);
       ldifWriter.writeChangeRecord(changeRecord);
     }
@@ -706,7 +706,7 @@
       {
         AddChangeRecordEntry changeRecord =
           new AddChangeRecordEntry(DN.decode(
-              exportContainer.getBaseDn() + "," + EXPORT_BASE_DN),
+              exportContainer.getBaseDn() + "," + BASE_DN),
               attributes);
         ldifWriter.writeChangeRecord(changeRecord);
       }
@@ -717,7 +717,7 @@
           TRACER.debugCaught(DebugLogLevel.ERROR, e);
         }
         Message message = ERR_BACKEND_EXPORT_ENTRY.get(
-            exportContainer.getBaseDn() + "," + EXPORT_BASE_DN,
+            exportContainer.getBaseDn() + "," + BASE_DN,
             String.valueOf(e));
         logError(message);
       }
@@ -788,7 +788,7 @@
 
         dn = DN.decode("puid=" + addMsg.getParentUid() + "," +
             "changeNumber=" + msg.getChangeNumber().toString() + "," +
-            msg.getDn() +","+ "dc=replicationChanges");
+            msg.getDn() +","+ BASE_DN);
 
         Map<AttributeType,List<Attribute>> attributes =
           new HashMap<AttributeType,List<Attribute>>();
@@ -831,7 +831,7 @@
 
         dn = DN.decode("uuid=" + msg.getUniqueId() + "," +
             "changeNumber=" + delMsg.getChangeNumber().toString()+ "," +
-            msg.getDn() +","+ "dc=replicationChanges");
+            msg.getDn() +","+ BASE_DN);
 
         DeleteChangeRecordEntry changeRecord =
           new DeleteChangeRecordEntry(dn);
@@ -854,7 +854,7 @@
 
         dn = DN.decode("uuid=" + msg.getUniqueId() + "," +
             "changeNumber=" + msg.getChangeNumber().toString()+ "," +
-            msg.getDn() +","+ "dc=replicationChanges");
+            msg.getDn() +","+ BASE_DN);
         op.setInternalOperation(true);
 
         ModifyChangeRecordEntry changeRecord =
@@ -878,7 +878,7 @@
 
         dn = DN.decode("uuid=" + msg.getUniqueId() + "," +
             "changeNumber=" + msg.getChangeNumber().toString()+ "," +
-            msg.getDn() +","+ "dc=replicationChanges");
+            msg.getDn() +","+ BASE_DN);
         op.setInternalOperation(true);
 
         ModifyDNChangeRecordEntry changeRecord =
@@ -907,12 +907,13 @@
       else
       {
         // Get the base DN, scope, and filter for the search.
-        DN           searchBaseDN = searchOperation.getBaseDN();
+        DN  searchBaseDN = searchOperation.getBaseDN();
         SearchScope  scope  = searchOperation.getScope();
         SearchFilter filter = searchOperation.getFilter();
 
-        if (entry.matchesBaseAndScope(searchBaseDN, scope) &&
-            filter.matchesEntry(entry))
+        boolean ms = entry.matchesBaseAndScope(searchBaseDN, scope);
+        boolean mf = filter.matchesEntry(entry);
+        if ( ms && mf )
         {
           searchOperation.returnEntry(entry, new LinkedList<Control>());
         }
@@ -1188,10 +1189,17 @@
       {
         if (baseDNSet.contains(searchBaseDN))
         {
-          searchOperation.returnEntry(
-              new Entry(searchBaseDN, rootObjectclasses, attributes,
-                  operationalAttributes),
-                  new LinkedList<Control>());
+          // Get the base DN, scope, and filter for the search.
+          SearchScope  scope  = searchOperation.getScope();
+          SearchFilter filter = searchOperation.getFilter();
+          Entry re = new Entry(searchBaseDN, rootObjectclasses, attributes,
+              operationalAttributes);
+
+          if (re.matchesBaseAndScope(searchBaseDN, scope) &&
+              filter.matchesEntry(re))
+          {
+            searchOperation.returnEntry(re, new LinkedList<Control>());
+          }
           return;
         }
         else
@@ -1204,6 +1212,18 @@
       }
     }
 
+    // Get the base DN, scope, and filter for the search.
+    SearchScope  scope  = searchOperation.getScope();
+    SearchFilter filter = searchOperation.getFilter();
+    Entry re = new Entry(searchBaseDN, rootObjectclasses, attributes,
+        operationalAttributes);
+
+    if (re.matchesBaseAndScope(searchBaseDN, scope) &&
+        filter.matchesEntry(re))
+    {
+      searchOperation.returnEntry(re, new LinkedList<Control>());
+    }
+
     // Walk through all entries and send the ones that match.
     Iterator<ReplicationServerDomain> rsdi = server.getCacheIterator();
     if (rsdi != null)
@@ -1213,7 +1233,7 @@
         ReplicationServerDomain rsd = rsdi.next();
 
         // Skip containers that are not covered by the include branches.
-        baseDN = DN.decode(rsd.getBaseDn().toString() + "," + EXPORT_BASE_DN);
+        baseDN = DN.decode(rsd.getBaseDn().toString() + "," + BASE_DN);
 
             if (searchBaseDN.isDescendantOf(baseDN) ||
                 searchBaseDN.isAncestorOf(baseDN))

--
Gitblit v1.10.0