From 9f0904fda87bfcf921deeccdbaeafe834fbad696 Mon Sep 17 00:00:00 2001
From: Yannick Lecaillez <yannick.lecaillez@forgerock.com>
Date: Fri, 24 Apr 2015 14:30:47 +0000
Subject: [PATCH] OPENDJ-1725: Persistit: very long recovery and many discarded txns after addrate test

---
 opendj-server-legacy/src/main/java/org/opends/server/backends/MemoryBackend.java |   35 ++++++++++++++++++++++-------------
 1 files changed, 22 insertions(+), 13 deletions(-)

diff --git a/opendj-server-legacy/src/main/java/org/opends/server/backends/MemoryBackend.java b/opendj-server-legacy/src/main/java/org/opends/server/backends/MemoryBackend.java
index cb45e4b..b85555f 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/backends/MemoryBackend.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/backends/MemoryBackend.java
@@ -26,6 +26,7 @@
  */
 package org.opends.server.backends;
 
+import static org.forgerock.util.Reject.*;
 import static org.opends.messages.BackendMessages.*;
 import static org.opends.server.util.ServerConstants.*;
 import static org.opends.server.util.StaticUtils.*;
@@ -263,7 +264,7 @@
   public synchronized ConditionResult hasSubordinates(DN entryDN)
          throws DirectoryException
   {
-    long ret = numSubordinates(entryDN, false);
+    long ret = getNumberOfSubordinates(entryDN, false);
     if(ret < 0)
     {
       return ConditionResult.UNDEFINED;
@@ -273,11 +274,22 @@
 
   /** {@inheritDoc} */
   @Override
-  public synchronized long numSubordinates(DN entryDN, boolean subtree)
-         throws DirectoryException
+  public long getNumberOfEntriesInBaseDN(DN baseDN) throws DirectoryException {
+    checkNotNull(baseDN, "baseDN must not be null");
+    return getNumberOfSubordinates(baseDN, true) + 1;
+  }
+
+  /** {@inheritDoc} */
+  @Override
+  public long getNumberOfChildren(DN parentDN) throws DirectoryException {
+    checkNotNull(parentDN, "parentDN must not be null");
+    return getNumberOfSubordinates(parentDN, false);
+  }
+
+  private synchronized long getNumberOfSubordinates(DN entryDN, boolean includeSubtree) throws DirectoryException
   {
     // Try to look up the immediate children for the DN
-    Set<DN> children = childDNs.get(entryDN);
+    final Set<DN> children = childDNs.get(entryDN);
     if (children == null)
     {
       if(entryMap.get(entryDN) != null)
@@ -288,20 +300,17 @@
       return -1;
     }
 
-    if(!subtree)
+    if(!includeSubtree)
     {
       return children.size();
     }
-    else
+    long count = 0;
+    for (DN child : children)
     {
-      long count = 0;
-      for(DN child : children)
-      {
-        count += numSubordinates(child, true);
-        count++;
-      }
-      return count;
+      count += getNumberOfSubordinates(child, true);
+      count++;
     }
+    return count;
   }
 
   /** {@inheritDoc} */

--
Gitblit v1.10.0