From 7eda83737e5c2a09bef758ac2bcd3b7ea8b32ce3 Mon Sep 17 00:00:00 2001
From: boli <boli@localhost>
Date: Wed, 20 Jun 2007 18:27:41 +0000
Subject: [PATCH] This refactoring includes the following changes to the JE backend: - Extracted common interface DatabaseContainer from DN2ID, ID2Entry, etc... classes. - Moved database read and write methods from EntryContainer to DatabaseContainer. - Added index configuration to the XML based admin framework. - Removed redundant configuration objects (Config, IndexConfig). - Added exclusive/shared lock to EntryContainer. All access to an EntryContainer must acquire a lock before using the internal  DatabaseContainers or making configuration changes. - Added the ability to add/remove/modify indexes with the backend online. Server will issue rebuild required warning when adding new indexes  or sub-indexes (equality, substring, presence...). - Added the ability to change the index entry limit for both the backend and each index with the backend online. Server will issue rebuild  required warning if the previous limit has been exceeded. - Added the ability to change entry compression and index substring length setting while the backend is online. - Added a persistent state database to each EntryContainer to persist backend configuration between server restarts. Server will issue  rebuild required warning if a new index is added when the backend is offline. - Added a trusted flag to indexes so that non existent keys will not be interpreted as an empty entry ID set when an index is untrusted. An  index is untrusted when it is added to an non-empty EntryContainer or an inconsistency is detected. Server will issue warning on startup to  rebuild the index.  - Fixed a issue where the LDIF import process stops responding if the temporary import dir is full or unwritable. 

---
 opends/src/server/org/opends/server/backends/jeb/ID2Entry.java |  148 +++++++++++++-----------------------------------
 1 files changed, 41 insertions(+), 107 deletions(-)

diff --git a/opends/src/server/org/opends/server/backends/jeb/ID2Entry.java b/opends/src/server/org/opends/server/backends/jeb/ID2Entry.java
index ce61886..1cd8fd1 100644
--- a/opends/src/server/org/opends/server/backends/jeb/ID2Entry.java
+++ b/opends/src/server/org/opends/server/backends/jeb/ID2Entry.java
@@ -31,15 +31,7 @@
 import static org.opends.server.messages.MessageHandler.getMessage;
 import static org.opends.server.messages.JebMessages.*;
 
-import com.sleepycat.je.Cursor;
-import com.sleepycat.je.CursorConfig;
-import com.sleepycat.je.Database;
-import com.sleepycat.je.DatabaseConfig;
-import com.sleepycat.je.DatabaseEntry;
-import com.sleepycat.je.DatabaseException;
-import com.sleepycat.je.LockMode;
-import com.sleepycat.je.OperationStatus;
-import com.sleepycat.je.Transaction;
+import com.sleepycat.je.*;
 
 import org.opends.server.types.DirectoryException;
 import org.opends.server.types.Entry;
@@ -49,7 +41,7 @@
  * the entry ID and the value is the entry contents.
  *
  */
-public class ID2Entry
+public class ID2Entry extends DatabaseContainer
 {
   /**
    * The tracer object for the debug logger.
@@ -57,83 +49,49 @@
   private static final DebugTracer TRACER = getTracer();
 
   /**
-   * The database entryContainer.
-   */
-  private EntryContainer entryContainer;
-
-  /**
-   * The JE database configuration.
-   */
-  private DatabaseConfig dbConfig;
-
-  /**
    * Parameters for compression and encryption.
    */
   private DataConfig dataConfig;
 
   /**
-   * The name of the database within the entryContainer.
-   */
-  private String name;
-
-  /**
-   * A cached per-thread JE database handle.
-   */
-  private ThreadLocal<Database> threadLocalDatabase =
-       new ThreadLocal<Database>();
-
-  /**
    * Create a new ID2Entry object.
-   * @param entryContainer The entryContainer of the entry database.
-   * @param dbConfig The JE database configuration to be used to open the
-   * underlying JE database.
+   *
+   * @param name The name of the entry database.
    * @param dataConfig The desired compression and encryption options for data
    * stored in the entry database.
-   * @param name The name of the entry database.
+   * @param env The JE Environment.
+   * @param entryContainer The entryContainer of the entry database.
+   * @throws DatabaseException If an error occurs in the JE database.
+   *
    */
-  public ID2Entry(EntryContainer entryContainer, DatabaseConfig dbConfig,
-                  DataConfig dataConfig, String name)
+  ID2Entry(String name, DataConfig dataConfig,
+           Environment env, EntryContainer entryContainer)
+      throws DatabaseException
   {
-    this.entryContainer = entryContainer;
-    this.dbConfig = dbConfig.cloneConfig();
-    this.name = name;
+    super(name, env, entryContainer);
     this.dataConfig = dataConfig;
-  }
 
-  /**
-   * Open the entry database.
-   *
-   * @throws DatabaseException If an error occurs in the JE database.
-   */
-  public void open() throws DatabaseException
-  {
-    getDatabase();
-  }
+    DatabaseConfig dbNodupsConfig = new DatabaseConfig();
 
-  /**
-   * Get a handle to the database. It returns a per-thread handle to avoid
-   * any thread contention on the database handle. The entryContainer is
-   * responsible for closing all handles.
-   *
-   * @return A database handle.
-   *
-   * @throws DatabaseException If an error occurs in the JE database.
-   */
-  private Database getDatabase() throws DatabaseException
-  {
-    Database database = threadLocalDatabase.get();
-    if (database == null)
+    if(env.getConfig().getReadOnly())
     {
-      database = entryContainer.openDatabase(dbConfig, name);
-      threadLocalDatabase.set(database);
-
-      if(debugEnabled())
-      {
-        TRACER.debugInfo("JE ID2Entry database %s opened with %d records.",
-                  database.getDatabaseName(), database.count());
-      }
+      dbNodupsConfig.setReadOnly(true);
+      dbNodupsConfig.setAllowCreate(false);
+      dbNodupsConfig.setTransactional(false);
     }
-    return database;
+    else if(!env.getConfig().getTransactional())
+    {
+      dbNodupsConfig.setAllowCreate(true);
+      dbNodupsConfig.setTransactional(false);
+      dbNodupsConfig.setDeferredWrite(true);
+    }
+    else
+    {
+      dbNodupsConfig.setAllowCreate(true);
+      dbNodupsConfig.setTransactional(true);
+    }
+
+    this.dbConfig = dbNodupsConfig;
   }
 
   /**
@@ -172,7 +130,7 @@
     DatabaseEntry data = entryData(entry);
 
     OperationStatus status;
-    status = EntryContainer.insert(getDatabase(), txn, key, data);
+    status = insert(txn, key, data);
     if (status != OperationStatus.SUCCESS)
     {
       return false;
@@ -198,7 +156,7 @@
     DatabaseEntry data = entryData(entry);
 
     OperationStatus status;
-    status = EntryContainer.put(getDatabase(), txn, key, data);
+    status = put(txn, key, data);
     if (status != OperationStatus.SUCCESS)
     {
       return false;
@@ -219,7 +177,7 @@
        throws DatabaseException
   {
     OperationStatus status;
-    status = EntryContainer.put(getDatabase(), txn, key, data);
+    status = put(txn, key, data);
     if (status != OperationStatus.SUCCESS)
     {
       return false;
@@ -240,7 +198,7 @@
   {
     DatabaseEntry key = id.getDatabaseEntry();
 
-    OperationStatus status = EntryContainer.delete(getDatabase(), txn, key);
+    OperationStatus status = delete(txn, key);
     if (status != OperationStatus.SUCCESS)
     {
       return false;
@@ -264,7 +222,7 @@
     DatabaseEntry data = new DatabaseEntry();
 
     OperationStatus status;
-    status = EntryContainer.read(getDatabase(), txn, key, data,
+    status = read(txn, key, data,
                                  LockMode.DEFAULT);
 
     if (status != OperationStatus.SUCCESS)
@@ -311,38 +269,14 @@
   }
 
   /**
-   * Open a database cursor on the entry database.
+   * Set the desired compression and encryption options for data
+   * stored in the entry database.
    *
-   * @param txn The database transaction, or null if none.
-   * @param cursorConfig The JE cursor configuration.
-   * @return A new cursor.
-   * @throws DatabaseException If an error occurs in the JE database.
+   * @param dataConfig The desired compression and encryption options for data
+   * stored in the entry database.
    */
-  public Cursor openCursor(Transaction txn, CursorConfig cursorConfig)
-       throws DatabaseException
+  public void setDataConfig(DataConfig dataConfig)
   {
-    Database database = getDatabase();
-    return database.openCursor(txn, cursorConfig);
-  }
-
-  /**
-   * 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;
+    this.dataConfig = dataConfig;
   }
 }

--
Gitblit v1.10.0