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:
java.io.Closeable
Enclosing class:
HFile

public static class HFile.Reader
extends java.lang.Object
implements java.io.Closeable

HFile Reader.


Nested Class Summary
protected static class HFile.Reader.Scanner
           
 
Field Summary
 int blockLoads
           
 int cacheHits
           
 int metaLoads
           
protected  java.lang.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()
           
 java.nio.ByteBuffer getMetaBlock(java.lang.String metaBlockName, boolean cacheBlock)
           
 java.lang.String getName()
           
 HFileScanner getScanner(boolean cacheBlocks, boolean pread)
          Create a Scanner on this file.
 java.lang.String getTrailerInfo()
           
 long indexSize()
           
 boolean inMemory()
           
 long length()
           
 java.util.Map<byte[],byte[]> loadFileInfo()
          Read in the index and file info.
 byte[] midkey()
           
 java.lang.String toString()
           
protected  java.lang.String toStringFirstKey()
           
protected  java.lang.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 java.lang.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 java.io.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:
java.io.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:
java.io.IOException
Method Detail

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

toStringFirstKey

protected java.lang.String toStringFirstKey()

toStringLastKey

protected java.lang.String toStringLastKey()

length

public long length()

inMemory

public boolean inMemory()

loadFileInfo

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

Returns:
A map of fileinfo data. See HFile.Writer.appendFileInfo(byte[], byte[]).
Throws:
java.io.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 java.nio.ByteBuffer getMetaBlock(java.lang.String metaBlockName,
                                        boolean cacheBlock)
                                 throws java.io.IOException
Parameters:
metaBlockName -
cacheBlock - Add block to cache, if found
Returns:
Block wrapped in a ByteBuffer
Throws:
java.io.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 java.io.IOException
Returns:
Midkey for this file. We work with block boundaries only so returned midkey is an approximation only.
Throws:
java.io.IOException

close

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

getName

public java.lang.String getName()

getTrailerInfo

public java.lang.String getTrailerInfo()


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