Top Description Fields Constructors Methods
org.apache.derby.impl.store.access.btree

public Class BranchControlRow

extends ControlRow
Class Inheritance
Imports
org.apache.derby.shared.common.reference.SQLState, org.apache.derby.iapi.services.io.StoredFormatIds, .FormatableBitSet, org.apache.derby.shared.common.sanity.SanityManager, org.apache.derby.shared.common.error.StandardException, org.apache.derby.iapi.store.access.conglomerate.LogicalUndo, org.apache.derby.iapi.store.access.AccessFactoryGlobals, org.apache.derby.iapi.store.raw.ContainerHandle, .FetchDescriptor, .Page, .RecordHandle, org.apache.derby.iapi.types.DataValueDescriptor, .SQLLongint

A branch row contains key fields and the pointer to the child page.

Field Summary

Modifier and TypeField and Description
pack-priv transient SQLLongint
child_pageno_buf

Only allocate one child_pageno_buf to read the page pointer field into, then cache to "empty" object for reuse by the page itself.

private static final int
private static final int
protected static final FormatableBitSet
CR_LEFTCHILD_BITMAP

bit sets used to fetch single columns at a time.

private static final int
protected SQLLongint
Inherited from org.apache.derby.impl.store.access.btree.ControlRow:
CR_COLID_FIRSTCR_CONGLOM_BITSETCR_CONGLOM_COLIDCR_ISROOT_BITSETCR_ISROOT_COLIDCR_LEFTSIB_BITSETCR_LEFTSIB_COLIDCR_LEVEL_BITSETCR_LEVEL_COLIDCR_PARENT_BITSETCR_PARENT_COLIDCR_RIGHTSIB_BITSETCR_RIGHTSIB_COLIDCR_SLOTCR_VERSION_BITSETCR_VERSION_COLIDfetchDesclast_search_resultpagerowscratch_rowSPLIT_FLAG_FIRST_IN_TABLESPLIT_FLAG_FIRST_ON_PAGESPLIT_FLAG_LAST_IN_TABLESPLIT_FLAG_LAST_ON_PAGEuse_last_search_result_hint

Constructor Summary

AccessConstructor and Description
public
BranchControlRow()

No arg constructor.

public
BranchControlRow(OpenBTree open_btree, Page page, int level, ControlRow parent, boolean isRoot, long left_child)

Method Summary

Modifier and TypeMethod and Description
private static BranchControlRow
allocate(OpenBTree open_btree, ControlRow leftchild, int level, ControlRow parent)

Allocate a new leaf page to the conglomerate.

private void
private int
public int
checkConsistency(OpenBTree
The open btree to associate latches/locks with.
btree
,
ControlRow
The parent page of this page, "null" if this page is root or if not maintaining parent links.
parent
,
boolean
Should the consistency check go to other pages (this option breaks the latch protocol).
check_other_pages
)

Implements abstract org.apache.derby.impl.store.access.btree.ControlRow.checkConsistency.

Perform consistency checks for a branch page.</menu>

protected final void
controlRowInit()

Implements abstract org.apache.derby.impl.store.access.btree.ControlRow.controlRowInit.

Perform page specific initialization.

private void
fixChildrensParents(OpenBTree btree, ControlRow leftchild)

A branch page that has just been allocated as part of a split has index rows and a left child pointer that were copied from another page.

protected ControlRow
getChildPageAtSlot(OpenBTree open_btree, int slot)

private long
public ControlRow

Returns:

The page which is the leftmost child of this page.
getLeftChild
(OpenBTree
The open btree to associate latches/locks with.
open_btree
)

Implements abstract org.apache.derby.impl.store.access.btree.ControlRow.getLeftChild.

Return the left child pointer for the page.

pack-priv long
getLeftChildPageno()

Return the left child page number for the page.

protected final int

Returns:

The total number of columns in the control row.
getNumberOfControlRowColumns
()

Implements abstract org.apache.derby.impl.store.access.btree.ControlRow.getNumberOfControlRowColumns.

Get the number of columns in the control row.

protected ControlRow

Returns:

The page which is the rightmost child of this page.
getRightChild
(OpenBTree
The open btree to associate latches/locks with.
open_btree
)

Implements abstract org.apache.derby.impl.store.access.btree.ControlRow.getRightChild.

Return the right child pointer for the page.

public DataValueDescriptor[]

Returns:

Newly allocated template.
getRowTemplate
(OpenBTree open_btree)

Overrides org.apache.derby.impl.store.access.btree.ControlRow.getRowTemplate.

Return a new template for reading a data row from the current page.

public int
private static void
growRoot(OpenBTree open_btree, DataValueDescriptor[] template, BranchControlRow root)

Add a level to the tree by moving the current branch-root page up one level and adding a new page as it's left child.

public boolean

Returns:

true if the current page is the leftmost leaf of the tree, else return false.
isLeftmostLeaf
()

Implements abstract org.apache.derby.impl.store.access.btree.ControlRow.isLeftmostLeaf.

Is the current page the leftmost leaf of tree?

public boolean

Returns:

true if the current page is the rightmost leaf of the tree, else return false.
isRightmostLeaf
()

Implements abstract org.apache.derby.impl.store.access.btree.ControlRow.isRightmostLeaf.

Is the current page the rightmost leaf of tree?

public void
printTree(OpenBTree
the open btree to print.
btree
)

Implements abstract org.apache.derby.impl.store.access.btree.ControlRow.printTree.

Recursively print the tree starting at current node in tree.

public static long
restartSplitFor(OpenBTree open_btree, DataValueDescriptor[] template, BranchControlRow parent, ControlRow child, DataValueDescriptor[] newbranchrow, DataValueDescriptor[] splitrow, int flag)

public ControlRow
search(SearchParameters sp)

Implements abstract org.apache.derby.impl.store.access.btree.ControlRow.search.

Perform a recursive search, ultimately returning the latched leaf page and row slot after which the given key belongs.

protected ControlRow

Returns:

The leftmost leaf page.
searchLeft
(OpenBTree
The open btree to associate latches/locks with.
btree
)

Implements abstract org.apache.derby.impl.store.access.btree.ControlRow.searchLeft.

Search and return the left most leaf page.

protected ControlRow

Returns:

The rightmost leaf page.
searchRight
(OpenBTree
The open btree to associate latches/locks with.
btree
)

Implements abstract org.apache.derby.impl.store.access.btree.ControlRow.searchRight.

Search and return the right most leaf page.

protected void
protected void
setLeftChildPageno(long leftchild_pageno)

protected boolean
shrinkFor(OpenBTree open_btree, DataValueDescriptor[] shrink_key)

Implements abstract org.apache.derby.impl.store.access.btree.ControlRow.shrinkFor.

Perform a recursive shrink operation for the key.

protected long

Returns:

page number of the newly allocated leaf page created by split.
splitFor
(OpenBTree
The open btree to associate latches with.
open_btree
,
DataValueDescriptor[]
A scratch area to use while searching for split pass.
template
,
BranchControlRow
The parent page of the current page in the split pass. starts at null for root.
parent
,
DataValueDescriptor[]
The key to make room for during the split pass.
splitrow
,
int
A flag used to direct where point of split should be chosen.
flag
)

Implements abstract org.apache.derby.impl.store.access.btree.ControlRow.splitFor.

Perform a top down split pass making room for the the key in "row".

public String
Inherited from org.apache.derby.impl.store.access.btree.ControlRow:
auxObjectInvalidatedcheckGenericcheckRowOrdercheckSiblingscompareIndexRowFromPageToKeycompareIndexRowToKeycompareRowsOnSiblingsdebugPagegetgetgetConglomgetControlRowForPagegetIsRootgetLeftSiblinggetleftSiblingPageNumbergetLevelgetNoWaitgetPagegetParentPageNumbergetRightSiblinggetrightSiblingPageNumbergetRowgetVersionlinkRightreleasesearchForEntrysearchForEntryBackwardsetIsRootsetLeftSiblingsetLevelsetParentsetRightSiblingsetVersionunlink

Field Detail

child_pageno_bufback to summary
pack-priv transient SQLLongint child_pageno_buf

Only allocate one child_pageno_buf to read the page pointer field into, then cache to "empty" object for reuse by the page itself.

CR_COLID_LASTback to summary
private static final int CR_COLID_LAST

Hides org.apache.derby.impl.store.access.btree.ControlRow.CR_COLID_LAST.

CR_LEFTCHILDback to summary
private static final int CR_LEFTCHILD
CR_LEFTCHILD_BITMAPback to summary
protected static final FormatableBitSet CR_LEFTCHILD_BITMAP

bit sets used to fetch single columns at a time.

CR_NCOLUMNSback to summary
private static final int CR_NCOLUMNS

Hides org.apache.derby.impl.store.access.btree.ControlRow.CR_NCOLUMNS.

left_child_pageback to summary
protected SQLLongint left_child_page

Constructor Detail

BranchControlRowback to summary
public BranchControlRow()

No arg constructor.

Public no arg constructor is for the monitor to call for format id implementation, it should not be called for any other reason.

BranchControlRowback to summary
public BranchControlRow(OpenBTree open_btree, Page page, int level, ControlRow parent, boolean isRoot, long left_child) throws StandardException

Method Detail

allocateback to summary
private static BranchControlRow allocate(OpenBTree open_btree, ControlRow leftchild, int level, ControlRow parent) throws StandardException

Allocate a new leaf page to the conglomerate.

Exceptions
StandardException:
Standard exception policy.
checkChildOrderAgainstRowOrderback to summary
private void checkChildOrderAgainstRowOrder(OpenBTree btree) throws StandardException
checkChildrenback to summary
private int checkChildren(OpenBTree btree) throws StandardException
checkConsistencyback to summary
public int checkConsistency(OpenBTree btree, ControlRow parent, boolean check_other_pages) throws StandardException

Implements abstract org.apache.derby.impl.store.access.btree.ControlRow.checkConsistency.

Perform consistency checks for a branch page. The checks specific to a branch page are:

  • The rows on the page are indeed branch rows, and they all have the correct number of fields (which is the b-tree's key fields plus one for the child page number.
  • The child pages pointed to by the left child pointer and the index rows are linked together in the same order that they appear on the page.
  • The child pages themselves are all consistent.
  • This method also performs the consistency checks that are common to both leaf and branch pages (see ControlRow.checkGeneric).
    Parameters
    btree:OpenBTree

    Doc from org.apache.derby.impl.store.access.btree.ControlRow.checkConsistency.

    The open btree to associate latches/locks with.

    parent:ControlRow

    Doc from org.apache.derby.impl.store.access.btree.ControlRow.checkConsistency.

    The parent page of this page, "null" if this page is root or if not maintaining parent links.

    check_other_pages:boolean

    Doc from org.apache.derby.impl.store.access.btree.ControlRow.checkConsistency.

    Should the consistency check go to other pages (this option breaks the latch protocol).

    Returns:int

    Doc from org.apache.derby.impl.store.access.btree.ControlRow.checkConsistency.

    The identifier to be used to open the conglomerate later.

    Exceptions
    StandardException:
    Standard exception policy.
    controlRowInitback to summary
    protected final void controlRowInit()

    Implements abstract org.apache.derby.impl.store.access.btree.ControlRow.controlRowInit.

    Perform page specific initialization.

    fixChildrensParentsback to summary
    private void fixChildrensParents(OpenBTree btree, ControlRow leftchild) throws StandardException

    A branch page that has just been allocated as part of a split has index rows and a left child pointer that were copied from another page. The parent link on the corresponding pages will still point to the original page. This method fixes their parent pointers so that they point to the curren page like they're supposed to.

    Note that maintaining the parent link is kind of a pain, and will slow down applications. It's only needed for consistency checks, so we may want to have implementations that don't bother to maintain it.

    This

    getChildPageAtSlotback to summary
    protected ControlRow getChildPageAtSlot(OpenBTree open_btree, int slot) throws StandardException
    getChildPageIdAtSlotback to summary
    private long getChildPageIdAtSlot(OpenBTree btree, int slot) throws StandardException
    getLeftChildback to summary
    public ControlRow getLeftChild(OpenBTree open_btree) throws StandardException

    Implements abstract org.apache.derby.impl.store.access.btree.ControlRow.getLeftChild.

    Return the left child pointer for the page.

    Leaf pages don't have children, so they override this and return null.

    Parameters
    open_btree:OpenBTree

    The open btree to associate latches/locks with.

    Returns:ControlRow

    The page which is the leftmost child of this page.

    Exceptions
    StandardException:
    Standard exception policy.
    getLeftChildPagenoback to summary
    pack-priv long getLeftChildPageno() throws StandardException

    Return the left child page number for the page. Leaf pages don't have left children, so they override this and return null.

    getNumberOfControlRowColumnsback to summary
    protected final int getNumberOfControlRowColumns()

    Implements abstract org.apache.derby.impl.store.access.btree.ControlRow.getNumberOfControlRowColumns.

    Get the number of columns in the control row.

    Control rows all share the first columns as defined by this class and then add columns to the end of the control row. For instance a branch control row add a child page pointer field.

    Returns:int

    The total number of columns in the control row.

    getRightChildback to summary
    protected ControlRow getRightChild(OpenBTree open_btree) throws StandardException

    Implements abstract org.apache.derby.impl.store.access.btree.ControlRow.getRightChild.

    Return the right child pointer for the page.

    Leaf pages don't have children, so they override this and return null.

    Parameters
    open_btree:OpenBTree

    The open btree to associate latches/locks with.

    Returns:ControlRow

    The page which is the rightmost child of this page.

    Exceptions
    StandardException:
    Standard exception policy.
    getRowTemplateback to summary
    public DataValueDescriptor[] getRowTemplate(OpenBTree open_btree) throws StandardException

    Overrides org.apache.derby.impl.store.access.btree.ControlRow.getRowTemplate.

    Return a new template for reading a data row from the current page.

    Default implementation for rows which are the same as the conglomerates template, sub-classes can alter if underlying template is different (for instance branch rows add an extra field at the end).

    Returns:DataValueDescriptor[]

    Newly allocated template.

    Exceptions
    StandardException:
    Standard exception policy.
    getTypeFormatIdback to summary
    public int getTypeFormatId()

    Implements org.apache.derby.iapi.services.io.TypedFormat.getTypeFormatId.

    Return my format identifier.

    Returns:int

    Doc from org.apache.derby.iapi.services.io.TypedFormat.getTypeFormatId.

    The identifier. (A UUID stuffed in an array of 16 bytes).

    See Also
    org.apache.derby.iapi.services.io.TypedFormat#getTypeFormatId
    growRootback to summary
    private static void growRoot(OpenBTree open_btree, DataValueDescriptor[] template, BranchControlRow root) throws StandardException

    Add a level to the tree by moving the current branch-root page up one level and adding a new page as it's left child. On exit the current root page remains the root of the tree.

    On entry, the current branch root page is expected to be latched. On exit, all latches will have been released.

    Latch order: o ROOT: on entry current root is latched. No other latches should be held. o ROOT_OLDCHILD: Get and Latch root's left child page. o ROOT_NEWCHILD: Allocate a new branch page with latch. o Conditionally fix up the parent links on the pages pointed at by the newly allocated page. Loop through slots on ROOT_NEWCHILD, from left to right getting and releasing latches. Note that fixChildrensParents() must not latch the leftchild as ROOT_OLDCHILD is already latched.

    Resolve

    (mikem) does order of release matter. o ROOT : released. o ROOT_NEWCHILD: released. o ROOT_OLDCHILD: released.

    isLeftmostLeafback to summary
    public boolean isLeftmostLeaf() throws StandardException

    Implements abstract org.apache.derby.impl.store.access.btree.ControlRow.isLeftmostLeaf.

    Is the current page the leftmost leaf of tree?

    Returns:boolean

    true if the current page is the leftmost leaf of the tree, else return false.

    Exceptions
    StandardException:
    Standard exception policy.
    isRightmostLeafback to summary
    public boolean isRightmostLeaf() throws StandardException

    Implements abstract org.apache.derby.impl.store.access.btree.ControlRow.isRightmostLeaf.

    Is the current page the rightmost leaf of tree?

    Returns:boolean

    true if the current page is the rightmost leaf of the tree, else return false.

    Exceptions
    StandardException:
    Standard exception policy.
    printTreeback to summary
    public void printTree(OpenBTree btree) throws StandardException

    Implements abstract org.apache.derby.impl.store.access.btree.ControlRow.printTree.

    Recursively print the tree starting at current node in tree.

    Parameters
    btree:OpenBTree

    the open btree to print.

    Exceptions
    StandardException:
    Standard exception policy.
    restartSplitForback to summary
    public static long restartSplitFor(OpenBTree open_btree, DataValueDescriptor[] template, BranchControlRow parent, ControlRow child, DataValueDescriptor[] newbranchrow, DataValueDescriptor[] splitrow, int flag) throws StandardException
    searchback to summary
    public ControlRow search(SearchParameters sp) throws StandardException

    Implements abstract org.apache.derby.impl.store.access.btree.ControlRow.search.

    Perform a recursive search, ultimately returning the latched leaf page and row slot after which the given key belongs. The slot is returned in the result structure. If the key exists on the page, the result.exact will be true. Otherwise, result.exact will be false, and the row slot returned will be the one immediately preceding the position at which the key belongs.

    Exceptions
    StandardException:
    Standard exception policy.
    searchLeftback to summary
    protected ControlRow searchLeft(OpenBTree btree) throws StandardException

    Implements abstract org.apache.derby.impl.store.access.btree.ControlRow.searchLeft.

    Search and return the left most leaf page.

    Perform a recursive search, ultimately returning the leftmost leaf page which is the first leaf page in the leaf sibling chain. (This method might better be called getFirstLeafPage()).

    Parameters
    btree:OpenBTree

    The open btree to associate latches/locks with.

    Returns:ControlRow

    The leftmost leaf page.

    Exceptions
    StandardException:
    Standard exception policy.
    searchRightback to summary
    protected ControlRow searchRight(OpenBTree btree) throws StandardException

    Implements abstract org.apache.derby.impl.store.access.btree.ControlRow.searchRight.

    Search and return the right most leaf page.

    Perform a recursive search, ultimately returning the rightmost leaf page which is the last leaf page in the leaf sibling chain. (This method might better be called getLastLeafPage()).

    Parameters
    btree:OpenBTree

    The open btree to associate latches/locks with.

    Returns:ControlRow

    The rightmost leaf page.

    Exceptions
    StandardException:
    Standard exception policy.
    setLeftChildback to summary
    protected void setLeftChild(ControlRow leftchild) throws StandardException
    setLeftChildPagenoback to summary
    protected void setLeftChildPageno(long leftchild_pageno) throws StandardException
    shrinkForback to summary
    protected boolean shrinkFor(OpenBTree open_btree, DataValueDescriptor[] shrink_key) throws StandardException

    Implements abstract org.apache.derby.impl.store.access.btree.ControlRow.shrinkFor.

    Perform a recursive shrink operation for the key. If this method returns true, the caller should remove the corresponding entry for the page. This routine is not guaranteed to successfully shrink anything. The page lead to by the key might turn out not to be empty by the time shrink gets there, and shrinks will give up if there is a deadlock.

    The receiver page must be latched on entry and is returned latched.

    Exceptions
    StandardException:
    Standard exception policy.
    splitForback to summary
    protected long splitFor(OpenBTree open_btree, DataValueDescriptor[] template, BranchControlRow parent, DataValueDescriptor[] splitrow, int flag) throws StandardException

    Implements abstract org.apache.derby.impl.store.access.btree.ControlRow.splitFor.

    Perform a top down split pass making room for the the key in "row".

    Perform a split such that a subsequent call to insert given the argument index row will likely find room for it. Since latches are released the client must code for the case where another user has grabbed the space made available by the split pass and be ready to do another split.

    Latches: o PARENT : is latched on entry (unless the split is the root then there is no parent. o THISBRANCH: the current page is latched on entry. o CHILD : latch the child page which will be pointed at by the left child pointer of the new page. RESOLVE (mikem) -see comments below o NEWPAGE : Allocate and latch new page. o CHILD : release. (RESOLVE) o fixparents: latch pages and reset their parent pointers. Conditionally fix up the parent links on the pages pointed at by the newly allocated page. First get latch and release on the left child page and then loop through slots on NEWPAGE, from left to right getting and releasing latches.

    Parameters
    open_btree:OpenBTree

    The open btree to associate latches with.

    template:DataValueDescriptor[]

    A scratch area to use while searching for split pass.

    parent:BranchControlRow

    The parent page of the current page in the split pass. starts at null for root.

    splitrow:DataValueDescriptor[]

    The key to make room for during the split pass.

    flag:int

    A flag used to direct where point of split should be chosen.

    Returns:long

    page number of the newly allocated leaf page created by split.

    Exceptions
    StandardException:
    Standard exception policy.
    toStringback to summary
    public String toString()

    Overrides org.apache.derby.impl.store.access.btree.ControlRow.toString.

    The standard toString.

    Returns:String

    Doc from java.lang.Object.toString.

    a string representation of the object