org.opends.server.backends.jeb
Class AttributeIndex

java.lang.Object
  extended by org.opends.server.backends.jeb.AttributeIndex
All Implemented Interfaces:
ConfigurationChangeListener<LocalDBIndexCfg>

public class AttributeIndex
extends java.lang.Object
implements ConfigurationChangeListener<LocalDBIndexCfg>

Class representing an attribute index. We have a separate database for each type of indexing, which makes it easy to tell which attribute indexes are configured. The different types of indexing are equality, presence, substrings and ordering. The keys in the ordering index are ordered by setting the btree comparator to the ordering matching rule comparator. Note that the values in the equality index are normalized by the equality matching rule, whereas the values in the ordering index are normalized by the ordering matching rule. If these could be guaranteed to be identical then we would not need a separate ordering index.


Nested Class Summary
static class AttributeIndex.KeyComparator
          The default lexicographic byte array comparator.
 
Field Summary
static com.sleepycat.je.DatabaseEntry presenceKey
          A database key for the presence index.
 
Constructor Summary
AttributeIndex(LocalDBIndexCfg indexConfig, State state, com.sleepycat.je.Environment env, EntryContainer entryContainer)
          Create a new attribute index object.
 
Method Summary
 boolean addEntry(IndexBuffer buffer, EntryID entryID, Entry entry)
          Update the attribute index for a new entry.
 boolean addEntry(com.sleepycat.je.Transaction txn, EntryID entryID, Entry entry)
          Update the attribute index for a new entry.
 ConfigChangeResult applyConfigurationChange(LocalDBIndexCfg cfg)
          Applies the configuration changes to this change listener.
 void close()
          Close the attribute index.
 EntryIDSet evaluateApproximateFilter(SearchFilter approximateFilter, java.lang.StringBuilder debugBuffer)
          Retrieve the entry IDs that might match an approximate filter.
 EntryIDSet evaluateBoundedRange(AttributeValue lowerValue, AttributeValue upperValue)
          Retrieve the entry IDs that might have a value greater than or equal to the lower bound value, and less than or equal to the upper bound value.
 EntryIDSet evaluateEqualityFilter(SearchFilter equalityFilter, java.lang.StringBuilder debugBuffer)
          Retrieve the entry IDs that might match an equality filter.
 EntryIDSet evaluateGreaterOrEqualFilter(SearchFilter filter, java.lang.StringBuilder debugBuffer)
          Retrieve the entry IDs that might match a greater-or-equal filter.
 EntryIDSet evaluateLessOrEqualFilter(SearchFilter filter, java.lang.StringBuilder debugBuffer)
          Retrieve the entry IDs that might match a less-or-equal filter.
 EntryIDSet evaluatePresenceFilter(SearchFilter filter, java.lang.StringBuilder debugBuffer)
          Retrieve the entry IDs that might match a presence filter.
 EntryIDSet evaluateSubstringFilter(SearchFilter filter, java.lang.StringBuilder debugBuffer)
          Retrieve the entry IDs that might match a substring filter.
 java.util.Collection<Index> getAllIndexes()
          Retrieves all the indexes used by this attribute index.
 Index getApproximateIndex()
          Return the approximate index.
 AttributeType getAttributeType()
          Get the attribute type of this attribute index.
 LocalDBIndexCfg getConfiguration()
          Get the JE index configuration used by this index.
 long getEntryLimitExceededCount()
          Return the number of values that have exceeded the entry limit since this object was created.
 Index getEqualityIndex()
          Return the equality index.
 java.lang.String getName()
          Get the JE database name prefix for indexes in this attribute index.
 Index getOrderingIndex()
          Return the ordering index.
 Index getPresenceIndex()
          Return the presence index.
 Index getSubstringIndex()
          Return the substring index.
 boolean isConfigurationChangeAcceptable(LocalDBIndexCfg cfg, java.util.List<Message> unacceptableReasons)
          Indicates whether the proposed change to the configuration is acceptable to this change listener.
 void listDatabases(java.util.List<DatabaseContainer> dbList)
          Get a list of the databases opened by this attribute index.
 void modifyEntry(IndexBuffer buffer, EntryID entryID, Entry oldEntry, Entry newEntry, java.util.List<Modification> mods)
          Update the index to reflect a sequence of modifications in a Modify operation.
 void modifyEntry(com.sleepycat.je.Transaction txn, EntryID entryID, Entry oldEntry, Entry newEntry, java.util.List<Modification> mods)
          Update the index to reflect a sequence of modifications in a Modify operation.
 void open()
          Open the attribute index.
 void removeEntry(IndexBuffer buffer, EntryID entryID, Entry entry)
          Update the attribute index for a deleted entry.
 void removeEntry(com.sleepycat.je.Transaction txn, EntryID entryID, Entry entry)
          Update the attribute index for a deleted entry.
 void setRebuildStatus(boolean rebuildRunning)
          Set the rebuild status of this index.
 void setTrusted(com.sleepycat.je.Transaction txn, boolean trusted)
          Set the index truststate.
 java.lang.String toString()
          Get a string representation of this object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

presenceKey

public static final com.sleepycat.je.DatabaseEntry presenceKey
A database key for the presence index.

Constructor Detail

AttributeIndex

public AttributeIndex(LocalDBIndexCfg indexConfig,
                      State state,
                      com.sleepycat.je.Environment env,
                      EntryContainer entryContainer)
               throws com.sleepycat.je.DatabaseException,
                      ConfigException
Create a new attribute index object.

Parameters:
entryContainer - The entryContainer of this attribute index.
state - The state database to persist index state info.
env - The JE environment handle.
indexConfig - The attribute index configuration.
Throws:
com.sleepycat.je.DatabaseException - if a JE database error occurs.
ConfigException - if a configuration related error occurs.
Method Detail

open

public void open()
          throws com.sleepycat.je.DatabaseException
Open the attribute index.

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 attribute index.

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

getAttributeType

public AttributeType getAttributeType()
Get the attribute type of this attribute index.

Returns:
The attribute type of this attribute index.

getConfiguration

public LocalDBIndexCfg getConfiguration()
Get the JE index configuration used by this index.

Returns:
The configuration in effect.

addEntry

public boolean addEntry(IndexBuffer buffer,
                        EntryID entryID,
                        Entry entry)
                 throws com.sleepycat.je.DatabaseException,
                        DirectoryException,
                        JebException
Update the attribute index for a new entry.

Parameters:
buffer - The index buffer to use to store the added keys
entryID - The entry ID.
entry - The contents of the new entry.
Returns:
True if all the index keys for the entry are added. False if the entry ID already exists for some keys.
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(com.sleepycat.je.Transaction txn,
                        EntryID entryID,
                        Entry entry)
                 throws com.sleepycat.je.DatabaseException,
                        DirectoryException,
                        JebException
Update the attribute index for a new entry.

Parameters:
txn - The database transaction to be used for the insertions.
entryID - The entry ID.
entry - The contents of the new entry.
Returns:
True if all the index keys for the entry are added. False if the entry ID already exists for some keys.
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 void removeEntry(IndexBuffer buffer,
                        EntryID entryID,
                        Entry entry)
                 throws com.sleepycat.je.DatabaseException,
                        DirectoryException,
                        JebException
Update the attribute index for a deleted entry.

Parameters:
buffer - The index buffer to use to store the deleted keys
entryID - The entry ID
entry - The contents of the deleted entry.
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 void removeEntry(com.sleepycat.je.Transaction txn,
                        EntryID entryID,
                        Entry entry)
                 throws com.sleepycat.je.DatabaseException,
                        DirectoryException,
                        JebException
Update the attribute index 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.
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.

modifyEntry

public void modifyEntry(com.sleepycat.je.Transaction txn,
                        EntryID entryID,
                        Entry oldEntry,
                        Entry newEntry,
                        java.util.List<Modification> mods)
                 throws com.sleepycat.je.DatabaseException
Update the index 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.
Throws:
com.sleepycat.je.DatabaseException - If an error occurs during an operation on a JE database.

modifyEntry

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

Parameters:
buffer - The index buffer used to buffer up the index changes.
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.
Throws:
com.sleepycat.je.DatabaseException - If an error occurs during an operation on a JE database.

evaluateEqualityFilter

public EntryIDSet evaluateEqualityFilter(SearchFilter equalityFilter,
                                         java.lang.StringBuilder debugBuffer)
Retrieve the entry IDs that might match an equality filter.

Parameters:
equalityFilter - The equality filter.
debugBuffer - If not null, a diagnostic string will be written which will help determine how the indexes contributed to this search.
Returns:
The candidate entry IDs that might contain the filter assertion value.

evaluatePresenceFilter

public EntryIDSet evaluatePresenceFilter(SearchFilter filter,
                                         java.lang.StringBuilder debugBuffer)
Retrieve the entry IDs that might match a presence filter.

Parameters:
filter - The presence filter.
debugBuffer - If not null, a diagnostic string will be written which will help determine how the indexes contributed to this search.
Returns:
The candidate entry IDs that might contain one or more values of the attribute type in the filter.

evaluateGreaterOrEqualFilter

public EntryIDSet evaluateGreaterOrEqualFilter(SearchFilter filter,
                                               java.lang.StringBuilder debugBuffer)
Retrieve the entry IDs that might match a greater-or-equal filter.

Parameters:
filter - The greater-or-equal filter.
debugBuffer - If not null, a diagnostic string will be written which will help determine how the indexes contributed to this search.
Returns:
The candidate entry IDs that might contain a value greater than or equal to the filter assertion value.

evaluateLessOrEqualFilter

public EntryIDSet evaluateLessOrEqualFilter(SearchFilter filter,
                                            java.lang.StringBuilder debugBuffer)
Retrieve the entry IDs that might match a less-or-equal filter.

Parameters:
filter - The less-or-equal filter.
debugBuffer - If not null, a diagnostic string will be written which will help determine how the indexes contributed to this search.
Returns:
The candidate entry IDs that might contain a value less than or equal to the filter assertion value.

evaluateSubstringFilter

public EntryIDSet evaluateSubstringFilter(SearchFilter filter,
                                          java.lang.StringBuilder debugBuffer)
Retrieve the entry IDs that might match a substring filter.

Parameters:
filter - The substring filter.
debugBuffer - If not null, a diagnostic string will be written which will help determine how the indexes contributed to this search.
Returns:
The candidate entry IDs that might contain a value that matches the filter substrings.

evaluateBoundedRange

public EntryIDSet evaluateBoundedRange(AttributeValue lowerValue,
                                       AttributeValue upperValue)
Retrieve the entry IDs that might have a value greater than or equal to the lower bound value, and less than or equal to the upper bound value.

Parameters:
lowerValue - The lower bound value
upperValue - The upper bound value
Returns:
The candidate entry IDs.

evaluateApproximateFilter

public EntryIDSet evaluateApproximateFilter(SearchFilter approximateFilter,
                                            java.lang.StringBuilder debugBuffer)
Retrieve the entry IDs that might match an approximate filter.

Parameters:
approximateFilter - The approximate filter.
debugBuffer - If not null, a diagnostic string will be written which will help determine how the indexes contributed to this search.
Returns:
The candidate entry IDs that might contain the filter assertion value.

getEntryLimitExceededCount

public long getEntryLimitExceededCount()
Return the number of values that have exceeded the entry limit since this object was created.

Returns:
The number of values that have exceeded the entry limit.

listDatabases

public void listDatabases(java.util.List<DatabaseContainer> dbList)
Get a list of the databases opened by this attribute index.

Parameters:
dbList - A list of database containers.

toString

public java.lang.String toString()
Get a string representation of this object.

Overrides:
toString in class java.lang.Object
Returns:
return A string representation of this object.

isConfigurationChangeAcceptable

public boolean isConfigurationChangeAcceptable(LocalDBIndexCfg 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<LocalDBIndexCfg>
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(LocalDBIndexCfg cfg)
Applies the configuration changes to this change listener.

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

setTrusted

public void setTrusted(com.sleepycat.je.Transaction txn,
                       boolean trusted)
                throws com.sleepycat.je.DatabaseException
Set the index truststate.

Parameters:
txn - A database transaction, or null if none is required.
trusted - True if this index 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 index.

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

getName

public java.lang.String getName()
Get the JE database name prefix for indexes in this attribute index.

Returns:
JE database name for this database container.

getEqualityIndex

public Index getEqualityIndex()
Return the equality index.

Returns:
The equality index.

getApproximateIndex

public Index getApproximateIndex()
Return the approximate index.

Returns:
The approximate index.

getOrderingIndex

public Index getOrderingIndex()
Return the ordering index.

Returns:
The ordering index.

getSubstringIndex

public Index getSubstringIndex()
Return the substring index.

Returns:
The substring index.

getPresenceIndex

public Index getPresenceIndex()
Return the presence index.

Returns:
The presence index.

getAllIndexes

public java.util.Collection<Index> getAllIndexes()
Retrieves all the indexes used by this attribute index.

Returns:
A collection of all indexes in use by this attribute index.