org.apache.directory.server.core.partition.impl.btree.jdbm
Class JdbmIndex<K,O>

java.lang.Object
  extended by org.apache.directory.server.core.partition.impl.btree.jdbm.JdbmIndex<K,O>
All Implemented Interfaces:
Index<K,O,java.lang.Long>

public class JdbmIndex<K,O>
extends java.lang.Object
implements Index<K,O,java.lang.Long>

A Jdbm based index implementation.

Version:
$Rev: 928296 $
Author:
Apache Directory Project
XBean

Field Summary
protected  int cacheSize
          the size (number of index entries) for the cache
static int DEFAULT_DUPLICATE_LIMIT
          default duplicate limit before duplicate keys switch to using a btree for values
protected  JdbmTable<K,java.lang.Long> forward
          the forward btree where the btree key is the value of the indexed attribute and the value of the btree is the entry id of the entry containing an attribute with that value
static java.lang.String FORWARD_BTREE
          the key used for the forward btree name
protected  boolean initialized
          whether or not this index has been initialized
protected  org.apache.directory.shared.ldap.util.SynchronizedLRUMap keyCache
          the normalized value cache for this index
protected  int numDupLimit
          duplicate limit before duplicate keys switch to using a btree for values
protected  RecordManager recMan
          the JDBM record manager for the file containing this index
protected  JdbmTable<java.lang.Long,K> reverse
          the reverse btree where the btree key is the entry id of the entry containing a value for the indexed attribute, and the btree value is the value of the indexed attribute
static java.lang.String REVERSE_BTREE
          the key used for the reverse btree name
protected  java.io.File wkDirPath
          a custom working directory path when specified in configuration
 
Fields inherited from interface org.apache.directory.server.xdbm.Index
DEFAULT_INDEX_CACHE_SIZE
 
Constructor Summary
JdbmIndex()
           
JdbmIndex(java.lang.String attributeId)
           
 
Method Summary
 void add(K attrVal, java.lang.Long id)
           
 void close()
           
 int count()
          Gets the total scan count for this index.
 int count(K attrVal)
          Gets the scan count for the occurance of a specific attribute value within the index.
 void drop(K attrVal, java.lang.Long id)
           
 void drop(java.lang.Long entryId)
          Remove all the reference to an entry from the index.
 boolean forward(K attrVal)
           
 boolean forward(K attrVal, java.lang.Long id)
           
 IndexCursor<K,O,java.lang.Long> forwardCursor()
           
 IndexCursor<K,O,java.lang.Long> forwardCursor(K key)
           
 boolean forwardGreaterOrEq(K attrVal)
           
 boolean forwardGreaterOrEq(K attrVal, java.lang.Long id)
           
 boolean forwardLessOrEq(K attrVal)
           
 boolean forwardLessOrEq(K attrVal, java.lang.Long id)
           
 java.lang.Long forwardLookup(K attrVal)
           
 org.apache.directory.shared.ldap.cursor.Cursor<java.lang.Long> forwardValueCursor(K key)
           
 org.apache.directory.shared.ldap.schema.AttributeType getAttribute()
          Gets the attribute this Index is built upon.
 java.lang.String getAttributeId()
          Gets the attribute identifier set at configuration time for this index which may not be the OID but an alias name for the attributeType associated with this Index
 int getCacheSize()
          Gets the size of the index cache in terms of the number of index entries to be cached.
 K getNormalized(K attrVal)
          TODO I don't think the keyCache is required anymore since the normalizer will cache values for us.
 int getNumDupLimit()
          Gets the threshold at which point duplicate keys use btree indirection to store their values.
 java.io.File getWkDirPath()
          Gets the working directory path to something other than the default.
 int greaterThanCount(K attrVal)
           
 void init(org.apache.directory.shared.ldap.schema.SchemaManager schemaManager, org.apache.directory.shared.ldap.schema.AttributeType attributeType, java.io.File wkDirPath)
           
 boolean isCountExact()
          Checks whether or not calls to count the number of keys greater than or less than the key are exact.
 int lessThanCount(K attrVal)
           
 boolean reverse(java.lang.Long id)
           
 boolean reverse(java.lang.Long id, K attrVal)
           
 IndexCursor<K,O,java.lang.Long> reverseCursor()
           
 IndexCursor<K,O,java.lang.Long> reverseCursor(java.lang.Long id)
           
 boolean reverseGreaterOrEq(java.lang.Long id)
           
 boolean reverseGreaterOrEq(java.lang.Long id, K attrVal)
           
 boolean reverseLessOrEq(java.lang.Long id)
           
 boolean reverseLessOrEq(java.lang.Long id, K attrVal)
           
 K reverseLookup(java.lang.Long id)
           
 org.apache.directory.shared.ldap.cursor.Cursor<K> reverseValueCursor(java.lang.Long id)
           
 void setAttributeId(java.lang.String attributeId)
          Sets the attribute identifier set at configuration time for this index which may not be the OID but an alias name for the attributeType associated with this Index
 void setCacheSize(int cacheSize)
          Sets the size of the index cache in terms of the number of index entries to be cached.
 void setNumDupLimit(int numDupLimit)
          Sets the threshold at which point duplicate keys use btree indirection to store their values.
 void setWkDirPath(java.io.File wkDirPath)
          Sets the working directory path to something other than the default.
 void sync()
           
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DEFAULT_DUPLICATE_LIMIT

public static final int DEFAULT_DUPLICATE_LIMIT
default duplicate limit before duplicate keys switch to using a btree for values

See Also:
Constant Field Values

FORWARD_BTREE

public static final java.lang.String FORWARD_BTREE
the key used for the forward btree name

See Also:
Constant Field Values

REVERSE_BTREE

public static final java.lang.String REVERSE_BTREE
the key used for the reverse btree name

See Also:
Constant Field Values

forward

protected JdbmTable<K,java.lang.Long> forward
the forward btree where the btree key is the value of the indexed attribute and the value of the btree is the entry id of the entry containing an attribute with that value


reverse

protected JdbmTable<java.lang.Long,K> reverse
the reverse btree where the btree key is the entry id of the entry containing a value for the indexed attribute, and the btree value is the value of the indexed attribute


recMan

protected RecordManager recMan
the JDBM record manager for the file containing this index


keyCache

protected org.apache.directory.shared.ldap.util.SynchronizedLRUMap keyCache
the normalized value cache for this index

TODO
I don't think the keyCache is required anymore since the normalizer will cache values for us.

cacheSize

protected int cacheSize
the size (number of index entries) for the cache


numDupLimit

protected int numDupLimit
duplicate limit before duplicate keys switch to using a btree for values


initialized

protected boolean initialized
whether or not this index has been initialized


wkDirPath

protected java.io.File wkDirPath
a custom working directory path when specified in configuration

Constructor Detail

JdbmIndex

public JdbmIndex()

JdbmIndex

public JdbmIndex(java.lang.String attributeId)
Method Detail

init

public void init(org.apache.directory.shared.ldap.schema.SchemaManager schemaManager,
                 org.apache.directory.shared.ldap.schema.AttributeType attributeType,
                 java.io.File wkDirPath)
          throws java.io.IOException
Throws:
java.io.IOException

getAttribute

public org.apache.directory.shared.ldap.schema.AttributeType getAttribute()
Description copied from interface: Index
Gets the attribute this Index is built upon.

Specified by:
getAttribute in interface Index<K,O,java.lang.Long>
Returns:
the id of the Index's attribute
See Also:
Index.getAttribute()

isCountExact

public boolean isCountExact()
Description copied from interface: Index
Checks whether or not calls to count the number of keys greater than or less than the key are exact. Checking to see the number of values greater than or less than some key may be excessively costly. Since this is not a critical function but one that assists in optimizing searches some implementations can just return a worst case (maximum) guess.

Specified by:
isCountExact in interface Index<K,O,java.lang.Long>
Returns:
true if the count is an exact value or a worst case guess

getAttributeId

public java.lang.String getAttributeId()
Gets the attribute identifier set at configuration time for this index which may not be the OID but an alias name for the attributeType associated with this Index

Specified by:
getAttributeId in interface Index<K,O,java.lang.Long>
Returns:
configured attribute oid or alias name

setAttributeId

public void setAttributeId(java.lang.String attributeId)
Sets the attribute identifier set at configuration time for this index which may not be the OID but an alias name for the attributeType associated with this Index

Specified by:
setAttributeId in interface Index<K,O,java.lang.Long>
Parameters:
attributeId - configured attribute oid or alias name

getNumDupLimit

public int getNumDupLimit()
Gets the threshold at which point duplicate keys use btree indirection to store their values.

Returns:
the threshold for storing a keys values in another btree

setNumDupLimit

public void setNumDupLimit(int numDupLimit)
Sets the threshold at which point duplicate keys use btree indirection to store their values.

Parameters:
numDupLimit - the threshold for storing a keys values in another btree

getCacheSize

public int getCacheSize()
Gets the size of the index cache in terms of the number of index entries to be cached.

Specified by:
getCacheSize in interface Index<K,O,java.lang.Long>
Returns:
the size of the index cache

setCacheSize

public void setCacheSize(int cacheSize)
Sets the size of the index cache in terms of the number of index entries to be cached.

Specified by:
setCacheSize in interface Index<K,O,java.lang.Long>
Parameters:
cacheSize - the size of the index cache

setWkDirPath

public void setWkDirPath(java.io.File wkDirPath)
Sets the working directory path to something other than the default. Sometimes more performance is gained by locating indices on separate disk spindles.

Specified by:
setWkDirPath in interface Index<K,O,java.lang.Long>
Parameters:
wkDirPath - optional working directory path

getWkDirPath

public java.io.File getWkDirPath()
Gets the working directory path to something other than the default. Sometimes more performance is gained by locating indices on separate disk spindles.

Specified by:
getWkDirPath in interface Index<K,O,java.lang.Long>
Returns:
optional working directory path

count

public int count()
          throws java.io.IOException
Description copied from interface: Index
Gets the total scan count for this index.

Specified by:
count in interface Index<K,O,java.lang.Long>
Returns:
the number of key/value pairs in this index
Throws:
java.io.IOException
See Also:
Index.count()

count

public int count(K attrVal)
          throws java.lang.Exception
Description copied from interface: Index
Gets the scan count for the occurance of a specific attribute value within the index.

Specified by:
count in interface Index<K,O,java.lang.Long>
Parameters:
attrVal - the value of the attribute to get a scan count for
Returns:
the number of key/value pairs in this index with the value value
Throws:
java.lang.Exception - on failure to access index db files
See Also:
Index.count(java.lang.Object)

greaterThanCount

public int greaterThanCount(K attrVal)
                     throws java.lang.Exception
Specified by:
greaterThanCount in interface Index<K,O,java.lang.Long>
Throws:
java.lang.Exception

lessThanCount

public int lessThanCount(K attrVal)
                  throws java.lang.Exception
Specified by:
lessThanCount in interface Index<K,O,java.lang.Long>
Throws:
java.lang.Exception
See Also:
Index.lessThanCount(java.lang.Object)

forwardLookup

public java.lang.Long forwardLookup(K attrVal)
                             throws java.lang.Exception
Specified by:
forwardLookup in interface Index<K,O,java.lang.Long>
Throws:
java.lang.Exception
See Also:
Index.forwardLookup(java.lang.Object)

reverseLookup

public K reverseLookup(java.lang.Long id)
                throws java.lang.Exception
Specified by:
reverseLookup in interface Index<K,O,java.lang.Long>
Throws:
java.lang.Exception
See Also:
org.apache.directory.server.xdbm.Index#reverseLookup(Long)

add

public void add(K attrVal,
                java.lang.Long id)
         throws java.lang.Exception
Specified by:
add in interface Index<K,O,java.lang.Long>
Throws:
java.lang.Exception
See Also:
Index#add(Object, Long)

drop

public void drop(K attrVal,
                 java.lang.Long id)
          throws java.lang.Exception
Specified by:
drop in interface Index<K,O,java.lang.Long>
Throws:
java.lang.Exception
See Also:
Index#drop(Object,Long)

drop

public void drop(java.lang.Long entryId)
          throws java.lang.Exception
Remove all the reference to an entry from the index. As an entry might be referenced more than once in the forward index, depending on which index we are dealing with, we need to iterate over all the values contained into the reverse index for this entryId. For instance, considering the ObjectClass index for an entry having three ObjectClasses (top, person, inetOrgPerson), then the reverse index will contain : [entryId, [top, person, inetOrgPerson]] and the forward index will contain many entries like : [top, [..., entryId, ...]] [person, [..., entryId, ...]] [inetOrgPerson, [..., entryId, ...]] So dropping the entryId means that we must first get all the values from the reverse index (and we will get [top, person, inetOrgPerson]) then to iterate through all those values to remove entryId from the associated list of entryIds.

Specified by:
drop in interface Index<K,O,java.lang.Long>
Parameters:
entryId - The master table entry ID to remove
Throws:
java.lang.Exception

reverseCursor

public IndexCursor<K,O,java.lang.Long> reverseCursor()
                                              throws java.lang.Exception
Specified by:
reverseCursor in interface Index<K,O,java.lang.Long>
Throws:
java.lang.Exception

forwardCursor

public IndexCursor<K,O,java.lang.Long> forwardCursor()
                                              throws java.lang.Exception
Specified by:
forwardCursor in interface Index<K,O,java.lang.Long>
Throws:
java.lang.Exception

reverseCursor

public IndexCursor<K,O,java.lang.Long> reverseCursor(java.lang.Long id)
                                              throws java.lang.Exception
Specified by:
reverseCursor in interface Index<K,O,java.lang.Long>
Throws:
java.lang.Exception

forwardCursor

public IndexCursor<K,O,java.lang.Long> forwardCursor(K key)
                                              throws java.lang.Exception
Specified by:
forwardCursor in interface Index<K,O,java.lang.Long>
Throws:
java.lang.Exception

reverseValueCursor

public org.apache.directory.shared.ldap.cursor.Cursor<K> reverseValueCursor(java.lang.Long id)
                                                                     throws java.lang.Exception
Specified by:
reverseValueCursor in interface Index<K,O,java.lang.Long>
Throws:
java.lang.Exception

forwardValueCursor

public org.apache.directory.shared.ldap.cursor.Cursor<java.lang.Long> forwardValueCursor(K key)
                                                                                  throws java.lang.Exception
Specified by:
forwardValueCursor in interface Index<K,O,java.lang.Long>
Throws:
java.lang.Exception

forward

public boolean forward(K attrVal)
                throws java.lang.Exception
Specified by:
forward in interface Index<K,O,java.lang.Long>
Throws:
java.lang.Exception
See Also:
Index.forward(Object)

forward

public boolean forward(K attrVal,
                       java.lang.Long id)
                throws java.lang.Exception
Specified by:
forward in interface Index<K,O,java.lang.Long>
Throws:
java.lang.Exception
See Also:
Index#forward(Object,Long)

reverse

public boolean reverse(java.lang.Long id)
                throws java.lang.Exception
Specified by:
reverse in interface Index<K,O,java.lang.Long>
Throws:
java.lang.Exception
See Also:
Index#reverse(Long)

reverse

public boolean reverse(java.lang.Long id,
                       K attrVal)
                throws java.lang.Exception
Specified by:
reverse in interface Index<K,O,java.lang.Long>
Throws:
java.lang.Exception
See Also:
Index#reverse(Long,Object)

forwardGreaterOrEq

public boolean forwardGreaterOrEq(K attrVal)
                           throws java.lang.Exception
Specified by:
forwardGreaterOrEq in interface Index<K,O,java.lang.Long>
Throws:
java.lang.Exception
See Also:
Index.forwardGreaterOrEq(Object)

forwardGreaterOrEq

public boolean forwardGreaterOrEq(K attrVal,
                                  java.lang.Long id)
                           throws java.lang.Exception
Specified by:
forwardGreaterOrEq in interface Index<K,O,java.lang.Long>
Throws:
java.lang.Exception
See Also:
org.apache.directory.server.xdbm.Index#forwardGreaterOrEq(Object, Long)

forwardLessOrEq

public boolean forwardLessOrEq(K attrVal)
                        throws java.lang.Exception
Specified by:
forwardLessOrEq in interface Index<K,O,java.lang.Long>
Throws:
java.lang.Exception
See Also:
Index.forwardLessOrEq(Object)

forwardLessOrEq

public boolean forwardLessOrEq(K attrVal,
                               java.lang.Long id)
                        throws java.lang.Exception
Specified by:
forwardLessOrEq in interface Index<K,O,java.lang.Long>
Throws:
java.lang.Exception
See Also:
org.apache.directory.server.xdbm.Index#forwardLessOrEq(Object, Long)

reverseGreaterOrEq

public boolean reverseGreaterOrEq(java.lang.Long id)
                           throws java.lang.Exception
Specified by:
reverseGreaterOrEq in interface Index<K,O,java.lang.Long>
Throws:
java.lang.Exception
See Also:
org.apache.directory.server.xdbm.Index#reverseGreaterOrEq(Long)

reverseGreaterOrEq

public boolean reverseGreaterOrEq(java.lang.Long id,
                                  K attrVal)
                           throws java.lang.Exception
Specified by:
reverseGreaterOrEq in interface Index<K,O,java.lang.Long>
Throws:
java.lang.Exception
See Also:
org.apache.directory.server.xdbm.Index#reverseGreaterOrEq(Long,Object)

reverseLessOrEq

public boolean reverseLessOrEq(java.lang.Long id)
                        throws java.lang.Exception
Specified by:
reverseLessOrEq in interface Index<K,O,java.lang.Long>
Throws:
java.lang.Exception
See Also:
org.apache.directory.server.xdbm.Index#reverseLessOrEq(Long)

reverseLessOrEq

public boolean reverseLessOrEq(java.lang.Long id,
                               K attrVal)
                        throws java.lang.Exception
Specified by:
reverseLessOrEq in interface Index<K,O,java.lang.Long>
Throws:
java.lang.Exception
See Also:
org.apache.directory.server.xdbm.Index#reverseLessOrEq(Long,Object)

close

public void close()
           throws java.io.IOException
Specified by:
close in interface Index<K,O,java.lang.Long>
Throws:
java.io.IOException
See Also:
Index.close()

sync

public void sync()
          throws java.io.IOException
Specified by:
sync in interface Index<K,O,java.lang.Long>
Throws:
java.io.IOException
See Also:
Index.sync()

getNormalized

public K getNormalized(K attrVal)
                throws java.lang.Exception
TODO I don't think the keyCache is required anymore since the normalizer will cache values for us.

Specified by:
getNormalized in interface Index<K,O,java.lang.Long>
Parameters:
attrVal - the user provided value to normalize
Returns:
the normalized value.
Throws:
java.lang.Exception - if something goes wrong.

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object
See Also:
Object.toString()


Copyright © 2003-2011 Apache Software Foundation. All Rights Reserved.