com.sleepycat.je.tree
Class FileSummaryLN

java.lang.Object
  extended by com.sleepycat.je.tree.Node
      extended by com.sleepycat.je.tree.LN
          extended by com.sleepycat.je.tree.FileSummaryLN
All Implemented Interfaces:
LoggableObject, LogReadable, LogWritable

public final class FileSummaryLN
extends LN

A FileSummaryLN represents a Leaf Node in the UtilizationProfile database.

The contents of the FileSummaryLN are not fixed until the moment at which the LN is added to the log. A base summary object contains the summary last added to the log. A tracked summary object contains live summary info being updated in real time. The tracked summary is added to the base summary just before logging it, and then the tracked summary is reset. This ensures that the logged summary will accurately reflect the totals calculated at the point in the log where the LN is added.

This is all done in the writeToLog method, which operates under the log write latch. All utilization tracking must be done under the log write latch.

In record version 1, obsolete offset tracking was added and multiple records are stored for a single file rather than a single record. Each record contains the offsets that were tracked since the last record was written.

The key is 8 bytes: 4 bytes for the file number followed by 4 bytes for the sequence number. The lowest valued key for a given file contains the most recent summary information, while to get a complete list of obsolete offsets all records for the file must be read. A range search using just the first 4 bytes can be used to find the most recent record -- this is possible because the sequence number values are decreasing over time for a given file. Here are example keys for three summary records in file 1:

 (file=1, sequence=Integer.MAX_VALUE - 300)
 (file=1, sequence=Integer.MAX_VALUE - 200)
 (file=1, sequence=Integer.MAX_VALUE - 100)
 

The sequence number is the number of obsolete entries counted so far, subtracted from Integer.MAX_VALUE to cause the latest written record to have the lowest key.

Log version information

Version 0: Keys are old format strings. No obsolete detail is present.

Version 1: Keys are two 4 byte integers: {file, sequence}. Obsolete detail is present. Some offsets may be invalid if RMW was used.

Version 2: The RMW problem with invalid offsets was corrected. There is no data format change; all versions of JE 2.0.x can read version 1.

See Also:
UtilizationProfile

Constructor Summary
FileSummaryLN()
          Creates an empty LN to be filled in from the log.
FileSummaryLN(FileSummary baseSummary)
          Creates a new LN with a given base summary.
 
Method Summary
 String beginTag()
           
 boolean countAsObsoleteWhenLogged()
          Returns true if this item should be counted as obsoleted when logged.
protected  void dumpLogAdditional(StringBuffer sb)
          Dump additional fields.
 String dumpString(int nSpaces, boolean dumpTags)
           
 String endTag()
           
 FileSummary getBaseSummary()
          Returns the base summary for the file that is stored in the LN.
 long getFileNumber(byte[] bytes)
          Convert a FileSummaryLN key from a byte array to a long.
 int getLogSize()
           
 LogEntryType getLogType()
          All objects that are reponsible for a generating a type of log entry must implement this.
 PackedOffsets getObsoleteOffsets()
          Returns the obsolete offsets for the file.
 TrackedFileSummary getTrackedSummary()
          Returns the tracked summary, or null if setTrackedSummary was not called.
protected  LogEntryType getTransactionalLogType()
          Log type for transactional entries.
 boolean hasStringKey(byte[] bytes)
          Returns true if the given key for this LN is a String file number key.
static byte[] makeFullKey(long fileNum, int sequence)
          Returns the full two-part key for a given file number and unique sequence.
static byte[] makePartialKey(long fileNum)
          Returns the first 4 bytes of the key for the given file number.
 boolean marshallOutsideWriteLatch()
          Return true if this item can be marshalled outside the log write latch.
 void postFetchInit(DatabaseImpl db, long sourceLsn)
          Initialize a node that has been faulted in from the log.
 void readFromLog(ByteBuffer itemBuffer, byte entryTypeVersion)
          Initialize this object from the data in itemBuf.
 void setTrackedSummary(TrackedFileSummary trackedSummary)
          Sets the live summary object that will be added to the base summary at the time the LN is logged.
 String toString()
          Default toString method at the root of the tree.
 void writeToLog(ByteBuffer logBuffer)
          Serialize this object into the buffer.
 
Methods inherited from class com.sleepycat.je.tree.LN
accountForSubtreeRemoval, addToDirtyMap, canBeAncestor, copyData, delete, dumpLog, getData, getMemorySizeIncludedByParent, getTransactionId, isDeleted, isSoughtNode, isValidForDelete, log, logEntryIsTransactional, logProvisional, makeDeleted, modify, rebuildINList
 
Methods inherited from class com.sleepycat.je.tree.Node
containsDuplicates, dump, getLastId, getLevel, getNextNodeId, getNodeId, getType, matchLNByNodeId, postLogWork, setLastNodeId, setNodeId, shortDescription, verify
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface com.sleepycat.je.log.LoggableObject
postLogWork
 

Constructor Detail

FileSummaryLN

public FileSummaryLN(FileSummary baseSummary)
Creates a new LN with a given base summary.


FileSummaryLN

public FileSummaryLN()
              throws DatabaseException
Creates an empty LN to be filled in from the log.

Throws:
DatabaseException
Method Detail

setTrackedSummary

public void setTrackedSummary(TrackedFileSummary trackedSummary)
Sets the live summary object that will be added to the base summary at the time the LN is logged.


getTrackedSummary

public TrackedFileSummary getTrackedSummary()
Returns the tracked summary, or null if setTrackedSummary was not called.


getBaseSummary

public FileSummary getBaseSummary()
Returns the base summary for the file that is stored in the LN.


getObsoleteOffsets

public PackedOffsets getObsoleteOffsets()
Returns the obsolete offsets for the file.


hasStringKey

public boolean hasStringKey(byte[] bytes)
Returns true if the given key for this LN is a String file number key. For the old version of the LN there will be a single record per file. If this is a version 0 log entry, the key is a string. However, such an LN may be migrated by the cleaner, in which case the version will be 1 or greater [#13061]. In the latter case, we can distinguish a string key by: 1) If the key is not 8 bytes long, it has to be a string key. 2) If the key is 8 bytes long, but bytes[4] is ascii "0" to "9", then it must be a string key. bytes[4] to bytes[7] are a sequence number that is the number of log entries counted. For this number to be greater than 0x30000000, the binary value of 4 digits starting with ascii "0", over 400 million log entries would have to occur in a single file; this should never happen. Note that having to rely on method (2) is unlikely. A string key will only be 8 bytes if the file number reach 8 decimal digits (10,000,000 to 99,999,999). This is a very large file number and unlikely to have occurred using JE 1.7.1 or earlier. In summary, the only time the algorithm here could fail is if there were more than 400 million log entries per file, and more than 10 million were written with JE 1.7.1 or earlier.


getFileNumber

public long getFileNumber(byte[] bytes)
Convert a FileSummaryLN key from a byte array to a long. The file number is the first 4 bytes of the key.


makePartialKey

public static byte[] makePartialKey(long fileNum)
Returns the first 4 bytes of the key for the given file number. This can be used to do a range search to find the first LN for the file.


makeFullKey

public static byte[] makeFullKey(long fileNum,
                                 int sequence)
Returns the full two-part key for a given file number and unique sequence. This can be used to insert a new LN.

Parameters:
sequence - is a unique identifier for the LN for the given file, and must be greater than the last sequence.

postFetchInit

public void postFetchInit(DatabaseImpl db,
                          long sourceLsn)
                   throws DatabaseException
Initialize a node that has been faulted in from the log. If this FSLN contains version 1 offsets that can be incorrect when RMW was used, and if je.cleaner.rmwFix is enabled, discard the offsets. [#13158]

Overrides:
postFetchInit in class Node
Throws:
DatabaseException

toString

public String toString()
Description copied from class: Node
Default toString method at the root of the tree.

Overrides:
toString in class Node

beginTag

public String beginTag()
Overrides:
beginTag in class LN

endTag

public String endTag()
Overrides:
endTag in class LN

dumpString

public String dumpString(int nSpaces,
                         boolean dumpTags)
Overrides:
dumpString in class LN

dumpLogAdditional

protected void dumpLogAdditional(StringBuffer sb)
Dump additional fields. Done this way so the additional info can be within the XML tags defining the dumped log entry.

Overrides:
dumpLogAdditional in class LN

getTransactionalLogType

protected LogEntryType getTransactionalLogType()
Log type for transactional entries.

Overrides:
getTransactionalLogType in class LN

getLogType

public LogEntryType getLogType()
Description copied from interface: LoggableObject
All objects that are reponsible for a generating a type of log entry must implement this.

Specified by:
getLogType in interface LoggableObject
Overrides:
getLogType in class LN
Returns:
the type of log entry
See Also:
LN.getLogType()

marshallOutsideWriteLatch

public boolean marshallOutsideWriteLatch()
Description copied from interface: LoggableObject
Return true if this item can be marshalled outside the log write latch.

Specified by:
marshallOutsideWriteLatch in interface LoggableObject
Overrides:
marshallOutsideWriteLatch in class Node
See Also:
FileSummaryLNs must be marshalled within the log write latch, because that critical section is used to guarantee that all previous log entries are reflected in the summary.

countAsObsoleteWhenLogged

public boolean countAsObsoleteWhenLogged()
Description copied from interface: LoggableObject
Returns true if this item should be counted as obsoleted when logged. This currently applies to deleted LNs only.

Specified by:
countAsObsoleteWhenLogged in interface LoggableObject
Overrides:
countAsObsoleteWhenLogged in class LN
See Also:
LoggableObject.countAsObsoleteWhenLogged()

getLogSize

public int getLogSize()
Specified by:
getLogSize in interface LogWritable
Overrides:
getLogSize in class LN
Returns:
number of bytes used to store this object.
See Also:
LN.getLogSize()

writeToLog

public void writeToLog(ByteBuffer logBuffer)
Description copied from interface: LogWritable
Serialize this object into the buffer.

Specified by:
writeToLog in interface LogWritable
Overrides:
writeToLog in class LN
Parameters:
logBuffer - is the destination buffer
See Also:
LN.writeToLog(java.nio.ByteBuffer)

readFromLog

public void readFromLog(ByteBuffer itemBuffer,
                        byte entryTypeVersion)
                 throws LogException
Description copied from interface: LogReadable
Initialize this object from the data in itemBuf.

Specified by:
readFromLog in interface LogReadable
Overrides:
readFromLog in class LN
Throws:
LogException
See Also:
LN.readFromLog(java.nio.ByteBuffer, byte)


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