org.apache.hadoop.hbase.util
Class MetaUtils

java.lang.Object
  extended by org.apache.hadoop.hbase.util.MetaUtils

public class MetaUtils
extends Object

Contains utility methods for manipulating HBase meta tables. Be sure to call shutdown() when done with this class so it closes resources opened during meta processing (ROOT, META, etc.). Be careful how you use this class. If used during migrations, be careful when using this class to check whether migration is needed.


Nested Class Summary
static interface MetaUtils.ScannerListener
          Used by scanRootRegion and scanMetaRegion to call back the caller so it can process the data for a row.
 
Constructor Summary
MetaUtils()
          Default constructor
MetaUtils(org.apache.hadoop.conf.Configuration conf)
           
 
Method Summary
 void addColumn(byte[] tableName, HColumnDescriptor hcd)
          Offline version of the online TableOperation, org.apache.hadoop.hbase.master.AddColumn.
static void changeOnlineStatus(org.apache.hadoop.conf.Configuration c, byte[] row, boolean onlineOffline)
          Set a single region on/offline.
 void deleteColumn(byte[] tableName, byte[] columnFamily)
          Offline version of the online TableOperation, org.apache.hadoop.hbase.master.DeleteColumn.
 HLog getLog()
           
 HRegion getMetaRegion(HRegionInfo metaInfo)
          Open or return cached opened meta region
 List<HRegionInfo> getMETARows(byte[] tableName)
           
 HRegion getRootRegion()
           
 void scanMetaRegion(HRegionInfo metaRegionInfo, MetaUtils.ScannerListener listener)
          Scans a meta region.
 void scanMetaRegion(HRegion r, MetaUtils.ScannerListener listener)
          Scan the passed in metaregion m invoking the passed listener per row found.
 void scanRootRegion(MetaUtils.ScannerListener listener)
          Scans the root region.
 void shutdown()
          Closes catalog regions if open.
 void updateMETARegionInfo(HRegion r, HRegionInfo hri)
          Update COL_REGIONINFO in meta region r with HRegionInfo hri
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MetaUtils

public MetaUtils()
          throws IOException
Default constructor

Throws:
IOException - e

MetaUtils

public MetaUtils(org.apache.hadoop.conf.Configuration conf)
          throws IOException
Parameters:
conf - Configuration
Throws:
IOException - e
Method Detail

getLog

public HLog getLog()
            throws IOException
Returns:
the HLog
Throws:
IOException - e

getRootRegion

public HRegion getRootRegion()
                      throws IOException
Returns:
HRegion for root region
Throws:
IOException - e

getMetaRegion

public HRegion getMetaRegion(HRegionInfo metaInfo)
                      throws IOException
Open or return cached opened meta region

Parameters:
metaInfo - HRegionInfo for meta region
Returns:
meta HRegion
Throws:
IOException - e

shutdown

public void shutdown()
Closes catalog regions if open. Also closes and deletes the HLog. You must call this method if you want to persist changes made during a MetaUtils edit session.


scanRootRegion

public void scanRootRegion(MetaUtils.ScannerListener listener)
                    throws IOException
Scans the root region. For every meta region found, calls the listener with the HRegionInfo of the meta region.

Parameters:
listener - method to be called for each meta region found
Throws:
IOException - e

scanMetaRegion

public void scanMetaRegion(HRegion r,
                           MetaUtils.ScannerListener listener)
                    throws IOException
Scan the passed in metaregion m invoking the passed listener per row found.

Parameters:
r - region
listener - scanner listener
Throws:
IOException - e

scanMetaRegion

public void scanMetaRegion(HRegionInfo metaRegionInfo,
                           MetaUtils.ScannerListener listener)
                    throws IOException
Scans a meta region. For every region found, calls the listener with the HRegionInfo of the region. TODO: Use Visitor rather than Listener pattern. Allow multiple Visitors. Use this everywhere we scan meta regions: e.g. in metascanners, in close handling, etc. Have it pass in the whole row, not just HRegionInfo.

Use for reading meta only. Does not close region when done. Use getMetaRegion(HRegionInfo) instead if writing. Adds meta region to list that will get a close on shutdown().

Parameters:
metaRegionInfo - HRegionInfo for meta region
listener - method to be called for each meta region found
Throws:
IOException - e

changeOnlineStatus

public static void changeOnlineStatus(org.apache.hadoop.conf.Configuration c,
                                      byte[] row,
                                      boolean onlineOffline)
                               throws IOException
Set a single region on/offline. This is a tool to repair tables that have offlined tables in their midst. Can happen on occasion. Use at your own risk. Call from a bit of java or jython script. This method is 'expensive' in that it creates a HTable instance per invocation to go against .META.

Parameters:
c - A configuration that has its hbase.master properly set.
row - Row in the catalog .META. table whose HRegionInfo's offline status we want to change.
onlineOffline - Pass true to OFFLINE the region.
Throws:
IOException - e

addColumn

public void addColumn(byte[] tableName,
                      HColumnDescriptor hcd)
               throws IOException
Offline version of the online TableOperation, org.apache.hadoop.hbase.master.AddColumn.

Parameters:
tableName - table name
hcd - Add this column to tableName
Throws:
IOException - e

deleteColumn

public void deleteColumn(byte[] tableName,
                         byte[] columnFamily)
                  throws IOException
Offline version of the online TableOperation, org.apache.hadoop.hbase.master.DeleteColumn.

Parameters:
tableName - table name
columnFamily - Name of column name to remove.
Throws:
IOException - e

updateMETARegionInfo

public void updateMETARegionInfo(HRegion r,
                                 HRegionInfo hri)
                          throws IOException
Update COL_REGIONINFO in meta region r with HRegionInfo hri

Parameters:
r - region
hri - region info
Throws:
IOException - e

getMETARows

public List<HRegionInfo> getMETARows(byte[] tableName)
                              throws IOException
Parameters:
tableName - Name of table to go looking for.
Returns:
List of HRegionInfo rows found in the ROOT or META catalog table.
Throws:
IOException - e
See Also:
getMetaRegion(HRegionInfo)


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