org.apache.hadoop.hbase.codec.prefixtree
Class PrefixTreeSeeker

java.lang.Object
  extended by org.apache.hadoop.hbase.codec.prefixtree.PrefixTreeSeeker
All Implemented Interfaces:
DataBlockEncoder.EncodedSeeker

@InterfaceAudience.Private
public class PrefixTreeSeeker
extends Object
implements DataBlockEncoder.EncodedSeeker

These methods have the same definition as any implementation of the EncodedSeeker. In the future, the EncodedSeeker could be modified to work with the Cell interface directly. It currently returns a new KeyValue object each time getKeyValue is called. This is not horrible, but in order to create a new KeyValue object, we must first allocate a new byte[] and copy in the data from the PrefixTreeCell. It is somewhat heavyweight right now.


Field Summary
protected  ByteBuffer block
           
protected  boolean includeMvccVersion
           
protected  boolean movedToPrevious
           
protected  PrefixTreeArraySearcher ptSearcher
           
 
Constructor Summary
PrefixTreeSeeker(boolean includeMvccVersion)
           
 
Method Summary
 boolean advance()
           
 int compareKey(KeyValue.KVComparator comparator, byte[] key, int offset, int length)
           
 Cell get()
          Currently unused.
 ByteBuffer getKeyDeepCopy()
           
 KeyValue getKeyValue()
          currently must do deep copy into new array
 ByteBuffer getKeyValueBuffer()
          currently must do deep copy into new array
 ByteBuffer getValueShallowCopy()
           
 boolean next()
           
 void releaseCurrentSearcher()
          Currently unused.
 void rewind()
           
 int seekToKeyInBlock(byte[] keyOnlyBytes, int offset, int length, boolean forceBeforeOnExactMatch)
          Seek forward only (should be called reseekToKeyInBlock?).
protected  int seekToOrBeforeUsingPositionAtOrAfter(byte[] keyOnlyBytes, int offset, int length, boolean seekBefore)
           
protected  int seekToOrBeforeUsingPositionAtOrBefore(byte[] keyOnlyBytes, int offset, int length, boolean seekBefore)
           
 void setCurrentBuffer(ByteBuffer fullBlockBuffer)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

block

protected ByteBuffer block

includeMvccVersion

protected boolean includeMvccVersion

ptSearcher

protected PrefixTreeArraySearcher ptSearcher

movedToPrevious

protected boolean movedToPrevious
Constructor Detail

PrefixTreeSeeker

public PrefixTreeSeeker(boolean includeMvccVersion)
Method Detail

setCurrentBuffer

public void setCurrentBuffer(ByteBuffer fullBlockBuffer)
Specified by:
setCurrentBuffer in interface DataBlockEncoder.EncodedSeeker

releaseCurrentSearcher

public void releaseCurrentSearcher()
Currently unused.

TODO performance leak. should reuse the searchers. hbase does not currently have a hook where this can be called


getKeyDeepCopy

public ByteBuffer getKeyDeepCopy()
Specified by:
getKeyDeepCopy in interface DataBlockEncoder.EncodedSeeker

getValueShallowCopy

public ByteBuffer getValueShallowCopy()
Specified by:
getValueShallowCopy in interface DataBlockEncoder.EncodedSeeker

getKeyValueBuffer

public ByteBuffer getKeyValueBuffer()
currently must do deep copy into new array

Specified by:
getKeyValueBuffer in interface DataBlockEncoder.EncodedSeeker

getKeyValue

public KeyValue getKeyValue()
currently must do deep copy into new array

Specified by:
getKeyValue in interface DataBlockEncoder.EncodedSeeker

get

public Cell get()
Currently unused.

A nice, lightweight reference, though the underlying cell is transient. This method may return the same reference to the backing PrefixTreeCell repeatedly, while other implementations may return a different reference for each Cell.

The goal will be to transition the upper layers of HBase, like Filters and KeyValueHeap, to use this method instead of the getKeyValue() methods above.


rewind

public void rewind()
Specified by:
rewind in interface DataBlockEncoder.EncodedSeeker

next

public boolean next()
Specified by:
next in interface DataBlockEncoder.EncodedSeeker

advance

public boolean advance()

seekToKeyInBlock

public int seekToKeyInBlock(byte[] keyOnlyBytes,
                            int offset,
                            int length,
                            boolean forceBeforeOnExactMatch)
Seek forward only (should be called reseekToKeyInBlock?).

If the exact key is found look at the seekBefore variable and:
- if true: go to the previous key if it's true
- if false: stay on the exact key

If the exact key is not found, then go to the previous key *if possible*, but remember to leave the scanner in a valid state if possible.

Specified by:
seekToKeyInBlock in interface DataBlockEncoder.EncodedSeeker
Parameters:
keyOnlyBytes - KeyValue format of a Cell's key at which to position the seeker
offset - offset into the keyOnlyBytes array
length - number of bytes of the keyOnlyBytes array to use
forceBeforeOnExactMatch - if an exact match is found and seekBefore=true, back up 1 Cell
Returns:
0 if the seeker is on the exact key
1 if the seeker is not on the key for any reason, including seekBefore being true

seekToOrBeforeUsingPositionAtOrBefore

protected int seekToOrBeforeUsingPositionAtOrBefore(byte[] keyOnlyBytes,
                                                    int offset,
                                                    int length,
                                                    boolean seekBefore)

seekToOrBeforeUsingPositionAtOrAfter

protected int seekToOrBeforeUsingPositionAtOrAfter(byte[] keyOnlyBytes,
                                                   int offset,
                                                   int length,
                                                   boolean seekBefore)

compareKey

public int compareKey(KeyValue.KVComparator comparator,
                      byte[] key,
                      int offset,
                      int length)
Specified by:
compareKey in interface DataBlockEncoder.EncodedSeeker


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