OPENDJ-1848: minor improvements to DatabaseContainer
* delegate implementation of DatabaseContainer.getRecordCount() to Storage impl
* added DatabaseContainer.delete() and fix all calls to WriteableStorage.deleteTree().
| | |
| | | } |
| | | |
| | | @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); |
| | |
| | | */ |
| | | 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; |
| | |
| | | } |
| | | |
| | | /** |
| | | * 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 |
| | |
| | | |
| | | 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); |
| | | } |
| | | |
| | | /** |
| | |
| | | |
| | | for (DatabaseContainer db : databases) |
| | | { |
| | | txn.deleteTree(db.getName()); |
| | | db.delete(txn); |
| | | } |
| | | } |
| | | |
| | |
| | | // The state database can not be removed individually. |
| | | return; |
| | | } |
| | | txn.deleteTree(database.getName()); |
| | | database.delete(txn); |
| | | if(database instanceof Index) |
| | | { |
| | | state.removeIndexTrustState(txn, database); |
| | |
| | | attributeIndex.close(); |
| | | for (Index index : attributeIndex.getAllIndexes()) |
| | | { |
| | | txn.deleteTree(index.getName()); |
| | | index.delete(txn); |
| | | state.removeIndexTrustState(txn, index); |
| | | } |
| | | } |
| | |
| | | { |
| | | for (DatabaseContainer db : databases) |
| | | { |
| | | txn.deleteTree(db.getName()); |
| | | db.delete(txn); |
| | | } |
| | | } |
| | | finally |
| | |
| | | { |
| | | try |
| | | { |
| | | txn.deleteTree(database.getName()); |
| | | database.delete(txn); |
| | | } |
| | | finally |
| | | { |
| | |
| | | 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; |
| | |
| | | EntryContainer entryContainer) throws StorageRuntimeException |
| | | { |
| | | super(name, indexer, state, 0, 0, false, txn, entryContainer); |
| | | state.putIndexTrustState(txn, this, false); |
| | | super.delete(txn); |
| | | } |
| | | |
| | | @Override |
| | |
| | | { |
| | | return 0; |
| | | } |
| | | |
| | | @Override |
| | | void delete(WriteableStorage txn) throws StorageRuntimeException |
| | | { |
| | | // Do nothing. |
| | | } |
| | | |
| | | @Override |
| | | void indexEntry(Entry entry, Set<ByteString> keys, IndexingOptions options) |
| | | { |
| | | // Do nothing. |
| | | } |
| | | |
| | | } |
| | |
| | | } |
| | | |
| | | @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); |
| | |
| | | } |
| | | |
| | | @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); |
| | |
| | | * @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); |
| | | } |