mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

Matthew Swift
14.46.2015 65aba8bb05fb4a117a527496be2d0342b343963a
OPENDJ-1848: minor improvements to DatabaseContainer

* delegate implementation of DatabaseContainer.getRecordCount() to Storage impl
* added DatabaseContainer.delete() and fix all calls to WriteableStorage.deleteTree().
6 files modified
137 ■■■■■ changed files
opendj-server-legacy/src/main/java/org/opends/server/backends/persistit/PersistItStorage.java 20 ●●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/DatabaseContainer.java 59 ●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/EntryContainer.java 17 ●●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/NullIndex.java 16 ●●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/TracedStorage.java 16 ●●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/spi/ReadableStorage.java 9 ●●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/server/backends/persistit/PersistItStorage.java
@@ -326,6 +326,26 @@
    }
    @Override
    public long getRecordCount(TreeName treeName)
    {
      // FIXME: is the a better/quicker way to do this?
      final Cursor cursor = openCursor(treeName);
      try
      {
        long count = 0;
        while (cursor.next())
        {
          count++;
        }
        return count;
      }
      finally
      {
        cursor.close();
      }
    }
    @Override
    public ByteString getRMW(final TreeName treeName, final ByteSequence key)
    {
      return read(treeName, key);
opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/DatabaseContainer.java
@@ -26,7 +26,6 @@
 */
package org.opends.server.backends.pluggable;
import org.opends.server.backends.pluggable.spi.Cursor;
import org.opends.server.backends.pluggable.spi.ReadableStorage;
import org.opends.server.backends.pluggable.spi.StorageRuntimeException;
import org.opends.server.backends.pluggable.spi.TreeName;
@@ -52,51 +51,49 @@
  }
  /**
   * Opens a JE database in this database container. If the provided
   * database configuration is transactional, a transaction will be
   * created and used to perform the open.
   * Opens a JE database in this database container. If the provided database configuration is
   * transactional, a transaction will be created and used to perform the open.
   *
   * @param txn The JE transaction handle, or null if none.
   * @throws StorageRuntimeException if a JE database error occurs while
   * opening the index.
   * @param txn
   *          The transaction.
   * @throws StorageRuntimeException
   *           if a JE database error occurs while opening the index.
   */
  void open(WriteableStorage txn) throws StorageRuntimeException
  {
    // FIXME: remove?
    txn.openTree(name);
  }
  /**
   * Get the count of key/data pairs in the database in a JE database.
   * This is a simple wrapper around the JE Database.count method.
   * @param txn The JE transaction handle, or null if none.
   * @return The count of key/data pairs in the database.
   * @throws StorageRuntimeException If an error occurs in the JE operation.
   * Deletes this database and all of its contents.
   *
   * @param txn
   *          The transaction.
   * @throws StorageRuntimeException
   *           if a database error occurs while deleting the index.
   */
  void delete(WriteableStorage txn) throws StorageRuntimeException
  {
    txn.deleteTree(name);
  }
  /**
   * Returns the number of key/value pairs in this database container.
   *
   * @param txn
   *          The transaction.
   * @return the number of key/value pairs in the provided tree.
   * @throws StorageRuntimeException
   *           If an error occurs in the DB operation.
   */
  long getRecordCount(ReadableStorage txn) throws StorageRuntimeException
  {
    /*
     * FIXME: push down to storage. Some DBs have native support for this, e.g. using counted
     * B-Trees.
     */
    final Cursor cursor = txn.openCursor(name);
    try
    {
      long count = 0;
      while (cursor.next())
      {
        count++;
      }
      return count;
    }
    finally
    {
      cursor.close();
    }
    return txn.getRecordCount(name);
  }
  /**
   * Get a string representation of this object.
   *
   * @return return A string representation of this object.
   */
  @Override
opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/EntryContainer.java
@@ -545,12 +545,7 @@
  private NullIndex openNewNullIndex(WriteableStorage txn, String indexId, Indexer indexer)
  {
    final TreeName indexName = getIndexName(indexId);
    final NullIndex index = new NullIndex(indexName, indexer, state, txn, this);
    state.putIndexTrustState(txn, index, false);
    txn.deleteTree(indexName);
    index.open(txn); // No-op
    return index;
    return new NullIndex(getIndexName(indexId), indexer, state, txn, this);
  }
  /**
@@ -2801,7 +2796,7 @@
    for (DatabaseContainer db : databases)
    {
      txn.deleteTree(db.getName());
      db.delete(txn);
    }
  }
@@ -2820,7 +2815,7 @@
      // The state database can not be removed individually.
      return;
    }
    txn.deleteTree(database.getName());
    database.delete(txn);
    if(database instanceof Index)
    {
      state.removeIndexTrustState(txn, database);
@@ -2839,7 +2834,7 @@
    attributeIndex.close();
    for (Index index : attributeIndex.getAllIndexes())
    {
      txn.deleteTree(index.getName());
      index.delete(txn);
      state.removeIndexTrustState(txn, index);
    }
  }
@@ -3063,7 +3058,7 @@
    {
      for (DatabaseContainer db : databases)
      {
        txn.deleteTree(db.getName());
        db.delete(txn);
      }
    }
    finally
@@ -3095,7 +3090,7 @@
  {
    try
    {
      txn.deleteTree(database.getName());
      database.delete(txn);
    }
    finally
    {
opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/NullIndex.java
@@ -25,6 +25,7 @@
package org.opends.server.backends.pluggable;
import java.util.List;
import java.util.Set;
import org.forgerock.opendj.ldap.ByteSequence;
import org.forgerock.opendj.ldap.ByteString;
@@ -48,6 +49,8 @@
      EntryContainer entryContainer) throws StorageRuntimeException
  {
    super(name, indexer, state, 0, 0, false, txn, entryContainer);
    state.putIndexTrustState(txn, this, false);
    super.delete(txn);
  }
  @Override
@@ -163,4 +166,17 @@
  {
    return 0;
  }
  @Override
  void delete(WriteableStorage txn) throws StorageRuntimeException
  {
    // Do nothing.
  }
  @Override
  void indexEntry(Entry entry, Set<ByteString> keys, IndexingOptions options)
  {
    // Do nothing.
  }
}
opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/TracedStorage.java
@@ -95,6 +95,14 @@
    }
    @Override
    public long getRecordCount(TreeName name)
    {
      final long count = txn.getRecordCount(name);
      logger.trace("Storage.ReadableStorage.getRecordCount(%s, %s) = %d", backendId, name, count);
      return count;
    }
    @Override
    public ByteString getRMW(final TreeName name, final ByteSequence key)
    {
      final ByteString value = txn.getRMW(name, key);
@@ -155,6 +163,14 @@
    }
    @Override
    public long getRecordCount(TreeName name)
    {
      final long count = txn.getRecordCount(name);
      logger.trace("Storage.WriteableStorage.getRecordCount(%s, %s) = %d", backendId, name, count);
      return count;
    }
    @Override
    public ByteString getRMW(final TreeName name, final ByteSequence key)
    {
      final ByteString value = txn.getRMW(name, key);
opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/spi/ReadableStorage.java
@@ -66,4 +66,13 @@
   * @return a new cursor
   */
  Cursor openCursor(TreeName treeName);
  /**
   * Returns the number of key/value pairs in the provided tree.
   *
   * @param treeName
   *          the tree name
   * @return the number of key/value pairs in the provided tree.
   */
  long getRecordCount(TreeName treeName);
}