com.sleepycat.je.dbi
Class DatabaseImpl

java.lang.Object
  extended by com.sleepycat.je.dbi.DatabaseImpl
All Implemented Interfaces:
Loggable, Cloneable

public class DatabaseImpl
extends Object
implements Loggable, Cloneable

The underlying object for a given database.


Nested Class Summary
(package private) static class DatabaseImpl.StatsAccumulator
           
 
Constructor Summary
DatabaseImpl()
          Create an empty database object for initialization from the log.
DatabaseImpl(String dbName, DatabaseId id, EnvironmentImpl envImpl, DatabaseConfig dbConfig)
          Create a database object for a new database.
 
Method Summary
 void addReferringHandle(Database db)
          Add a referring handle
 void checkIsDeleted(String operation)
           
 DatabaseImpl cloneDb()
          Clone.
 long count()
          Count entries in the database including dups, but don't dirty the cache.
(package private)  void decrementUseCount()
          Decrements the use count of this DB, allowing it to be evicted if the use count reaches zero.
 void deleteAndReleaseINs()
          Purge a DatabaseImpl and corresponding MapLN in the db mapping tree.
 void dumpLog(StringBuffer sb, boolean verbose)
          Write the object into the string buffer for log dumping.
 String dumpString(int nSpaces)
           
 Database findPrimaryDatabase()
          For this secondary database return the primary that it is associated with, or null if not associated with any primary.
(package private)  void finishedINListHarvest()
           
 int getAdditionalMemorySize()
          Returns the memory size that should be added to MAPLN_OVERHEAD.
 int getBinDeltaPercent()
           
 int getBinMaxDeltas()
           
 Comparator getBtreeComparator()
           
 boolean getBtreeComparatorByClass()
           
 EnvironmentImpl getDbEnvironment()
           
 String getDebugName()
           
 Comparator getDuplicateComparator()
           
 boolean getDuplicateComparatorByClass()
           
 DatabaseStats getEmptyStats()
           
 long getEofNodeId()
           
 DatabaseId getId()
           
 int getLogSize()
           
 String getName()
           
 int getNodeMaxDupTreeEntries()
           
 int getNodeMaxEntries()
           
(package private)  int getReferringHandleCount()
           
 boolean getSortedDuplicates()
           
 long getTransactionId()
           
 Tree getTree()
           
 boolean hasOpenHandles()
          Returns whether one or more handles are open.
(package private)  void incrementUseCount()
          Increments the use count of this DB to prevent it from being evicted.
static Comparator instantiateComparator(Class comparator, String comparatorType)
          Used both to read from the log and to validate a comparator when set in DatabaseConfig.
static Comparator instantiateComparator(Comparator comparator, String comparatorType)
          Used to validate a comparator when set in DatabaseConfig.
 boolean isDeferredWrite()
           
 boolean isDeleted()
           
 boolean isDeleteFinished()
           
 boolean isInUse()
          Returns whether this DB is in use and cannot be evicted.
(package private)  boolean isInUseDuringDbRemove()
          Checks whether a database is in use during a remove or truncate database operation.
 boolean isTransactional()
           
static byte[] objectToBytes(Object obj, String comparatorType)
          Converts an arbitrary object to a serialized byte array.
 PreloadStats preload(PreloadConfig config)
          Preload the cache, using up to maxBytes bytes or maxMillsecs msec.
 void readFromLog(ByteBuffer itemBuffer, byte entryTypeVersion)
          Initialize this object from the data in itemBuf.
 void releaseDeletedINs()
           
 void removeReferringHandle(Database db)
          Decrement the reference count.
 boolean setBtreeComparator(Comparator comparator, boolean byClassName)
          Set the btree comparison function for this database.
 void setDebugDatabaseName(String debugName)
           
 void setDeferredWrite(boolean deferredWrite)
           
 boolean setDuplicateComparator(Comparator comparator, boolean byClassName)
          Set the duplicate comparison function for this database.
 void setEnvironmentImpl(EnvironmentImpl envImpl)
          Set the db environment during recovery, after instantiating the database from the log
(package private)  void setId(DatabaseId id)
           
 void setPendingDeletedHook(TestHook hook)
           
 void setTransactional(boolean transactional)
          Sets the transactional property for the first opened handle.
(package private)  void setTree(Tree tree)
           
 void startDeleteProcessing()
           
 DatabaseStats stat(StatsConfig config)
           
 void sync(boolean flushLog)
          Flush all dirty nodes for this database to disk.
 boolean verify(VerifyConfig config, DatabaseStats emptyStats)
           
 void writeToLog(ByteBuffer logBuffer)
          Serialize this object into the buffer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DatabaseImpl

public DatabaseImpl(String dbName,
                    DatabaseId id,
                    EnvironmentImpl envImpl,
                    DatabaseConfig dbConfig)
             throws DatabaseException
Create a database object for a new database.

Throws:
DatabaseException

DatabaseImpl

public DatabaseImpl()
             throws DatabaseException
Create an empty database object for initialization from the log. Note that the rest of the initialization comes from readFromLog(), except for the debugDatabaseName, which is set by the caller.

Throws:
DatabaseException
Method Detail

setDebugDatabaseName

public void setDebugDatabaseName(String debugName)

getDebugName

public String getDebugName()

setPendingDeletedHook

public void setPendingDeletedHook(TestHook hook)

cloneDb

public DatabaseImpl cloneDb()
                     throws DatabaseException
Clone. For the most part, just pass off to the super class for a field-by-field copy.

Throws:
DatabaseException

getTree

public Tree getTree()
Returns:
the database tree.

setTree

void setTree(Tree tree)

getId

public DatabaseId getId()
Returns:
the database id.

setId

void setId(DatabaseId id)

getEofNodeId

public long getEofNodeId()

isTransactional

public boolean isTransactional()
Returns:
true if this database is transactional.

setTransactional

public void setTransactional(boolean transactional)
Sets the transactional property for the first opened handle.


isDeferredWrite

public boolean isDeferredWrite()
Returns:
true if this database is in deferred write mode.

setDeferredWrite

public void setDeferredWrite(boolean deferredWrite)

getSortedDuplicates

public boolean getSortedDuplicates()
Returns:
true if duplicates are allowed in this database.

getNodeMaxEntries

public int getNodeMaxEntries()

getNodeMaxDupTreeEntries

public int getNodeMaxDupTreeEntries()

getAdditionalMemorySize

public int getAdditionalMemorySize()
Returns the memory size that should be added to MAPLN_OVERHEAD. This is a start at budgeting per-Database memory. For future reference, other things that could be budgeted are: - debugDatabaseName as it is set - Database handles as they are added/removed in referringHandles


setDuplicateComparator

public boolean setDuplicateComparator(Comparator comparator,
                                      boolean byClassName)
                               throws DatabaseException
Set the duplicate comparison function for this database.

Parameters:
duplicateComparator - - The Duplicate Comparison function.
Returns:
true if the comparator was actually changed
Throws:
DatabaseException

setBtreeComparator

public boolean setBtreeComparator(Comparator comparator,
                                  boolean byClassName)
                           throws DatabaseException
Set the btree comparison function for this database.

Parameters:
btreeComparator - - The btree Comparison function.
Returns:
true if the comparator was actually changed
Throws:
DatabaseException

getBtreeComparator

public Comparator getBtreeComparator()
Returns:
the btree Comparator object.

getDuplicateComparator

public Comparator getDuplicateComparator()
Returns:
the duplicate Comparator object.

getBtreeComparatorByClass

public boolean getBtreeComparatorByClass()
Returns:
whether Comparator is set by class name, not by serializable Comparator object.

getDuplicateComparatorByClass

public boolean getDuplicateComparatorByClass()
Returns:
whether Comparator is set by class name, not by serializable Comparator object.

setEnvironmentImpl

public void setEnvironmentImpl(EnvironmentImpl envImpl)
                        throws DatabaseException
Set the db environment during recovery, after instantiating the database from the log

Throws:
DatabaseException

getDbEnvironment

public EnvironmentImpl getDbEnvironment()
Returns:
the database environment.

hasOpenHandles

public boolean hasOpenHandles()
Returns whether one or more handles are open.


addReferringHandle

public void addReferringHandle(Database db)
Add a referring handle


removeReferringHandle

public void removeReferringHandle(Database db)
Decrement the reference count.


getReferringHandleCount

int getReferringHandleCount()
Returns:
the referring handle count.

incrementUseCount

void incrementUseCount()
Increments the use count of this DB to prevent it from being evicted. Called by the DbTree.createDb/getDb methods that return a DatabaseImpl. Must be called while holding a lock on the MapLN. See isInUse. [#13415]


decrementUseCount

void decrementUseCount()
Decrements the use count of this DB, allowing it to be evicted if the use count reaches zero. Called via DbTree.releaseDb to release a DatabaseImpl that was returned by a DbTree.createDb/getDb method. See isInUse. [#13415]


isInUse

public boolean isInUse()
Returns whether this DB is in use and cannot be evicted. Called by MapLN.isEvictable while holding a write-lock on the MapLN and a latch on its parent BIN. [#13415] When isInUse returns false (while holding a write-lock on the MapLN and a latch on the parent BIN), it guarantees that the database object is not in use and cannot be acquired by another thread (via DbTree.createDb/getDb) until both the MapLN lock and BIN latch are released. This guarantee is due to the fact that DbTree.createDb/getDb only increment the use count while holding a read-lock on the MapLN. Therefore, it is safe to evict the MapLN when isInUse returns false. When isInUse returns true, it is possible that another thread may decrement the use count at any time, since no locking or latching is performed when calling DbTree.releaseDb (which calls decrementUseCount). Therefore, it is not guaranteed that the MapLN is in use when isInUse returns true. A true result means: the DB may be in use, so it is not safe to evict it.


isInUseDuringDbRemove

boolean isInUseDuringDbRemove()
Checks whether a database is in use during a remove or truncate database operation.


sync

public void sync(boolean flushLog)
          throws DatabaseException
Flush all dirty nodes for this database to disk.

Throws:
DatabaseException

findPrimaryDatabase

public Database findPrimaryDatabase()
                             throws DatabaseException
For this secondary database return the primary that it is associated with, or null if not associated with any primary. Note that not all handles need be associated with a primary.

Throws:
DatabaseException

getName

public String getName()
               throws DatabaseException
Throws:
DatabaseException

isDeleted

public boolean isDeleted()

isDeleteFinished

public boolean isDeleteFinished()

startDeleteProcessing

public void startDeleteProcessing()

finishedINListHarvest

void finishedINListHarvest()

deleteAndReleaseINs

public void deleteAndReleaseINs()
                         throws DatabaseException
Purge a DatabaseImpl and corresponding MapLN in the db mapping tree. Purging consists of removing all related INs from the db mapping tree and deleting the related MapLN. Used at the transaction end in these cases: - purge the deleted database after a commit of Environment.removeDatabase - purge the deleted database after a commit of Environment.truncateDatabase - purge the newly created database after an abort of Environment.truncateDatabase

Throws:
DatabaseException

releaseDeletedINs

public void releaseDeletedINs()
                       throws DatabaseException
Throws:
DatabaseException

checkIsDeleted

public void checkIsDeleted(String operation)
                    throws DatabaseException
Throws:
DatabaseException

stat

public DatabaseStats stat(StatsConfig config)
                   throws DatabaseException
Throws:
DatabaseException

verify

public boolean verify(VerifyConfig config,
                      DatabaseStats emptyStats)
               throws DatabaseException
Throws:
DatabaseException

getEmptyStats

public DatabaseStats getEmptyStats()

preload

public PreloadStats preload(PreloadConfig config)
                     throws DatabaseException
Preload the cache, using up to maxBytes bytes or maxMillsecs msec.

Throws:
DatabaseException

count

public long count()
           throws DatabaseException
Count entries in the database including dups, but don't dirty the cache.

Throws:
DatabaseException

dumpString

public String dumpString(int nSpaces)

getLogSize

public int getLogSize()
Specified by:
getLogSize in interface Loggable
Returns:
number of bytes used to store this object.
See Also:
Loggable.getLogSize()

writeToLog

public void writeToLog(ByteBuffer logBuffer)
Description copied from interface: Loggable
Serialize this object into the buffer.

Specified by:
writeToLog in interface Loggable
Parameters:
logBuffer - is the destination buffer
See Also:
Loggable.writeToLog(java.nio.ByteBuffer)

readFromLog

public void readFromLog(ByteBuffer itemBuffer,
                        byte entryTypeVersion)
                 throws LogException
Description copied from interface: Loggable
Initialize this object from the data in itemBuf.

Specified by:
readFromLog in interface Loggable
Throws:
LogException
See Also:
Loggable.readFromLog(java.nio.ByteBuffer, byte)

dumpLog

public void dumpLog(StringBuffer sb,
                    boolean verbose)
Description copied from interface: Loggable
Write the object into the string buffer for log dumping. Each object should be dumped without indentation or new lines and should be valid XML.

Specified by:
dumpLog in interface Loggable
Parameters:
sb - destination string buffer
verbose - if true, dump the full, verbose version
See Also:
Loggable.dumpLog(java.lang.StringBuffer, boolean)

getTransactionId

public long getTransactionId()
Specified by:
getTransactionId in interface Loggable
Returns:
the transaction id embedded within this loggable object. Objects that have no transaction id should return 0.
See Also:
Loggable.getTransactionId()

instantiateComparator

public static Comparator instantiateComparator(Class comparator,
                                               String comparatorType)
                                        throws LogException
Used both to read from the log and to validate a comparator when set in DatabaseConfig.

Throws:
LogException

instantiateComparator

public static Comparator instantiateComparator(Comparator comparator,
                                               String comparatorType)
                                        throws DatabaseException
Used to validate a comparator when set in DatabaseConfig.

Throws:
DatabaseException

objectToBytes

public static byte[] objectToBytes(Object obj,
                                   String comparatorType)
                            throws LogException
Converts an arbitrary object to a serialized byte array. Assumes that the object given is non-null.

Throws:
LogException

getBinDeltaPercent

public int getBinDeltaPercent()

getBinMaxDeltas

public int getBinMaxDeltas()


Copyright 2004,2008 Oracle. All rights reserved.