com.sleepycat.je.dbi
Class EnvironmentImpl

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

public class EnvironmentImpl
extends Object
implements EnvConfigObserver

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


Nested Class Summary
static interface EnvironmentImpl.MBeanRegistrar
          Because the Android platform does not have any javax.management classes, we load JEMonitor dynamically to ensure that there are no explicit references to com.sleepycat.je.jmx.*.
 
Field Summary
protected  DbConfigManager configManager
           
protected  DbTree dbMapTree
           
protected  Environment envInternal
           
protected  Logger envLogger
           
protected  Formatter formatter
           
static boolean IS_DALVIK
           
protected  boolean needRepConvert
           
 EnvironmentFailureException SAVED_EFE
           
protected  StartupTracker startupTracker
           
static boolean USE_JAVA5_ADLER32
           
 
Constructor Summary
  EnvironmentImpl(File envHome, EnvironmentConfig envConfig, EnvironmentImpl sharedCacheEnv)
           
protected EnvironmentImpl(File envHome, EnvironmentConfig envConfig, EnvironmentImpl sharedCacheEnv, RepConfigProxy repConfigProxy)
          Create a database environment to represent the data in envHome.
 
Method Summary
 void abnormalClose()
          Used by error handling to forcibly close an environment, and by tests to close an environment to simulate a crash.
 void addConfigObserver(EnvConfigObserver o)
          Adds an observer of mutable config changes.
 boolean addDbBackup(DbBackup backup)
          For replicated environments only; just return true for a standalone environment.
 void addToCompressorQueue(BIN bin, 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<BINReference> binRefs, boolean doWakeup)
          Tells the asynchronous IN compressor thread about a collections of BINReferences with deleted entries.
(package private)  void alertEvictor()
           
 void awaitVLSNConsistency()
          Ensure that the in-memory vlsn index encompasses all logged entries before it is flushed to disk.
 VLSN bumpVLSN()
           
 void checkIfInvalid()
           
 void checkImmutablePropsForEquality(Properties handleConfigProps)
          Throws an exception if an immutable property is changed.
 void checkNotClosed()
           
 void checkRulesForExistingEnv(boolean dbTreeReplicatedBit, boolean dbTreePreserveVLSN)
          Check whether this environment can be opened on an existing environment directory.
 EnvironmentConfig cloneConfig()
          Clones the current configuration.
 EnvironmentMutableConfig cloneMutableConfig()
          Clones the current mutable configuration.
 void close()
          Decrements the reference count and closes the environment when it reaches zero.
 void close(boolean doCheckpoint)
          Decrements the reference count and closes the environment when it reaches zero.
 void closeAfterInvalid()
           
 OperationFailureException createDatabasePreemptedException(String msg, String dbName, Database db)
          For replicated environments only; only the overridden method should ever be called.
protected  Environment createInternalEnvironment()
          Is overridden in RepImpl to create a ReplicatedEnvironment.
 OperationFailureException createLockPreemptedException(Locker locker, Throwable cause)
          For replicated environments only; only the overridden method should ever be called.
 OperationFailureException createLogOverwriteException(String msg)
          For replicated environments only; only the overridden method should ever be called.
 Txn createReplayTxn(long txnId)
          For replicated environments only; only the overridden method should ever be called.
 ThreadLocker createRepThreadLocker()
          For replicated environments only; only the overridden method should ever be called.
 Txn createRepTxn(TransactionConfig config, long mandatedId)
          For replicated environments only; only the overridden method should ever be called.
 Txn createRepUserTxn(TransactionConfig config)
          For replicated environments only; only the overridden method should ever be called.
 void criticalEviction(boolean backgroundIO)
          Performs critical eviction if necessary.
 void daemonEviction(boolean backgroundIO)
          Do eviction if the memory budget is over.
(package private)  void decBackupCount()
           
(package private)  boolean decOpenCount()
          Returns true if the environment should be closed.
 void decrementVLSN()
           
(package private) static void decThreadLocalReferenceCount()
           
(package private)  void doClose(boolean doCheckpoint, boolean isAbnormalClose)
          Closes the environment, optionally performing a checkpoint and checking for resource leaks.
 void doCloseAfterInvalid()
          This method must be called while synchronized on DbEnvPool.
(package private)  void doSetMutableConfig(EnvironmentMutableConfig config)
          This method must be called while synchronized on DbEnvPool.
 void envConfigUpdate(DbConfigManager mgr, EnvironmentMutableConfig newConfig)
          Respond to config updates.
 boolean finishInit(EnvironmentConfig envConfig)
          Initialize the environment, including running recovery, if it is not already initialized.
 void flushLog(boolean fsync)
          Flush the log buffers and write to the log, and optionally fsync.
 long forceLogFileFlip()
          Flip the log to a new file, forcing an fsync.
 void freezeLocalCBVLSN()
           
static int getAdler32ChunkSize()
           
 boolean getAllowRepConvert()
          True if ReplicationConfig set allowConvert as true.
protected  int getAppOpenCount()
          Returns the count of environment handles that were opened explicitly by the application.
protected  int getBackupCount()
          Returns a count of the number of in-progress DbBackups.
 int getCachedVLSNMinLength()
          Returns the number of initial bytes per VLSN in the VLSNCache.
 boolean getCacheVLSN()
          Returns true if the VLSN is both preserved and cached.
 Checkpointer getCheckpointer()
           
 ClassLoader getClassLoader()
           
 Cleaner getCleaner()
           
 long getCleanerBarrierStartFile()
          Returns the first protected file number.
 int getCompactMaxKeyLength()
          Returns EnvironmentConfig.TREE_COMPACT_MAX_KEY_LENGTH.
 DbConfigManager getConfigManager()
          Returns the config manager for the current base configuration.
 Handler getConfiguredHandler()
           
 ConsoleHandler getConsoleHandler()
           
 boolean getDbEviction()
          Returns whether DB/MapLN eviction is enabled.
 DbTree getDbTree()
           
 CacheMode getDefaultCacheMode()
          Returns the default cache mode for this environment.
 CacheModeStrategy getDefaultCacheModeStrategy()
          Returns the environment cache mode strategy.
 ReplicaConsistencyPolicy getDefaultConsistencyPolicy()
           
protected  String getDiagnosticsClassName()
           
 PreloadConfig getDupConvertPreloadConfig()
           
 long getEndOfLog()
           
 File getEnvironmentHome()
          Get the environment home directory.
 Evictor getEvictor()
           
 ExceptionListener getExceptionListener()
           
 FileHandler getFileHandler()
           
 FileManager getFileManager()
           
 VLSN getGroupDurableVLSN()
           
 INCompressor getINCompressor()
          Return the incompressor.
 int getINCompressorQueueSize()
           
 INList getInMemoryINs()
           
 Environment getInternalEnvHandle()
           
 EnvironmentFailureException getInvalidatingException()
           
 long getLockTimeout()
           
 Logger getLogger()
           
 LogManager getLogManager()
           
 long getLsnForVLSN(VLSN vlsn, int readBufferSize)
           
 MemoryBudget getMemoryBudget()
           
protected  String getMonitorClassName()
           
 String getName()
          Get an environment name, for tagging onto logging and debug message.
 boolean getNoComparators()
           
 String getNodeName()
           
 NodeSequence getNodeSequence()
           
 boolean getPreserveVLSN()
          Returns true if the VLSN is preserved as the record version.
 ProgressListener<RecoveryProgress> getRecoveryProgressListener()
           
 long getReplayTxnTimeout()
           
 long getRootLsn()
           
 boolean getSharedCache()
           
static boolean getSharedLatches()
           
 StartupTracker getStartupTracker()
           
 SyncCleanerBarrier getSyncCleanerBarrier()
           
static int getThreadLocalReferenceCount()
           
 SharedLatch getTriggerLatch()
          Returns the shared trigger latch.
 TxnManager getTxnManager()
           
 long getTxnTimeout()
           
 UtilizationProfile getUtilizationProfile()
          Returns the UtilizationProfile.
 UtilizationTracker getUtilizationTracker()
          Returns the UtilizationTracker.
 VLSNRecoveryProxy getVLSNProxy()
           
(package private)  void incBackupCount()
           
(package private)  void incOpenCount()
           
 void incRelatchesRequired()
           
(package private) static void incThreadLocalReferenceCount()
           
protected  DbConfigManager initConfigManager(EnvironmentConfig envConfig, RepConfigProxy repParams)
          Create a config manager that holds the configuration properties that have been passed in.
protected  void initConfigParams(EnvironmentConfig envConfig, RepConfigProxy repConfigProxy)
          Init configuration params during environment creation.
protected  Formatter initFormatter()
           
 void invalidate(EnvironmentFailureException e)
          Invalidate the environment.
 void invalidate(Error e)
          Invalidate the environment when a Java Error is thrown.
 boolean invokeCheckpoint(CheckpointConfig config, String invokingSource)
          Invoke a checkpoint programmatically.
 int invokeCleaner()
           
 boolean invokeCompressor()
          Invoke a compress programatically.
 void invokeEvictor()
           
 boolean isCacheFull()
          See Evictor.isCacheFull
 boolean isClosed()
           
 boolean isClosing()
           
 boolean isDbLoggingDisabled()
           
 boolean isInInit()
           
 boolean isInvalid()
          Predicate used to determine whether the EnvironmentImpl is valid.
 boolean isMaster()
           
 boolean isMemOnly()
           
 boolean isNoLocking()
           
 boolean isReadOnly()
           
 boolean isRepConverted()
          True if this environment is converted from non-replicated to replicated.
 boolean isReplicated()
          Return true if this environment is part of a replication group.
 boolean isTransactional()
           
 boolean isValid()
           
 void lazyCompress(IN in)
          Do lazy compression at opportune moments.
 StatGroup loadEnvImplStats(StatsConfig config)
           
 EnvironmentStats loadStats(StatsConfig config)
          Retrieve and return stat information.
 LockStats lockStat(StatsConfig config)
          Retrieve lock statistics
 void logMapTreeRoot()
          Logs the map tree root and saves the LSN.
 void logMapTreeRoot(long ifBeforeLsn)
          Logs the map tree root, but only if its current LSN is before the ifBeforeLsn parameter or ifBeforeLsn is NULL_LSN.
static boolean maybeForceYield()
          For stress testing.
 boolean mayNotWrite()
          When a EnvironmentFailureException occurs or the environment is closed, further writing can cause log corruption.
 boolean needRepConvert()
           
 void open()
          Not much to do, mark state.
protected  void postCheckpointClose(boolean checkpointed)
          Release any resources from a subclass that need to be released after the closing checkpoint.
protected  void postRecoveryConversion()
          Called after recovery but before any other initialization.
 void preCheckpointEndFlush()
          Do any work that must be done before the checkpoint end is written, as as part of the checkpoint process.
 PreloadStats preload(DatabaseImpl[] dbImpls, PreloadConfig config)
           
 void preRecoveryCheckpointInit(RecoveryInfo recoveryInfo)
           
 void readMapTreeFromLog(long rootLsn)
          Set the mapping tree from the log.
 void registerExceptionListenerUser(ExceptionListenerUser u)
           
 void registerMBean(Environment env)
           
 void registerVLSN(LogItem logItem)
           
 void removeConfigObserver(EnvConfigObserver o)
          Removes an observer of mutable config changes.
 void removeDbBackup(DbBackup backup)
          For replicated environments only; do nothing for a standalone environment.
 void requestShutdownDaemons()
           
protected  DbConfigManager resetConfigManager(EnvironmentConfig newConfig)
          Make a new config manager that has all the properties needed.
 void resetLoggingLevel(String changedLoggerName, Level level)
          Reset the logging level for specified loggers in a JE environment.
 void rewriteMapTreeRoot(long cleanerTargetLsn)
          Force a rewrite of the map tree root if required.
 void setBackgroundSleepHook(TestHook<?> hook)
           
 void setCleanerBarrierHook(TestHook<Long> hook)
           
 void setMutableConfig(EnvironmentMutableConfig config)
          Changes the mutable config properties that are present in the given config, and notifies all config observer.
protected  void setupClose(PrintWriter errors)
          Release any resources from a subclass that need to be released before close is called on regular environment components.
(package private)  void shutdownCheckpointer()
           
 void shutdownCleaner()
          public for unit tests.
 void shutdownDaemons()
          Ask all daemon threads to shut down.
(package private)  void shutdownEvictor()
           
(package private)  void shutdownINCompressor()
           
 void sleepAfterBackgroundIO()
          If the sleep backlog is non-zero (set by updateBackgroundReads or updateBackgroundWrites), sleep for the configured interval and decrement the backlog.
 long specialEviction()
          Performs special eviction (eviction other than standard IN eviction) for this environment.
 void stopDaemons()
          For unit testing -- shuts down daemons completely but leaves environment usable since environment references are not nulled out.
 Txn txnBegin(Transaction parent, TransactionConfig txnConfig)
          Transactional services.
 TransactionStats txnStat(StatsConfig config)
          Retrieve txn statistics
 void unfreezeLocalCBVLSN()
           
 boolean unregisterExceptionListenerUser(ExceptionListenerUser u)
           
 void updateBackgroundReads(int nReads)
          If a background read limit has been configured and that limit is exceeded when the cumulative total is incremented by the given number of reads, increment the sleep backlog to cause a sleep to occur.
 void updateBackgroundWrites(int writeSize, int logBufferSize)
          If a background write limit has been configured and that limit is exceeded when the given amount written is added to the cumulative total, increment the sleep backlog to cause a sleep to occur.
 boolean verify(VerifyConfig config, PrintStream out)
           
 void verifyCursors()
           
 void vlsnHeadTruncate(VLSN lastVLSN, long deleteFileNum)
          Adjust the vlsn index after cleaning.
 boolean wasCacheEverFull()
          See Evictor.wasCacheEverFull
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

needRepConvert

protected boolean needRepConvert

dbMapTree

protected DbTree dbMapTree

configManager

protected DbConfigManager configManager

envLogger

protected Logger envLogger

startupTracker

protected final StartupTracker startupTracker

SAVED_EFE

public final EnvironmentFailureException SAVED_EFE

USE_JAVA5_ADLER32

public static final boolean USE_JAVA5_ADLER32

formatter

protected final Formatter formatter

envInternal

protected Environment envInternal

IS_DALVIK

public static final boolean IS_DALVIK
Constructor Detail

EnvironmentImpl

public EnvironmentImpl(File envHome,
                       EnvironmentConfig envConfig,
                       EnvironmentImpl sharedCacheEnv)
                throws EnvironmentNotFoundException,
                       EnvironmentLockedException
Throws:
EnvironmentNotFoundException
EnvironmentLockedException

EnvironmentImpl

protected EnvironmentImpl(File envHome,
                          EnvironmentConfig envConfig,
                          EnvironmentImpl sharedCacheEnv,
                          RepConfigProxy repConfigProxy)
                   throws EnvironmentNotFoundException,
                          EnvironmentLockedException
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 - is the configuration to be used. It's already had the je.properties file applied, and has been validated.
sharedCacheEnv - if non-null, is another environment that is sharing the cache with this environment; if null, this environment is not sharing the cache or is the first environment to share the cache.
Throws:
DatabaseException - on all other failures
IllegalArgumentException - via Environment ctor.
EnvironmentNotFoundException
EnvironmentLockedException
Method Detail

initConfigManager

protected DbConfigManager initConfigManager(EnvironmentConfig envConfig,
                                            RepConfigProxy repParams)
Create a config manager that holds the configuration properties that have been passed in. These properties are already validated, and have had the proper order of precedence applied; that is, the je.properties file has been applied. The configuration properties need to be available before the rest of environment creation proceeds. This method is overridden by replication environments.

Parameters:
envConfig - is the environment configuration to use
repParams - are the replication configurations to use. In this case, the Properties bag has been extracted from the configuration instance, to avoid crossing the compilation firewall.

initConfigParams

protected void initConfigParams(EnvironmentConfig envConfig,
                                RepConfigProxy repConfigProxy)
Init configuration params during environment creation. This method is overridden by RepImpl to get init params also. This allows certain rep params to be accessed from the EnvironmentImpl constructor using methods such as getPreserveVLSN. The overridden method calls this method first.


finishInit

public boolean finishInit(EnvironmentConfig envConfig)
                   throws DatabaseException
Initialize the environment, including running recovery, if it is not already initialized. Note that this method should be called even when opening additional handles for an already initialized environment. If initialization is still in progress then this method will block until it is finished.

Returns:
true if we are opening the first handle for this environment and recovery is run (when ENV_RECOVERY is configured to true); false if we are opening an additional handle and recovery is not run.
Throws:
DatabaseException

createInternalEnvironment

protected Environment createInternalEnvironment()
Is overridden in RepImpl to create a ReplicatedEnvironment.


registerMBean

public void registerMBean(Environment env)
                   throws DatabaseException
Throws:
DatabaseException

getMonitorClassName

protected String getMonitorClassName()

getDiagnosticsClassName

protected String getDiagnosticsClassName()

getDefaultConsistencyPolicy

public ReplicaConsistencyPolicy getDefaultConsistencyPolicy()

getGroupDurableVLSN

public VLSN getGroupDurableVLSN()

getLsnForVLSN

public long getLsnForVLSN(VLSN vlsn,
                          int readBufferSize)

freezeLocalCBVLSN

public void freezeLocalCBVLSN()

unfreezeLocalCBVLSN

public void unfreezeLocalCBVLSN()

getEndOfLog

public long getEndOfLog()

getSyncCleanerBarrier

public SyncCleanerBarrier getSyncCleanerBarrier()

envConfigUpdate

public void envConfigUpdate(DbConfigManager mgr,
                            EnvironmentMutableConfig newConfig)
Respond to config updates.

Specified by:
envConfigUpdate in interface EnvConfigObserver

registerExceptionListenerUser

public void registerExceptionListenerUser(ExceptionListenerUser u)

unregisterExceptionListenerUser

public boolean unregisterExceptionListenerUser(ExceptionListenerUser u)

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.


getDefaultCacheMode

public CacheMode getDefaultCacheMode()
Returns the default cache mode for this environment. If the environment has a null cache mode, CacheMode.DEFAULT is returned. Null is never returned.


getDefaultCacheModeStrategy

public CacheModeStrategy getDefaultCacheModeStrategy()
Returns the environment cache mode strategy. Null may be returned.


getCompactMaxKeyLength

public int getCompactMaxKeyLength()
Returns EnvironmentConfig.TREE_COMPACT_MAX_KEY_LENGTH.


updateBackgroundReads

public void updateBackgroundReads(int nReads)
If a background read limit has been configured and that limit is exceeded when the cumulative total is incremented by the given number of reads, increment the sleep backlog to cause a sleep to occur. Called by background activities such as the cleaner after performing a file read operation.

See Also:
sleepAfterBackgroundIO()

updateBackgroundWrites

public void updateBackgroundWrites(int writeSize,
                                   int logBufferSize)
If a background write limit has been configured and that limit is exceeded when the given amount written is added to the cumulative total, increment the sleep backlog to cause a sleep to occur. Called by background activities such as the checkpointer and evictor after performing a file write operation.

The number of writes is estimated by dividing the bytes written by the log buffer size. Since the log write buffer is shared by all writers, this is the best approximation possible.

See Also:
sleepAfterBackgroundIO()

sleepAfterBackgroundIO

public void sleepAfterBackgroundIO()
If the sleep backlog is non-zero (set by updateBackgroundReads or updateBackgroundWrites), sleep for the configured interval and decrement the backlog.

If two threads call this method and the first call causes a sleep, the call by the second thread will block until the first thread's sleep interval is over. When the call by the second thread is unblocked, if another sleep is needed then the second thread will sleep again. In other words, when lots of sleeps are needed, background threads may backup. This is intended to give foreground threads a chance to "catch up" when background threads are doing a lot of IO.


setBackgroundSleepHook

public void setBackgroundSleepHook(TestHook<?> hook)

setCleanerBarrierHook

public void setCleanerBarrierHook(TestHook<Long> hook)

logMapTreeRoot

public void logMapTreeRoot()
                    throws DatabaseException
Logs the map tree root and saves the LSN.

Throws:
DatabaseException

logMapTreeRoot

public void logMapTreeRoot(long ifBeforeLsn)
                    throws DatabaseException
Logs the map tree root, but only if its current LSN is before the ifBeforeLsn parameter or ifBeforeLsn is NULL_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,
                                 boolean doWakeup)
Tells the asynchronous IN compressor thread about a BIN with a deleted entry.


addToCompressorQueue

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


addToCompressorQueue

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


lazyCompress

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

Throws:
DatabaseException

resetLoggingLevel

public void resetLoggingLevel(String changedLoggerName,
                              Level level)
Reset the logging level for specified loggers in a JE environment.

Throws:
IllegalArgumentException - via JEDiagnostics.OP_RESET_LOGGING

initFormatter

protected Formatter initFormatter()

getConsoleHandler

public ConsoleHandler getConsoleHandler()

getFileHandler

public FileHandler getFileHandler()

getConfiguredHandler

public Handler getConfiguredHandler()

open

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


invalidate

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


getInvalidatingException

public EnvironmentFailureException getInvalidatingException()

invalidate

public void invalidate(Error e)
Invalidate the environment when a Java Error is thrown.


isInvalid

public boolean isInvalid()
Predicate used to determine whether the EnvironmentImpl is valid.

Returns:
true if it's valid, false otherwise

isValid

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

isInInit

public boolean isInInit()
Returns:
true if environment is still in init

isClosing

public boolean isClosing()
Returns:
true if close has begun, although the state may still be open.

isClosed

public boolean isClosed()

mayNotWrite

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


checkIfInvalid

public void checkIfInvalid()
                    throws EnvironmentFailureException
Throws:
EnvironmentFailureException

checkNotClosed

public void checkNotClosed()
                    throws DatabaseException
Throws:
DatabaseException

close

public void close()
           throws DatabaseException
Decrements the reference count and closes the environment when it reaches zero. A checkpoint is always performed when closing.

Throws:
DatabaseException

close

public void close(boolean doCheckpoint)
           throws DatabaseException
Decrements the reference count and closes the environment when it reaches zero. A checkpoint when closing is optional.

Throws:
DatabaseException

abnormalClose

public void abnormalClose()
                   throws DatabaseException
Used by error handling to forcibly close an environment, and by tests to close an environment to simulate a crash. Database handles do not have to be closed before calling this method. A checkpoint is not performed.

Throws:
DatabaseException

doClose

void doClose(boolean doCheckpoint,
             boolean isAbnormalClose)
Closes the environment, optionally performing a checkpoint and checking for resource leaks. This method must be called while synchronized on DbEnvPool.

Throws:
IllegalStateException - if the environment is already closed.
EnvironmentFailureException - if leaks or other problems are detected while closing.

setupClose

protected void setupClose(PrintWriter errors)
                   throws DatabaseException
Release any resources from a subclass that need to be released before close is called on regular environment components.

Throws:
DatabaseException

postCheckpointClose

protected void postCheckpointClose(boolean checkpointed)
                            throws DatabaseException
Release any resources from a subclass that need to be released after the closing checkpoint.

Parameters:
checkpointed - if true, a checkpoint as issued before the close
Throws:
DatabaseException

postRecoveryConversion

protected void postRecoveryConversion()
Called after recovery but before any other initialization. Is overridden by ReplImpl to convert user defined databases to replicated after doing recovery.


closeAfterInvalid

public void closeAfterInvalid()
                       throws DatabaseException
Throws:
DatabaseException

doCloseAfterInvalid

public void doCloseAfterInvalid()
This method must be called while synchronized on DbEnvPool.


incOpenCount

void incOpenCount()

decOpenCount

boolean decOpenCount()
Returns true if the environment should be closed.


getAppOpenCount

protected int getAppOpenCount()
Returns the count of environment handles that were opened explicitly by the application. Because the internal environment handle is not included in the openCount, this method is currently equivalent to getOpenCount.

Returns:
the count of open application handles

incBackupCount

void incBackupCount()

decBackupCount

void decBackupCount()

getBackupCount

protected int getBackupCount()
Returns a count of the number of in-progress DbBackups.


getThreadLocalReferenceCount

public static int getThreadLocalReferenceCount()

incThreadLocalReferenceCount

static void incThreadLocalReferenceCount()

decThreadLocalReferenceCount

static void decThreadLocalReferenceCount()

getNoComparators

public boolean getNoComparators()

invokeCheckpoint

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

Throws:
DatabaseException

flushLog

public void flushLog(boolean fsync)
Flush the log buffers and write to the log, and optionally fsync. [#19111]


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:
UnsupportedOperationException - via Environment.cleanLog.
DatabaseException

requestShutdownDaemons

public void requestShutdownDaemons()

stopDaemons

public void stopDaemons()
For unit testing -- shuts down daemons completely but leaves environment usable since environment references are not nulled out.


shutdownDaemons

public void shutdownDaemons()
Ask all daemon threads to shut down.


shutdownINCompressor

void shutdownINCompressor()

shutdownEvictor

void shutdownEvictor()

shutdownCheckpointer

void shutdownCheckpointer()

shutdownCleaner

public void shutdownCleaner()
public for unit tests.


isNoLocking

public boolean isNoLocking()

isTransactional

public boolean isTransactional()

isReadOnly

public boolean isReadOnly()

isMemOnly

public boolean isMemOnly()

getNodeName

public String getNodeName()

getSharedLatches

public static boolean getSharedLatches()

getDbEviction

public boolean getDbEviction()
Returns whether DB/MapLN eviction is enabled.


getAdler32ChunkSize

public static int getAdler32ChunkSize()

getSharedCache

public boolean getSharedCache()

txnBegin

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

Throws:
DatabaseException

getLogManager

public LogManager getLogManager()

getFileManager

public FileManager getFileManager()

getDbTree

public DbTree getDbTree()

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.


getNodeSequence

public NodeSequence getNodeSequence()

cloneConfig

public EnvironmentConfig cloneConfig()
Clones the current configuration.


cloneMutableConfig

public EnvironmentMutableConfig cloneMutableConfig()
Clones the current mutable configuration.


checkImmutablePropsForEquality

public void checkImmutablePropsForEquality(Properties handleConfigProps)
                                    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

doSetMutableConfig

void doSetMutableConfig(EnvironmentMutableConfig config)
                  throws DatabaseException
This method must be called while synchronized on DbEnvPool.

Throws:
DatabaseException

resetConfigManager

protected DbConfigManager resetConfigManager(EnvironmentConfig newConfig)
Make a new config manager that has all the properties needed. More complicated for subclasses.


getExceptionListener

public ExceptionListener getExceptionListener()

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.

isDbLoggingDisabled

public boolean isDbLoggingDisabled()

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

loadEnvImplStats

public StatGroup loadEnvImplStats(StatsConfig config)

incRelatchesRequired

public void incRelatchesRequired()

addDbBackup

public boolean addDbBackup(DbBackup backup)
For replicated environments only; just return true for a standalone environment.


removeDbBackup

public void removeDbBackup(DbBackup backup)
For replicated environments only; do nothing for a standalone environment.


lockStat

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

Throws:
DatabaseException

txnStat

public TransactionStats txnStat(StatsConfig config)
Retrieve txn statistics


getINCompressorQueueSize

public int getINCompressorQueueSize()

getStartupTracker

public StartupTracker getStartupTracker()

getEnvironmentHome

public File getEnvironmentHome()
Get the environment home directory.


getInternalEnvHandle

public Environment getInternalEnvHandle()

getName

public String getName()
Get an environment name, for tagging onto logging and debug message. Useful for multiple environments in a JVM, or for HA.


getTxnTimeout

public long getTxnTimeout()

getLockTimeout

public long getLockTimeout()

getReplayTxnTimeout

public long getReplayTxnTimeout()

getTriggerLatch

public SharedLatch getTriggerLatch()
Returns the shared trigger latch.


getEvictor

public Evictor getEvictor()

alertEvictor

void alertEvictor()

criticalEviction

public void criticalEviction(boolean backgroundIO)
Performs critical eviction if necessary. Is called before and after each cursor operation. We prefer to have the application thread do as little eviction as possible, to reduce the impact on latency, so critical eviction has an explicit set of criteria for determining when this should run. WARNING: The action performed here should be as inexpensive as possible, since it will impact app operation latency. Unconditional synchronization must not be performed, since that would introduce a new synchronization point for all app threads. An overriding method must call super.criticalEviction. No latches are held or synchronization is in use when this method is called.


daemonEviction

public void daemonEviction(boolean backgroundIO)
Do eviction if the memory budget is over. Called by JE daemon threads that do not have the same latency concerns as application threads.


specialEviction

public long specialEviction()
Performs special eviction (eviction other than standard IN eviction) for this environment. This method is called once per eviction batch to give other components an opportunity to perform eviction. For a shared cached, it is called for only one environment (in rotation) per batch. An overriding method must call super.specialEviction and return the sum of the long value it returns and any additional amount of budgeted memory that is evicted. No latches are held when this method is called, but it is called while synchronized on the evictor.

Returns:
the number of bytes evicted from the JE cache.

isCacheFull

public boolean isCacheFull()
See Evictor.isCacheFull


wasCacheEverFull

public boolean wasCacheEverFull()
See Evictor.wasCacheEverFull


maybeForceYield

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


isReplicated

public boolean isReplicated()
Return true if this environment is part of a replication group.


getPreserveVLSN

public boolean getPreserveVLSN()
Returns true if the VLSN is preserved as the record version. Always false in a standalone environment. Overridden by RepImpl.


getCacheVLSN

public boolean getCacheVLSN()
Returns true if the VLSN is both preserved and cached. Always false in a standalone environment. Overridden by RepImpl.


getCachedVLSNMinLength

public int getCachedVLSNMinLength()
Returns the number of initial bytes per VLSN in the VLSNCache. May not be called in a standalone environment. Overridden by RepImpl.


getAllowRepConvert

public boolean getAllowRepConvert()
True if ReplicationConfig set allowConvert as true. Standalone environment is prohibited from doing a conversion, return false.


isRepConverted

public boolean isRepConverted()
True if this environment is converted from non-replicated to replicated.


needRepConvert

public boolean needRepConvert()

bumpVLSN

public VLSN bumpVLSN()

decrementVLSN

public void decrementVLSN()

getVLSNProxy

public VLSNRecoveryProxy getVLSNProxy()
                               throws DatabaseException
Throws:
DatabaseException - from subclasses.

isMaster

public boolean isMaster()

preRecoveryCheckpointInit

public void preRecoveryCheckpointInit(RecoveryInfo recoveryInfo)
Parameters:
recoveryInfo -

registerVLSN

public void registerVLSN(LogItem logItem)
Parameters:
logItem -

vlsnHeadTruncate

public void vlsnHeadTruncate(VLSN lastVLSN,
                             long deleteFileNum)
Adjust the vlsn index after cleaning.

Parameters:
lastVLSN -
deleteFileNum -

preCheckpointEndFlush

public void preCheckpointEndFlush()
                           throws DatabaseException
Do any work that must be done before the checkpoint end is written, as as part of the checkpoint process.

Throws:
DatabaseException

createReplayTxn

public Txn createReplayTxn(long txnId)
For replicated environments only; only the overridden method should ever be called.

Parameters:
txnId -
Throws:
DatabaseException - from subclasses.

createRepThreadLocker

public ThreadLocker createRepThreadLocker()
For replicated environments only; only the overridden method should ever be called.

Throws:
DatabaseException - from subclasses.

createRepUserTxn

public Txn createRepUserTxn(TransactionConfig config)
For replicated environments only; only the overridden method should ever be called.

Parameters:
config -
Throws:
DatabaseException - from subclasses.

createRepTxn

public Txn createRepTxn(TransactionConfig config,
                        long mandatedId)
For replicated environments only; only the overridden method should ever be called.

Parameters:
config -
mandatedId -
Throws:
DatabaseException - from subclasses.

createLockPreemptedException

public OperationFailureException createLockPreemptedException(Locker locker,
                                                              Throwable cause)
For replicated environments only; only the overridden method should ever be called.

Parameters:
locker -
cause -
Throws:
LockPreemptedException - from subclasses.

createDatabasePreemptedException

public OperationFailureException createDatabasePreemptedException(String msg,
                                                                  String dbName,
                                                                  Database db)
For replicated environments only; only the overridden method should ever be called.

Parameters:
msg -
dbName -
db -
Throws:
DatabasePreemptedException - from subclasses.

createLogOverwriteException

public OperationFailureException createLogOverwriteException(String msg)
For replicated environments only; only the overridden method should ever be called.

Parameters:
msg - unused
Throws:
LogOverwriteException - from subclasses.

getCleanerBarrierStartFile

public long getCleanerBarrierStartFile()
Returns the first protected file number. All files from this file (inclusive) to the end of the log will be protected from deletion. For replicated environments, this method should be overridden to return the CBVLSN file. Returns -1 if all file deletion is prohibited. Requirement: This method may never return a file number less that (prior to) a file number returned earlier.


checkRulesForExistingEnv

public void checkRulesForExistingEnv(boolean dbTreeReplicatedBit,
                                     boolean dbTreePreserveVLSN)
                              throws UnsupportedOperationException
Check whether this environment can be opened on an existing environment directory.

Parameters:
dbTreePreserveVLSN -
Throws:
UnsupportedOperationException - via Environment ctor.

awaitVLSNConsistency

public void awaitVLSNConsistency()
Ensure that the in-memory vlsn index encompasses all logged entries before it is flushed to disk. A No-Op for non-replicated systems. [#19754]


preload

public PreloadStats preload(DatabaseImpl[] dbImpls,
                            PreloadConfig config)
                     throws DatabaseException
Throws:
DatabaseException

getRecoveryProgressListener

public ProgressListener<RecoveryProgress> getRecoveryProgressListener()

getClassLoader

public ClassLoader getClassLoader()

getDupConvertPreloadConfig

public PreloadConfig getDupConvertPreloadConfig()


Copyright (c) 2004-2012 Oracle. All rights reserved.