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 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
(package private)  void close()
          Update memory budgets when this profile is closed and will never be accessed again.
 void flushFileSummary(TrackedFileSummary tfs)
          Updates and stores the FileSummary for a given tracked file, if flushing of the summary is allowed.
 void flushFileUtilization(Collection<TrackedFileSummary> activeFiles)
          Flush a FileSummaryLN node for each given TrackedFileSummary.
 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.
 SortedMap<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.
(package private)  int getNumberOfFiles()
          Returns the number of files in the profile.
(package private)  PackedOffsets getObsoleteDetail(Long fileNum, boolean logUpdate)
          Returns the stored/packed obsolete offsets offsets for the given file.
(package private)  long getTotalLogSize()
          Returns an approximation of the total log size.
 boolean insertFileSummary(FileSummaryLN ln, long fileNum, int sequence)
          Insert the given LN with the given key values.
 boolean populateCache(StartupTracker.Counter counter)
          Populate the profile for file selection.
(package private)  void removeFile(Long fileNum, Set<DatabaseId> databases)
          Removes a file from the MapLN utilization info, the utilization database and the profile, after it has been determined that the file does not exist.
(package private)  void removePerDbMetadata(Collection<Long> fileNums, Set<DatabaseId> databases)
          Updates all MapLNs to remove the DbFileSummary for the given set of file.
(package private)  void removePerFileMetadata(Long fileNum)
          Removes a file from the utilization database and the profile.
 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)
Creates an empty UP.

Method Detail

getNumberOfFiles

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


getTotalLogSize

long getTotalLogSize()
Returns an approximation of the total log size. Used for stats.


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(Collection<TrackedFileSummary> activeFiles)
                          throws DatabaseException
Flush a FileSummaryLN node for each given TrackedFileSummary.

Throws:
DatabaseException

getFileSummaryMap

public SortedMap<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. The returned map's key is a Long file number and its value is a FileSummary.


removeFile

void removeFile(Long fileNum,
                Set<DatabaseId> databases)
          throws DatabaseException
Removes a file from the MapLN utilization info, the utilization database and the profile, after it has been determined that the file does not exist.

Throws:
DatabaseException

removePerFileMetadata

void removePerFileMetadata(Long fileNum)
                     throws DatabaseException
Removes a file from the utilization database and the profile. For a given file, this method should be called after calling removePerDbMetadata. We update the MapLNs before deleting FileSummaryLNs in case there is an error during this process. If a FileSummaryLN exists, we will redo this process during the next recovery (populateCache).

Throws:
DatabaseException

removePerDbMetadata

void removePerDbMetadata(Collection<Long> fileNums,
                         Set<DatabaseId> databases)
                   throws DatabaseException
Updates all MapLNs to remove the DbFileSummary for the given set of file. This method performs eviction and is not synchronized. This method is optimally called with a set of files that will subsequently be passed to removePerFileMetadata. When a set of files is being deleted, this prevents writing a MapLN more than once when more than one file contains entries for that database. For a given file, this method should be called before calling removePerFileMetadata. We update the MapLNs before deleting FileSummaryLNs in case there is an error during this process. If a FileSummaryLN exists, we will redo this process during the next recovery (populateCache).

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

PackedOffsets getObsoleteDetail(Long fileNum,
                                boolean logUpdate)
                          throws DatabaseException
Returns the stored/packed obsolete offsets offsets for the given file.

Parameters:
logUpdate - if true, log any updates to the utilization profile. If false, only retrieve the new information.
Throws:
DatabaseException

populateCache

public boolean populateCache(StartupTracker.Counter counter)
                      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.


insertFileSummary

public boolean insertFileSummary(FileSummaryLN ln,
                                 long fileNum,
                                 int sequence)
                          throws DatabaseException
Insert the given LN with the given key values. This method is synchronized and may not perform eviction. Is public only for unit testing.

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) and eviction is allowed.

Returns:
true if no verification failures.
Throws:
DatabaseException

close

void close()
Update memory budgets when this profile is closed and will never be accessed again.



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