com.sleepycat.je.tree
Class MapLN

java.lang.Object
  extended by com.sleepycat.je.tree.Node
      extended by com.sleepycat.je.tree.LN
          extended by com.sleepycat.je.tree.MapLN
All Implemented Interfaces:
Loggable

public final class MapLN
extends LN

A MapLN represents a Leaf Node in the JE Db Mapping Tree. MapLNs contain a DatabaseImpl, which in turn contain three categories of information - database configuration information, the per-database File Summary utilization information, and each database's btree root. While LNs are written to the log as the result of API operations which create new data records, MapLNs are written to the log as a result of configuration changes, utilization information changes, or updates to the btree which cascade up the tree and result in a new root. Because they serve as a bridge between the application data btree and the db mapping tree, MapLNs must be written with special rules, and should only be written from DbTree.modifyDbRoot. The basic rule is that in order to ensure that the MapLN contains the proper btree root, the btree root latch is used to protect both any logging of the MapLN, and any updates to the root lsn. Updates to the internal btree nodes obey a strict bottom up approach, in accordance with the log semantics which require that later log entries are known to supercede earlier log entries. In other words, for a btree that looks like MapLN | IN | BIN | LN we know that update operations cause the btree nodes must be logged in this order: LN, BIN, IN, MapLN, so that the reference to each on disk node is correct. (Note that logging order is special and different when the btree is initially created.) However, MapLNs may need to be written to disk at arbitrary points in time in order to save database config or utilization data. Those writes don't have the time and context to be done in a cascading-upwards fashion. We ensure that MapLNs are not erroneously written with an out of sync root by requiring that DbTree.modifyDbRoot takes the root latch for the application data btree. RootINs are also written with the root latch, so it serves to ensure that the root doesn't change during the time when the MapLN is written. For example, suppose thread 1 is doing a cascading-up MapLN write, and thread 2 is doing an arbitrary-point MapLN write: Thread 1 Thread 2 -------- -------- latch root latch BIN parent of MapLN log root IN log MapLN (Tree root) wants to log MapLN too -- but has to take to refer to new root IN root latch, so we'll get the right rootIN Without latching the root this could produce the following, incorrect log 30 LNa 40 BIN 50 IN (first version of root) 60 MapLN, refers to IN(50) ... 90 LNb 100 BIN 110 IN (second version of root) 120 CkptStart (the tree is not dirty, no IN will be logged during the ckpt interval)) .. something arbirarily writes out the MapLN 130 MapLN refers to first root, IN(50) <------ impossible While a MapLN can't be written out with the wrong root, it's possible for a rootIN to be logged without the MapLN, and for that rootIN not to be processed at recovery. Suppose a checkpoint begins and ends in the window between when a rootIN is written, and DbTree.modifyDbRoot is called: 300 log new root IN, update root reference in tree unlatch root 310 Checkpoint starts 320 Checkpoint ends ...if we crash here, before the MapLN is logged, , we won't see the new root IN at lsn 300. However, the IN is non-txnal and will be * recreated during reply of txnal * information (LNs) by normal recovery processing.


Constructor Summary
MapLN()
          Create an empty MapLN, to be filled in from the log.
MapLN(DatabaseImpl db)
          Create a new MapLn to hold a new databaseImpl.
 
Method Summary
 java.lang.String beginTag()
           
protected  void dumpLogAdditional(java.lang.StringBuffer sb, boolean verbose)
          Dump additional fields.
 java.lang.String dumpString(int nSpaces, boolean dumpTags)
           
 java.lang.String endTag()
           
 DatabaseImpl getDatabase()
           
 int getLogSize()
           
 LogEntryType getLogType()
           
 long getMemorySizeIncludedByParent()
          Compute the approximate size of this node in memory for evictor invocation purposes.
protected  LogEntryType getTransactionalLogType()
          Log type for transactional entries.
 boolean isDeleted()
           
 boolean logicalEquals(Loggable other)
           
 void postFetchInit(DatabaseImpl db, long sourceLsn)
          Initialize a node that has been faulted in from the log.
 void readFromLog(java.nio.ByteBuffer itemBuffer, byte entryVersion)
          Initialize this object from the data in itemBuf.
 void releaseMemoryBudget()
          Release the memory budget for any objects referenced by this LN.
 java.lang.String toString()
          Default toString method at the root of the tree.
 void writeToLog(java.nio.ByteBuffer logBuffer)
          Serialize this object into the buffer.
 
Methods inherited from class com.sleepycat.je.tree.LN
canBeAncestor, copyData, delete, dumpLog, getData, getLastLoggedSize, isDirty, isSoughtNode, log, modify, optionalLog, optionalLogProvisional, setDirty, setLastLoggedSize
 
Methods inherited from class com.sleepycat.je.tree.Node
containsDuplicates, dump, getLevel, getNodeId, getTransactionId, getType, latchShared, latchShared, releaseLatch, 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.Loggable
getTransactionId
 

Constructor Detail

MapLN

public MapLN(DatabaseImpl db)
Create a new MapLn to hold a new databaseImpl. In the ideal world, we'd have a base LN class so that this MapLN doesn't have a superfluous data field, but we want to optimize the LN class for size and speed right now.


MapLN

public MapLN()
      throws DatabaseException
Create an empty MapLN, to be filled in from the log.

Throws:
DatabaseException
Method Detail

isDeleted

public boolean isDeleted()
Overrides:
isDeleted in class LN

getDatabase

public DatabaseImpl getDatabase()

postFetchInit

public void postFetchInit(DatabaseImpl db,
                          long sourceLsn)
                   throws DatabaseException
Initialize a node that has been faulted in from the log.

Overrides:
postFetchInit in class Node
Throws:
DatabaseException

getMemorySizeIncludedByParent

public long getMemorySizeIncludedByParent()
Compute the approximate size of this node in memory for evictor invocation purposes. Don't count the treeAdmin memory, because that goes into a different bucket.

Overrides:
getMemorySizeIncludedByParent in class LN

releaseMemoryBudget

public void releaseMemoryBudget()
Description copied from class: LN
Release the memory budget for any objects referenced by this LN. For now, only release treeAdmin memory, because treeMemory is handled in aggregate at the IN level. Over time, transition all of the LN's memory budget to this, so we update the memory budget counters more locally. Called when we are releasing a LN for garbage collection.

Overrides:
releaseMemoryBudget in class LN
See Also:
LN.releaseMemoryBudget()

toString

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

Overrides:
toString in class Node

beginTag

public java.lang.String beginTag()
Overrides:
beginTag in class LN

endTag

public java.lang.String endTag()
Overrides:
endTag in class LN

dumpString

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

getTransactionalLogType

protected LogEntryType getTransactionalLogType()
Log type for transactional entries.

Overrides:
getTransactionalLogType in class LN

getLogType

public LogEntryType getLogType()
Overrides:
getLogType in class LN
See Also:
Node.getLogType()

getLogSize

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

writeToLog

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

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

readFromLog

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

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

logicalEquals

public boolean logicalEquals(Loggable other)
Specified by:
logicalEquals in interface Loggable
Overrides:
logicalEquals in class LN
Returns:
true if these two loggable items are logically the same. Used for replication testing.
See Also:
Should never be replicated.

dumpLogAdditional

protected void dumpLogAdditional(java.lang.StringBuffer sb,
                                 boolean verbose)
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