From 325b2ee4a27d0c24aa0a539f7bd0a8cf24905ff7 Mon Sep 17 00:00:00 2001
From: boli <boli@localhost>
Date: Tue, 10 Apr 2007 20:41:27 +0000
Subject: [PATCH] Added the following capabilities to OpenDS: - Index rebuilding capabilities. All indexes including system and attribute indexes can  be rebuilt. Each index will be rebuilt by a seperate thread to increase performance. A  max number of rebuild threads could be set to limit the resources used by large rebuild  jobs. Partial rebuilds of attribute indexes could also be done by specifying the  attribute index type after the attribute type (ie. sn.approximate). - Index rebuilding standalone tool. Rebuilding of attribute indexes could be done with  the backend online. However, rebuilds including system indexes must be done with the  backend offline. - Index rebuilding task. Rebuilding of attribute indexes are done with the backend  online. Rebuilds that include system indexes will be performed after bring the backend  offline. The user must have index-rebuild privilages to rebuild indexes. - Approxitae indexing capability. The value of the attribute will be normalized using  the approximate maching rule of that attribute type. This is used as the key for the  index. Approximate indexes are fully supported by the index verify, rebuild, and import  jobs. - Fixed bug in build.xml where weave is enabled even if a test.* property is set. - Consolidated some common tool messages. - Consolidated some JE backend methods common to all tools. - Added unit tests for rebuild job and approximate indexes.

---
 opends/src/server/org/opends/server/backends/jeb/DN2URI.java |  108 +++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 106 insertions(+), 2 deletions(-)

diff --git a/opends/src/server/org/opends/server/backends/jeb/DN2URI.java b/opends/src/server/org/opends/server/backends/jeb/DN2URI.java
index 8da503e..554a9be 100644
--- a/opends/src/server/org/opends/server/backends/jeb/DN2URI.java
+++ b/opends/src/server/org/opends/server/backends/jeb/DN2URI.java
@@ -63,6 +63,8 @@
 import static org.opends.server.util.ServerConstants.ATTR_REFERRAL_URL;
 import static org.opends.server.loggers.debug.DebugLogger.debugCaught;
 import static org.opends.server.loggers.debug.DebugLogger.debugEnabled;
+import static org.opends.server.loggers.debug.DebugLogger.debugInfo;
+import static org.opends.server.loggers.debug.DebugLogger.debugVerbose;
 import org.opends.server.types.DebugLogLevel;
 import static org.opends.server.messages.JebMessages.
      MSGID_JEB_REFERRAL_RESULT_MESSAGE;
@@ -155,6 +157,12 @@
     {
       database = entryContainer.openDatabase(dbConfig, name);
       threadLocalDatabase.set(database);
+
+      if(debugEnabled())
+      {
+        debugInfo("JE DN2URI database %s opened with %d records.",
+                  database.getDatabaseName(), database.count());
+      }
     }
     return database;
   }
@@ -346,20 +354,26 @@
    * @param txn A database transaction used for the update, or null if none is
    * required.
    * @param entry The entry to be added.
+   * @return True if the entry was added successfully or False otherwise.
    * @throws DatabaseException If an error occurs in the JE database.
    */
-  public void addEntry(Transaction txn, Entry entry)
+  public boolean addEntry(Transaction txn, Entry entry)
        throws DatabaseException
   {
+    boolean success = true;
     Set<String> labeledURIs = entry.getReferralURLs();
     if (labeledURIs != null)
     {
       DN dn = entry.getDN();
       for (String labeledURI : labeledURIs)
       {
-        insert(txn, dn, labeledURI);
+        if(!insert(txn, dn, labeledURI))
+        {
+          success = false;
+        }
       }
     }
+    return success;
   }
 
   /**
@@ -381,6 +395,75 @@
   }
 
   /**
+   * Open a JE cursor on the DN database.
+   * @param txn A JE database transaction to be used by the cursor,
+   * or null if none.
+   * @param cursorConfig The JE cursor configuration.
+   * @return A JE cursor.
+   * @throws DatabaseException If an error occurs while attempting to open
+   * the cursor.
+   */
+  public Cursor openCursor(Transaction txn, CursorConfig cursorConfig)
+       throws DatabaseException
+  {
+    return getDatabase().openCursor(txn, cursorConfig);
+  }
+
+    /**
+   * Removes all records from the database.
+   * @param txn A JE database transaction to be used during the clear operation
+   *            or null if not required. Using transactions increases the chance
+   *            of lock contention.
+   * @return The number of records removed.
+   * @throws DatabaseException If an error occurs while cleaning the database.
+   */
+  public long clear(Transaction txn) throws DatabaseException
+  {
+    long deletedCount = 0;
+    Cursor cursor = openCursor(txn, null);
+    try
+    {
+      if(debugEnabled())
+      {
+        debugVerbose("%d existing records will be deleted from the " +
+            "database", getRecordCount());
+      }
+      DatabaseEntry data = new DatabaseEntry();
+      DatabaseEntry key = new DatabaseEntry();
+
+      OperationStatus status;
+
+      // Step forward until we deleted all records.
+      for (status = cursor.getFirst(key, data, LockMode.DEFAULT);
+           status == OperationStatus.SUCCESS;
+           status = cursor.getNext(key, data, LockMode.DEFAULT))
+      {
+        cursor.delete();
+        deletedCount++;
+      }
+      if(debugEnabled())
+      {
+        debugVerbose("%d records deleted", deletedCount);
+      }
+    }
+    catch(DatabaseException de)
+    {
+      if(debugEnabled())
+      {
+        debugCaught(DebugLogLevel.ERROR, de);
+      }
+
+      throw de;
+    }
+    finally
+    {
+      cursor.close();
+    }
+
+    return deletedCount;
+  }
+
+  /**
    * Checks whether the target of an operation is a referral entry and throws
    * a Directory referral exception if it is.
    * @param entry The target entry of the operation, or the base entry of a
@@ -713,4 +796,25 @@
 
     return true;
   }
+
+  /**
+   * Get the count of the number of entries stored.
+   *
+   * @return The number of entries stored.
+   *
+   * @throws DatabaseException If an error occurs in the JE database.
+   */
+  public long getRecordCount() throws DatabaseException
+  {
+    return EntryContainer.count(getDatabase());
+  }
+
+  /**
+   * Get a string representation of this object.
+   * @return return A string representation of this object.
+   */
+  public String toString()
+  {
+    return name;
+  }
 }

--
Gitblit v1.10.0