org.apache.hadoop.hbase.client
Class HTable

java.lang.Object
  extended by org.apache.hadoop.hbase.client.HTable
All Implemented Interfaces:
Closeable, HTableInterface

public class HTable
extends Object
implements HTableInterface, Closeable

Used to communicate with a single HBase table.

This class is not thread safe for reads nor write.

In case of writes (Put, Delete), the underlying write buffer can be corrupted if multiple threads contend over a single HTable instance.

In case of reads, some fields used by a Scan are shared among all threads. The HTable implementation can either not contract to be safe in case of a Get

To access a table in a multi threaded environment, please consider using the HTablePool class to create your HTable instances.

Instances of HTable passed the same Configuration instance will share connections to servers out on the cluster and to the zookeeper ensemble as well as caches of region locations. This is usually a *good* thing and it is recommended to reuse the same configuration object for all your tables. This happens because they will all share the same underlying HConnection instance. See HConnectionManager for more on how this mechanism works.

HConnection will read most of the configuration it needs from the passed Configuration on initial construction. Thereafter, for settings such as hbase.client.pause, hbase.client.retries.number, and hbase.client.rpc.maxattempts updating their values in the passed Configuration subsequent to HConnection construction will go unnoticed. To run with changed values, make a new HTable passing a new Configuration instance that has the new configuration.

Note that this class implements the Closeable interface. When a HTable instance is no longer required, it *should* be closed in order to ensure that the underlying resources are promptly released.

See Also:
for create, drop, list, enable and disable of tables., HConnection, HConnectionManager

Nested Class Summary
protected  class HTable.ClientScanner
          Implements the scanner interface for the HBase client.
 
Field Summary
protected  int scannerCaching
           
protected  int scannerTimeout
           
 
Constructor Summary
HTable(byte[] tableName)
          Creates an object to access a HBase table.
HTable(org.apache.hadoop.conf.Configuration conf, byte[] tableName)
          Creates an object to access a HBase table.
HTable(org.apache.hadoop.conf.Configuration conf, String tableName)
          Creates an object to access a HBase table.
HTable(String tableName)
          Creates an object to access a HBase table.
 
Method Summary
 Object[] batch(List<Row> actions)
          Method that does a batch call on Deletes, Gets and Puts.
 void batch(List<Row> actions, Object[] results)
          Method that does a batch call on Deletes, Gets and Puts.
 boolean checkAndDelete(byte[] row, byte[] family, byte[] qualifier, byte[] value, Delete delete)
          Atomically checks if a row/family/qualifier value match the expectedValue.
 boolean checkAndPut(byte[] row, byte[] family, byte[] qualifier, byte[] value, Put put)
          Atomically checks if a row/family/qualifier value match the expectedValue.
 void clearRegionCache()
          Explicitly clears the region cache to fetch the latest value from META.
 void close()
          Releases any resources help or pending changes in internal buffers.
 void delete(Delete delete)
          Deletes the specified cells/row.
 void delete(List<Delete> deletes)
          Deletes the specified cells/rows in bulk.
 Map<HRegionInfo,HServerAddress> deserializeRegionInfo(DataInput in)
          Read from in and deserialize the regions information.
 boolean exists(Get get)
          Test for the existence of columns in the table, as specified in the Get.
 void flushCommits()
          Executes all the buffered Put operations.
 Result get(Get get)
          Extracts certain cells from a given row.
 Result[] get(List<Get> gets)
          Extracts certain cells from the given rows, in batch.
 org.apache.hadoop.conf.Configuration getConfiguration()
          Returns the Configuration object used by this instance.
 HConnection getConnection()
          INTERNAL Used by unit tests and tools to do low-level manipulations.
 int getCurrentNrHRS()
           
 byte[][] getEndKeys()
          Gets the ending row key for every region in the currently open table.
static boolean getRegionCachePrefetch(byte[] tableName)
          Check whether region cache prefetch is enabled or not for the table.
static boolean getRegionCachePrefetch(org.apache.hadoop.conf.Configuration conf, byte[] tableName)
          Check whether region cache prefetch is enabled or not for the table.
 HRegionLocation getRegionLocation(byte[] row)
          Finds the region on which the given row is being served.
 HRegionLocation getRegionLocation(String row)
          Find region location hosting passed row using cached info
 Map<HRegionInfo,HServerAddress> getRegionsInfo()
          Gets all the regions and their address for this table.
 Result getRowOrBefore(byte[] row, byte[] family)
          Return the row that matches row exactly, or the one that immediately precedes it.
 ResultScanner getScanner(byte[] family)
          Gets a scanner on the current table for the given family.
 ResultScanner getScanner(byte[] family, byte[] qualifier)
          Gets a scanner on the current table for the given family and qualifier.
 ResultScanner getScanner(Scan scan)
          Returns a scanner on the current table as specified by the Scan object.
 int getScannerCaching()
          Gets the number of rows that a scanner will fetch at once.
 Pair<byte[][],byte[][]> getStartEndKeys()
          Gets the starting and ending row keys for every region in the currently open table.
 byte[][] getStartKeys()
          Gets the starting row key for every region in the currently open table.
 HTableDescriptor getTableDescriptor()
          Gets the table descriptor for this table.
 byte[] getTableName()
          Gets the name of this table.
 ArrayList<Put> getWriteBuffer()
          Returns the write buffer.
 long getWriteBufferSize()
          Returns the maximum size in bytes of the write buffer for this HTable.
 Result increment(Increment increment)
          Increments one or more columns within a single row.
 long incrementColumnValue(byte[] row, byte[] family, byte[] qualifier, long amount)
          Atomically increments a column value.
 long incrementColumnValue(byte[] row, byte[] family, byte[] qualifier, long amount, boolean writeToWAL)
          Atomically increments a column value.
 boolean isAutoFlush()
          Tells whether or not 'auto-flush' is turned on.
static boolean isTableEnabled(byte[] tableName)
          Tells whether or not a table is enabled or not.
static boolean isTableEnabled(org.apache.hadoop.conf.Configuration conf, byte[] tableName)
          Tells whether or not a table is enabled or not.
static boolean isTableEnabled(org.apache.hadoop.conf.Configuration conf, String tableName)
          Tells whether or not a table is enabled or not.
static boolean isTableEnabled(String tableName)
          Tells whether or not a table is enabled or not.
 RowLock lockRow(byte[] row)
          Obtains a lock on a row.
 void prewarmRegionCache(Map<HRegionInfo,HServerAddress> regionMap)
          Save the passed region information and the table's regions cache.
 void put(List<Put> puts)
          Puts some data in the table, in batch.
 void put(Put put)
          Puts some data in the table.
 void serializeRegionInfo(DataOutput out)
          Serialize the regions information of this table and output to out.
 void setAutoFlush(boolean autoFlush)
          See setAutoFlush(boolean, boolean)
 void setAutoFlush(boolean autoFlush, boolean clearBufferOnFail)
          Turns 'auto-flush' on or off.
static void setRegionCachePrefetch(byte[] tableName, boolean enable)
          Enable or disable region cache prefetch for the table.
static void setRegionCachePrefetch(org.apache.hadoop.conf.Configuration conf, byte[] tableName, boolean enable)
          Enable or disable region cache prefetch for the table.
 void setScannerCaching(int scannerCaching)
          Sets the number of rows that a scanner will fetch at once.
 void setWriteBufferSize(long writeBufferSize)
          Sets the size of the buffer in bytes.
 void unlockRow(RowLock rl)
          Releases a row lock.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

scannerTimeout

protected final int scannerTimeout

scannerCaching

protected int scannerCaching
Constructor Detail

HTable

public HTable(String tableName)
       throws IOException
Creates an object to access a HBase table. Internally it creates a new instance of Configuration and a new client to zookeeper as well as other resources. It also comes up with a fresh view of the cluster and must do discovery from scratch of region locations; i.e. it will not make use of already-cached region locations if available. Use only when being quick and dirty.

Throws:
IOException - if a remote or network exception occurs
See Also:
HTable(Configuration, String)

HTable

public HTable(byte[] tableName)
       throws IOException
Creates an object to access a HBase table. Internally it creates a new instance of Configuration and a new client to zookeeper as well as other resources. It also comes up with a fresh view of the cluster and must do discovery from scratch of region locations; i.e. it will not make use of already-cached region locations if available. Use only when being quick and dirty.

Parameters:
tableName - Name of the table.
Throws:
IOException - if a remote or network exception occurs
See Also:
HTable(Configuration, String)

HTable

public HTable(org.apache.hadoop.conf.Configuration conf,
              String tableName)
       throws IOException
Creates an object to access a HBase table. Shares zookeeper connection and other resources with other HTable instances created with the same conf instance. Uses already-populated region cache if one is available, populated by any other HTable instances sharing this conf instance. Recommended.

Parameters:
conf - Configuration object to use.
tableName - Name of the table.
Throws:
IOException - if a remote or network exception occurs

HTable

public HTable(org.apache.hadoop.conf.Configuration conf,
              byte[] tableName)
       throws IOException
Creates an object to access a HBase table. Shares zookeeper connection and other resources with other HTable instances created with the same conf instance. Uses already-populated region cache if one is available, populated by any other HTable instances sharing this conf instance. Recommended.

Parameters:
conf - Configuration object to use.
tableName - Name of the table.
Throws:
IOException - if a remote or network exception occurs
Method Detail

getCurrentNrHRS

public int getCurrentNrHRS()
                    throws IOException
Returns:
the number of region servers that are currently running
Throws:
IOException - if a remote or network exception occurs

getConfiguration

public org.apache.hadoop.conf.Configuration getConfiguration()
Description copied from interface: HTableInterface
Returns the Configuration object used by this instance.

The reference returned is not a copy, so any change made to it will affect this instance.

Specified by:
getConfiguration in interface HTableInterface

isTableEnabled

public static boolean isTableEnabled(String tableName)
                              throws IOException
Tells whether or not a table is enabled or not. Warning: use HBaseAdmin.isTableEnabled(byte[]) instead.

Parameters:
tableName - Name of table to check.
Returns:
true if table is online.
Throws:
IOException - if a remote or network exception occurs

isTableEnabled

public static boolean isTableEnabled(byte[] tableName)
                              throws IOException
Tells whether or not a table is enabled or not. Warning: use HBaseAdmin.isTableEnabled(byte[]) instead.

Parameters:
tableName - Name of table to check.
Returns:
true if table is online.
Throws:
IOException - if a remote or network exception occurs

isTableEnabled

public static boolean isTableEnabled(org.apache.hadoop.conf.Configuration conf,
                                     String tableName)
                              throws IOException
Tells whether or not a table is enabled or not. Warning: use HBaseAdmin.isTableEnabled(byte[]) instead.

Parameters:
conf - The Configuration object to use.
tableName - Name of table to check.
Returns:
true if table is online.
Throws:
IOException - if a remote or network exception occurs

isTableEnabled

public static boolean isTableEnabled(org.apache.hadoop.conf.Configuration conf,
                                     byte[] tableName)
                              throws IOException
Tells whether or not a table is enabled or not.

Parameters:
conf - The Configuration object to use.
tableName - Name of table to check.
Returns:
true if table is online.
Throws:
IOException - if a remote or network exception occurs

getRegionLocation

public HRegionLocation getRegionLocation(String row)
                                  throws IOException
Find region location hosting passed row using cached info

Parameters:
row - Row to find.
Returns:
The location of the given row.
Throws:
IOException - if a remote or network exception occurs

getRegionLocation

public HRegionLocation getRegionLocation(byte[] row)
                                  throws IOException
Finds the region on which the given row is being served.

Parameters:
row - Row to find.
Returns:
Location of the row.
Throws:
IOException - if a remote or network exception occurs

getTableName

public byte[] getTableName()
Description copied from interface: HTableInterface
Gets the name of this table.

Specified by:
getTableName in interface HTableInterface
Returns:
the table name.

getConnection

public HConnection getConnection()
INTERNAL Used by unit tests and tools to do low-level manipulations.

Returns:
An HConnection instance.

getScannerCaching

public int getScannerCaching()
Gets the number of rows that a scanner will fetch at once.

The default value comes from hbase.client.scanner.caching.


setScannerCaching

public void setScannerCaching(int scannerCaching)
Sets the number of rows that a scanner will fetch at once.

This will override the value specified by hbase.client.scanner.caching. Increasing this value will reduce the amount of work needed each time next() is called on a scanner, at the expense of memory use (since more rows will need to be maintained in memory by the scanners).

Parameters:
scannerCaching - the number of rows a scanner will fetch at once.

getTableDescriptor

public HTableDescriptor getTableDescriptor()
                                    throws IOException
Description copied from interface: HTableInterface
Gets the table descriptor for this table.

Specified by:
getTableDescriptor in interface HTableInterface
Throws:
IOException - if a remote or network exception occurs.

getStartKeys

public byte[][] getStartKeys()
                      throws IOException
Gets the starting row key for every region in the currently open table.

This is mainly useful for the MapReduce integration.

Returns:
Array of region starting row keys
Throws:
IOException - if a remote or network exception occurs

getEndKeys

public byte[][] getEndKeys()
                    throws IOException
Gets the ending row key for every region in the currently open table.

This is mainly useful for the MapReduce integration.

Returns:
Array of region ending row keys
Throws:
IOException - if a remote or network exception occurs

getStartEndKeys

public Pair<byte[][],byte[][]> getStartEndKeys()
                                        throws IOException
Gets the starting and ending row keys for every region in the currently open table.

This is mainly useful for the MapReduce integration.

Returns:
Pair of arrays of region starting and ending row keys
Throws:
IOException - if a remote or network exception occurs

getRegionsInfo

public Map<HRegionInfo,HServerAddress> getRegionsInfo()
                                               throws IOException
Gets all the regions and their address for this table.

This is mainly useful for the MapReduce integration.

Returns:
A map of HRegionInfo with it's server address
Throws:
IOException - if a remote or network exception occurs

prewarmRegionCache

public void prewarmRegionCache(Map<HRegionInfo,HServerAddress> regionMap)
Save the passed region information and the table's regions cache.

This is mainly useful for the MapReduce integration. You can call deserializeRegionInfo to deserialize regions information from a DataInput, then call this method to load them to cache.

 HTable t1 = new HTable("foo");
 FileInputStream fis = new FileInputStream("regions.dat");
 DataInputStream dis = new DataInputStream(fis);

 Map<HRegionInfo, HServerAddress> hm = t1.deserializeRegionInfo(dis);
 t1.prewarmRegionCache(hm);
 
 

Parameters:
regionMap - This piece of regions information will be loaded to region cache.

serializeRegionInfo

public void serializeRegionInfo(DataOutput out)
                         throws IOException
Serialize the regions information of this table and output to out.

This is mainly useful for the MapReduce integration. A client could perform a large scan for all the regions for the table, serialize the region info to a file. MR job can ship a copy of the meta for the table in the DistributedCache.

 FileOutputStream fos = new FileOutputStream("regions.dat");
 DataOutputStream dos = new DataOutputStream(fos);
 table.serializeRegionInfo(dos);
 dos.flush();
 dos.close();
 
 

Parameters:
out - DataOutput to serialize this object into.
Throws:
IOException - if a remote or network exception occurs

deserializeRegionInfo

public Map<HRegionInfo,HServerAddress> deserializeRegionInfo(DataInput in)
                                                      throws IOException
Read from in and deserialize the regions information.

It behaves similarly as getRegionsInfo, except that it loads the region map from a DataInput object.

It is supposed to be followed immediately by prewarmRegionCache.

Please refer to prewarmRegionCache for usage.

Parameters:
in - DataInput object.
Returns:
A map of HRegionInfo with its server address.
Throws:
IOException - if an I/O exception occurs.

getRowOrBefore

public Result getRowOrBefore(byte[] row,
                             byte[] family)
                      throws IOException
Description copied from interface: HTableInterface
Return the row that matches row exactly, or the one that immediately precedes it.

Specified by:
getRowOrBefore in interface HTableInterface
Parameters:
row - A row key.
family - Column family to include in the Result.
Throws:
IOException - if a remote or network exception occurs.

getScanner

public ResultScanner getScanner(Scan scan)
                         throws IOException
Description copied from interface: HTableInterface
Returns a scanner on the current table as specified by the Scan object.

Specified by:
getScanner in interface HTableInterface
Parameters:
scan - A configured Scan object.
Returns:
A scanner.
Throws:
IOException - if a remote or network exception occurs.

getScanner

public ResultScanner getScanner(byte[] family)
                         throws IOException
Description copied from interface: HTableInterface
Gets a scanner on the current table for the given family.

Specified by:
getScanner in interface HTableInterface
Parameters:
family - The column family to scan.
Returns:
A scanner.
Throws:
IOException - if a remote or network exception occurs.

getScanner

public ResultScanner getScanner(byte[] family,
                                byte[] qualifier)
                         throws IOException
Description copied from interface: HTableInterface
Gets a scanner on the current table for the given family and qualifier.

Specified by:
getScanner in interface HTableInterface
Parameters:
family - The column family to scan.
qualifier - The column qualifier to scan.
Returns:
A scanner.
Throws:
IOException - if a remote or network exception occurs.

get

public Result get(Get get)
           throws IOException
Description copied from interface: HTableInterface
Extracts certain cells from a given row.

Specified by:
get in interface HTableInterface
Parameters:
get - The object that specifies what data to fetch and from which row.
Returns:
The data coming from the specified row, if it exists. If the row specified doesn't exist, the Result instance returned won't contain any KeyValue, as indicated by Result.isEmpty().
Throws:
IOException - if a remote or network exception occurs.

get

public Result[] get(List<Get> gets)
             throws IOException
Description copied from interface: HTableInterface
Extracts certain cells from the given rows, in batch.

Specified by:
get in interface HTableInterface
Parameters:
gets - The objects that specify what data to fetch and from which rows.
Returns:
The data coming from the specified rows, if it exists. If the row specified doesn't exist, the Result instance returned won't contain any KeyValue, as indicated by Result.isEmpty(). A null in the return array means that the get operation for that Get failed, even after retries.
Throws:
IOException - if a remote or network exception occurs.

batch

public void batch(List<Row> actions,
                  Object[] results)
           throws InterruptedException,
                  IOException
Method that does a batch call on Deletes, Gets and Puts. The ordering of execution of the actions is not defined. Meaning if you do a Put and a Get in the same batch(java.util.List, java.lang.Object[]) call, you will not necessarily be guaranteed that the Get returns what the Put had put.

Specified by:
batch in interface HTableInterface
Parameters:
actions - list of Get, Put, Delete objects
results - Empty Result[], same size as actions. Provides access to partial results, in case an exception is thrown. If there are any failures, there will be a null or Throwable will be in the results array, AND an exception will be thrown.
Throws:
IOException
InterruptedException

batch

public Object[] batch(List<Row> actions)
               throws InterruptedException,
                      IOException
Method that does a batch call on Deletes, Gets and Puts.

Specified by:
batch in interface HTableInterface
Parameters:
actions - list of Get, Put, Delete objects
Returns:
the results from the actions. A null in the return array means that the call for that action failed, even after retries
Throws:
IOException
InterruptedException

delete

public void delete(Delete delete)
            throws IOException
Deletes the specified cells/row.

Specified by:
delete in interface HTableInterface
Parameters:
delete - The object that specifies what to delete.
Throws:
IOException - if a remote or network exception occurs.
Since:
0.20.0

delete

public void delete(List<Delete> deletes)
            throws IOException
Deletes the specified cells/rows in bulk.

Specified by:
delete in interface HTableInterface
Parameters:
deletes - List of things to delete. As a side effect, it will be modified: successful Deletes are removed. The ordering of the list will not change.
Throws:
IOException - if a remote or network exception occurs. In that case the deletes argument will contain the Delete instances that have not be successfully applied.
Since:
0.20.1
See Also:
batch(java.util.List, Object[])

put

public void put(Put put)
         throws IOException
Description copied from interface: HTableInterface
Puts some data in the table.

If isAutoFlush is false, the update is buffered until the internal buffer is full.

Specified by:
put in interface HTableInterface
Parameters:
put - The data to put.
Throws:
IOException - if a remote or network exception occurs.

put

public void put(List<Put> puts)
         throws IOException
Description copied from interface: HTableInterface
Puts some data in the table, in batch.

If isAutoFlush is false, the update is buffered until the internal buffer is full.

This can be used for group commit, or for submitting user defined batches. The writeBuffer will be periodically inspected while the List is processed, so depending on the List size the writeBuffer may flush not at all, or more than once.

Specified by:
put in interface HTableInterface
Parameters:
puts - The list of mutations to apply. The batch put is done by aggregating the iteration of the Puts over the write buffer at the client-side for a single RPC call.
Throws:
IOException - if a remote or network exception occurs.

increment

public Result increment(Increment increment)
                 throws IOException
Description copied from interface: HTableInterface
Increments one or more columns within a single row.

This operation does not appear atomic to readers. Increments are done under a single row lock, so write operations to a row are synchronized, but readers do not take row locks so get and scan operations can see this operation partially completed.

Specified by:
increment in interface HTableInterface
Parameters:
increment - object that specifies the columns and amounts to be used for the increment operations
Returns:
values of columns after the increment
Throws:
IOException - e

incrementColumnValue

public long incrementColumnValue(byte[] row,
                                 byte[] family,
                                 byte[] qualifier,
                                 long amount)
                          throws IOException
Description copied from interface: HTableInterface
Atomically increments a column value.

Equivalent to {@link #incrementColumnValue(byte[], byte[], byte[], long, boolean) incrementColumnValue}(row, family, qualifier, amount, <b>true</b>)

Specified by:
incrementColumnValue in interface HTableInterface
Parameters:
row - The row that contains the cell to increment.
family - The column family of the cell to increment.
qualifier - The column qualifier of the cell to increment.
amount - The amount to increment the cell with (or decrement, if the amount is negative).
Returns:
The new value, post increment.
Throws:
IOException - if a remote or network exception occurs.

incrementColumnValue

public long incrementColumnValue(byte[] row,
                                 byte[] family,
                                 byte[] qualifier,
                                 long amount,
                                 boolean writeToWAL)
                          throws IOException
Description copied from interface: HTableInterface
Atomically increments a column value. If the column value already exists and is not a big-endian long, this could throw an exception. If the column value does not yet exist it is initialized to amount and written to the specified column.

Setting writeToWAL to false means that in a fail scenario, you will lose any increments that have not been flushed.

Specified by:
incrementColumnValue in interface HTableInterface
Parameters:
row - The row that contains the cell to increment.
family - The column family of the cell to increment.
qualifier - The column qualifier of the cell to increment.
amount - The amount to increment the cell with (or decrement, if the amount is negative).
writeToWAL - if true, the operation will be applied to the Write Ahead Log (WAL). This makes the operation slower but safer, as if the call returns successfully, it is guaranteed that the increment will be safely persisted. When set to false, the call may return successfully before the increment is safely persisted, so it's possible that the increment be lost in the event of a failure happening before the operation gets persisted.
Returns:
The new value, post increment.
Throws:
IOException - if a remote or network exception occurs.

checkAndPut

public boolean checkAndPut(byte[] row,
                           byte[] family,
                           byte[] qualifier,
                           byte[] value,
                           Put put)
                    throws IOException
Atomically checks if a row/family/qualifier value match the expectedValue. If it does, it adds the put. If value == null, checks for non-existence of the value.

Specified by:
checkAndPut in interface HTableInterface
Parameters:
row - to check
family - column family
qualifier - column qualifier
value - the expected value
put - put to execute if value matches.
Returns:
true if the new put was execute, false otherwise
Throws:
IOException

checkAndDelete

public boolean checkAndDelete(byte[] row,
                              byte[] family,
                              byte[] qualifier,
                              byte[] value,
                              Delete delete)
                       throws IOException
Atomically checks if a row/family/qualifier value match the expectedValue. If it does, it adds the delete. If value == null, checks for non-existence of the value.

Specified by:
checkAndDelete in interface HTableInterface
Parameters:
row - to check
family - column family
qualifier - column qualifier
value - the expected value
delete - delete to execute if value matches.
Returns:
true if the new delete was executed, false otherwise
Throws:
IOException

exists

public boolean exists(Get get)
               throws IOException
Test for the existence of columns in the table, as specified in the Get.

This will return true if the Get matches one or more keys, false if not.

This is a server-side call so it prevents any data from being transfered to the client.

Specified by:
exists in interface HTableInterface
Parameters:
get - param to check for
Returns:
true if the specified Get matches one or more keys, false if not
Throws:
IOException

flushCommits

public void flushCommits()
                  throws IOException
Executes all the buffered Put operations.

This method gets called once automatically for every Put or batch of Puts (when batch(List) is used) when isAutoFlush() is true.

Specified by:
flushCommits in interface HTableInterface
Throws:
IOException - if a remote or network exception occurs.

close

public void close()
           throws IOException
Description copied from interface: HTableInterface
Releases any resources help or pending changes in internal buffers.

Specified by:
close in interface Closeable
Specified by:
close in interface HTableInterface
Throws:
IOException - if a remote or network exception occurs.

lockRow

public RowLock lockRow(byte[] row)
                throws IOException
Description copied from interface: HTableInterface
Obtains a lock on a row.

Specified by:
lockRow in interface HTableInterface
Parameters:
row - The row to lock.
Returns:
A RowLock containing the row and lock id.
Throws:
IOException - if a remote or network exception occurs.
See Also:
RowLock, HTableInterface.unlockRow(org.apache.hadoop.hbase.client.RowLock)

unlockRow

public void unlockRow(RowLock rl)
               throws IOException
Description copied from interface: HTableInterface
Releases a row lock.

Specified by:
unlockRow in interface HTableInterface
Parameters:
rl - The row lock to release.
Throws:
IOException - if a remote or network exception occurs.
See Also:
RowLock, HTableInterface.unlockRow(org.apache.hadoop.hbase.client.RowLock)

clearRegionCache

public void clearRegionCache()
Explicitly clears the region cache to fetch the latest value from META. This is a power user function: avoid unless you know the ramifications.


isAutoFlush

public boolean isAutoFlush()
Description copied from interface: HTableInterface
Tells whether or not 'auto-flush' is turned on.

Specified by:
isAutoFlush in interface HTableInterface
Returns:
true if 'auto-flush' is enabled (default), meaning Put operations don't get buffered/delayed and are immediately executed.

setAutoFlush

public void setAutoFlush(boolean autoFlush)
See setAutoFlush(boolean, boolean)

Parameters:
autoFlush - Whether or not to enable 'auto-flush'.

setAutoFlush

public void setAutoFlush(boolean autoFlush,
                         boolean clearBufferOnFail)
Turns 'auto-flush' on or off.

When enabled (default), Put operations don't get buffered/delayed and are immediately executed. Failed operations are not retried. This is slower but safer.

Turning off autoFlush means that multiple Puts will be accepted before any RPC is actually sent to do the write operations. If the application dies before pending writes get flushed to HBase, data will be lost.

When you turn autoFlush off, you should also consider the clearBufferOnFail option. By default, asynchronous Put requests will be retried on failure until successful. However, this can pollute the writeBuffer and slow down batching performance. Additionally, you may want to issue a number of Put requests and call flushCommits() as a barrier. In both use cases, consider setting clearBufferOnFail to true to erase the buffer after flushCommits() has been called, regardless of success.

Parameters:
autoFlush - Whether or not to enable 'auto-flush'.
clearBufferOnFail - Whether to keep Put failures in the writeBuffer
See Also:
flushCommits()

getWriteBufferSize

public long getWriteBufferSize()
Returns the maximum size in bytes of the write buffer for this HTable.

The default value comes from the configuration parameter hbase.client.write.buffer.

Returns:
The size of the write buffer in bytes.

setWriteBufferSize

public void setWriteBufferSize(long writeBufferSize)
                        throws IOException
Sets the size of the buffer in bytes.

If the new size is less than the current amount of data in the write buffer, the buffer gets flushed.

Parameters:
writeBufferSize - The new write buffer size, in bytes.
Throws:
IOException - if a remote or network exception occurs.

getWriteBuffer

public ArrayList<Put> getWriteBuffer()
Returns the write buffer.

Returns:
The current write buffer.

setRegionCachePrefetch

public static void setRegionCachePrefetch(byte[] tableName,
                                          boolean enable)
                                   throws IOException
Enable or disable region cache prefetch for the table. It will be applied for the given table's all HTable instances who share the same connection. By default, the cache prefetch is enabled.

Parameters:
tableName - name of table to configure.
enable - Set to true to enable region cache prefetch. Or set to false to disable it.
Throws:
IOException

setRegionCachePrefetch

public static void setRegionCachePrefetch(org.apache.hadoop.conf.Configuration conf,
                                          byte[] tableName,
                                          boolean enable)
                                   throws IOException
Enable or disable region cache prefetch for the table. It will be applied for the given table's all HTable instances who share the same connection. By default, the cache prefetch is enabled.

Parameters:
conf - The Configuration object to use.
tableName - name of table to configure.
enable - Set to true to enable region cache prefetch. Or set to false to disable it.
Throws:
IOException

getRegionCachePrefetch

public static boolean getRegionCachePrefetch(org.apache.hadoop.conf.Configuration conf,
                                             byte[] tableName)
                                      throws IOException
Check whether region cache prefetch is enabled or not for the table.

Parameters:
conf - The Configuration object to use.
tableName - name of table to check
Returns:
true if table's region cache prefecth is enabled. Otherwise it is disabled.
Throws:
IOException

getRegionCachePrefetch

public static boolean getRegionCachePrefetch(byte[] tableName)
                                      throws IOException
Check whether region cache prefetch is enabled or not for the table.

Parameters:
tableName - name of table to check
Returns:
true if table's region cache prefecth is enabled. Otherwise it is disabled.
Throws:
IOException


Copyright © 2013 Cloudera. All Rights Reserved.