From a411c55dfacc6d4e1fd237aaee2155a2d7dd6d25 Mon Sep 17 00:00:00 2001
From: dugan <dugan@localhost>
Date: Mon, 07 Apr 2008 13:51:03 +0000
Subject: [PATCH] Import performance commits:

---
 opends/src/server/org/opends/server/backends/jeb/importLDIF/IntegerImportIDSet.java |  120 ++++++++++++++++++++++++++++++++++++++++++++++-------------
 1 files changed, 93 insertions(+), 27 deletions(-)

diff --git a/opends/src/server/org/opends/server/backends/jeb/importLDIF/IntegerImportIDSet.java b/opends/src/server/org/opends/server/backends/jeb/importLDIF/IntegerImportIDSet.java
index 37b7db9..8ddc315 100644
--- a/opends/src/server/org/opends/server/backends/jeb/importLDIF/IntegerImportIDSet.java
+++ b/opends/src/server/org/opends/server/backends/jeb/importLDIF/IntegerImportIDSet.java
@@ -36,7 +36,7 @@
 public class IntegerImportIDSet implements ImportIDSet {
 
   //Gleamed from JHAT. The same for 32/64 bit.
-  private final static int THIS_OVERHEAD = 17;
+  private final static int THIS_OVERHEAD = 25;
 
   /**
    * The internal array where elements are stored.
@@ -53,6 +53,10 @@
   //Boolean to keep track if the instance is defined or not.
   private boolean isDefined=true;
 
+
+  //Size of the undefines.
+  private long undefinedSize = 0;
+
   /**
    * Create an empty import set.
    */
@@ -78,6 +82,12 @@
     return isDefined;
   }
 
+   /**
+   * {@inheritDoc}
+   */
+  public long getUndefinedSize() {
+    return undefinedSize;
+  }
 
   /**
    * {@inheritDoc}
@@ -103,22 +113,62 @@
   /**
    * {@inheritDoc}
    */
-  public boolean merge(byte[] dBbytes, ImportIDSet importIdSet, int limit) {
+  public void addEntryID(EntryID entryID, int limit, boolean maintainCount) {
+    if(!isDefined()) {
+      if(maintainCount)  {
+        undefinedSize++;
+      }
+      return;
+    }
+    if(isDefined() && ((count + 1) > limit)) {
+      isDefined = false;
+      array = null;
+      if(maintainCount)  {
+        undefinedSize = count + 1;
+      } else {
+        undefinedSize = Long.MAX_VALUE;
+      }
+      count = 0;
+    } else {
+      add((int)entryID.longValue());
+    }
+  }
+
+  /**
+   * More complicated version of merge below that keeps track of the undefined
+   * sizes when in undefined mode or moving to undefined mode.
+   *
+   * @param dBbytes The bytes read from jeb.
+   * @param importIdSet
+   * @param limit
+   * @return
+   */
+  private boolean
+  mergeCount(byte[] dBbytes, ImportIDSet importIdSet, int limit)  {
     boolean incrLimitCount=false;
     boolean dbUndefined = ((dBbytes[0] & 0x80) == 0x80);
 
-    if(dbUndefined) {
-      isDefined=false;
+    if(dbUndefined && (!importIdSet.isDefined()))  {
+       undefinedSize = JebFormat.entryIDUndefinedSizeFromDatabase(dBbytes) +
+                                                 importIdSet.getUndefinedSize();
+       isDefined=false;
+    } else if(dbUndefined && (importIdSet.isDefined()))  {
+       undefinedSize = JebFormat.entryIDUndefinedSizeFromDatabase(dBbytes) +
+                                                 importIdSet.size();
+       importIdSet.setUndefined();
+       isDefined=false;
     } else if(!importIdSet.isDefined()) {
-      isDefined=false;
-      incrLimitCount=true;
+       int dbSize = JebFormat.entryIDListFromDatabase(dBbytes).length;
+       undefinedSize= dbSize + importIdSet.getUndefinedSize();
+       isDefined=false;
+       incrLimitCount = true;
     } else {
       array = JebFormat.intArrayFromDatabaseBytes(dBbytes);
       if(array.length + importIdSet.size() > limit) {
-        isDefined=false;
-        incrLimitCount=true;
-        count = 0;
-        importIdSet.setUndefined();
+          undefinedSize = array.length + importIdSet.size();
+          importIdSet.setUndefined();
+          isDefined=false;
+          incrLimitCount=true;
       } else {
         count = array.length;
         addAll((IntegerImportIDSet) importIdSet);
@@ -128,6 +178,38 @@
   }
 
   /**
+   * {@inheritDoc}
+   */
+  public boolean merge(byte[] dBbytes, ImportIDSet importIdSet,
+                       int limit, boolean maintainCount) {
+    boolean incrLimitCount=false;
+    if(maintainCount) {
+      incrLimitCount = mergeCount(dBbytes,  importIdSet, limit);
+    } else {
+      boolean dbUndefined = ((dBbytes[0] & 0x80) == 0x80);
+      if(dbUndefined) {
+        isDefined=false;
+        importIdSet.setUndefined();
+      } else if(!importIdSet.isDefined()) {
+        isDefined=false;
+        incrLimitCount=true;
+      } else {
+        array = JebFormat.intArrayFromDatabaseBytes(dBbytes);
+        if(array.length + importIdSet.size() > limit) {
+          isDefined=false;
+          incrLimitCount=true;
+          count = 0;
+          importIdSet.setUndefined();
+        } else {
+          count = array.length;
+          addAll((IntegerImportIDSet) importIdSet);
+        }
+      }
+    }
+    return incrLimitCount;
+  }
+
+  /**
    * Add all of the specified import ID set to the import set.
    *
    * @param that The import ID set to add.
@@ -222,22 +304,6 @@
 
 
   /**
-   * {@inheritDoc}
-   */
-  public void addEntryID(EntryID entryID, int limit) {
-    if(!isDefined()) {
-      return;
-    }
-    if(isDefined() && ((count + 1) > limit)) {
-      isDefined = false;
-      array = null;
-      count = 0;
-    } else {
-      add((int)entryID.longValue());
-    }
-  }
-
-  /**
    * Add the specified integer to the import set.
    *
    * @param v The integer value to add.
@@ -330,7 +396,7 @@
     if(isDefined) {
        return encode(null);
      } else {
-       return JebFormat.entryIDUndefinedSizeToDatabase(Long.MAX_VALUE);
+       return JebFormat.entryIDUndefinedSizeToDatabase(undefinedSize);
      }
    }
 

--
Gitblit v1.10.0