org.apache.hadoop.hbase.client
Class HBaseAdmin

java.lang.Object
  extended by org.apache.hadoop.hbase.client.HBaseAdmin
Direct Known Subclasses:
HBaseFsck

public class HBaseAdmin
extends Object

Provides an interface to manage HBase database table metadata + general administrative functions. Use HBaseAdmin to create, drop, list, enable and disable tables. Use it also to add and drop table column families. See HTable to add, update, and delete data from an individual table.


Constructor Summary
HBaseAdmin(org.apache.hadoop.conf.Configuration conf)
          Constructor
 
Method Summary
 void addColumn(byte[] tableName, HColumnDescriptor column)
          Add a column to an existing table.
 void addColumn(String tableName, HColumnDescriptor column)
          Add a column to an existing table.
static void checkHBaseAvailable(org.apache.hadoop.conf.Configuration conf)
          Check to see if HBase is running.
 void closeRegion(byte[] regionname, Object... args)
          Close a region.
 void closeRegion(String regionname, Object... args)
          Close a region.
 void compact(byte[] tableNameOrRegionName)
          Compact a table or an individual region.
 void compact(String tableNameOrRegionName)
          Compact a table or an individual region.
 void createTable(HTableDescriptor desc)
          Creates a new table.
 void createTable(HTableDescriptor desc, byte[][] splitKeys)
          Creates a new table with an initial set of empty regions defined by the specified split keys.
 void createTable(HTableDescriptor desc, byte[] startKey, byte[] endKey, int numRegions)
          Creates a new table with the specified number of regions.
 void createTableAsync(HTableDescriptor desc, byte[][] splitKeys)
          Creates a new table but does not block and wait for it to come online.
 void deleteColumn(byte[] tableName, byte[] columnName)
          Delete a column from a table.
 void deleteColumn(String tableName, String columnName)
          Delete a column from a table.
 void deleteTable(byte[] tableName)
          Deletes a table.
 void deleteTable(String tableName)
          Deletes a table.
 void disableTable(byte[] tableName)
          Disables a table (takes it off-line) If it is being served, the master will tell the servers to stop serving it.
 void disableTable(String tableName)
          Disables a table (takes it off-line) If it is being served, the master will tell the servers to stop serving it.
 void enableTable(byte[] tableName)
          Brings a table on-line (enables it).
 void enableTable(String tableName)
          Brings a table on-line (enables it).
 void flush(byte[] tableNameOrRegionName)
          Flush a table or an individual region.
 void flush(String tableNameOrRegionName)
          Flush a table or an individual region.
 ClusterStatus getClusterStatus()
           
 HConnection getConnection()
           
 HMasterInterface getMaster()
           
 HTableDescriptor getTableDescriptor(byte[] tableName)
          Method for getting the tableDescriptor
 boolean isMasterRunning()
           
 boolean isTableAvailable(byte[] tableName)
           
 boolean isTableAvailable(String tableName)
           
 boolean isTableDisabled(byte[] tableName)
           
 boolean isTableEnabled(byte[] tableName)
           
 boolean isTableEnabled(String tableName)
           
 HTableDescriptor[] listTables()
          List all the userspace tables.
 void majorCompact(byte[] tableNameOrRegionName)
          Major compact a table or an individual region.
 void majorCompact(String tableNameOrRegionName)
          Major compact a table or an individual region.
 void modifyColumn(byte[] tableName, byte[] columnName, HColumnDescriptor descriptor)
          Modify an existing column family on a table.
 void modifyColumn(String tableName, String columnName, HColumnDescriptor descriptor)
          Modify an existing column family on a table.
 void modifyTable(byte[] tableName, HConstants.Modify op, Object... args)
          Modify an existing table.
 void modifyTable(byte[] tableName, HTableDescriptor htd)
          Modify an existing table, more IRB friendly version.
 void shutdown()
          Shuts down the HBase instance
 void split(byte[] tableNameOrRegionName)
          Split a table or an individual region.
 void split(String tableNameOrRegionName)
          Split a table or an individual region.
 boolean tableExists(byte[] tableName)
           
 boolean tableExists(String tableName)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HBaseAdmin

public HBaseAdmin(org.apache.hadoop.conf.Configuration conf)
           throws MasterNotRunningException
Constructor

Parameters:
conf - Configuration object
Throws:
MasterNotRunningException - if the master is not running
Method Detail

getConnection

public HConnection getConnection()
Returns:
HConnection used by this object.

getMaster

public HMasterInterface getMaster()
                           throws MasterNotRunningException
Returns:
proxy connection to master server for this instance
Throws:
MasterNotRunningException - if the master is not running

isMasterRunning

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

tableExists

public boolean tableExists(String tableName)
                    throws MasterNotRunningException
Parameters:
tableName - Table to check.
Returns:
True if table exists already.
Throws:
MasterNotRunningException - if the master is not running

tableExists

public boolean tableExists(byte[] tableName)
                    throws MasterNotRunningException
Parameters:
tableName - Table to check.
Returns:
True if table exists already.
Throws:
MasterNotRunningException - if the master is not running

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 - if a remote or network exception occurs

getTableDescriptor

public HTableDescriptor getTableDescriptor(byte[] tableName)
                                    throws IOException
Method for getting the tableDescriptor

Parameters:
tableName - as a byte []
Returns:
the tableDescriptor
Throws:
IOException - if a remote or network exception occurs

createTable

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

Parameters:
desc - table descriptor for table
Throws:
IllegalArgumentException - if the table name is reserved
MasterNotRunningException - if master is not running
TableExistsException - if table already exists (If concurrent threads, the table may have been created between test-for-existence and attempt-at-creation).
IOException - if a remote or network exception occurs

createTable

public void createTable(HTableDescriptor desc,
                        byte[] startKey,
                        byte[] endKey,
                        int numRegions)
                 throws IOException
Creates a new table with the specified number of regions. The start key specified will become the end key of the first region of the table, and the end key specified will become the start key of the last region of the table (the first region has a null start key and the last region has a null end key). BigInteger math will be used to divide the key range specified into enough segments to make the required number of total regions. Synchronous operation.

Parameters:
desc - table descriptor for table
startKey - beginning of key range
endKey - end of key range
numRegions - the total number of regions to create
Throws:
IllegalArgumentException - if the table name is reserved
MasterNotRunningException - if master is not running
TableExistsException - if table already exists (If concurrent threads, the table may have been created between test-for-existence and attempt-at-creation).
IOException

createTable

public void createTable(HTableDescriptor desc,
                        byte[][] splitKeys)
                 throws IOException
Creates a new table with an initial set of empty regions defined by the specified split keys. The total number of regions created will be the number of split keys plus one (the first region has a null start key and the last region has a null end key). Synchronous operation.

Parameters:
desc - table descriptor for table
splitKeys - array of split keys for the initial regions of the table
Throws:
IllegalArgumentException - if the table name is reserved
MasterNotRunningException - if master is not running
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,
                             byte[][] splitKeys)
                      throws IOException
Creates a new table but does not block and wait for it to come online. Asynchronous operation.

Parameters:
desc - table descriptor for table
Throws:
IllegalArgumentException - Bad table name.
MasterNotRunningException - if master is not running
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(String tableName)
                 throws IOException
Deletes a table. Synchronous operation.

Parameters:
tableName - name of table to delete
Throws:
IOException - if a remote or network exception occurs

deleteTable

public void deleteTable(byte[] tableName)
                 throws IOException
Deletes a table. Synchronous operation.

Parameters:
tableName - name of table to delete
Throws:
IOException - if a remote or network exception occurs

enableTable

public void enableTable(String tableName)
                 throws IOException
Brings a table on-line (enables it). Synchronous operation.

Parameters:
tableName - name of the table
Throws:
IOException - if a remote or network exception occurs

enableTable

public void enableTable(byte[] tableName)
                 throws IOException
Brings a table on-line (enables it). Synchronous operation.

Parameters:
tableName - name of the table
Throws:
IOException - if a remote or network exception occurs

disableTable

public void disableTable(String 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. Synchronous operation.

Parameters:
tableName - name of table
Throws:
IOException - if a remote or network exception occurs

disableTable

public void disableTable(byte[] 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. Synchronous operation.

Parameters:
tableName - name of table
Throws:
IOException - if a remote or network exception occurs

isTableEnabled

public boolean isTableEnabled(String tableName)
                       throws IOException
Parameters:
tableName - name of table to check
Returns:
true if table is on-line
Throws:
IOException - if a remote or network exception occurs

isTableEnabled

public boolean isTableEnabled(byte[] tableName)
                       throws IOException
Parameters:
tableName - name of table to check
Returns:
true if table is on-line
Throws:
IOException - if a remote or network exception occurs

isTableDisabled

public boolean isTableDisabled(byte[] tableName)
                        throws IOException
Parameters:
tableName - name of table to check
Returns:
true if table is off-line
Throws:
IOException - if a remote or network exception occurs

isTableAvailable

public boolean isTableAvailable(byte[] tableName)
                         throws IOException
Parameters:
tableName - name of table to check
Returns:
true if all regions of the table are available
Throws:
IOException - if a remote or network exception occurs

isTableAvailable

public boolean isTableAvailable(String tableName)
                         throws IOException
Parameters:
tableName - name of table to check
Returns:
true if all regions of the table are available
Throws:
IOException - if a remote or network exception occurs

addColumn

public void addColumn(String tableName,
                      HColumnDescriptor column)
               throws IOException
Add a column to an existing table. Asynchronous operation.

Parameters:
tableName - name of the table to add column to
column - column descriptor of column to be added
Throws:
IOException - if a remote or network exception occurs

addColumn

public void addColumn(byte[] tableName,
                      HColumnDescriptor column)
               throws IOException
Add a column to an existing table. Asynchronous operation.

Parameters:
tableName - name of the table to add column to
column - column descriptor of column to be added
Throws:
IOException - if a remote or network exception occurs

deleteColumn

public void deleteColumn(String tableName,
                         String columnName)
                  throws IOException
Delete a column from a table. Asynchronous operation.

Parameters:
tableName - name of table
columnName - name of column to be deleted
Throws:
IOException - if a remote or network exception occurs

deleteColumn

public void deleteColumn(byte[] tableName,
                         byte[] columnName)
                  throws IOException
Delete a column from a table. Asynchronous operation.

Parameters:
tableName - name of table
columnName - name of column to be deleted
Throws:
IOException - if a remote or network exception occurs

modifyColumn

public void modifyColumn(String tableName,
                         String columnName,
                         HColumnDescriptor descriptor)
                  throws IOException
Modify an existing column family on a table. Asynchronous operation.

Parameters:
tableName - name of table
columnName - name of column to be modified
descriptor - new column descriptor to use
Throws:
IOException - if a remote or network exception occurs

modifyColumn

public void modifyColumn(byte[] tableName,
                         byte[] columnName,
                         HColumnDescriptor descriptor)
                  throws IOException
Modify an existing column family on a table. Asynchronous operation.

Parameters:
tableName - name of table
columnName - name of column to be modified
descriptor - new column descriptor to use
Throws:
IOException - if a remote or network exception occurs

closeRegion

public void closeRegion(String regionname,
                        Object... args)
                 throws IOException
Close a region. For expert-admins. Asynchronous operation.

Parameters:
regionname - region name to close
args - Optional server name. Otherwise, we'll send close to the server registered in .META.
Throws:
IOException - if a remote or network exception occurs

closeRegion

public void closeRegion(byte[] regionname,
                        Object... args)
                 throws IOException
Close a region. For expert-admins. Asynchronous operation.

Parameters:
regionname - region name to close
args - Optional server name. Otherwise, we'll send close to the server registered in .META.
Throws:
IOException - if a remote or network exception occurs

flush

public void flush(String tableNameOrRegionName)
           throws IOException
Flush a table or an individual region. Asynchronous operation.

Parameters:
tableNameOrRegionName - table or region to flush
Throws:
IOException - if a remote or network exception occurs

flush

public void flush(byte[] tableNameOrRegionName)
           throws IOException
Flush a table or an individual region. Asynchronous operation.

Parameters:
tableNameOrRegionName - table or region to flush
Throws:
IOException - if a remote or network exception occurs

compact

public void compact(String tableNameOrRegionName)
             throws IOException
Compact a table or an individual region. Asynchronous operation.

Parameters:
tableNameOrRegionName - table or region to compact
Throws:
IOException - if a remote or network exception occurs

compact

public void compact(byte[] tableNameOrRegionName)
             throws IOException
Compact a table or an individual region. Asynchronous operation.

Parameters:
tableNameOrRegionName - table or region to compact
Throws:
IOException - if a remote or network exception occurs

majorCompact

public void majorCompact(String tableNameOrRegionName)
                  throws IOException
Major compact a table or an individual region. Asynchronous operation.

Parameters:
tableNameOrRegionName - table or region to major compact
Throws:
IOException - if a remote or network exception occurs

majorCompact

public void majorCompact(byte[] tableNameOrRegionName)
                  throws IOException
Major compact a table or an individual region. Asynchronous operation.

Parameters:
tableNameOrRegionName - table or region to major compact
Throws:
IOException - if a remote or network exception occurs

split

public void split(String tableNameOrRegionName)
           throws IOException
Split a table or an individual region. Asynchronous operation.

Parameters:
tableNameOrRegionName - table or region to split
Throws:
IOException - if a remote or network exception occurs

split

public void split(byte[] tableNameOrRegionName)
           throws IOException
Split a table or an individual region. Asynchronous operation.

Parameters:
tableNameOrRegionName - table to region to split
Throws:
IOException - if a remote or network exception occurs

modifyTable

public void modifyTable(byte[] tableName,
                        HTableDescriptor htd)
                 throws IOException
Modify an existing table, more IRB friendly version. Asynchronous operation.

Parameters:
tableName - name of table.
htd - modified description of the table
Throws:
IOException - if a remote or network exception occurs

modifyTable

public void modifyTable(byte[] tableName,
                        HConstants.Modify op,
                        Object... args)
                 throws IOException
Modify an existing table. Asynchronous operation.

Parameters:
tableName - name of table. May be null if we are operating on a region.
op - table modification operation
args - operation specific arguments
Throws:
IOException - if a remote or network exception occurs

shutdown

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

Throws:
IOException - if a remote or network exception occurs

getClusterStatus

public ClusterStatus getClusterStatus()
                               throws IOException
Returns:
cluster status
Throws:
IOException - if a remote or network exception occurs

checkHBaseAvailable

public static void checkHBaseAvailable(org.apache.hadoop.conf.Configuration conf)
                                throws MasterNotRunningException
Check to see if HBase is running. Throw an exception if not.

Parameters:
conf - system configuration
Throws:
MasterNotRunningException - if a remote or network exception occurs


Copyright © 2010 Apache Software Foundation. All Rights Reserved.