com.sleepycat.je.cleaner
Class UtilizationTracker

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

public class UtilizationTracker
extends Object

Tracks changes to the utilization profile since the last checkpoint.

All changes to this object occur must under the log write latch. It is possible to read tracked info without holding the latch. This is done by the cleaner when selecting a file and by the checkpointer when determining what FileSummaryLNs need to be written. To read tracked info outside the log write latch, call getTrackedFile or getTrackedFiles. activateCleaner can also be called outside the latch.


Constructor Summary
UtilizationTracker(EnvironmentImpl env)
          Creates an empty tracker.
 
Method Summary
 void activateCleaner()
          Wakeup the cleaner thread and reset the log byte counter.
 void addSummary(long fileNumber, TrackedFileSummary other)
          Adds changes from a given TrackedFileSummary.
 boolean countNewLogEntry(long lsn, LogEntryType type, int size)
          Counts the addition of all new log entries including LNs, and returns whether the cleaner should be woken.
 void countObsoleteNode(long lsn, LogEntryType type)
          Counts a node that has become obsolete and tracks the LSN offset to avoid a lookup during cleaning.
 void countObsoleteNodeInexact(long lsn, LogEntryType type)
          Counts as countObsoleteNode does, but since the LSN may be inexact, does not track the obsolete LSN offset.
 long evictMemory()
          Evicts tracked detail if the budget for the tracker is exceeded.
 EnvironmentImpl getEnvironment()
           
(package private)  boolean getTrackDetail()
           
 TrackedFileSummary getTrackedFile(long fileNum)
          Returns one file from the snapshot of tracked files, or null if the given file number is not in the snapshot array.
 TrackedFileSummary[] getTrackedFiles()
          Returns a snapshot of the files being tracked as of the last time a log entry was added.
 TrackedFileSummary getUnflushableTrackedSummary(long fileNum)
          Returns a tracked summary for the given file which will not be flushed.
(package private)  void resetFile(TrackedFileSummary file)
          Called after the FileSummaryLN is written to the log during checkpoint.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

UtilizationTracker

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

Throws:
DatabaseException
Method Detail

getEnvironment

public EnvironmentImpl getEnvironment()

getTrackDetail

boolean getTrackDetail()

evictMemory

public long evictMemory()
                 throws DatabaseException
Evicts tracked detail if the budget for the tracker is exceeded. Evicts only one file summary LN at most to keep eviction batches small. Returns the number of bytes freed.

When flushFileSummary is called, the TrackedFileSummary is cleared via its reset method, which is called by FileSummaryLN.writeToLog. This is how memory is subtracted from the budget.

Throws:
DatabaseException

activateCleaner

public void activateCleaner()
Wakeup the cleaner thread and reset the log byte counter.


getTrackedFiles

public TrackedFileSummary[] getTrackedFiles()
Returns a snapshot of the files being tracked as of the last time a log entry was added. The summary info returned is the delta since the last checkpoint, not the grand totals, and is approximate since it is changing in real time. This method may be called without holding the log write latch.

If files are added or removed from the list of tracked files in real time, the returned array will not be changed since it is a snapshot. But the objects contained in the array are live and will be updated in real time under the log write latch. The array and the objects in the array should not be modified by the caller.


getTrackedFile

public TrackedFileSummary getTrackedFile(long fileNum)
Returns one file from the snapshot of tracked files, or null if the given file number is not in the snapshot array.

See Also:
getTrackedFiles()

countNewLogEntry

public boolean countNewLogEntry(long lsn,
                                LogEntryType type,
                                int size)
Counts the addition of all new log entries including LNs, and returns whether the cleaner should be woken.

Must be called under the log write latch.


countObsoleteNode

public void countObsoleteNode(long lsn,
                              LogEntryType type)
Counts a node that has become obsolete and tracks the LSN offset to avoid a lookup during cleaning.

This method should only be called for LNs and INs (i.e, only for nodes). If type is null we assume it is an LN.

Must be called under the log write latch.


countObsoleteNodeInexact

public void countObsoleteNodeInexact(long lsn,
                                     LogEntryType type)
Counts as countObsoleteNode does, but since the LSN may be inexact, does not track the obsolete LSN offset.

This method should only be called for LNs and INs (i.e, only for nodes). If type is null we assume it is an LN.

Must be called under the log write latch.


addSummary

public void addSummary(long fileNumber,
                       TrackedFileSummary other)
Adds changes from a given TrackedFileSummary.

Must be called under the log write latch.


getUnflushableTrackedSummary

public TrackedFileSummary getUnflushableTrackedSummary(long fileNum)
                                                throws DatabaseException
Returns a tracked summary for the given file which will not be flushed. Used for watching changes that occur while a file is being cleaned.

Throws:
DatabaseException

resetFile

void resetFile(TrackedFileSummary file)
Called after the FileSummaryLN is written to the log during checkpoint.

We keep the active file summary in the tracked file list, but we remove older files to prevent unbounded growth of the list.

Must be called under the log write latch.



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