org.apache.hadoop.hbase.io.hfile
Class HFile.Reader

java.lang.Object
  extended by org.apache.hadoop.hbase.io.hfile.HFile.Reader
All Implemented Interfaces:
Closeable
Enclosing class:
HFile

public static class HFile.Reader
extends Object
implements Closeable

HFile Reader.


Nested Class Summary
protected static class HFile.Reader.Scanner
           
 
Field Summary
 int blockLoads
           
 int cacheHits
           
 int metaLoads
           
protected  String name
           
 
Constructor Summary
HFile.Reader(org.apache.hadoop.fs.FileSystem fs, org.apache.hadoop.fs.Path path, BlockCache cache, boolean inMemory)
          Opens a HFile.
HFile.Reader(org.apache.hadoop.fs.FSDataInputStream fsdis, long size, BlockCache cache, boolean inMemory)
          Opens a HFile.
 
Method Summary
protected  int blockContainingKey(byte[] key, int offset, int length)
           
 void close()
           
 org.apache.hadoop.io.RawComparator<byte[]> getComparator()
           
 int getEntries()
           
 int getFilterEntries()
           
 byte[] getFirstKey()
           
 byte[] getFirstRowKey()
           
 byte[] getLastKey()
           
 byte[] getLastRowKey()
           
 ByteBuffer getMetaBlock(String metaBlockName, boolean cacheBlock)
           
 String getName()
           
 HFileScanner getScanner(boolean cacheBlocks, boolean pread)
          Create a Scanner on this file.
 String getTrailerInfo()
           
 long indexSize()
           
 boolean inMemory()
           
 long length()
           
 Map<byte[],byte[]> loadFileInfo()
          Read in the index and file info.
 byte[] midkey()
           
 String toString()
           
protected  String toStringFirstKey()
           
protected  String toStringLastKey()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

cacheHits

public int cacheHits

blockLoads

public int blockLoads

metaLoads

public int metaLoads

name

protected String name
Constructor Detail

HFile.Reader

public HFile.Reader(org.apache.hadoop.fs.FileSystem fs,
                    org.apache.hadoop.fs.Path path,
                    BlockCache cache,
                    boolean inMemory)
             throws IOException
Opens a HFile. You must load the file info before you can use it by calling loadFileInfo().

Parameters:
fs - filesystem to load from
path - path within said filesystem
cache - block cache. Pass null if none.
Throws:
IOException

HFile.Reader

public HFile.Reader(org.apache.hadoop.fs.FSDataInputStream fsdis,
                    long size,
                    BlockCache cache,
                    boolean inMemory)
Opens a HFile. You must load the index before you can use it by calling loadFileInfo().

Parameters:
fsdis - input stream. Caller is responsible for closing the passed stream.
size - Length of the stream.
cache - block cache. Pass null if none.
Throws:
IOException
Method Detail

toString

public String toString()
Overrides:
toString in class Object

toStringFirstKey

protected String toStringFirstKey()

toStringLastKey

protected String toStringLastKey()

length

public long length()

inMemory

public boolean inMemory()

loadFileInfo

public Map<byte[],byte[]> loadFileInfo()
                                throws IOException
Read in the index and file info.

Returns:
A map of fileinfo data. See HFile.Writer.appendFileInfo(byte[], byte[]).
Throws:
IOException

getScanner

public HFileScanner getScanner(boolean cacheBlocks,
                               boolean pread)
Create a Scanner on this file. No seeks or reads are done on creation. Call HFileScanner.seekTo(byte[]) to position an start the read. There is nothing to clean up in a Scanner. Letting go of your references to the scanner is sufficient.

Parameters:
pread - Use positional read rather than seek+read if true (pread is better for random reads, seek+read is better scanning).
cacheBlocks - True if we should cache blocks read in by this scanner.
Returns:
Scanner on this file.

blockContainingKey

protected int blockContainingKey(byte[] key,
                                 int offset,
                                 int length)
Parameters:
key - Key to search.
Returns:
Block number of the block containing the key or -1 if not in this file.

getMetaBlock

public ByteBuffer getMetaBlock(String metaBlockName,
                               boolean cacheBlock)
                        throws IOException
Parameters:
metaBlockName -
cacheBlock - Add block to cache, if found
Returns:
Block wrapped in a ByteBuffer
Throws:
IOException

getFirstKey

public byte[] getFirstKey()
Returns:
First key in the file. May be null if file has no entries. Note that this is not the first rowkey, but rather the byte form of the first KeyValue.

getFirstRowKey

public byte[] getFirstRowKey()
Returns:
the first row key, or null if the file is empty. TODO move this to StoreFile after Ryan's patch goes in to eliminate KeyValue here

getEntries

public int getEntries()
Returns:
number of KV entries in this HFile

getLastKey

public byte[] getLastKey()
Returns:
Last key in the file. May be null if file has no entries. Note that this is not the last rowkey, but rather the byte form of the last KeyValue.

getLastRowKey

public byte[] getLastRowKey()
Returns:
the last row key, or null if the file is empty. TODO move this to StoreFile after Ryan's patch goes in to eliminate KeyValue here

getFilterEntries

public int getFilterEntries()
Returns:
number of K entries in this HFile's filter. Returns KV count if no filter.

getComparator

public org.apache.hadoop.io.RawComparator<byte[]> getComparator()
Returns:
Comparator.

indexSize

public long indexSize()
Returns:
index size

midkey

public byte[] midkey()
              throws IOException
Returns:
Midkey for this file. We work with block boundaries only so returned midkey is an approximation only.
Throws:
IOException

close

public void close()
           throws IOException
Specified by:
close in interface Closeable
Throws:
IOException

getName

public String getName()

getTrailerInfo

public String getTrailerInfo()


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