com.sleepycat.je.dbi
Class EnvironmentImpl

java.lang.Object
  extended by com.sleepycat.je.dbi.EnvironmentImpl
All Implemented Interfaces:
EnvConfigObserver

public class EnvironmentImpl
extends Object
implements EnvConfigObserver

Underlying Environment implementation. There is a single instance for any database environment opened by the application.


Field Summary
protected  LogManager logManager
           
 
Constructor Summary
EnvironmentImpl(File envHome, EnvironmentConfig envConfig)
          Create a database environment to represent the data in envHome.
 
Method Summary
 void addConfigObserver(EnvConfigObserver o)
          Adds an observer of mutable config changes.
 void addToCompressorQueue(BIN bin, Key deletedKey, boolean doWakeup)
          Tells the asynchronous IN compressor thread about a BIN with a deleted entry.
 void addToCompressorQueue(BINReference binRef, boolean doWakeup)
          Tells the asynchronous IN compressor thread about a BINReference with a deleted entry.
 void addToCompressorQueue(Collection binRefs, boolean doWakeup)
          Tells the asynchronous IN compressor thread about a collections of BINReferences with deleted entries.
(package private)  void alertEvictor()
           
 void checkIfInvalid()
           
 void checkImmutablePropsForEquality(EnvironmentConfig config)
          Throws an exception if an immutable property is changed.
 void checkNotClosed()
           
 EnvironmentConfig cloneConfig()
          Clones the current configuration.
 EnvironmentMutableConfig cloneMutableConfig()
          Clones the current mutable configuration.
 void close()
           
 void close(boolean doCheckpoint)
           
 void closeAfterRunRecovery()
           
 void closeLogger()
          Close down the logger.
 DatabaseImpl createDb(Locker locker, String databaseName, DatabaseConfig dbConfig, Database databaseHandle)
           
 void dbRemove(Locker locker, String databaseName)
          Remove a database.
 void dbRename(Locker locker, String databaseName, String newName)
          Rename a database.
static void decThreadLocalReferenceCount()
           
 void dumpMapTree()
          For debugging.
 void enableDebugLoggingToDbLog()
          Add the database log as one of the debug logging destinations when the logging system is sufficiently initialized.
 void envConfigUpdate(DbConfigManager mgr)
          Respond to config updates.
 void forceClose()
           
 long forceLogFileFlip()
          Flip the log to a new file, forcing an fsync.
 Checkpointer getCheckpointer()
           
 Cleaner getCleaner()
           
 DbConfigManager getConfigManager()
          Returns the config manager for the current base configuration.
 DatabaseImpl getDb(Locker locker, String databaseName, Database databaseHandle)
          Get a database object given a database name.
 DbTree getDbMapTree()
           
 List getDbNames()
           
 File getEnvironmentHome()
          Get the environment home directory.
 Evictor getEvictor()
           
 FileManager getFileManager()
           
 INCompressor getINCompressor()
          Return the incompressor.
 int getINCompressorQueueSize()
           
 INList getInMemoryINs()
           
 RecoveryInfo getLastRecoveryInfo()
          Info about the last recovery
 long getLockTimeout()
           
 Logger getLogger()
           
 LogManager getLogManager()
           
 MemoryBudget getMemoryBudget()
           
static boolean getNoComparators()
           
 long getRootLsn()
           
static int getThreadLocalReferenceCount()
           
 SharedLatch getTriggerLatch()
          Returns the shared trigger latch.
 TxnManager getTxnManager()
           
 long getTxnTimeout()
           
 UtilizationProfile getUtilizationProfile()
          Returns the UtilizationProfile.
 UtilizationTracker getUtilizationTracker()
          Returns the UtilizationTracker.
 void incReferenceCount()
           
static void incThreadLocalReferenceCount()
           
 void invalidate(RunRecoveryException e)
          Invalidate the environment.
 boolean invokeCheckpoint(CheckpointConfig config, boolean flushAll, String invokingSource)
          Invoke a checkpoint programatically.
 int invokeCleaner()
           
 boolean invokeCompressor()
          Invoke a compress programatically.
 void invokeEvictor()
           
 boolean isClosed()
           
 boolean isOpen()
           
 boolean isReadOnly()
           
 boolean isTransactional()
           
 void lazyCompress(IN in)
          Do lazy compression at opportune moments.
 EnvironmentStats loadStats(StatsConfig config)
          Retrieve and return stat information.
 LockStats lockStat(StatsConfig config)
          Retrieve lock statistics
 void logMapTreeRoot()
          Log the map tree root and save the LSN.
static boolean maybeForceYield()
          For stress testing.
 boolean mayNotWrite()
          When a RunRecoveryException occurs or the environment is closed, further writing can cause log corruption.
 void open()
          Not much to do, mark state.
 void readMapTreeFromLog(long rootLsn)
          Set the mapping tree from the log.
 void removeConfigObserver(EnvConfigObserver o)
          Removes an observer of mutable config changes.
 void rewriteMapTreeRoot(long cleanerTargetLsn)
          Force a rewrite of the map tree root if required.
 void setMutableConfig(EnvironmentMutableConfig config)
          Changes the mutable config properties that are present in the given config, and notifies all config observer.
(package private)  void shutdownCheckpointer()
           
 void shutdownCleaner()
          public for unit tests.
 void shutdownEvictor()
           
 void shutdownINCompressor()
          Available for the unit tests.
 TruncateResult truncate(Locker locker, DatabaseImpl database)
          Deprecated. This supports Database.truncate(), which is deprecated.
 long truncate(Locker locker, String databaseName)
          Truncate a database.
 Txn txnBegin(Transaction parent, TransactionConfig txnConfig)
          Transactional services.
 TransactionStats txnStat(StatsConfig config)
          Retrieve txn statistics
 boolean useDirectNIO()
           
 boolean verify(VerifyConfig config, PrintStream out)
           
 void verifyCursors()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logManager

protected LogManager logManager
Constructor Detail

EnvironmentImpl

public EnvironmentImpl(File envHome,
                       EnvironmentConfig envConfig)
                throws DatabaseException
Create a database environment to represent the data in envHome. dbHome. Properties from the je.properties file in that directory are used to initialize the system wide property bag. Properties passed to this method are used to influence the open itself.

Parameters:
envHome - absolute path of the database environment home directory
envConfig -
Throws:
DatabaseException - on all other failures
Method Detail

envConfigUpdate

public void envConfigUpdate(DbConfigManager mgr)
                     throws DatabaseException
Respond to config updates.

Specified by:
envConfigUpdate in interface EnvConfigObserver
Throws:
DatabaseException

getINCompressor

public INCompressor getINCompressor()
Return the incompressor. In general, don't use this directly because it's easy to forget that the incompressor can be null at times (i.e during the shutdown procedure. Instead, wrap the functionality within this class, like lazyCompress.


getUtilizationTracker

public UtilizationTracker getUtilizationTracker()
Returns the UtilizationTracker.


getUtilizationProfile

public UtilizationProfile getUtilizationProfile()
Returns the UtilizationProfile.


logMapTreeRoot

public void logMapTreeRoot()
                    throws DatabaseException
Log the map tree root and save the LSN.

Throws:
DatabaseException

rewriteMapTreeRoot

public void rewriteMapTreeRoot(long cleanerTargetLsn)
                        throws DatabaseException
Force a rewrite of the map tree root if required.

Throws:
DatabaseException

getRootLsn

public long getRootLsn()
Returns:
the mapping tree root LSN.

readMapTreeFromLog

public void readMapTreeFromLog(long rootLsn)
                        throws DatabaseException
Set the mapping tree from the log. Called during recovery.

Throws:
DatabaseException

addToCompressorQueue

public void addToCompressorQueue(BIN bin,
                                 Key deletedKey,
                                 boolean doWakeup)
                          throws DatabaseException
Tells the asynchronous IN compressor thread about a BIN with a deleted entry.

Throws:
DatabaseException

addToCompressorQueue

public void addToCompressorQueue(BINReference binRef,
                                 boolean doWakeup)
                          throws DatabaseException
Tells the asynchronous IN compressor thread about a BINReference with a deleted entry.

Throws:
DatabaseException

addToCompressorQueue

public void addToCompressorQueue(Collection binRefs,
                                 boolean doWakeup)
                          throws DatabaseException
Tells the asynchronous IN compressor thread about a collections of BINReferences with deleted entries.

Throws:
DatabaseException

lazyCompress

public void lazyCompress(IN in)
                  throws DatabaseException
Do lazy compression at opportune moments.

Throws:
DatabaseException

enableDebugLoggingToDbLog

public void enableDebugLoggingToDbLog()
                               throws DatabaseException
Add the database log as one of the debug logging destinations when the logging system is sufficiently initialized.

Throws:
DatabaseException

closeLogger

public void closeLogger()
Close down the logger.


open

public void open()
Not much to do, mark state.


invalidate

public void invalidate(RunRecoveryException e)
Invalidate the environment. Done when a fatal exception (RunRecoveryException) is thrown.


isOpen

public boolean isOpen()
Returns:
true if environment is open.

isClosed

public boolean isClosed()

mayNotWrite

public boolean mayNotWrite()
When a RunRecoveryException occurs or the environment is closed, further writing can cause log corruption.


checkIfInvalid

public void checkIfInvalid()
                    throws RunRecoveryException
Throws:
RunRecoveryException

checkNotClosed

public void checkNotClosed()
                    throws DatabaseException
Throws:
DatabaseException

close

public void close()
           throws DatabaseException
Throws:
DatabaseException

close

public void close(boolean doCheckpoint)
           throws DatabaseException
Throws:
DatabaseException

closeAfterRunRecovery

public void closeAfterRunRecovery()
                           throws DatabaseException
Throws:
DatabaseException

forceClose

public void forceClose()
                throws DatabaseException
Throws:
DatabaseException

incReferenceCount

public void incReferenceCount()

getThreadLocalReferenceCount

public static int getThreadLocalReferenceCount()

incThreadLocalReferenceCount

public static void incThreadLocalReferenceCount()

decThreadLocalReferenceCount

public static void decThreadLocalReferenceCount()

getNoComparators

public static boolean getNoComparators()

invokeCheckpoint

public boolean invokeCheckpoint(CheckpointConfig config,
                                boolean flushAll,
                                String invokingSource)
                         throws DatabaseException
Invoke a checkpoint programatically. Note that only one checkpoint may run at a time.

Throws:
DatabaseException

forceLogFileFlip

public long forceLogFileFlip()
                      throws DatabaseException
Flip the log to a new file, forcing an fsync. Return the LSN of the trace record in the new file.

Throws:
DatabaseException

invokeCompressor

public boolean invokeCompressor()
                         throws DatabaseException
Invoke a compress programatically. Note that only one compress may run at a time.

Throws:
DatabaseException

invokeEvictor

public void invokeEvictor()
                   throws DatabaseException
Throws:
DatabaseException

invokeCleaner

public int invokeCleaner()
                  throws DatabaseException
Throws:
DatabaseException

shutdownINCompressor

public void shutdownINCompressor()
                          throws InterruptedException
Available for the unit tests.

Throws:
InterruptedException

shutdownEvictor

public void shutdownEvictor()
                     throws InterruptedException
Throws:
InterruptedException

shutdownCheckpointer

void shutdownCheckpointer()
                    throws InterruptedException
Throws:
InterruptedException

shutdownCleaner

public void shutdownCleaner()
                     throws InterruptedException
public for unit tests.

Throws:
InterruptedException

isTransactional

public boolean isTransactional()

isReadOnly

public boolean isReadOnly()

useDirectNIO

public boolean useDirectNIO()

createDb

public DatabaseImpl createDb(Locker locker,
                             String databaseName,
                             DatabaseConfig dbConfig,
                             Database databaseHandle)
                      throws DatabaseException
Throws:
DatabaseException

getDb

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

Parameters:
databaseName - target database.
Returns:
null if database doesn't exist.
Throws:
DatabaseException

getDbNames

public List getDbNames()
                throws DatabaseException
Throws:
DatabaseException

dumpMapTree

public void dumpMapTree()
                 throws DatabaseException
For debugging.

Throws:
DatabaseException

dbRename

public void dbRename(Locker locker,
                     String databaseName,
                     String newName)
              throws DatabaseException
Rename a database.

Throws:
DatabaseException

dbRemove

public void dbRemove(Locker locker,
                     String databaseName)
              throws DatabaseException
Remove a database.

Throws:
DatabaseException

truncate

public TruncateResult truncate(Locker locker,
                               DatabaseImpl database)
                        throws DatabaseException
Deprecated. This supports Database.truncate(), which is deprecated.

Truncate a database. Return a new DatabaseImpl object which represents the new truncated database. The old database is marked as deleted.

Throws:
DatabaseException

truncate

public long truncate(Locker locker,
                     String databaseName)
              throws DatabaseException
Truncate a database.

Throws:
DatabaseException

txnBegin

public Txn txnBegin(Transaction parent,
                    TransactionConfig txnConfig)
             throws DatabaseException
Transactional services.

Throws:
DatabaseException

getLogManager

public LogManager getLogManager()

getFileManager

public FileManager getFileManager()

getDbMapTree

public DbTree getDbMapTree()

getConfigManager

public DbConfigManager getConfigManager()
Returns the config manager for the current base configuration.

The configuration can change, but changes are made by replacing the config manager object with a enw one. To use a consistent set of properties, call this method once and query the returned manager repeatedly for each property, rather than getting the config manager via this method for each property individually.


cloneConfig

public EnvironmentConfig cloneConfig()
Clones the current configuration.


cloneMutableConfig

public EnvironmentMutableConfig cloneMutableConfig()
Clones the current mutable configuration.


checkImmutablePropsForEquality

public void checkImmutablePropsForEquality(EnvironmentConfig config)
                                    throws IllegalArgumentException
Throws an exception if an immutable property is changed.

Throws:
IllegalArgumentException

setMutableConfig

public void setMutableConfig(EnvironmentMutableConfig config)
                      throws DatabaseException
Changes the mutable config properties that are present in the given config, and notifies all config observer.

Throws:
DatabaseException

addConfigObserver

public void addConfigObserver(EnvConfigObserver o)
Adds an observer of mutable config changes.


removeConfigObserver

public void removeConfigObserver(EnvConfigObserver o)
Removes an observer of mutable config changes.


getInMemoryINs

public INList getInMemoryINs()

getTxnManager

public TxnManager getTxnManager()

getCheckpointer

public Checkpointer getCheckpointer()

getCleaner

public Cleaner getCleaner()

getMemoryBudget

public MemoryBudget getMemoryBudget()

getLogger

public Logger getLogger()
Returns:
environment Logger, for use in debugging output.

verify

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

verifyCursors

public void verifyCursors()
                   throws DatabaseException
Throws:
DatabaseException

loadStats

public EnvironmentStats loadStats(StatsConfig config)
                           throws DatabaseException
Retrieve and return stat information.

Throws:
DatabaseException

lockStat

public LockStats lockStat(StatsConfig config)
                   throws DatabaseException
Retrieve lock statistics

Throws:
DatabaseException

txnStat

public TransactionStats txnStat(StatsConfig config)
                         throws DatabaseException
Retrieve txn statistics

Throws:
DatabaseException

getINCompressorQueueSize

public int getINCompressorQueueSize()
                             throws DatabaseException
Throws:
DatabaseException

getLastRecoveryInfo

public RecoveryInfo getLastRecoveryInfo()
Info about the last recovery


getEnvironmentHome

public File getEnvironmentHome()
Get the environment home directory.


getTxnTimeout

public long getTxnTimeout()

getLockTimeout

public long getLockTimeout()

getTriggerLatch

public SharedLatch getTriggerLatch()
Returns the shared trigger latch.


getEvictor

public Evictor getEvictor()

alertEvictor

void alertEvictor()

maybeForceYield

public static boolean maybeForceYield()
For stress testing. Should only ever be called from an assert.



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