org.apache.hadoop.hbase.rest.client
Class RemoteHTable

java.lang.Object
  extended by org.apache.hadoop.hbase.rest.client.RemoteHTable
All Implemented Interfaces:
HTableInterface

public class RemoteHTable
extends Object
implements HTableInterface

HTable interface to remote tables accessed via REST gateway


Constructor Summary
RemoteHTable(Client client, org.apache.hadoop.conf.Configuration conf, byte[] name, String accessToken)
          Constructor
RemoteHTable(Client client, org.apache.hadoop.conf.Configuration conf, String name, String accessToken)
          Constructor
RemoteHTable(Client client, String name)
          Constructor
RemoteHTable(Client client, String name, String accessToken)
          Constructor
 
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.
protected  CellSetModel buildModelFromPut(Put put)
           
protected  Result[] buildResultFromModel(CellSetModel model)
           
protected  String buildRowSpec(byte[] row, Map familyMap, long startTime, long endTime, int maxVersions)
           
 boolean checkAndDelete(byte[] row, byte[] family, byte[] qualifier, byte[] value, Delete delete)
          Atomically checks if a row/family/qualifier value matches the expected value.
 boolean checkAndPut(byte[] row, byte[] family, byte[] qualifier, byte[] value, Put put)
          Atomically checks if a row/family/qualifier value matches the expected value.
 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.
 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.
 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.
 HTableDescriptor getTableDescriptor()
          Gets the table descriptor for this table.
 byte[] getTableName()
          Gets the name of this table.
 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.
 RowLock lockRow(byte[] row)
          Obtains a lock on a row.
 void put(List<Put> puts)
          Puts some data in the table, in batch.
 void put(Put put)
          Puts some data in the table.
 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
 

Constructor Detail

RemoteHTable

public RemoteHTable(Client client,
                    String name)
Constructor

Parameters:
client -
name -

RemoteHTable

public RemoteHTable(Client client,
                    String name,
                    String accessToken)
Constructor

Parameters:
client -
name -
accessToken -

RemoteHTable

public RemoteHTable(Client client,
                    org.apache.hadoop.conf.Configuration conf,
                    String name,
                    String accessToken)
Constructor

Parameters:
client -
conf -
name -
accessToken -

RemoteHTable

public RemoteHTable(Client client,
                    org.apache.hadoop.conf.Configuration conf,
                    byte[] name,
                    String accessToken)
Constructor

Parameters:
conf -
Method Detail

buildRowSpec

protected String buildRowSpec(byte[] row,
                              Map familyMap,
                              long startTime,
                              long endTime,
                              int maxVersions)

buildResultFromModel

protected Result[] buildResultFromModel(CellSetModel model)

buildModelFromPut

protected CellSetModel buildModelFromPut(Put put)

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.

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

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.

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 HTableInterface
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.

exists

public boolean exists(Get get)
               throws IOException
Description copied from interface: HTableInterface
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 - the Get
Returns:
true if the specified Get matches one or more keys, false if not
Throws:
IOException - e

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.

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.

delete

public void delete(Delete delete)
            throws IOException
Description copied from interface: HTableInterface
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.

delete

public void delete(List<Delete> deletes)
            throws IOException
Description copied from interface: HTableInterface
Deletes the specified cells/rows in bulk.

Specified by:
delete in interface HTableInterface
Parameters:
deletes - List of things to delete. List gets modified by this method (in particular it gets re-ordered, so the order in which the elements are inserted in the list gives no guarantee as to the order in which the Deletes are executed).
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.

flushCommits

public void flushCommits()
                  throws IOException
Description copied from interface: HTableInterface
Executes all the buffered Put operations.

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

Specified by:
flushCommits in interface HTableInterface
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.

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.

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.

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)

checkAndPut

public boolean checkAndPut(byte[] row,
                           byte[] family,
                           byte[] qualifier,
                           byte[] value,
                           Put put)
                    throws IOException
Description copied from interface: HTableInterface
Atomically checks if a row/family/qualifier value matches the expected value. If it does, it adds the put. If the passed value is null, the check is for the lack of column (ie: non-existance)

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

checkAndDelete

public boolean checkAndDelete(byte[] row,
                              byte[] family,
                              byte[] qualifier,
                              byte[] value,
                              Delete delete)
                       throws IOException
Description copied from interface: HTableInterface
Atomically checks if a row/family/qualifier value matches the expected value. If it does, it adds the delete. If the passed value is null, the check is for the lack of column (ie: non-existance)

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

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.

batch

public void batch(List<Row> actions,
                  Object[] results)
           throws IOException
Description copied from interface: HTableInterface
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
results - Empty Object[], same size as actions. Provides access to partial results, in case an exception is thrown. A null in the result array means that the call for that action failed, even after retries
Throws:
IOException

batch

public Object[] batch(List<Row> actions)
               throws IOException
Description copied from interface: HTableInterface
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

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.


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