public final class Tree extends Object implements Loggable
| Modifier and Type | Class and Description |
|---|---|
static class |
Tree.SearchType
Embodies an enum for the type of search being performed.
|
| Constructor and Description |
|---|
Tree()
Create a tree that's being read in from the log.
|
Tree(DatabaseImpl database)
Create a new tree.
|
| Modifier and Type | Method and Description |
|---|---|
void |
delete(byte[] idKey)
Deletes a BIN specified by key from the tree.
|
void |
dump() |
void |
dumpLog(StringBuilder sb,
boolean verbose)
Write the object into the string buffer for log dumping.
|
String |
dumpString(int nSpaces) |
BIN |
findBinForInsert(byte[] key,
CacheMode cacheMode)
Find the BIN that is relevant to the insert.
|
DatabaseImpl |
getDatabase() |
BIN |
getFirstNode(CacheMode cacheMode)
Find the leftmost node (IN or BIN) in the tree.
|
BIN |
getLastNode(CacheMode cacheMode)
Find the rightmost node (IN or BIN) in the tree.
|
int |
getLogSize() |
long |
getMaxLNs()
Cheaply calculates and returns the maximum possible number of LNs in the
btree.
|
BIN |
getNextBin(BIN bin,
CacheMode cacheMode)
Return a reference to the adjacent BIN.
|
IN |
getNextIN(IN prevIn,
boolean forward,
boolean latchShared,
CacheMode cacheMode)
Returns the next IN in the tree before/after the given IN, and at the
same level.
|
boolean |
getParentBINForChildLN(TreeLocation location,
byte[] key,
boolean splitsAllowed,
boolean blindDeltaOps,
CacheMode cacheMode)
Return a reference to the parent of this LN.
|
SearchResult |
getParentINForChildIN(IN child,
boolean useTargetLevel,
boolean doFetch,
CacheMode cacheMode)
Search for the parent P of a given IN C (where C is viewed as a logical
node; not as a java obj).
|
SearchResult |
getParentINForChildIN(IN child,
boolean useTargetLevel,
boolean doFetch,
CacheMode cacheMode,
List<TrackingInfo> trackingList)
This version of getParentINForChildIN does the same thing as the version
above, but also adds a "trackingList" param.
|
SearchResult |
getParentINForChildIN(long targetNodeId,
byte[] targetKey,
int targetLevel,
int exclusiveLevel,
boolean requireExactMatch,
boolean doFetch,
CacheMode cacheMode,
List<TrackingInfo> trackingList)
This version of getParentINForChildIN() is the actual implementation
of the previous 2 versions (read the comments there), but it also
implements one additional use cases via the extra "requireExactMatch"
param.
|
BIN |
getPrevBin(BIN bin,
CacheMode cacheMode)
Return a reference to the previous BIN.
|
IN |
getResidentRootIN(boolean latched) |
IN |
getRootIN(CacheMode cacheMode)
Helper to obtain the root IN with shared root latching.
|
IN |
getRootINLatchedExclusive(CacheMode cacheMode)
Helper to obtain the root IN with exclusive root latching.
|
IN |
getRootINRootAlreadyLatched(CacheMode cacheMode,
boolean exclusive)
Helper to obtain the root IN, when the root latch is already held.
|
long |
getRootLsn()
Get LSN of the rootIN.
|
long |
getTransactionId() |
boolean |
isRootResident()
Perform a fast check to see if the root IN is resident.
|
void |
latchRootLatchExclusive() |
boolean |
logicalEquals(Loggable other) |
ChildReference |
makeRootChildReference(Node target,
byte[] key,
long lsn) |
void |
readFromLog(ByteBuffer itemBuffer,
int entryVersion)
Initialize this object from the data in itemBuf.
|
void |
rebuildINList()
rebuildINList is used by recovery to add all the resident nodes to the
IN list.
|
void |
releaseRootLatch() |
boolean |
rootExists() |
BIN |
search(byte[] key,
CacheMode cacheMode) |
BIN |
search(byte[] key,
Tree.SearchType searchType,
BINBoundary binBoundary,
CacheMode cacheMode,
Comparator<byte[]> comparator)
Search the tree, starting at the root.
|
BIN |
searchSplitsAllowed(byte[] key,
CacheMode cacheMode)
Do a key based search, permitting pre-emptive splits.
|
void |
setCkptHook(TestHook hook) |
void |
setDatabase(DatabaseImpl database)
Set the database for this tree.
|
void |
setFetchINHook(TestHook hook) |
void |
setGetParentINHook(TestHook hook) |
void |
setRoot(ChildReference newRoot,
boolean notLatched)
Set the root for the tree.
|
void |
setSearchHook(TestHook hook) |
void |
setTreeStatsAccumulator(TreeWalkerStatsAccumulator tSA) |
void |
setWaitHook(TestHook hook) |
void |
validateINList(IN parent)
Debugging check that all resident nodes are on the INList and no stray
nodes are present in the unused portion of the IN arrays.
|
IN |
withRootLatchedExclusive(WithRootLatched wrl) |
IN |
withRootLatchedShared(WithRootLatched wrl) |
void |
writeToLog(ByteBuffer logBuffer)
Serialize this object into the buffer.
|
public Tree(DatabaseImpl database)
public Tree()
public void setDatabase(DatabaseImpl database)
public DatabaseImpl getDatabase()
public void latchRootLatchExclusive()
throws DatabaseException
DatabaseExceptionpublic void releaseRootLatch()
throws DatabaseException
DatabaseExceptionpublic void setRoot(ChildReference newRoot, boolean notLatched)
public ChildReference makeRootChildReference(Node target, byte[] key, long lsn)
public boolean rootExists()
public boolean isRootResident()
public IN getRootIN(CacheMode cacheMode) throws DatabaseException
DatabaseExceptionpublic IN getRootINLatchedExclusive(CacheMode cacheMode) throws DatabaseException
DatabaseExceptionpublic IN getRootINRootAlreadyLatched(CacheMode cacheMode, boolean exclusive)
public IN getResidentRootIN(boolean latched) throws DatabaseException
DatabaseExceptionpublic IN withRootLatchedExclusive(WithRootLatched wrl) throws DatabaseException
DatabaseExceptionpublic IN withRootLatchedShared(WithRootLatched wrl) throws DatabaseException
DatabaseExceptionpublic long getRootLsn()
public long getMaxLNs()
public void delete(byte[] idKey)
throws NodeNotEmptyException,
CursorsExistException
idKey - - the identifier key of the node to delete.NodeNotEmptyException - if the BIN is not empty. The deletion is
no longer possible.CursorsExistException - is the BIN has cursors. The deletion
should be retried later by the INCompressor.public BIN getFirstNode(CacheMode cacheMode) throws DatabaseException
DatabaseExceptionpublic BIN getLastNode(CacheMode cacheMode) throws DatabaseException
DatabaseExceptionpublic BIN getNextBin(BIN bin, CacheMode cacheMode) throws DatabaseException
bin - The BIN to find the next BIN for. This BIN is latched.DatabaseExceptionpublic BIN getPrevBin(BIN bin, CacheMode cacheMode) throws DatabaseException
bin - The BIN to find the next BIN for. This BIN is latched.DatabaseExceptionpublic IN getNextIN(IN prevIn, boolean forward, boolean latchShared, CacheMode cacheMode)
public SearchResult getParentINForChildIN(IN child, boolean useTargetLevel, boolean doFetch, CacheMode cacheMode) throws DatabaseException
child - The child node for which to find the parent. This node is
latched by the caller and is unlatched by this function before returning
to the caller.useTargetLevel - If true, the search is considered successful if
a node P is reached at one level above C's level. P is the parent to
return to the caller.doFetch - if false, stop the search if we run into a non-resident
child and assume that no parent exists.cacheMode - The CacheMode for affecting the hotness of the nodes
visited during the search.DatabaseExceptionpublic SearchResult getParentINForChildIN(IN child, boolean useTargetLevel, boolean doFetch, CacheMode cacheMode, List<TrackingInfo> trackingList) throws DatabaseException
DatabaseExceptionpublic SearchResult getParentINForChildIN(long targetNodeId, byte[] targetKey, int targetLevel, int exclusiveLevel, boolean requireExactMatch, boolean doFetch, CacheMode cacheMode, List<TrackingInfo> trackingList) throws DatabaseException
DatabaseExceptionpublic boolean getParentBINForChildLN(TreeLocation location, byte[] key, boolean splitsAllowed, boolean blindDeltaOps, CacheMode cacheMode) throws DatabaseException
When this method returns with location.bin non-null, the BIN is latched and must be unlatched by the caller. Note that location.bin may be non-null even if this method returns false.
location - a holder class to hold state about the location
of our search. Sort of an internal cursor.key - key to navigate through main keysplitsAllowed - true if this method is allowed to cause tree splits
as a side effect. In practice, recovery can cause splits, but abort
can't.blindDeltaOps - Normally, if this method lands on a BIN-delta and
the search key is not in that delta, it will mutate the delta to a full
BIN to make sure whether the search key exists in the tree or not.
However, by passing true for blindDeltaOps, the caller indicates that
it doesn't really care whether the key is in the tree or not: it is
going to insert the key in the BIN-delta, if not already there,
essentially overwritting the slot that may exist in the full BIN. So,
if blindDeltaOps is true, the method will not mutate a BIN-delta parent
(unless the BIN-delta has no space for a slot insertion).cacheMode - The CacheMode for affecting the hotness of the tree.DatabaseExceptionpublic BIN findBinForInsert(byte[] key, CacheMode cacheMode)
public BIN searchSplitsAllowed(byte[] key, CacheMode cacheMode)
public BIN search(byte[] key, Tree.SearchType searchType, BINBoundary binBoundary, CacheMode cacheMode, Comparator<byte[]> comparator)
key - - the key to search for, or null if searchType is LEFT or
RIGHT.searchType - - The type of tree search to perform. NORMAL means
we're searching for key in the tree. LEFT/RIGHT means we're descending
down the left or right side, resp.binBoundary - - If non-null, information is returned about whether
the BIN found is the first or last BIN in the database.public void rebuildINList()
throws DatabaseException
DatabaseExceptionpublic void validateINList(IN parent) throws DatabaseException
DatabaseExceptionpublic int getLogSize()
getLogSize in interface LoggableLoggable.getLogSize()public void writeToLog(ByteBuffer logBuffer)
LoggablewriteToLog in interface LoggablelogBuffer - is the destination bufferLoggable.writeToLog(java.nio.ByteBuffer)public void readFromLog(ByteBuffer itemBuffer, int entryVersion)
LoggablereadFromLog in interface LoggableitemBuffer - the source bufferentryVersion - the log version of the dataLoggable.readFromLog(java.nio.ByteBuffer, int)public void dumpLog(StringBuilder sb, boolean verbose)
LoggabledumpLog in interface Loggablesb - destination string bufferverbose - if true, dump the full, verbose versionLoggable.dumpLog(java.lang.StringBuilder, boolean)public long getTransactionId()
getTransactionId in interface LoggableLoggable.getTransactionId()public boolean logicalEquals(Loggable other)
logicalEquals in interface LoggableAlways return false, this item should never be compared.public void setTreeStatsAccumulator(TreeWalkerStatsAccumulator tSA)
public void dump()
public String dumpString(int nSpaces)
public void setWaitHook(TestHook hook)
public void setSearchHook(TestHook hook)
public void setCkptHook(TestHook hook)
public void setGetParentINHook(TestHook hook)
public void setFetchINHook(TestHook hook)
Copyright © 2024. All rights reserved.