com.sleepycat.je.tree
Class BIN

java.lang.Object
  extended by com.sleepycat.je.tree.Node
      extended by com.sleepycat.je.tree.IN
          extended by com.sleepycat.je.tree.BIN
All Implemented Interfaces:
Loggable, java.lang.Comparable<IN>
Direct Known Subclasses:
DBIN

public class BIN
extends IN
implements Loggable

A BIN represents a Bottom Internal Node in the JE tree.


Field Summary
 
Fields inherited from class com.sleepycat.je.tree.IN
ACCUMULATED_LIMIT, BIN_LEVEL, DBMAP_LEVEL, EXACT_MATCH, INSERT_SUCCESS, latch, LEVEL_MASK, MAIN_LEVEL, MAX_LEVEL, MAY_EVICT_LNS, MAY_EVICT_NODE, MAY_NOT_EVICT, MIN_LEVEL
 
Constructor Summary
BIN()
           
BIN(DatabaseImpl db, byte[] identifierKey, int maxEntriesPerNode, int level)
           
 
Method Summary
 void addCursor(CursorImpl cursor)
          Register a cursor with this BIN.
 void afterLog(LogManager logManager, INLogItem item, INLogContext context)
          Post-log processing.
 void beforeLog(LogManager logManager, INLogItem item, INLogContext context)
          Pre-log processing.
 java.lang.String beginTag()
           
protected  boolean canBeAncestor(boolean targetContainsDuplicates)
           
 void clearKnownDeleted(int index)
          Clear the known deleted flag.
 boolean compress(BINReference binRef, boolean canFetch, LocalUtilizationTracker localTracker)
          Compress this BIN by removing any entries that are deleted.
static long computeOverhead(DbConfigManager configManager)
           
protected  IN createNewInstance(byte[] identifierKey, int maxEntries, int level)
          Create a new BIN.
 BINReference createReference()
          Create a holder object that encapsulates information about this BIN for the INCompressor.
protected  void descendOnParentSearch(SearchResult result, boolean targetContainsDuplicates, boolean targetIsRoot, long targetNodeId, Node child, boolean requireExactMatch)
           
 java.lang.String endTag()
           
 void evictLN(int index)
          Evict a single LN if allowed and adjust the memory budget.
 long evictLNs()
          Reduce memory consumption by evicting all LN targets.
 byte[] getChildKey(IN child)
          Get the key (dupe or identifier) in child that is used to locate it in 'this' node.
 java.util.Set<CursorImpl> getCursorSet()
           
 java.util.Comparator<byte[]> getKeyComparator()
          Return the relevant user defined comparison function for this type of node.
 long getLastDeltaVersion()
           
 LogEntryType getLogType()
           
protected  long getMemoryOverhead(MemoryBudget mb)
           
 long getTreeAdminMemorySize()
          Returns the treeAdmin memory in objects referenced by this BIN.
 boolean isCompressible()
           
 void logDirtyChildren()
          When splits and checkpoints intermingle in a deferred write databases, a checkpoint target may appear which has a valid target but a null LSN.
 int nCursors()
           
 void removeCursor(CursorImpl cursor)
          Unregister a cursor with this bin.
 void setKnownDeleted(int index)
          Mark this entry as deleted, using the delete flag.
 void setKnownDeletedLeaveTarget(int index)
          Mark this entry as deleted, using the delete flag.
 void setProhibitNextDelta()
          If cleaned or compressed, must log full version.
 java.lang.String shortClassName()
           
 void verifyCursors()
          For each cursor in this BIN's cursor set, ensure that the cursor is actually referring to this BIN.
 
Methods inherited from class com.sleepycat.je.tree.IN
clearLsn, clearPendingDeleted, compareTo, computeArraysOverhead, computeMemorySize, deleteEntry, dumpLog, dumpLogAdditional, dumpString, equals, fetchTarget, findEntry, generateLevel, getBudgetedMemorySize, getDatabase, getDatabaseId, getDirty, getDupKey, getDupTreeKey, getEntryInMemorySize, getEvictionType, getGeneration, getIdentifierKey, getInListResident, getInMemorySize, getKey, getLastFullVersion, getLevel, getLogSize, getLsn, getMainTreeKey, getMigrate, getNEntries, getRecalcToggle, getState, getTarget, hashCode, init, initMemorySize, insertEntry, insertEntry1, isDbRoot, isEntryKnownDeleted, isEntryPendingDeleted, isEvictable, isKeyInBounds, isLatchOwnerForRead, isLatchOwnerForWrite, isRoot, isSoughtNode, latch, latch, latchNoWait, latchNoWait, latchShared, latchShared, log, log, log, logicalEquals, needsSplitting, optionalLog, optionalLogProvisional, postFetchInit, postRecoveryInit, readFromLog, releaseLatch, releaseLatchIfOwner, selectKey, setDatabase, setDirty, setEntry, setGeneration, setGeneration, setInListResident, setMigrate, setPendingDeleted, setRecalcToggle, splitInternal, toString, updateEntry, updateEntry, updateEntry, updateMemorySize, updateMemorySize, updateNode, updateNode, updateNode, verify, verifyMemorySize, writeToLog
 
Methods inherited from class com.sleepycat.je.tree.Node
containsDuplicates, dump, getMemorySizeIncludedByParent, getNodeId, getTransactionId, getType, shortDescription
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface com.sleepycat.je.log.Loggable
dumpLog, getLogSize, getTransactionId, logicalEquals, readFromLog, writeToLog
 

Constructor Detail

BIN

public BIN()

BIN

public BIN(DatabaseImpl db,
           byte[] identifierKey,
           int maxEntriesPerNode,
           int level)
Method Detail

createReference

public BINReference createReference()
Create a holder object that encapsulates information about this BIN for the INCompressor.


createNewInstance

protected IN createNewInstance(byte[] identifierKey,
                               int maxEntries,
                               int level)
Create a new BIN. Need this because we can't call newInstance() without getting a 0 for nodeid.

Overrides:
createNewInstance in class IN

getChildKey

public byte[] getChildKey(IN child)
                   throws DatabaseException
Get the key (dupe or identifier) in child that is used to locate it in 'this' node. For BIN's, the child node has to be a DIN so we use the Dup Key to cross the main-tree/dupe-tree boundary.

Overrides:
getChildKey in class IN
Throws:
DatabaseException

getLastDeltaVersion

public long getLastDeltaVersion()
Returns:
location of last logged delta version. If never set, return null.

setProhibitNextDelta

public void setProhibitNextDelta()
If cleaned or compressed, must log full version.

Overrides:
setProhibitNextDelta in class IN

descendOnParentSearch

protected void descendOnParentSearch(SearchResult result,
                                     boolean targetContainsDuplicates,
                                     boolean targetIsRoot,
                                     long targetNodeId,
                                     Node child,
                                     boolean requireExactMatch)
                              throws DatabaseException
Overrides:
descendOnParentSearch in class IN
Throws:
DatabaseException

canBeAncestor

protected boolean canBeAncestor(boolean targetContainsDuplicates)
Overrides:
canBeAncestor in class IN
Returns:
true if you can be the ancestor of the target IN. Currently the determining factor is whether the target IN contains duplicates.

setKnownDeleted

public void setKnownDeleted(int index)
Mark this entry as deleted, using the delete flag. Only BINS may do this.

Parameters:
index - indicates target entry

setKnownDeletedLeaveTarget

public void setKnownDeletedLeaveTarget(int index)
Mark this entry as deleted, using the delete flag. Only BINS may do this. Don't null the target field. This is used so that an LN can still be locked by the compressor even if the entry is knownDeleted. See BIN.compress.

Parameters:
index - indicates target entry

clearKnownDeleted

public void clearKnownDeleted(int index)
Clear the known deleted flag. Only BINS may do this.

Parameters:
index - indicates target entry

computeOverhead

public static long computeOverhead(DbConfigManager configManager)
                            throws DatabaseException
Throws:
DatabaseException

getMemoryOverhead

protected long getMemoryOverhead(MemoryBudget mb)
Overrides:
getMemoryOverhead in class IN

getTreeAdminMemorySize

public long getTreeAdminMemorySize()
Returns the treeAdmin memory in objects referenced by this BIN. Specifically, this refers to the DbFileSummaryMap held by MapLNs

Overrides:
getTreeAdminMemorySize in class IN

getCursorSet

public java.util.Set<CursorImpl> getCursorSet()

addCursor

public void addCursor(CursorImpl cursor)
Register a cursor with this BIN. Caller has this BIN already latched.

Parameters:
cursor - Cursor to register.

removeCursor

public void removeCursor(CursorImpl cursor)
Unregister a cursor with this bin. Caller has this BIN already latched.

Parameters:
cursor - Cursor to unregister.

nCursors

public int nCursors()
Returns:
the number of cursors currently referring to this BIN.

verifyCursors

public void verifyCursors()
For each cursor in this BIN's cursor set, ensure that the cursor is actually referring to this BIN.


compress

public boolean compress(BINReference binRef,
                        boolean canFetch,
                        LocalUtilizationTracker localTracker)
                 throws DatabaseException
Compress this BIN by removing any entries that are deleted. Deleted entries are those that have LN's marked deleted or if the knownDeleted flag is set. Caller is responsible for latching and unlatching this node.

Overrides:
compress in class IN
Parameters:
binRef - is used to determine the set of keys to be checked for deletedness, or is null to check all keys.
canFetch - if false, don't fetch any non-resident children. We don't want some callers of compress, such as the evictor, to fault in other nodes.
Returns:
true if we had to requeue the entry because we were unable to get locks, false if all entries were processed and therefore any remaining deleted keys in the BINReference must now be in some other BIN because of a split.
Throws:
DatabaseException

isCompressible

public boolean isCompressible()
Overrides:
isCompressible in class IN

evictLNs

public long evictLNs()
              throws DatabaseException
Reduce memory consumption by evicting all LN targets. Note that this may cause LNs to be logged, which would require marking this BIN dirty. The BIN should be latched by the caller.

Returns:
number of evicted bytes. Note that a 0 return does not necessarily mean that the BIN had no evictable LNs. It's possible that resident, dirty LNs were not lockable.
Throws:
DatabaseException

evictLN

public void evictLN(int index)
             throws DatabaseException
Evict a single LN if allowed and adjust the memory budget.

Throws:
DatabaseException

getKeyComparator

public java.util.Comparator<byte[]> getKeyComparator()
Return the relevant user defined comparison function for this type of node. For IN's and BIN's, this is the BTree Comparison function. Overriden by DBIN.

Overrides:
getKeyComparator in class IN

beginTag

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

endTag

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

logDirtyChildren

public void logDirtyChildren()
                      throws DatabaseException
Description copied from class: IN
When splits and checkpoints intermingle in a deferred write databases, a checkpoint target may appear which has a valid target but a null LSN. Deferred write dbs are written out in checkpoint style by either Database.sync() or a checkpoint which has cleaned a file containing deferred write entries. For example, INa | BINb A checkpoint or Database.sync starts The INList is traversed, dirty nodes are selected BINb is bypassed on the INList, since it's not dirty BINb is split, creating a new sibling, BINc, and dirtying INa INa is selected as a dirty node for the ckpt If this happens, INa is in the selected dirty set, but not its dirty child BINb and new child BINc. In a durable db, the existence of BINb and BINc are logged anyway. But in a deferred write db, there is an entry that points to BINc, but no logged version. This will not cause problems with eviction, because INa can't be evicted until BINb and BINc are logged, are non-dirty, and are detached. But it can cause problems at recovery, because INa will have a null LSN for a valid entry, and the LN children of BINc will not find a home. To prevent this, search for all dirty children that might have been missed during the selection phase, and write them out. It's not sufficient to write only null-LSN children, because the existing sibling must be logged lest LN children recover twice (once in the new sibling, once in the old existing sibling.

Overrides:
logDirtyChildren in class IN
Throws:
DatabaseException
See Also:
IN.logDirtyChildren();

getLogType

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

shortClassName

public java.lang.String shortClassName()
Overrides:
shortClassName in class IN

beforeLog

public void beforeLog(LogManager logManager,
                      INLogItem item,
                      INLogContext context)
               throws DatabaseException
Description copied from class: IN
Pre-log processing. Used implicitly for single-item logging and explicitly for multi-item logging. Overridden by subclasses as needed. Decide how to log this node. INs are always logged in full. Cleaner LN migration is never performed since it only applies to BINs.

Overrides:
beforeLog in class IN
Throws:
DatabaseException

afterLog

public void afterLog(LogManager logManager,
                     INLogItem item,
                     INLogContext context)
              throws DatabaseException
Description copied from class: IN
Post-log processing. Used implicitly for single-item logging and explicitly for multi-item logging. Overridden by subclasses as needed. The last version of this node must be counted obsolete at the correct time. If logging non-provisionally, the last version of this node and any provisionally logged descendants are immediately obsolete and can be flushed. If logging provisionally, the last version isn't obsolete until an ancestor is logged non-provisionally, so propagate obsolete lsns upwards.

Overrides:
afterLog in class IN
Throws:
DatabaseException