Class SegmentScanner

java.lang.Object
org.apache.hadoop.hbase.regionserver.SegmentScanner
All Implemented Interfaces:
Closeable, AutoCloseable, KeyValueScanner, Shipper

@Private public class SegmentScanner extends Object implements KeyValueScanner
A scanner of a single memstore segment.
  • Field Details

  • Constructor Details

    • SegmentScanner

      protected SegmentScanner(Segment segment, long readPoint)
      Scanners are ordered from 0 (oldest) to newest in increasing order.
  • Method Details

    • peek

      public ExtendedCell peek()
      Look at the next Cell in this scanner, but do not iterate the scanner
      Specified by:
      peek in interface KeyValueScanner
      Returns:
      the currently observed Cell
    • next

      public ExtendedCell next() throws IOException
      Return the next Cell in this scanner, iterating the scanner
      Specified by:
      next in interface KeyValueScanner
      Returns:
      the next Cell or null if end of scanner
      Throws:
      IOException
    • seek

      public boolean seek(ExtendedCell cell) throws IOException
      Seek the scanner at or after the specified Cell.
      Specified by:
      seek in interface KeyValueScanner
      Parameters:
      cell - seek value
      Returns:
      true if scanner has values left, false if end of scanner
      Throws:
      IOException
    • getIterator

    • reseek

      public boolean reseek(ExtendedCell cell) throws IOException
      Reseek the scanner at or after the specified KeyValue. This method is guaranteed to seek at or after 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:
      cell - seek value (should be non-null)
      Returns:
      true if scanner has values left, false if end of scanner
      Throws:
      IOException
    • backwardSeek

      public boolean backwardSeek(ExtendedCell key) throws IOException
      Seek the scanner at or before the row of specified Cell, it firstly tries to seek the scanner at or after the specified Cell, return if peek KeyValue of scanner has the same row with specified Cell, otherwise seek the scanner at the first Cell of the row which is the previous row of specified KeyValue
      Specified by:
      backwardSeek in interface KeyValueScanner
      Parameters:
      key - seek Cell
      Returns:
      true if the scanner is at the valid KeyValue, false if such Cell does not exist
      Throws:
      IOException
    • seekToPreviousRow

      public boolean seekToPreviousRow(ExtendedCell cell) throws IOException
      Seek the scanner at the first Cell of the row which is the previous row of specified key
      Specified by:
      seekToPreviousRow in interface KeyValueScanner
      Parameters:
      cell - seek value
      Returns:
      true if the scanner at the first valid Cell of previous row, false if not existing such Cell
      Throws:
      IOException
    • seekToLastRow

      public boolean seekToLastRow() throws IOException
      Seek the scanner at the first KeyValue of last row
      Specified by:
      seekToLastRow in interface KeyValueScanner
      Returns:
      true if scanner has values left, false if the underlying data is empty
      Throws:
      IOException
    • close

      public void close()
      Close the KeyValue scanner.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Specified by:
      close in interface KeyValueScanner
    • shouldUseScanner

      public boolean shouldUseScanner(Scan scan, HStore store, long oldestUnexpiredTS)
      This functionality should be resolved in the higher level which is MemStoreScanner, currently returns true as default. Doesn't throw IllegalStateException in order not to change the signature of the overridden method
      Specified by:
      shouldUseScanner in interface KeyValueScanner
      Parameters:
      scan - the scan that we are selecting scanners for
      store - the store we are performing the scan on.
      oldestUnexpiredTS - the oldest timestamp we are interested in for this query, based on TTL
      Returns:
      true if the scanner should be included in the query
    • requestSeek

      public boolean requestSeek(ExtendedCell c, boolean forward, boolean useBloom) throws IOException
      Description copied from interface: KeyValueScanner
      Similar to KeyValueScanner.seek(org.apache.hadoop.hbase.ExtendedCell) (or KeyValueScanner.reseek(org.apache.hadoop.hbase.ExtendedCell) if forward is true) but only does a seek operation after checking that it is really necessary for the row/column combination specified by the kv parameter. This function was added to avoid unnecessary disk seeks by checking row-column Bloom filters before a seek on multi-column get/scan queries, and to optimize by looking up more recent files first.
      Specified by:
      requestSeek in interface KeyValueScanner
      forward - do a forward-only "reseek" instead of a random-access seek
      useBloom - whether to enable multi-column Bloom filter optimization
      Throws:
      IOException
    • realSeekDone

      public boolean realSeekDone()
      This scanner is working solely on the in-memory MemStore and doesn't work on store files, MutableCellSetSegmentScanner always does the seek, therefore always returning true.
      Specified by:
      realSeekDone in interface KeyValueScanner
    • enforceSeek

      public void enforceSeek() throws IOException
      This function should be never called on scanners that always do real seek operations (i.e. most of the scanners and also this one). The easiest way to achieve this is to call realSeekDone() first.
      Specified by:
      enforceSeek in interface KeyValueScanner
      Throws:
      IOException
    • isFileScanner

      public boolean isFileScanner()
      Returns true if this is a file scanner. Otherwise a memory scanner is assumed.
      Specified by:
      isFileScanner in interface KeyValueScanner
    • recordBlockSize

      public void recordBlockSize(IntConsumer blockSizeConsumer)
      Description copied from interface: KeyValueScanner
      Record the size of the current block in bytes, passing as an argument to the blockSizeConsumer. Implementations should ensure that blockSizeConsumer is only called once per block.
      Specified by:
      recordBlockSize in interface KeyValueScanner
      Parameters:
      blockSizeConsumer - to be called with block size in bytes, once per block.
    • getFilePath

      public org.apache.hadoop.fs.Path getFilePath()
      Specified by:
      getFilePath in interface KeyValueScanner
      Returns:
      the file path if this is a file scanner, otherwise null.
      See Also:
    • getNextIndexedKey

      Specified by:
      getNextIndexedKey in interface KeyValueScanner
      Returns:
      the next key in the index (the key to seek to the next block) if known, or null otherwise Not relevant for in-memory scanner
    • shipped

      public void shipped() throws IOException
      Called after a batch of rows scanned (RPC) and set to be returned to client. Any in between cleanup can be done here. Nothing to be done for MutableCellSetSegmentScanner.
      Specified by:
      shipped in interface Shipper
      Throws:
      IOException
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • getSegment

      private Segment getSegment()
      Private Methods
    • updateCurrent

      protected void updateCurrent()
      Private internal method for iterating over the segment, skipping the cells with irrelevant MVCC
    • getHighest

      Private internal method that returns the higher of the two key values, or null if they are both null