com.sleepycat.je.recovery
Class Checkpointer

java.lang.Object
  extended by com.sleepycat.je.utilint.DaemonThread
      extended by com.sleepycat.je.recovery.Checkpointer
All Implemented Interfaces:
EnvConfigObserver, DaemonRunner, java.lang.Runnable

public class Checkpointer
extends DaemonThread
implements EnvConfigObserver

The Checkpointer looks through the tree for internal nodes that must be flushed to the log. Checkpoint flushes must be done in ascending order from the bottom of the tree up.


Nested Class Summary
static class Checkpointer.CheckpointReference
           
static class Checkpointer.FlushStats
          A struct to hold log flushing stats for checkpoint and database sync.
 
Field Summary
static TestHook beforeFlushHook
           
static TestHook maxFlushLevelHook
          For unit testing only.
 
Fields inherited from class com.sleepycat.je.utilint.DaemonThread
name, nWakeupRequests, stifleExceptionChatter
 
Constructor Summary
Checkpointer(EnvironmentImpl envImpl, long waitTime, java.lang.String name)
           
 
Method Summary
 void clearEnv()
           
 void doCheckpoint(CheckpointConfig config, boolean flushAll, java.lang.String invokingSource)
          The real work to do a checkpoint.
 void envConfigUpdate(DbConfigManager cm, EnvironmentMutableConfig ignore)
          Process notifications of mutable property changes.
 int getHighestFlushLevel(DatabaseImpl db)
          Returns the highest flush level for a database that is part of a checkpoint currently in progress.
static long getWakeupPeriod(DbConfigManager configManager)
          Figure out the wakeup period.
 void initIntervals(long lastCheckpointEnd, long lastCheckpointMillis)
          Initializes the checkpoint intervals when no checkpoint is performed while opening the environment.
 void loadStats(StatsConfig config, EnvironmentStats stat)
          Load stats.
protected  long nDeadlockRetries()
          Return the number of retries when a deadlock exception occurs.
protected  void onWakeup()
          Called whenever the DaemonThread wakes up from a sleep.
static void setBeforeFlushHook(TestHook hook)
           
 void setCheckpointId(long lastCheckpointId)
          Set checkpoint id -- can only be done after recovery.
static void setMaxFlushLevelHook(TestHook hook)
           
static void syncDatabase(EnvironmentImpl envImpl, DatabaseImpl dbImpl, boolean flushLog)
          Flush a given database to disk.
 void wakeupAfterWrite()
          Wakes up the checkpointer if a checkpoint log interval is configured and the number of bytes written since the last checkpoint exeeds the size of the interval.
 
Methods inherited from class com.sleepycat.je.utilint.DaemonThread
checkErrorListener, getExceptionListener, getNWakeupRequests, getThread, isPaused, isRunning, isShutdownRequested, requestShutdown, run, runOrPause, setExceptionListener, shutdown, toString, wakeup
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

maxFlushLevelHook

public static TestHook maxFlushLevelHook
For unit testing only. Called before we flush the max level. This field is static because it is called from the static flushIN method.


beforeFlushHook

public static TestHook beforeFlushHook
Constructor Detail

Checkpointer

public Checkpointer(EnvironmentImpl envImpl,
                    long waitTime,
                    java.lang.String name)
             throws DatabaseException
Throws:
DatabaseException
Method Detail

envConfigUpdate

public void envConfigUpdate(DbConfigManager cm,
                            EnvironmentMutableConfig ignore)
                     throws DatabaseException
Process notifications of mutable property changes.

Specified by:
envConfigUpdate in interface EnvConfigObserver
Throws:
DatabaseException

initIntervals

public void initIntervals(long lastCheckpointEnd,
                          long lastCheckpointMillis)
Initializes the checkpoint intervals when no checkpoint is performed while opening the environment.


getHighestFlushLevel

public int getHighestFlushLevel(DatabaseImpl db)
Returns the highest flush level for a database that is part of a checkpoint currently in progress. Used by the evictor to determine whether to log INs provisionally. If an IN's level is less than the level returned, it should be logged provisionally by the evictor. IN.MIN_LEVEL is returned if no checkpoint is in progress or the given database is not part of the checkpoint.


getWakeupPeriod

public static long getWakeupPeriod(DbConfigManager configManager)
                            throws java.lang.IllegalArgumentException,
                                   DatabaseException
Figure out the wakeup period. Supplied through this static method because we need to pass wakeup period to the superclass and need to do the calcuation outside this constructor.

Throws:
java.lang.IllegalArgumentException
DatabaseException

setCheckpointId

public void setCheckpointId(long lastCheckpointId)
Set checkpoint id -- can only be done after recovery.


loadStats

public void loadStats(StatsConfig config,
                      EnvironmentStats stat)
               throws DatabaseException
Load stats.

Throws:
DatabaseException

clearEnv

public void clearEnv()

nDeadlockRetries

protected long nDeadlockRetries()
                         throws DatabaseException
Return the number of retries when a deadlock exception occurs.

Overrides:
nDeadlockRetries in class DaemonThread
Throws:
DatabaseException

onWakeup

protected void onWakeup()
                 throws DatabaseException
Called whenever the DaemonThread wakes up from a sleep.

Specified by:
onWakeup in class DaemonThread
Throws:
DatabaseException

wakeupAfterWrite

public void wakeupAfterWrite()
Wakes up the checkpointer if a checkpoint log interval is configured and the number of bytes written since the last checkpoint exeeds the size of the interval.


doCheckpoint

public void doCheckpoint(CheckpointConfig config,
                         boolean flushAll,
                         java.lang.String invokingSource)
                  throws DatabaseException
The real work to do a checkpoint. This may be called by the checkpoint thread when waking up, or it may be invoked programatically through the api.

Parameters:
flushAll - if true, this checkpoint must flush all the way to the top of the dbtree, instead of stopping at the highest level last modified.
invokingSource - a debug aid, to indicate who invoked this checkpoint. (i.e. recovery, the checkpointer daemon, the cleaner, programatically)
Throws:
DatabaseException

syncDatabase

public static void syncDatabase(EnvironmentImpl envImpl,
                                DatabaseImpl dbImpl,
                                boolean flushLog)
                         throws DatabaseException
Flush a given database to disk. Like checkpoint, log from the bottom up so that parents properly represent their children.

Throws:
DatabaseException

setMaxFlushLevelHook

public static void setMaxFlushLevelHook(TestHook hook)

setBeforeFlushHook

public static void setBeforeFlushHook(TestHook hook)