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(KeyValueScanner[] scanners, KeyValue.KVComparator comparator)
          Constructor.
 
Method Summary
 void close()
          Close the KeyValue scanner.
 PriorityQueue<KeyValueScanner> getHeap()
           
 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.
 KeyValue peek()
          Look at the next KeyValue in this scanner, but do not iterate scanner.
 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(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()
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

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
Returns:
true if there are more keys, false if all scanners are done
Throws:
IOException

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)
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

getHeap

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


Copyright © 2009 The Apache Software Foundation