com.sleepycat.je.cleaner
Class UtilizationProfile

java.lang.Object
  extended by com.sleepycat.je.cleaner.UtilizationProfile

public class UtilizationProfile
extends Object

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. It is accessed by four other entities: the cleaner, the checkpointer, the compressor, and the recovery manager. It is not accessed during the primary data access path, except for when committing the Database truncate and remove operations.

The cleaner will ask the UP to populate its cache in order to determine the total log size or to select the best file for cleaning. The UP will then read all records in the UP database that are not already cached. The checkpointer calls putFileSummary to write file summary LNs to the log.

Because this object is synchronized it is possible that the cleaner will hold up the checkpointer if the cleaner is populating its cache or calculating the best file, and the checkpointer tries to write the file summary LNs to the log. This blocking is acceptable. Deadlocks will not occur since calls are always from the checkpointer or cleaner to the UP, and not in the other direction.


Constructor Summary
UtilizationProfile(EnvironmentImpl env, UtilizationTracker tracker)
          Creates an empty UP.
 
Method Summary
 void clearCache()
          Clears the cache of file summary info.
 void countAndLogSummaries(TrackedFileSummary[] summaries)
          Count the given tracked info as obsolete and then log the summaries.
 void flushFileSummary(TrackedFileSummary tfs)
          Updates and stores the FileSummary for a given tracked file, if flushing of the summary is allowed.
(package private)  Long getBestFileForCleaning(FileSelector fileSelector, boolean forceCleaning, Set lowUtilizationFiles)
          Returns the best file that qualifies for cleaning, or null if no file qualifies.
(package private)  Long getCheapestFileToClean(List files)
          Returns the cheapest file to clean from the given list of files.
 SortedMap 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.
(package private)  int getNumberOfFiles()
          Returns the number of files in the profile.
(package private)  TrackedFileSummary getObsoleteDetail(Long fileNum, PackedOffsets packedOffsets)
          Returns the stored/packed obsolete offsets and the tracked obsolete offsets for the given file.
 boolean isRMWFixEnabled()
           
(package private)  void removeFile(Long fileNum)
          Removes a file from the utilization database and the profile, after it has been deleted by the cleaner.
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

isRMWFixEnabled

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

getNumberOfFiles

int getNumberOfFiles()
               throws DatabaseException
Returns the number of files in the profile.

Throws:
DatabaseException

getCheapestFileToClean

Long getCheapestFileToClean(List files)
                      throws DatabaseException
Returns the cheapest file to clean from the given list of files. This method is used to select the first file to be cleaned in the batch of to-be-cleaned files.

Throws:
DatabaseException

getBestFileForCleaning

Long getBestFileForCleaning(FileSelector fileSelector,
                            boolean forceCleaning,
                            Set lowUtilizationFiles)
                      throws DatabaseException
Returns the best file that qualifies for cleaning, or null if no file qualifies.

Parameters:
fileSelector - is used to determine valid cleaning candidates.
forceCleaning - is true to always select a file, even if its utilization is above the minimum utilization threshold.
lowUtilizationFiles - is a returned set of files that are below the minimum utilization threshold.
Throws:
DatabaseException

utilization

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


countAndLogSummaries

public void countAndLogSummaries(TrackedFileSummary[] summaries)
                          throws DatabaseException
Count the given tracked info as obsolete and then log the summaries.

Throws:
DatabaseException

getFileSummaryMap

public SortedMap 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.


removeFile

void removeFile(Long fileNum)
          throws DatabaseException
Removes a file from the utilization database and the profile, after it has been deleted by the cleaner.

Throws:
DatabaseException

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

getObsoleteDetail

TrackedFileSummary getObsoleteDetail(Long fileNum,
                                     PackedOffsets packedOffsets)
                               throws DatabaseException
Returns the stored/packed obsolete offsets and the tracked obsolete offsets for the given file. The tracked summary object returned can be used to test for obsolete offsets that are being added during cleaning by other threads participating in lazy migration. The caller must call TrackedFileSummary.setAllowFlush(true) when cleaning is complete.

Throws:
DatabaseException

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.

Returns:
true if no verification failures.
Throws:
DatabaseException


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