com.sleepycat.je.dbi
Class DbTree

java.lang.Object
  extended by com.sleepycat.je.dbi.DbTree
All Implemented Interfaces:
LoggableObject, LogReadable, LogWritable

public class DbTree
extends Object
implements LoggableObject, LogReadable

Represents the DatabaseImpl Naming Tree.


Field Summary
static DatabaseId ID_DB_ID
           
static String ID_DB_NAME
           
static DatabaseId NAME_DB_ID
           
static String NAME_DB_NAME
           
static String UTILIZATION_DB_NAME
           
 
Constructor Summary
DbTree()
          Create a dbTree from the log.
DbTree(EnvironmentImpl env)
          Create a new dbTree for a new environment.
 
Method Summary
 boolean countAsObsoleteWhenLogged()
          Returns true if this item should be counted as obsoleted when logged.
 DatabaseImpl createDb(Locker locker, String databaseName, DatabaseConfig dbConfig, Database databaseHandle)
          Create a database.
 DatabaseImpl createDb(Locker locker, String databaseName, DatabaseConfig dbConfig, Database databaseHandle, boolean allowEviction)
          Create a database.
(package private)  void dbRemove(Locker locker, String databaseName)
          Remove the database by deleting the nameLN.
(package private)  boolean dbRename(Locker locker, String databaseName, String newName)
          Return true if the operation succeeded, false otherwise.
(package private)  void deleteMapLN(DatabaseId id)
           
 void dump()
          For debugging.
 void dumpLog(StringBuffer sb, boolean verbose)
          Write the object into the string buffer for log dumping.
(package private)  String dumpString(int nSpaces)
           
 DatabaseImpl getDb(DatabaseId dbId)
          Get a database object based on an id only.
 DatabaseImpl getDb(DatabaseId dbId, long lockTimeout)
          Get a database object based on an id only.
 DatabaseImpl getDb(DatabaseId dbId, long lockTimeout, boolean allowEviction, String dbNameIfAvailable)
          Get a database object based on an id only.
 DatabaseImpl getDb(Locker nameLocker, String databaseName, Database databaseHandle)
          Get a database object given a database name.
 DatabaseImpl getDb(Locker nameLocker, String databaseName, Database databaseHandle, boolean allowEviction)
          Get a database object given a database name.
 String getDbName(DatabaseId id)
          Return the database name for a given db.
 List getDbNames()
           
 int getHighestLevel()
           
 int getLastDbId()
          Get the latest allocated id, for checkpoint info.
 int getLogSize()
           
 LogEntryType getLogType()
          All objects that are reponsible for a generating a type of log entry must implement this.
 long getTransactionId()
           
 boolean isReservedDbName(String name)
          Returns true if the name is a reserved JE database name.
 boolean logEntryIsTransactional()
           
 boolean marshallOutsideWriteLatch()
          Return true if this item can be marshalled outside the log write latch.
 void modifyDbRoot(DatabaseImpl db)
          Called by the Tree to propagate a root change.
 void postLogWork(long justLoggedLsn)
          Do any processing we need to do after logging, while under the logging latch.
 void readFromLog(ByteBuffer itemBuffer, byte entryTypeVersion)
          Initialize this object from the data in itemBuf.
 void rebuildINListMapDb()
          Rebuild the IN list after recovery.
(package private)  void setEnvironmentImpl(EnvironmentImpl envImpl)
          Set the db environment during recovery, after instantiating the tree from the log.
 void setLastDbId(int maxDbId)
          Initialize the db id, from recovery.
 String toString()
           
(package private)  TruncateResult truncate(Locker locker, DatabaseImpl oldDatabase)
          Deprecated. This method used by Database.truncate()
(package private)  long truncate(Locker locker, String databaseName)
          To truncate, remove the database named by databaseName and create a new database in its place.
 boolean verify(VerifyConfig config, PrintStream out)
           
 void writeToLog(ByteBuffer logBuffer)
          Serialize this object into the buffer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

ID_DB_ID

public static final DatabaseId ID_DB_ID

NAME_DB_ID

public static final DatabaseId NAME_DB_ID

ID_DB_NAME

public static final String ID_DB_NAME
See Also:
Constant Field Values

NAME_DB_NAME

public static final String NAME_DB_NAME
See Also:
Constant Field Values

UTILIZATION_DB_NAME

public static final String UTILIZATION_DB_NAME
See Also:
Constant Field Values
Constructor Detail

DbTree

public DbTree()
       throws DatabaseException
Create a dbTree from the log.

Throws:
DatabaseException

DbTree

public DbTree(EnvironmentImpl env)
       throws DatabaseException
Create a new dbTree for a new environment.

Throws:
DatabaseException
Method Detail

getLastDbId

public int getLastDbId()
Get the latest allocated id, for checkpoint info.


setLastDbId

public void setLastDbId(int maxDbId)
Initialize the db id, from recovery.


setEnvironmentImpl

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

Throws:
DatabaseException

createDb

public DatabaseImpl createDb(Locker locker,
                             String databaseName,
                             DatabaseConfig dbConfig,
                             Database databaseHandle)
                      throws DatabaseException
Create a database.

Throws:
DatabaseException

createDb

public DatabaseImpl createDb(Locker locker,
                             String databaseName,
                             DatabaseConfig dbConfig,
                             Database databaseHandle,
                             boolean allowEviction)
                      throws DatabaseException
Create a database.

Parameters:
locker - owning locker
databaseName - identifier for database
dbConfig -
allowEviction - is whether eviction is allowed during cursor operations.
Throws:
DatabaseException

modifyDbRoot

public void modifyDbRoot(DatabaseImpl db)
                  throws DatabaseException
Called by the Tree to propagate a root change. If the tree is a data database, we will write the MapLn that represents this db to the log. If the tree is one of the mapping dbs, we'll write the dbtree to the log.

Parameters:
db - the target db
Throws:
DatabaseException

dbRename

boolean dbRename(Locker locker,
                 String databaseName,
                 String newName)
           throws DatabaseException
Return true if the operation succeeded, false otherwise.

Throws:
DatabaseException

dbRemove

void dbRemove(Locker locker,
              String databaseName)
        throws DatabaseException
Remove the database by deleting the nameLN.

Throws:
DatabaseException

truncate

long truncate(Locker locker,
              String databaseName)
        throws DatabaseException
To truncate, remove the database named by databaseName and create a new database in its place.

Throws:
DatabaseException

deleteMapLN

void deleteMapLN(DatabaseId id)
           throws DatabaseException
Throws:
DatabaseException

truncate

TruncateResult truncate(Locker locker,
                        DatabaseImpl oldDatabase)
                  throws DatabaseException
Deprecated. This method used by Database.truncate()

Truncate a database named by databaseName. Return the new DatabaseImpl object that represents the truncated database. The old one is marked as deleted.

Throws:
DatabaseException

getDb

public DatabaseImpl getDb(Locker nameLocker,
                          String databaseName,
                          Database databaseHandle)
                   throws DatabaseException
Get a database object given a database name.

Throws:
DatabaseException

getDb

public DatabaseImpl getDb(Locker nameLocker,
                          String databaseName,
                          Database databaseHandle,
                          boolean allowEviction)
                   throws DatabaseException
Get a database object given a database name.

Parameters:
nameLocker - is used to access the NameLN. As always, a NullTxn is used to access the MapLN.
databaseName - target database
allowEviction - is whether eviction is allowed during cursor operations.
Returns:
null if database doesn't exist
Throws:
DatabaseException

getDb

public DatabaseImpl getDb(DatabaseId dbId)
                   throws DatabaseException
Get a database object based on an id only. Used by recovery, cleaning and other clients who have an id in hand, and don't have a resident node, to find the matching database for a given log entry.

Throws:
DatabaseException

getDb

public DatabaseImpl getDb(DatabaseId dbId,
                          long lockTimeout)
                   throws DatabaseException
Get a database object based on an id only. Specify the lock timeout to use, or -1 to use the default timeout. A timeout should normally only be specified by daemons with their own timeout configuration. public for unit tests.

Throws:
DatabaseException

getDb

public DatabaseImpl getDb(DatabaseId dbId,
                          long lockTimeout,
                          boolean allowEviction,
                          String dbNameIfAvailable)
                   throws DatabaseException
Get a database object based on an id only. Specify the lock timeout to use, or -1 to use the default timeout. A timeout should normally only be specified by daemons with their own timeout configuration. public for unit tests.

Parameters:
allowEviction - is whether eviction is allowed during cursor operations.
Throws:
DatabaseException

rebuildINListMapDb

public void rebuildINListMapDb()
                        throws DatabaseException
Rebuild the IN list after recovery.

Throws:
DatabaseException

verify

public boolean verify(VerifyConfig config,
                      PrintStream out)
               throws DatabaseException
Throws:
DatabaseException

getDbName

public String getDbName(DatabaseId id)
                 throws DatabaseException
Return the database name for a given db. Slow, must traverse. Used by truncate and for debugging.

Throws:
DatabaseException

getDbNames

public List getDbNames()
                throws DatabaseException
Returns:
a list of database names held in the environment, as strings.
Throws:
DatabaseException

isReservedDbName

public boolean isReservedDbName(String name)
Returns true if the name is a reserved JE database name.


getHighestLevel

public int getHighestLevel()
                    throws DatabaseException
Returns:
the higest level node in the environment.
Throws:
DatabaseException

getLogType

public LogEntryType getLogType()
Description copied from interface: LoggableObject
All objects that are reponsible for a generating a type of log entry must implement this.

Specified by:
getLogType in interface LoggableObject
Returns:
the type of log entry
See Also:
LoggableObject.getLogType()

marshallOutsideWriteLatch

public boolean marshallOutsideWriteLatch()
Description copied from interface: LoggableObject
Return true if this item can be marshalled outside the log write latch.

Specified by:
marshallOutsideWriteLatch in interface LoggableObject
See Also:
Can be marshalled outside the log write latch.

countAsObsoleteWhenLogged

public boolean countAsObsoleteWhenLogged()
Description copied from interface: LoggableObject
Returns true if this item should be counted as obsoleted when logged. This currently applies to deleted LNs only.

Specified by:
countAsObsoleteWhenLogged in interface LoggableObject
See Also:
LoggableObject.countAsObsoleteWhenLogged()

getLogSize

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

writeToLog

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

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

postLogWork

public void postLogWork(long justLoggedLsn)
                 throws DatabaseException
Description copied from interface: LoggableObject
Do any processing we need to do after logging, while under the logging latch.

Specified by:
postLogWork in interface LoggableObject
Throws:
DatabaseException
See Also:
LoggableObject.postLogWork(long)

readFromLog

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

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

dumpLog

public void dumpLog(StringBuffer sb,
                    boolean verbose)
Description copied from interface: LogReadable
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 LogReadable
Parameters:
sb - destination string buffer
verbose - if true, dump the full, verbose version
See Also:
LogReadable.dumpLog(java.lang.StringBuffer, boolean)

logEntryIsTransactional

public boolean logEntryIsTransactional()
Specified by:
logEntryIsTransactional in interface LogReadable
Returns:
true if the LogEntry is a transactional log entry type.
See Also:
LogReadable#logEntryIsTransactional.

getTransactionId

public long getTransactionId()
Specified by:
getTransactionId in interface LogReadable
Returns:
return the transaction id if this log entry is transactional, 0 otherwise.
See Also:
LogReadable.getTransactionId()

dumpString

String dumpString(int nSpaces)

toString

public String toString()
Overrides:
toString in class Object

dump

public void dump()
          throws DatabaseException
For debugging.

Throws:
DatabaseException


Copyright 2004-2005 Sleepycat, Inc. All Rights Reserved.