com.sleepycat.je.cleaner
Class UtilizationProfile

java.lang.Object
  extended by com.sleepycat.je.cleaner.UtilizationProfile
All Implemented Interfaces:
EnvConfigObserver

public class UtilizationProfile
extends java.lang.Object
implements EnvConfigObserver

The UP tracks utilization summary information for all log files.

Unlike the UtilizationTracker, the UP is not accessed under the log write latch and is instead synchronized on itself for protecting the cache. It is not accessed during the primary data access path, except for when flushing (writing) file summary LNs. This occurs in the following cases:

  1. The summary information is flushed at the end of a checkpoint. This allows tracking to occur in memory in between checkpoints, and replayed during recovery.
  2. When committing the truncateDatabase and removeDatabase operations, the summary information is flushed because detail tracking for those operations is not replayed during recovery
  3. The evictor will ask the UtilizationTracker to flush the largest summary if the memory taken by the tracker exeeds its budget.

The cache is populated by the RecoveryManager just before performing the initial checkpoint. The UP must be open and populated in order to respond to requests to flush summaries and to evict tracked detail, even if the cleaner is disabled.

WARNING: While synchronized on this object, eviction is not permitted. If it were, this could cause deadlocks because the order of locking would be the UP object and then the evictor. During normal eviction the order is to first lock the evictor and then the UP, when evicting tracked detail.

The methods in this class synchronize to protect the cached summary information. Some methods also access the UP database. However, because eviction must not occur while synchronized, UP database access is not performed while synchronized except in one case: when inserting a new summary record. In that case we disallow eviction during the database operation.


Constructor Summary
UtilizationProfile(EnvironmentImpl env, UtilizationTracker tracker)
          Creates an empty UP.
 
Method Summary
 void clearCache()
          Clears the cache of file summary info.
 void envConfigUpdate(DbConfigManager cm, EnvironmentMutableConfig ignore)
          Process notifications of mutable property changes.
 void flushFileSummary(TrackedFileSummary tfs)
          Updates and stores the FileSummary for a given tracked file, if flushing of the summary is allowed.
 void flushFileUtilization(java.util.Collection<TrackedFileSummary> activeFiles)
          Flush a FileSummaryLN node for each TrackedFileSummary that is currently active in the given tracker.
 void flushLocalTracker(LocalUtilizationTracker localTracker)
          Count the given locally tracked info as obsolete and then log the file and database info..
 DatabaseImpl getFileSummaryDb()
          For unit testing.
 java.util.SortedMap<java.lang.Long,FileSummary> getFileSummaryMap(boolean includeTrackedFiles)
          Returns a copy of the current file summary map, optionally including tracked summary information, for use by the DbSpace utility and by unit tests.
 boolean isRMWFixEnabled()
           
 boolean populateCache()
          Populate the profile for file selection.
static int utilization(long obsoleteSize, long totalSize)
          Calculate the utilization percentage.
 boolean verifyFileSummaryDatabase()
          Checks that all FSLN offsets are indeed obsolete.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

UtilizationProfile

public UtilizationProfile(EnvironmentImpl env,
                          UtilizationTracker tracker)
                   throws DatabaseException
Creates an empty UP.

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

isRMWFixEnabled

public boolean isRMWFixEnabled()
See Also:
EnvironmentParams.CLEANER_RMW_FIX, FileSummaryLN.postFetchInit(com.sleepycat.je.dbi.DatabaseImpl, long)

utilization

public static int utilization(long obsoleteSize,
                              long totalSize)
Calculate the utilization percentage.


flushLocalTracker

public void flushLocalTracker(LocalUtilizationTracker localTracker)
                       throws DatabaseException
Count the given locally tracked info as obsolete and then log the file and database info..

Throws:
DatabaseException

flushFileUtilization

public void flushFileUtilization(java.util.Collection<TrackedFileSummary> activeFiles)
                          throws DatabaseException
Flush a FileSummaryLN node for each TrackedFileSummary that is currently active in the given tracker.

Throws:
DatabaseException

getFileSummaryMap

public java.util.SortedMap<java.lang.Long,FileSummary> getFileSummaryMap(boolean includeTrackedFiles)
                                                                  throws DatabaseException
Returns a copy of the current file summary map, optionally including tracked summary information, for use by the DbSpace utility and by unit tests. The returned map's key is a Long file number and its value is a FileSummary.

Throws:
DatabaseException

clearCache

public void clearCache()
Clears the cache of file summary info. The cache starts out unpopulated and is populated on the first call to getBestFileForCleaning.


flushFileSummary

public void flushFileSummary(TrackedFileSummary tfs)
                      throws DatabaseException
Updates and stores the FileSummary for a given tracked file, if flushing of the summary is allowed.

Throws:
DatabaseException

populateCache

public boolean populateCache()
                      throws DatabaseException
Populate the profile for file selection. This method performs eviction and is not synchronized. It must be called before recovery is complete so that synchronization is unnecessary. It must be called before the recovery checkpoint so that the checkpoint can flush file summary information.

Throws:
DatabaseException

getFileSummaryDb

public DatabaseImpl getFileSummaryDb()
For unit testing.


verifyFileSummaryDatabase

public boolean verifyFileSummaryDatabase()
                                  throws DatabaseException
Checks that all FSLN offsets are indeed obsolete. Assumes that the system is quiesent (does not lock LNs). This method is not synchronized (because it doesn't access fileSummaryMap) and eviction is allowed.

Returns:
true if no verification failures.
Throws:
DatabaseException