org.apache.hadoop.hbase.regionserver
Class KeyValueHeap

java.lang.Object
  extended by org.apache.hadoop.hbase.regionserver.KeyValueHeap
All Implemented Interfaces:
Closeable, InternalScanner, KeyValueScanner

public class KeyValueHeap
extends Object
implements KeyValueScanner, InternalScanner

Implements a heap merge across any number of KeyValueScanners.

Implements KeyValueScanner itself.

This class is used at the Region level to merge across Stores and at the Store level to merge across the memstore and StoreFiles.

In the Region case, we also need InternalScanner.next(List), so this class also implements InternalScanner. WARNING: As is, if you try to use this as an InternalScanner at the Store level, you will get runtime exceptions.


Constructor Summary
KeyValueHeap(List<? extends KeyValueScanner> scanners, KeyValue.KVComparator comparator)
          Constructor.
 
Method Summary
 void close()
          Close the KeyValue scanner.
 PriorityQueue<KeyValueScanner> getHeap()
           
 long getSequenceID()
          Get the sequence id associated with this KeyValueScanner.
 KeyValue next()
          Return the next KeyValue in this scanner, iterating the scanner
 boolean next(List<KeyValue> result)
          Gets the next row of keys from the top-most scanner.
 boolean next(List<KeyValue> result, int limit)
          Gets the next row of keys from the top-most scanner.
 KeyValue peek()
          Look at the next KeyValue in this scanner, but do not iterate scanner.
 boolean reseek(KeyValue seekKey)
          Reseek the scanner at or after the specified KeyValue.
 boolean seek(KeyValue seekKey)
          Seeks all scanners at or below the specified seek key.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

KeyValueHeap

public KeyValueHeap(List<? extends KeyValueScanner> scanners,
                    KeyValue.KVComparator comparator)
Constructor. This KeyValueHeap will handle closing of passed in KeyValueScanners.

Parameters:
scanners -
comparator -
Method Detail

peek

public KeyValue peek()
Description copied from interface: KeyValueScanner
Look at the next KeyValue in this scanner, but do not iterate scanner.

Specified by:
peek in interface KeyValueScanner
Returns:
the next KeyValue

next

public KeyValue next()
              throws IOException
Description copied from interface: KeyValueScanner
Return the next KeyValue in this scanner, iterating the scanner

Specified by:
next in interface KeyValueScanner
Returns:
the next KeyValue
Throws:
IOException

next

public boolean next(List<KeyValue> result,
                    int limit)
             throws IOException
Gets the next row of keys from the top-most scanner.

This method takes care of updating the heap.

This can ONLY be called when you are using Scanners that implement InternalScanner as well as KeyValueScanner (a StoreScanner).

Specified by:
next in interface InternalScanner
Parameters:
result -
limit -
Returns:
true if there are more keys, false if all scanners are done
Throws:
IOException - e

next

public boolean next(List<KeyValue> result)
             throws IOException
Gets the next row of keys from the top-most scanner.

This method takes care of updating the heap.

This can ONLY be called when you are using Scanners that implement InternalScanner as well as KeyValueScanner (a StoreScanner).

Specified by:
next in interface InternalScanner
Parameters:
result -
Returns:
true if there are more keys, false if all scanners are done
Throws:
IOException - e

close

public void close()
Description copied from interface: KeyValueScanner
Close the KeyValue scanner.

Specified by:
close in interface Closeable
Specified by:
close in interface InternalScanner
Specified by:
close in interface KeyValueScanner

seek

public boolean seek(KeyValue seekKey)
             throws IOException
Seeks all scanners at or below the specified seek key. If we earlied-out of a row, we may end up skipping values that were never reached yet. Rather than iterating down, we want to give the opportunity to re-seek.

As individual scanners may run past their ends, those scanners are automatically closed and removed from the heap.

Specified by:
seek in interface KeyValueScanner
Parameters:
seekKey - KeyValue to seek at or after
Returns:
true if KeyValues exist at or after specified key, false if not
Throws:
IOException

reseek

public boolean reseek(KeyValue seekKey)
               throws IOException
Description copied from interface: KeyValueScanner
Reseek the scanner at or after the specified KeyValue. This method is guaranteed to seek to or before the required key only if the key comes after the current position of the scanner. Should not be used to seek to a key which may come before the current position.

Specified by:
reseek in interface KeyValueScanner
Parameters:
seekKey - seek value (should be non-null)
Returns:
true if scanner has values left, false if end of scanner
Throws:
IOException

getHeap

public PriorityQueue<KeyValueScanner> getHeap()
Returns:
the current Heap

getSequenceID

public long getSequenceID()
Description copied from interface: KeyValueScanner
Get the sequence id associated with this KeyValueScanner. This is required for comparing multiple files to find out which one has the latest data. The default implementation for this would be to return 0. A file having lower sequence id will be considered to be the older one.

Specified by:
getSequenceID in interface KeyValueScanner


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