com.sleepycat.je.cleaner
Class Cleaner

java.lang.Object
  extended bycom.sleepycat.je.utilint.DaemonThread
      extended bycom.sleepycat.je.cleaner.Cleaner
All Implemented Interfaces:
Runnable

public class Cleaner
extends DaemonThread

The Cleaner is responsible for effectively garbage collecting the JE log. It looks through log files and locates log records (IN's and LN's of all flavors) that are superceded by later versions. Those that are "current" are propagated to a newer log file so that older log files can be deleted.


Field Summary
 
Fields inherited from class com.sleepycat.je.utilint.DaemonThread
name, nWakeupRequests, workQueue, workQueueLatch
 
Constructor Summary
Cleaner(EnvironmentImpl env, long waitTime, String name, UtilizationProfile profile)
           
 
Method Summary
 void addToQueue(Object o)
          Cleaner doesn't have a work queue so just throw an exception if it's ever called.
 void clearEnv()
           
 void deleteCleanedFiles(Set cleanedFiles)
          Delete files that were previously returned by getCleanedFiles, after performing a checkpoint with no deltas and that flushed to the root.
 int doClean(boolean invokedFromDaemon, boolean cleanMultipleFiles, boolean forceAggressive)
          Cleans selected files and returns the number of files cleaned.
 Set getCleanedFiles(boolean getAll)
          Called when starting a checkpoint to get the files to be deleted when the checkpoint is complete.
 boolean isNearDiskBudget(boolean calcIfNecessary)
          Returns whether we are near to using the disk budget.
 void loadStats(StatsConfig config, EnvironmentStats stat)
          Load stats.
protected  int nDeadlockRetries()
          Return the number of retries when a deadlock exception occurs.
 void onWakeup()
          Called whenever the daemon thread wakes up from a sleep.
 String toString()
           
 
Methods inherited from class com.sleepycat.je.utilint.DaemonThread
addToQueueAlreadyLatched, getNWakeupRequests, getQueueSize, getThread, isShutdownRequested, requestShutdown, run, runOrPause, shutdown, wakeup
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Cleaner

public Cleaner(EnvironmentImpl env,
               long waitTime,
               String name,
               UtilizationProfile profile)
        throws DatabaseException
Method Detail

toString

public String toString()
Overrides:
toString in class DaemonThread

addToQueue

public void addToQueue(Object o)
                throws DatabaseException
Cleaner doesn't have a work queue so just throw an exception if it's ever called.

Overrides:
addToQueue in class DaemonThread
Throws:
DatabaseException

loadStats

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

Throws:
DatabaseException

clearEnv

public void clearEnv()

nDeadlockRetries

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

Overrides:
nDeadlockRetries in class DaemonThread
Throws:
DatabaseException

onWakeup

public void onWakeup()
              throws DatabaseException
Called whenever the daemon thread wakes up from a sleep.

Specified by:
onWakeup in class DaemonThread
Throws:
DatabaseException

doClean

public int doClean(boolean invokedFromDaemon,
                   boolean cleanMultipleFiles,
                   boolean forceAggressive)
            throws DatabaseException
Cleans selected files and returns the number of files cleaned. May be called by the daemon thread or programatically.

Parameters:
invokedFromDaemon - currently has no effect.
cleanMultipleFiles - is true to clean until we're under * budget,
forceAggressive - is true to clean as if we were under budget even when we're not.
Returns:
the number of files deleted, not including files cleaned unsuccessfully.
Throws:
DatabaseException

getCleanedFiles

public Set getCleanedFiles(boolean getAll)
Called when starting a checkpoint to get the files to be deleted when the checkpoint is complete.

If non-null is returned, the checkpoint should not allow deltas, the checkpoint should flush to the root, and deleteCleanedFiles() should be called when the checkpoint is complete. The caller must call deleteCleanedFiles() or the files will have to be cleaned again later.

The checkpoint can't have deltas because the checkpointer is essentially rewriting INs for the cleaner. We flush all the way to the root to make sure there are no references left to the old file.

Parameters:
getAll - is true to get all files even if the number of cleaned files is below the threshold. Even if getAll is true, null will be returned if zero files have been cleaned.

deleteCleanedFiles

public void deleteCleanedFiles(Set cleanedFiles)
                        throws DatabaseException
Delete files that were previously returned by getCleanedFiles, after performing a checkpoint with no deltas and that flushed to the root.

Throws:
DatabaseException

isNearDiskBudget

public boolean isNearDiskBudget(boolean calcIfNecessary)
                         throws DatabaseException
Returns whether we are near to using the disk budget.

Parameters:
calcIfNecessary - is true if this method should calculate the total log size by reading the utilization database if the size is not already available. It will only calculate it the first time it is called and if the cleaner has not yet been invoked.
Returns:
true if we are near the disk budget or, to be conservative, if the total log size is not available and calcIfNecessary is false. False is returned only if we have calculated the total size and we are not near the budget.
Throws:
DatabaseException


Copyright 2004 Sleepycat, Inc. All Rights Reserved.