java.lang.Object
org.apache.ignite.internal.persistence.tree.io.PageIO
org.apache.ignite.internal.persistence.tree.io.BPlusIO<L>
All Implemented Interfaces:
CompactablePageIO
Direct Known Subclasses:
BPlusInnerIO, BPlusLeafIO

public abstract class BPlusIO<L> extends PageIO implements CompactablePageIO
Abstract IO routines for B+Tree pages.
  • Field Details

    • ITEMS_OFF

      protected static final int ITEMS_OFF
      See Also:
    • itemSize

      protected final int itemSize
      All the items must be of fixed size.
  • Constructor Details

    • BPlusIO

      protected BPlusIO(int type, int ver, boolean leaf, boolean canGetRow, int itemSize)
      Parameters:
      type - Page type.
      ver - Page format version.
      leaf - If this is a leaf IO.
      canGetRow - If we can get full row from this page.
  • Method Details

    • getItemSize

      public final int getItemSize()
      Returns:
      Item size in bytes.
    • initNewPage

      public void initNewPage(long pageAddr, long pageId, int pageSize)
      Overrides:
      initNewPage in class PageIO
      Parameters:
      pageAddr - Page address.
      pageId - Page ID.
      pageSize - Page size.
      See Also:
      • EncryptionSpi#encryptedSize(int)
    • getForward

      public final long getForward(long pageAddr)
      Parameters:
      pageAddr - Page address.
      Returns:
      Forward page ID.
    • setForward

      public final void setForward(long pageAddr, long pageId)
      Parameters:
      pageAddr - Page address.
      pageId - Forward page ID.
    • getRemoveId

      public final long getRemoveId(long pageAddr)
      Parameters:
      pageAddr - Page address.
      Returns:
      Remove ID.
    • setRemoveId

      public final void setRemoveId(long pageAddr, long rmvId)
      Parameters:
      pageAddr - Page address.
      rmvId - Remove ID.
    • getCount

      public final int getCount(long pageAddr)
      Parameters:
      pageAddr - Page address.
      Returns:
      Items count in the page.
    • setCount

      public final void setCount(long pageAddr, int cnt)
      Parameters:
      pageAddr - Page address.
      cnt - Count.
    • canGetRow

      public final boolean canGetRow()
      Returns:
      true If we can get the full row from this page using method BPlusTree.getRow(BPlusIO, long, int). Must always be true for leaf pages.
    • isLeaf

      public final boolean isLeaf()
      Returns:
      true if it is a leaf page.
    • getMaxCount

      public abstract int getMaxCount(long pageAddr, int pageSize)
      Parameters:
      pageAddr - Page address.
      pageSize - Page size without encryption overhead.
      Returns:
      Max items count.
    • store

      public final byte[] store(long pageAddr, int idx, L row, byte[] rowBytes, boolean needRowBytes) throws IgniteCheckedException
      Store the needed info about the row in the page. Leaf and inner pages can store different info.
      Parameters:
      pageAddr - Page address.
      idx - Index.
      row - Lookup or full row.
      rowBytes - Row bytes.
      needRowBytes - If we need stored row bytes.
      Returns:
      Stored row bytes.
      Throws:
      IgniteCheckedException - If failed.
    • offset

      public abstract int offset(int idx)
      Parameters:
      idx - Index of element.
      Returns:
      Offset from byte buffer begin in bytes.
    • storeByOffset

      public abstract void storeByOffset(long pageAddr, int off, L row) throws IgniteCheckedException
      Store the needed info about the row in the page. Leaf and inner pages can store different info.
      Parameters:
      pageAddr - Page address.
      off - Offset in bytes.
      row - Lookup or full row.
      Throws:
      IgniteCheckedException - If failed.
    • store

      public abstract void store(long dstPageAddr, int dstIdx, BPlusIO<L> srcIo, long srcPageAddr, int srcIdx) throws IgniteCheckedException
      Store row info from the given source.
      Parameters:
      dstPageAddr - Destination page address.
      dstIdx - Destination index.
      srcIo - Source IO.
      srcPageAddr - Source page address.
      srcIdx - Source index.
      Throws:
      IgniteCheckedException - If failed.
    • getLookupRow

      public abstract L getLookupRow(BPlusTree<L,?> tree, long pageAddr, int idx) throws IgniteCheckedException
      Get lookup row.
      Parameters:
      tree - Tree.
      pageAddr - Page address.
      idx - Index.
      Returns:
      Lookup row.
      Throws:
      IgniteCheckedException - If failed.
    • copyItems

      public abstract void copyItems(long srcPageAddr, long dstPageAddr, int srcIdx, int dstIdx, int cnt, boolean cpLeft) throws IgniteCheckedException
      Copy items from source page to destination page. Both pages must be of the same type and the same version.
      Parameters:
      srcPageAddr - Source page address.
      dstPageAddr - Destination page address.
      srcIdx - Source begin index.
      dstIdx - Destination begin index.
      cnt - Items count.
      cpLeft - Copy leftmost link (makes sense only for inner pages).
      Throws:
      IgniteCheckedException - If failed.
    • insert

      public byte[] insert(long pageAddr, int idx, L row, byte[] rowBytes, long rightId, boolean needRowBytes) throws IgniteCheckedException
      Parameters:
      pageAddr - Page address.
      idx - Index.
      row - Row to insert.
      rowBytes - Row bytes.
      rightId - Page ID which will be to the right child for the inserted item.
      needRowBytes - If we need stored row bytes.
      Returns:
      Row bytes.
      Throws:
      IgniteCheckedException - If failed.
    • splitForwardPage

      public void splitForwardPage(long pageAddr, long fwdId, long fwdPageAddr, int mid, int cnt, int pageSize) throws IgniteCheckedException
      Parameters:
      pageAddr - Splitting page address.
      fwdId - Forward page ID.
      fwdPageAddr - Forward page address.
      mid - Bisection index.
      cnt - Initial elements count in the page being split.
      pageSize - Page size.
      Throws:
      IgniteCheckedException - If failed.
    • splitExistingPage

      public void splitExistingPage(long pageAddr, int mid, long fwdId)
      Parameters:
      pageAddr - Page address.
      mid - Bisection index.
      fwdId - New forward page ID.
    • remove

      public void remove(long pageAddr, int idx, int cnt) throws IgniteCheckedException
      Parameters:
      pageAddr - Page address.
      idx - Index.
      cnt - Count.
      Throws:
      IgniteCheckedException - If failed.
    • merge

      public boolean merge(BPlusIO<L> prntIo, long prntPageAddr, int prntIdx, long leftPageAddr, long rightPageAddr, boolean emptyBranch, int pageSize) throws IgniteCheckedException
      Parameters:
      prntIo - Parent IO.
      prntPageAddr - Parent page address.
      prntIdx - Split key index in parent.
      leftPageAddr - Left page address.
      rightPageAddr - Right page address.
      emptyBranch - We are merging an empty branch.
      pageSize - Page size without encryption overhead.
      Returns:
      false If we were not able to merge.
      Throws:
      IgniteCheckedException - If failed.
    • visit

      public void visit(long pageAddr, IgniteInClosure<L> c)
      Parameters:
      pageAddr - Page address.
      c - Closure.
    • printPage

      protected void printPage(long addr, int pageSize, GridStringBuilder sb) throws IgniteCheckedException
      Specified by:
      printPage in class PageIO
      Parameters:
      addr - Address.
      pageSize - Page size.
      sb - Sb.
      Throws:
      IgniteCheckedException
    • getItemsEnd

      public int getItemsEnd(long pageAddr)
      Parameters:
      pageAddr - Page address.
      Returns:
      Offset after the last item.
    • compactPage

      public void compactPage(ByteBuffer page, ByteBuffer out, int pageSize)
      Compacts page contents to the output buffer. Implementation must not change contents, position and limit of the original page buffer.
      Specified by:
      compactPage in interface CompactablePageIO
      Parameters:
      page - Page buffer.
      out - Output buffer.
      pageSize - Page size.
    • restorePage

      public void restorePage(ByteBuffer compactPage, int pageSize)
      Restores the original page in place.
      Specified by:
      restorePage in interface CompactablePageIO
      Parameters:
      compactPage - Compact page.
      pageSize - Page size.