org.apache.hadoop.hbase
Class HClient

java.lang.Object
  extended by org.apache.hadoop.hbase.HClient
All Implemented Interfaces:
HConstants

public class HClient
extends Object
implements HConstants

HClient manages a connection to a single HRegionServer.


Nested Class Summary
protected  class HClient.BatchHandler
           
protected static class HClient.RegionLocation
           
 
Field Summary
 
Fields inherited from interface org.apache.hadoop.hbase.HConstants
COL_REGIONINFO, COL_SERVER, COL_STARTCODE, COLUMN_FAMILY, COLUMN_FAMILY_ARRAY, COMPLETE_CACHEFLUSH, DEFAULT_HBASE_DIR, DEFAULT_HOST, DEFAULT_MASTER_ADDRESS, DEFAULT_MAX_FILE_SIZE, DEFAULT_REGION_SERVER_CLASS, DEFAULT_REGIONSERVER_ADDRESS, DELETE_BYTES, HBASE_DIR, HREGION_LOGDIR_NAME, HREGION_OLDLOGFILE_NAME, HREGIONDIR_PREFIX, MASTER_ADDRESS, META_TABLE_NAME, REGION_SERVER_CLASS, REGIONSERVER_ADDRESS, ROOT_TABLE_NAME, THREAD_WAKE_FREQUENCY, UTF8_ENCODING
 
Constructor Summary
HClient(Configuration conf)
          Creates a new HClient
 
Method Summary
 void abort(long lockid)
          Abort a row mutation
 void abortBatch()
          Abort a batch mutation
 void addColumn(Text tableName, HColumnDescriptor column)
          Add a column to an existing table
protected  void checkMaster()
           
protected  void checkReservedTableName(Text tableName)
           
 void commit(long lockid)
          Finalize a row mutation
 void commit(long lockid, long timestamp)
          Finalize a row mutation
 void commitBatch()
          Finalize a batch mutation
 void commitBatch(long timestamp)
          Finalize a batch mutation
 void createTable(HTableDescriptor desc)
          Creates a new table
 void createTableAsync(HTableDescriptor desc)
          Creates a new table but does not block and wait for it to come online.
 void delete(long lockid, Text column)
          Delete the value for a column
 void deleteColumn(Text tableName, Text columnName)
          Delete a column from a table
 void deleteTable(Text tableName)
          Deletes a table
 void disableTable(Text tableName)
          Disables a table (takes it off-line) If it is being served, the master will tell the servers to stop serving it.
 int doCommandLine(String[] args)
          Process command-line args.
 void enableTable(Text tableName)
          Brings a table on-line (enables it)
 byte[] get(Text row, Text column)
          Get a single value for the specified row and column
 byte[][] get(Text row, Text column, int numVersions)
          Get the specified number of versions of the specified row and column
 byte[][] get(Text row, Text column, long timestamp, int numVersions)
          Get the specified number of versions of the specified row and column with the specified timestamp.
protected  Configuration getConf()
           
protected  HRegionInterface getHRegionConnection(HServerAddress regionServer)
          Establishes a connection to the region server at the specified address.
protected  HClient.RegionLocation getRegionLocation(Text row)
           
 SortedMap<Text,byte[]> getRow(Text row)
          Get all the data for the specified row
 Text[] getStartKeys()
          Gets the starting row key for every region in the currently open table
protected  SortedMap<Text,HClient.RegionLocation> getTableServers(Text tableName)
          Gets the servers of the given table.
 boolean isMasterRunning()
           
 HTableDescriptor[] listTables()
          List all the userspace tables.
static void main(String[] args)
          Main program
 HScannerInterface obtainScanner(Text[] columns, Text startRow)
          Get a scanner on the current table starting at the specified row.
 HScannerInterface obtainScanner(Text[] columns, Text startRow, long timestamp)
          Get a scanner on the current table starting at the specified row.
 HScannerInterface obtainScanner(Text[] columns, Text startRow, long timestamp, RowFilterInterface filter)
          Get a scanner on the current table starting at the specified row.
 HScannerInterface obtainScanner(Text[] columns, Text startRow, RowFilterInterface filter)
          Get a scanner on the current table starting at the specified row.
 void openTable(Text tableName)
          Loads information so that a table can be manipulated.
 void put(long lockid, Text column, byte[] val)
          Change a value for the specified column.
 void renewLease(long lockid)
          Renew lease on update
 void shutdown()
          Shuts down the HBase instance
 void startBatchUpdate()
          Start a batch of row insertions/updates.
 long startUpdate(Text row)
          Start an atomic row insertion/update.
 boolean tableExists(Text tableName)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HClient

public HClient(Configuration conf)
Creates a new HClient

Parameters:
conf - - Configuration object
Method Detail

tableExists

public boolean tableExists(Text tableName)
                    throws IOException
Parameters:
tableName - Table to check.
Returns:
True if table exists already.
Throws:
IOException

checkMaster

protected void checkMaster()
                    throws MasterNotRunningException
Throws:
MasterNotRunningException

isMasterRunning

public boolean isMasterRunning()
Returns:
- true if the master server is running

createTable

public void createTable(HTableDescriptor desc)
                 throws IOException
Creates a new table

Parameters:
desc - table descriptor for table
Throws:
IllegalArgumentException - if the table name is reserved
MasterNotRunningException - if master is not running
NoServerForRegionException - if root region is not being served
TableExistsException - if table already exists (If concurrent threads, the table may have been created between test-for-existence and attempt-at-creation).
IOException

createTableAsync

public void createTableAsync(HTableDescriptor desc)
                      throws IOException
Creates a new table but does not block and wait for it to come online.

Parameters:
desc - table descriptor for table
Throws:
IllegalArgumentException - if the table name is reserved
MasterNotRunningException - if master is not running
NoServerForRegionException - if root region is not being served
TableExistsException - if table already exists (If concurrent threads, the table may have been created between test-for-existence and attempt-at-creation).
IOException

deleteTable

public void deleteTable(Text tableName)
                 throws IOException
Deletes a table

Parameters:
tableName - name of table to delete
Throws:
IOException

addColumn

public void addColumn(Text tableName,
                      HColumnDescriptor column)
               throws IOException
Add a column to an existing table

Parameters:
tableName - name of the table to add column to
column - column descriptor of column to be added
Throws:
IOException

deleteColumn

public void deleteColumn(Text tableName,
                         Text columnName)
                  throws IOException
Delete a column from a table

Parameters:
tableName - name of table
columnName - name of column to be deleted
Throws:
IOException

enableTable

public void enableTable(Text tableName)
                 throws IOException
Brings a table on-line (enables it)

Parameters:
tableName - name of the table
Throws:
IOException

disableTable

public void disableTable(Text tableName)
                  throws IOException
Disables a table (takes it off-line) If it is being served, the master will tell the servers to stop serving it.

Parameters:
tableName - name of table
Throws:
IOException

shutdown

public void shutdown()
              throws IOException
Shuts down the HBase instance

Throws:
IOException

checkReservedTableName

protected void checkReservedTableName(Text tableName)

openTable

public void openTable(Text tableName)
               throws IOException
Loads information so that a table can be manipulated.

Parameters:
tableName - the table to be located
Throws:
IOException - if the table can not be located after retrying

getStartKeys

public Text[] getStartKeys()
Gets the starting row key for every region in the currently open table

Returns:
Array of region starting row keys

getTableServers

protected SortedMap<Text,HClient.RegionLocation> getTableServers(Text tableName)
                                                          throws IOException
Gets the servers of the given table.

Parameters:
tableName - - the table to be located
Throws:
IOException - - if the table can not be located after retrying

getHRegionConnection

protected HRegionInterface getHRegionConnection(HServerAddress regionServer)
                                         throws IOException
Establishes a connection to the region server at the specified address.

Parameters:
regionServer - - the server to connect to
Throws:
IOException

listTables

public HTableDescriptor[] listTables()
                              throws IOException
List all the userspace tables. In other words, scan the META table. If we wanted this to be really fast, we could implement a special catalog table that just contains table names and their descriptors. Right now, it only exists as part of the META table's region info.

Returns:
- returns an array of HTableDescriptors
Throws:
IOException

getRegionLocation

protected HClient.RegionLocation getRegionLocation(Text row)

get

public byte[] get(Text row,
                  Text column)
           throws IOException
Get a single value for the specified row and column

Parameters:
row - row key
column - column name
Returns:
value for specified row/column
Throws:
IOException

get

public byte[][] get(Text row,
                    Text column,
                    int numVersions)
             throws IOException
Get the specified number of versions of the specified row and column

Parameters:
row - - row key
column - - column name
numVersions - - number of versions to retrieve
Returns:
- array byte values
Throws:
IOException

get

public byte[][] get(Text row,
                    Text column,
                    long timestamp,
                    int numVersions)
             throws IOException
Get the specified number of versions of the specified row and column with the specified timestamp.

Parameters:
row - - row key
column - - column name
timestamp - - timestamp
numVersions - - number of versions to retrieve
Returns:
- array of values that match the above criteria
Throws:
IOException

getRow

public SortedMap<Text,byte[]> getRow(Text row)
                              throws IOException
Get all the data for the specified row

Parameters:
row - - row key
Returns:
- map of colums to values
Throws:
IOException

obtainScanner

public HScannerInterface obtainScanner(Text[] columns,
                                       Text startRow)
                                throws IOException
Get a scanner on the current table starting at the specified row. Return the specified columns.

Parameters:
columns - array of columns to return
startRow - starting row in table to scan
Returns:
scanner
Throws:
IOException

obtainScanner

public HScannerInterface obtainScanner(Text[] columns,
                                       Text startRow,
                                       long timestamp)
                                throws IOException
Get a scanner on the current table starting at the specified row. Return the specified columns.

Parameters:
columns - array of columns to return
startRow - starting row in table to scan
timestamp - only return results whose timestamp <= this value
Returns:
scanner
Throws:
IOException

obtainScanner

public HScannerInterface obtainScanner(Text[] columns,
                                       Text startRow,
                                       RowFilterInterface filter)
                                throws IOException
Get a scanner on the current table starting at the specified row. Return the specified columns.

Parameters:
columns - array of columns to return
startRow - starting row in table to scan
filter - a row filter using row-key regexp and/or column data filter.
Returns:
scanner
Throws:
IOException

obtainScanner

public HScannerInterface obtainScanner(Text[] columns,
                                       Text startRow,
                                       long timestamp,
                                       RowFilterInterface filter)
                                throws IOException
Get a scanner on the current table starting at the specified row. Return the specified columns.

Parameters:
columns - array of columns to return
startRow - starting row in table to scan
timestamp - only return results whose timestamp <= this value
filter - a row filter using row-key regexp and/or column data filter.
Returns:
scanner
Throws:
IOException

startBatchUpdate

public void startBatchUpdate()
Start a batch of row insertions/updates. No changes are committed until the call to commitBatchUpdate returns. A call to abortBatchUpdate will abandon the entire batch. Note that in batch mode, calls to commit or abort are ignored.


abortBatch

public void abortBatch()
Abort a batch mutation


commitBatch

public void commitBatch()
                 throws IOException
Finalize a batch mutation

Throws:
IOException

commitBatch

public void commitBatch(long timestamp)
                 throws IOException
Finalize a batch mutation

Parameters:
timestamp - time to associate with all the changes
Throws:
IOException

startUpdate

public long startUpdate(Text row)
                 throws IOException
Start an atomic row insertion/update. No changes are committed until the call to commit() returns. A call to abort() will abandon any updates in progress. Callers to this method are given a lease for each unique lockid; before the lease expires, either abort() or commit() must be called. If it is not called, the system will automatically call abort() on the client's behalf. The client can gain extra time with a call to renewLease(). Start an atomic row insertion or update

Parameters:
row - Name of row to start update against.
Returns:
Row lockid.
Throws:
IOException

put

public void put(long lockid,
                Text column,
                byte[] val)
         throws IOException
Change a value for the specified column. Runs abort(long) if exception thrown.

Parameters:
lockid - lock id returned from startUpdate
column - column whose value is being set
val - new value for column
Throws:
IOException

delete

public void delete(long lockid,
                   Text column)
            throws IOException
Delete the value for a column

Parameters:
lockid - - lock id returned from startUpdate
column - - name of column whose value is to be deleted
Throws:
IOException

abort

public void abort(long lockid)
           throws IOException
Abort a row mutation

Parameters:
lockid - - lock id returned from startUpdate
Throws:
IOException

commit

public void commit(long lockid)
            throws IOException
Finalize a row mutation

Parameters:
lockid - - lock id returned from startUpdate
Throws:
IOException

commit

public void commit(long lockid,
                   long timestamp)
            throws IOException
Finalize a row mutation

Parameters:
lockid - - lock id returned from startUpdate
timestamp - - time to associate with the change
Throws:
IOException

renewLease

public void renewLease(long lockid)
                throws IOException
Renew lease on update

Parameters:
lockid - - lock id returned from startUpdate
Throws:
IOException

doCommandLine

public int doCommandLine(String[] args)
Process command-line args.

Parameters:
args - - command arguments
Returns:
0 if successful -1 otherwise

getConf

protected Configuration getConf()
Returns:
the configuration for this client

main

public static void main(String[] args)
Main program

Parameters:
args -


Copyright © 2006 The Apache Software Foundation