org.apache.hadoop.hbase.codec.prefixtree.decode
Class PrefixTreeArraySearcher

java.lang.Object
  extended by org.apache.hadoop.hbase.codec.prefixtree.decode.PrefixTreeCell
      extended by org.apache.hadoop.hbase.codec.prefixtree.decode.PrefixTreeArrayScanner
          extended by org.apache.hadoop.hbase.codec.prefixtree.decode.PrefixTreeArrayReversibleScanner
              extended by org.apache.hadoop.hbase.codec.prefixtree.decode.PrefixTreeArraySearcher
All Implemented Interfaces:
Comparable<Cell>, Cell, CellScanner, CellSearcher, ReversibleCellScanner

@InterfaceAudience.Private
public class PrefixTreeArraySearcher
extends PrefixTreeArrayReversibleScanner
implements CellSearcher

Searcher extends the capabilities of the Scanner + ReversibleScanner to add the ability to position itself on a requested Cell without scanning through cells before it. The PrefixTree is set up to be a Trie of rows, so finding a particular row is extremely cheap.

Once it finds the row, it does a binary search through the cells inside the row, which is not as fast as the trie search, but faster than iterating through every cell like existing block formats do. For this reason, this implementation is targeted towards schemas where rows are narrow enough to have several or many per block, and where you are generally looking for the entire row or the first cell. It will still be fast for wide rows or point queries, but could be improved upon.


Field Summary
 
Fields inherited from class org.apache.hadoop.hbase.codec.prefixtree.decode.PrefixTreeArrayScanner
afterLast, beforeFirst, blockMeta, currentCellIndex, currentRowNode, familyReader, mvccVersionDecoder, nubCellsRemain, qualifierReader, rowNodes, rowNodeStackIndex, tagsReader, timestampDecoder
 
Fields inherited from class org.apache.hadoop.hbase.codec.prefixtree.decode.PrefixTreeCell
absoluteValueOffset, block, DEFAULT_TYPE, familyBuffer, familyLength, familyOffset, includeMvccVersion, mvccVersion, qualifierBuffer, qualifierLength, qualifierOffset, rowBuffer, rowLength, tagsBuffer, tagsLength, tagsOffset, timestamp, type, TYPES, valueLength
 
Constructor Summary
PrefixTreeArraySearcher(PrefixTreeBlockMeta blockMeta, int rowTreeDepth, int rowBufferLength, int qualifierBufferLength, int tagsBufferLength)
          construct
 
Method Summary
protected  int compareToCurrentToken(Cell key)
          Compare only the bytes within the window of the current token
protected  boolean currentPositionIsAfter(Cell cell)
          internal methods
 boolean equals(Object obj)
          Object methods
protected  CellScannerPosition fixRowFanMissForward(int fanInsertionPoint)
           
protected  CellScannerPosition fixRowFanMissReverse(int fanInsertionPoint)
          complete seek when fan mismatch
protected  CellScannerPosition fixRowTokenMissForward(int searcherIsAfterInputKey)
           
protected  CellScannerPosition fixRowTokenMissReverse(int searcherIsAfterInputKey)
           
protected  void followLastFansUntilExhausted()
           
 void positionAfterLastCell()
          The content of the buffers doesn't matter here, only that afterLast=true and beforeFirst=false
 boolean positionAt(Cell key)
          CellSearcher methods
 CellScannerPosition positionAtOrAfter(Cell key)
          Identical workflow as positionAtOrBefore, but split them to avoid having ~10 extra if-statements.
 CellScannerPosition positionAtOrBefore(Cell key)
          Same as positionAt(..), but go to the extra effort of finding the previous key if there's no exact match.
protected  CellScannerPosition positionAtQualifierTimestamp(Cell key, boolean beforeOnMiss)
           
protected  boolean rowMatchesAfterCurrentPosition(Cell key)
          compare this.row to key.row but starting at the current rowLength
 boolean seekForwardTo(Cell key)
          Note: Added for backwards compatibility with KeyValueScanner

Look for the key, but only look after the current position.

 CellScannerPosition seekForwardToOrAfter(Cell key)
          Same as seekForwardTo(..), but go to the extra effort of finding the next key if there's no exact match.
 CellScannerPosition seekForwardToOrBefore(Cell key)
          Same as seekForwardTo(..), but go to the extra effort of finding the next key if there's no exact match.
 
Methods inherited from class org.apache.hadoop.hbase.codec.prefixtree.decode.PrefixTreeArrayReversibleScanner
descendToLastRowFromCurrentPosition, isDirectlyAfterNub, positionAtLastCell, positionAtLastRow, previous, previousRow
 
Methods inherited from class org.apache.hadoop.hbase.codec.prefixtree.decode.PrefixTreeArrayScanner
advance, appendCurrentTokenToRowBuffer, appendToRowBuffer, areBuffersBigEnough, current, discardCurrentRowNode, followCurrentFan, followFan, followFirstFan, followLastFan, followNextFan, followPreviousFan, getBlockMeta, getMaxRowTreeStackNodes, getQualifierBufferLength, getRowBufferLength, getTagBufferLength, getTreeBytes, hashCode, hasOccurrences, initFirstNode, initOnBlock, isAfterLast, isBeforeFirst, isBranch, isFirstCellInRow, isLastCellInRow, isLeaf, isNub, isOutOfBounds, markAfterLast, markBeforeFirst, nextRow, nextRowInternal, popFromRowBuffer, populateFamily, populateFirstNonRowFields, populateLastNonRowFields, populateMvccVersion, populateNonRowFields, populateNonRowFieldsAndCompareTo, populatePreviousNonRowFields, populateQualifier, populateTag, populateTimestamp, populateType, populateValueOffsets, positionAtFirstCell, reInitFirstNode, releaseBlockReference, resetToBeforeFirstEntry, toString
 
Methods inherited from class org.apache.hadoop.hbase.codec.prefixtree.decode.PrefixTreeCell
compareTo, getFamily, getFamilyArray, getFamilyLength, getFamilyOffset, getKeyValueString, getMvccVersion, getQualifier, getQualifierArray, getQualifierLength, getQualifierOffset, getRow, getRowArray, getRowLength, getRowOffset, getTagsArray, getTagsLength, getTagsLengthUnsigned, getTagsOffset, getTimestamp, getTypeByte, getValue, getValueArray, getValueLength, getValueOffset
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.apache.hadoop.hbase.codec.prefixtree.scanner.CellSearcher
resetToBeforeFirstEntry
 
Methods inherited from interface org.apache.hadoop.hbase.codec.prefixtree.scanner.ReversibleCellScanner
previous, previousRow
 
Methods inherited from interface org.apache.hadoop.hbase.CellScanner
advance, current
 

Constructor Detail

PrefixTreeArraySearcher

public PrefixTreeArraySearcher(PrefixTreeBlockMeta blockMeta,
                               int rowTreeDepth,
                               int rowBufferLength,
                               int qualifierBufferLength,
                               int tagsBufferLength)
construct

Method Detail

positionAt

public boolean positionAt(Cell key)
CellSearcher methods

Specified by:
positionAt in interface CellSearcher
Parameters:
key - position the CellScanner exactly on this key
Returns:
true if the cell existed and getCurrentCell() holds a valid cell

positionAtOrBefore

public CellScannerPosition positionAtOrBefore(Cell key)
Description copied from interface: CellSearcher
Same as positionAt(..), but go to the extra effort of finding the previous key if there's no exact match.

Specified by:
positionAtOrBefore in interface CellSearcher
Parameters:
key - position the CellScanner on this key or the closest cell before
Returns:
AT if exact match
BEFORE if on last cell before key
BEFORE_FIRST if key was before the first cell in this scanner's scope

positionAtOrAfter

public CellScannerPosition positionAtOrAfter(Cell key)
Identical workflow as positionAtOrBefore, but split them to avoid having ~10 extra if-statements. Priority on readability and debugability.

Specified by:
positionAtOrAfter in interface CellSearcher
Parameters:
key - position the CellScanner on this key or the closest cell after
Returns:
AT if exact match
AFTER if on first cell after key
AFTER_LAST if key was after the last cell in this scanner's scope

seekForwardTo

public boolean seekForwardTo(Cell key)
Description copied from interface: CellSearcher
Note: Added for backwards compatibility with KeyValueScanner

Look for the key, but only look after the current position. Probably not needed for an efficient tree implementation, but is important for implementations without random access such as unencoded KeyValue blocks.

Specified by:
seekForwardTo in interface CellSearcher
Parameters:
key - position the CellScanner exactly on this key
Returns:
true if getCurrent() holds a valid cell

seekForwardToOrBefore

public CellScannerPosition seekForwardToOrBefore(Cell key)
Description copied from interface: CellSearcher
Same as seekForwardTo(..), but go to the extra effort of finding the next key if there's no exact match.

Specified by:
seekForwardToOrBefore in interface CellSearcher
Returns:
AT if exact match
AFTER if on first cell after key
AFTER_LAST if key was after the last cell in this scanner's scope

seekForwardToOrAfter

public CellScannerPosition seekForwardToOrAfter(Cell key)
Description copied from interface: CellSearcher
Same as seekForwardTo(..), but go to the extra effort of finding the next key if there's no exact match.

Specified by:
seekForwardToOrAfter in interface CellSearcher
Returns:
AT if exact match
AFTER if on first cell after key
AFTER_LAST if key was after the last cell in this scanner's scope

positionAfterLastCell

public void positionAfterLastCell()
The content of the buffers doesn't matter here, only that afterLast=true and beforeFirst=false

Specified by:
positionAfterLastCell in interface CellSearcher

equals

public boolean equals(Object obj)
Object methods

Overrides:
equals in class PrefixTreeArrayReversibleScanner

currentPositionIsAfter

protected boolean currentPositionIsAfter(Cell cell)
internal methods


positionAtQualifierTimestamp

protected CellScannerPosition positionAtQualifierTimestamp(Cell key,
                                                           boolean beforeOnMiss)

rowMatchesAfterCurrentPosition

protected boolean rowMatchesAfterCurrentPosition(Cell key)
compare this.row to key.row but starting at the current rowLength

Parameters:
key - Cell being searched for
Returns:
true if row buffer contents match key.row

compareToCurrentToken

protected int compareToCurrentToken(Cell key)
Compare only the bytes within the window of the current token

Parameters:
key -
Returns:
return -1 if key is lessThan (before) this, 0 if equal, and 1 if key is after

followLastFansUntilExhausted

protected void followLastFansUntilExhausted()

fixRowTokenMissReverse

protected CellScannerPosition fixRowTokenMissReverse(int searcherIsAfterInputKey)
Parameters:
searcherIsAfterInputKey - <0: input key is before the searcher's position
>0: input key is after the searcher's position

fixRowTokenMissForward

protected CellScannerPosition fixRowTokenMissForward(int searcherIsAfterInputKey)
Parameters:
searcherIsAfterInputKey - <0: input key is before the searcher's position
>0: input key is after the searcher's position

fixRowFanMissReverse

protected CellScannerPosition fixRowFanMissReverse(int fanInsertionPoint)
complete seek when fan mismatch


fixRowFanMissForward

protected CellScannerPosition fixRowFanMissForward(int fanInsertionPoint)


Copyright © 2015 The Apache Software Foundation. All Rights Reserved.