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/BackendImpl.java |   94 +++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 94 insertions(+), 0 deletions(-)

diff --git a/opends/src/server/org/opends/server/backends/jeb/BackendImpl.java b/opends/src/server/org/opends/server/backends/jeb/BackendImpl.java
index af1aaab..93f8fc2 100644
--- a/opends/src/server/org/opends/server/backends/jeb/BackendImpl.java
+++ b/opends/src/server/org/opends/server/backends/jeb/BackendImpl.java
@@ -436,6 +436,7 @@
     try
     {
       rootContainer.close();
+      rootContainer = null;
     }
     catch (DatabaseException e)
     {
@@ -1220,6 +1221,99 @@
   }
 
 
+  /**
+   * Rebuild index(es) in the backend instance. Note that the server will not
+   * explicitly initialize this backend before calling this method.
+   * @param rebuildConfig The rebuild configuration.
+   * @param configEntry The backend instance configuration entry.
+   * @param  baseDNs      The set of base DNs that have been configured for this
+   *                      backend.
+   * @throws  ConfigException  If an unrecoverable problem arises during
+   *                           initialization.
+   * @throws  InitializationException  If a problem occurs during initialization
+   *                                   that is not related to the server
+   *                                   configuration.
+   * @throws DirectoryException If a Directory Server error occurs.
+   */
+  public void rebuildBackend(RebuildConfig rebuildConfig,
+                             ConfigEntry configEntry, DN[] baseDNs)
+       throws InitializationException, ConfigException, DirectoryException
+  {
+    // If the backend already has the root container open, we must use the same
+    // underlying root container
+    boolean openRootContainer = rootContainer == null;
+
+    // If the rootContainer is open, the backend is initizlied by something else
+    // We can't do any rebuild of system indexes while others are using this
+    // backend. Throw error. TODO: Need to make baseDNs disablable.
+    if(!openRootContainer && rebuildConfig.includesSystemIndex())
+    {
+      String message = getMessage(MSGID_JEB_REBUILD_BACKEND_ONLINE);
+      throw new DirectoryException(DirectoryServer.getServerErrorResultCode(),
+                                   message, MSGID_JEB_REBUILD_BACKEND_ONLINE);
+    }
+
+    try
+    {
+      if (openRootContainer)
+      {
+        // Initialize a config object.
+        config = new Config();
+        config.initializeConfig(configEntry, baseDNs);
+
+        // Open the database environment
+        rootContainer = new RootContainer(config, this);
+        rootContainer.open();
+        rootContainer.openEntryContainers(baseDNs);
+      }
+
+      RebuildJob rebuildJob = new RebuildJob(rebuildConfig);
+      rebuildJob.rebuildBackend(rootContainer);
+    }
+    catch (DatabaseException e)
+    {
+      if (debugEnabled())
+      {
+        debugCaught(DebugLogLevel.ERROR, e);
+      }
+      String message = getMessage(MSGID_JEB_DATABASE_EXCEPTION,
+                                  e.getMessage());
+      throw new DirectoryException(DirectoryServer.getServerErrorResultCode(),
+                                   message, MSGID_JEB_DATABASE_EXCEPTION);
+    }
+    catch (JebException e)
+    {
+      if (debugEnabled())
+      {
+        debugCaught(DebugLogLevel.ERROR, e);
+      }
+      throw new DirectoryException(DirectoryServer.getServerErrorResultCode(),
+                                   e.getMessage(),
+                                   e.getMessageID());
+    }
+    finally
+    {
+      //If a root container was opened in this method as read only, close it
+      //to leave the backend in the same state.
+      if (openRootContainer && rootContainer != null)
+      {
+        try
+        {
+          rootContainer.close();
+          rootContainer = null;
+        }
+        catch (DatabaseException e)
+        {
+          if (debugEnabled())
+          {
+            debugCaught(DebugLogLevel.ERROR, e);
+          }
+        }
+      }
+    }
+  }
+
+
 
   /**
    * Creates a backup of the contents of this backend in a form that may be

--
Gitblit v1.10.0