org.opends.server.backends.jeb
Class VLVIndex

java.lang.Object
  extended by org.opends.server.backends.jeb.DatabaseContainer
      extended by org.opends.server.backends.jeb.VLVIndex
All Implemented Interfaces:
ConfigurationChangeListener<LocalDBVLVIndexCfg>

public class VLVIndex
extends DatabaseContainer
implements ConfigurationChangeListener<LocalDBVLVIndexCfg>

This class represents a VLV index. Each database record is a sorted list of entry IDs followed by sets of attribute values used to sort the entries. The entire set of entry IDs are broken up into sorted subsets to decrease the number of database retrivals needed for a range lookup. The records are keyed by the last entry's first sort attribute value. The list of entries in a particular database record maintains the property where the first sort attribute value is bigger then the previous key but smaller or equal to its own key.


Field Summary
 VLVKeyComparator comparator
          The comparator for vlvIndex keys.
 SortOrder sortOrder
          The SortOrder in use by this VLV index to sort the entries.
 
Fields inherited from class org.opends.server.backends.jeb.DatabaseContainer
dbConfig, entryContainer, name
 
Constructor Summary
VLVIndex(LocalDBVLVIndexCfg config, State state, com.sleepycat.je.Environment env, EntryContainer entryContainer)
          Create a new VLV vlvIndex object.
 
Method Summary
 boolean addEntry(IndexBuffer buffer, EntryID entryID, Entry entry)
          Update the vlvIndex for a new entry.
 boolean addEntry(com.sleepycat.je.Transaction txn, EntryID entryID, Entry entry)
          Update the vlvIndex for a new entry.
 ConfigChangeResult applyConfigurationChange(LocalDBVLVIndexCfg cfg)
          Applies the configuration changes to this change listener.
 void close()
          Close the VLV index.
 boolean containsValues(com.sleepycat.je.Transaction txn, long entryID, AttributeValue[] values)
          Search for entries matching the entry ID and attribute values and return its entry ID.
 EntryIDSet evaluate(com.sleepycat.je.Transaction txn, SearchOperation searchOperation, ServerSideSortRequestControl sortControl, VLVRequestControl vlvRequest, java.lang.StringBuilder debugBuilder)
          Evaluate a search with sort control using this VLV index.
 int getSortedSetCapacity()
          Get the sorted set capacity configured for this VLV index.
 SortValuesSet getSortValuesSet(com.sleepycat.je.Transaction txn, long entryID, AttributeValue[] values)
          Get a sorted values set that should contain the entry with the given information.
 boolean isConfigurationChangeAcceptable(LocalDBVLVIndexCfg cfg, java.util.List<Message> unacceptableReasons)
          Indicates whether the proposed change to the configuration is acceptable to this change listener.
 boolean modifyEntry(IndexBuffer buffer, EntryID entryID, Entry oldEntry, Entry newEntry, java.util.List<Modification> mods)
          Update the vlvIndex to reflect a sequence of modifications in a Modify operation.
 boolean modifyEntry(com.sleepycat.je.Transaction txn, EntryID entryID, Entry oldEntry, Entry newEntry, java.util.List<Modification> mods)
          Update the vlvIndex to reflect a sequence of modifications in a Modify operation.
 void open()
          Opens a JE database in this database container.
 boolean putSortValuesSet(com.sleepycat.je.Transaction txn, SortValuesSet sortValuesSet)
          Put a sort values set in this VLV index.
 boolean removeEntry(IndexBuffer buffer, EntryID entryID, Entry entry)
          Update the vlvIndex for a deleted entry.
 boolean removeEntry(com.sleepycat.je.Transaction txn, EntryID entryID, Entry entry)
          Update the vlvIndex for a deleted entry.
 void setRebuildStatus(boolean rebuildRunning)
          Set the rebuild status of this vlvIndex.
 void setTrusted(com.sleepycat.je.Transaction txn, boolean trusted)
          Set the vlvIndex trust state.
 boolean shouldInclude(Entry entry)
          Indicates if the given entry should belong in this VLV index.
 void updateIndex(com.sleepycat.je.Transaction txn, java.util.TreeSet<SortValues> addedValues, java.util.TreeSet<SortValues> deletedValues)
          Update the vlvIndex with the specified values to add and delete.
 
Methods inherited from class org.opends.server.backends.jeb.DatabaseContainer
delete, getName, getRecordCount, insert, openCursor, preload, put, read, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

comparator

public VLVKeyComparator comparator
The comparator for vlvIndex keys.


sortOrder

public SortOrder sortOrder
The SortOrder in use by this VLV index to sort the entries.

Constructor Detail

VLVIndex

public VLVIndex(LocalDBVLVIndexCfg config,
                State state,
                com.sleepycat.je.Environment env,
                EntryContainer entryContainer)
         throws com.sleepycat.je.DatabaseException,
                ConfigException
Create a new VLV vlvIndex object.

Parameters:
config - The VLV index config object to use for this VLV index.
state - The state database to persist vlvIndex state info.
env - The JE Environemnt
entryContainer - The database entryContainer holding this vlvIndex.
Throws:
com.sleepycat.je.DatabaseException - If an error occurs in the JE database.
ConfigException - if a error occurs while reading the VLV index configuration
Method Detail

open

public void open()
          throws com.sleepycat.je.DatabaseException
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.

Overrides:
open in class DatabaseContainer
Throws:
com.sleepycat.je.DatabaseException - if a JE database error occurs while openning the index.

close

public void close()
           throws com.sleepycat.je.DatabaseException
Close the VLV index.

Throws:
com.sleepycat.je.DatabaseException - if a JE database error occurs while closing the index.

addEntry

public boolean addEntry(com.sleepycat.je.Transaction txn,
                        EntryID entryID,
                        Entry entry)
                 throws com.sleepycat.je.DatabaseException,
                        DirectoryException,
                        JebException
Update the vlvIndex for a new entry.

Parameters:
txn - A database transaction, or null if none is required.
entryID - The entry ID.
entry - The entry to be indexed.
Returns:
True if the entry ID for the entry are added. False if the entry ID already exists.
Throws:
com.sleepycat.je.DatabaseException - If an error occurs in the JE database.
DirectoryException - If a Directory Server error occurs.
JebException - If an error occurs in the JE backend.

addEntry

public boolean addEntry(IndexBuffer buffer,
                        EntryID entryID,
                        Entry entry)
                 throws DirectoryException
Update the vlvIndex for a new entry.

Parameters:
buffer - The index buffer to buffer the changes.
entryID - The entry ID.
entry - The entry to be indexed.
Returns:
True if the entry ID for the entry are added. False if the entry ID already exists.
Throws:
DirectoryException - If a Directory Server error occurs.

removeEntry

public boolean removeEntry(com.sleepycat.je.Transaction txn,
                           EntryID entryID,
                           Entry entry)
                    throws com.sleepycat.je.DatabaseException,
                           DirectoryException,
                           JebException
Update the vlvIndex for a deleted entry.

Parameters:
txn - The database transaction to be used for the deletions
entryID - The entry ID
entry - The contents of the deleted entry.
Returns:
True if the entry was successfully removed from this VLV index or False otherwise.
Throws:
com.sleepycat.je.DatabaseException - If an error occurs in the JE database.
DirectoryException - If a Directory Server error occurs.
JebException - If an error occurs in the JE backend.

removeEntry

public boolean removeEntry(IndexBuffer buffer,
                           EntryID entryID,
                           Entry entry)
                    throws DirectoryException
Update the vlvIndex for a deleted entry.

Parameters:
buffer - The database transaction to be used for the deletions
entryID - The entry ID
entry - The contents of the deleted entry.
Returns:
True if the entry was successfully removed from this VLV index or False otherwise.
Throws:
DirectoryException - If a Directory Server error occurs.

modifyEntry

public boolean modifyEntry(com.sleepycat.je.Transaction txn,
                           EntryID entryID,
                           Entry oldEntry,
                           Entry newEntry,
                           java.util.List<Modification> mods)
                    throws com.sleepycat.je.DatabaseException,
                           DirectoryException,
                           JebException
Update the vlvIndex to reflect a sequence of modifications in a Modify operation.

Parameters:
txn - The JE transaction to use for database updates.
entryID - The ID of the entry that was modified.
oldEntry - The entry before the modifications were applied.
newEntry - The entry after the modifications were applied.
mods - The sequence of modifications in the Modify operation.
Returns:
True if the modification was successfully processed or False otherwise.
Throws:
JebException - If an error occurs during an operation on a JE database.
com.sleepycat.je.DatabaseException - If an error occurs during an operation on a JE database.
DirectoryException - If a Directory Server error occurs.

modifyEntry

public boolean modifyEntry(IndexBuffer buffer,
                           EntryID entryID,
                           Entry oldEntry,
                           Entry newEntry,
                           java.util.List<Modification> mods)
                    throws com.sleepycat.je.DatabaseException,
                           DirectoryException,
                           JebException
Update the vlvIndex to reflect a sequence of modifications in a Modify operation.

Parameters:
buffer - The database transaction to be used for the deletions
entryID - The ID of the entry that was modified.
oldEntry - The entry before the modifications were applied.
newEntry - The entry after the modifications were applied.
mods - The sequence of modifications in the Modify operation.
Returns:
True if the modification was successfully processed or False otherwise.
Throws:
JebException - If an error occurs during an operation on a JE database.
com.sleepycat.je.DatabaseException - If an error occurs during an operation on a JE database.
DirectoryException - If a Directory Server error occurs.

putSortValuesSet

public boolean putSortValuesSet(com.sleepycat.je.Transaction txn,
                                SortValuesSet sortValuesSet)
                         throws JebException,
                                com.sleepycat.je.DatabaseException,
                                DirectoryException
Put a sort values set in this VLV index.

Parameters:
txn - The transaction to use when retriving the set or NULL if it is not required.
sortValuesSet - The SortValuesSet to put.
Returns:
True if the sortValuesSet was put successfully or False otherwise.
Throws:
JebException - If an error occurs during an operation on a JE database.
com.sleepycat.je.DatabaseException - If an error occurs during an operation on a JE database.
DirectoryException - If a Directory Server error occurs.

getSortValuesSet

public SortValuesSet getSortValuesSet(com.sleepycat.je.Transaction txn,
                                      long entryID,
                                      AttributeValue[] values)
                               throws com.sleepycat.je.DatabaseException,
                                      DirectoryException
Get a sorted values set that should contain the entry with the given information.

Parameters:
txn - The transaction to use when retriving the set or NULL if it is not required.
entryID - The entry ID to use.
values - The values to use.
Returns:
The SortValuesSet that should contain the entry with the given information.
Throws:
com.sleepycat.je.DatabaseException - If an error occurs during an operation on a JE database.
DirectoryException - If a Directory Server error occurs.

containsValues

public boolean containsValues(com.sleepycat.je.Transaction txn,
                              long entryID,
                              AttributeValue[] values)
                       throws JebException,
                              com.sleepycat.je.DatabaseException,
                              DirectoryException
Search for entries matching the entry ID and attribute values and return its entry ID.

Parameters:
txn - The JE transaction to use for database updates.
entryID - The entry ID to search for.
values - The values to search for.
Returns:
The index of the entry ID matching the values or -1 if its not found.
Throws:
com.sleepycat.je.DatabaseException - If an error occurs during an operation on a JE database.
JebException - If an error occurs during an operation on a JE database.
DirectoryException - If a Directory Server error occurs.

updateIndex

public void updateIndex(com.sleepycat.je.Transaction txn,
                        java.util.TreeSet<SortValues> addedValues,
                        java.util.TreeSet<SortValues> deletedValues)
                 throws DirectoryException,
                        com.sleepycat.je.DatabaseException,
                        JebException
Update the vlvIndex with the specified values to add and delete.

Parameters:
txn - A database transaction, or null if none is required.
addedValues - The values to add to the VLV index.
deletedValues - The values to delete from the VLV index.
Throws:
com.sleepycat.je.DatabaseException - If an error occurs in the JE database.
DirectoryException - If a Directory Server error occurs.
JebException - If an error occurs in the JE backend.

evaluate

public EntryIDSet evaluate(com.sleepycat.je.Transaction txn,
                           SearchOperation searchOperation,
                           ServerSideSortRequestControl sortControl,
                           VLVRequestControl vlvRequest,
                           java.lang.StringBuilder debugBuilder)
                    throws DirectoryException,
                           com.sleepycat.je.DatabaseException,
                           JebException
Evaluate a search with sort control using this VLV index.

Parameters:
txn - The transaction to used when reading the index or NULL if it is not required.
searchOperation - The search operation to evaluate.
sortControl - The sort request control to evaluate.
vlvRequest - The VLV request control to evaluate or NULL if VLV is not requested.
debugBuilder - If not null, a diagnostic string will be written which will help determine how this index contributed to this search.
Returns:
The sorted EntryIDSet containing the entry IDs that match the search criteria.
Throws:
DirectoryException - If a Directory Server error occurs.
com.sleepycat.je.DatabaseException - If an error occurs in the JE database.
JebException - If an error occurs in the JE database.

setTrusted

public void setTrusted(com.sleepycat.je.Transaction txn,
                       boolean trusted)
                throws com.sleepycat.je.DatabaseException
Set the vlvIndex trust state.

Parameters:
txn - A database transaction, or null if none is required.
trusted - True if this vlvIndex should be trusted or false otherwise.
Throws:
com.sleepycat.je.DatabaseException - If an error occurs in the JE database.

setRebuildStatus

public void setRebuildStatus(boolean rebuildRunning)
Set the rebuild status of this vlvIndex.

Parameters:
rebuildRunning - True if a rebuild process on this vlvIndex is running or False otherwise.

getSortedSetCapacity

public int getSortedSetCapacity()
Get the sorted set capacity configured for this VLV index.

Returns:
The sorted set capacity.

shouldInclude

public boolean shouldInclude(Entry entry)
                      throws DirectoryException
Indicates if the given entry should belong in this VLV index.

Parameters:
entry - The entry to check.
Returns:
True if the given entry should belong in this VLV index or False otherwise.
Throws:
DirectoryException - If a Directory Server error occurs.

isConfigurationChangeAcceptable

public boolean isConfigurationChangeAcceptable(LocalDBVLVIndexCfg cfg,
                                               java.util.List<Message> unacceptableReasons)
Indicates whether the proposed change to the configuration is acceptable to this change listener.

Specified by:
isConfigurationChangeAcceptable in interface ConfigurationChangeListener<LocalDBVLVIndexCfg>
Parameters:
cfg - The new configuration containing the changes.
unacceptableReasons - A list that can be used to hold messages about why the provided configuration is not acceptable.
Returns:
Returns true if the proposed change is acceptable, or false if it is not.

applyConfigurationChange

public ConfigChangeResult applyConfigurationChange(LocalDBVLVIndexCfg cfg)
Applies the configuration changes to this change listener.

Specified by:
applyConfigurationChange in interface ConfigurationChangeListener<LocalDBVLVIndexCfg>
Parameters:
cfg - The new configuration containing the changes.
Returns:
Returns information about the result of changing the configuration.