org.apache.hadoop.hbase.master
Class HMaster

java.lang.Object
  extended by java.lang.Thread
      extended by org.apache.hadoop.hbase.master.HMaster
All Implemented Interfaces:
Runnable, HBaseRPCProtocolVersion, HMasterInterface, HMasterRegionInterface, org.apache.hadoop.ipc.VersionedProtocol, org.apache.zookeeper.Watcher

public class HMaster
extends Thread
implements HMasterInterface, HMasterRegionInterface, org.apache.zookeeper.Watcher

HMaster is the "master server" for HBase. An HBase cluster has one active master. If many masters are started, all compete. Whichever wins goes on to run the cluster. All others park themselves in their constructor until master or cluster shutdown or until the active master loses its lease in zookeeper. Thereafter, all running master jostle to take over master role.

See Also:
HMasterInterface, HMasterRegionInterface, Watcher

Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
Thread.State, Thread.UncaughtExceptionHandler
 
Nested classes/interfaces inherited from interface org.apache.zookeeper.Watcher
org.apache.zookeeper.Watcher.Event
 
Field Summary
static String MASTER
           
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Fields inherited from interface org.apache.hadoop.hbase.ipc.HBaseRPCProtocolVersion
versionID
 
Constructor Summary
HMaster(org.apache.hadoop.conf.Configuration conf)
          Constructor
 
Method Summary
 void addColumn(byte[] tableName, HColumnDescriptor column)
          Adds a column to the specified table
protected  HMsg[] adornRegionServerAnswer(HServerInfo hsi, HMsg[] msgs)
          Override if you'd add messages to return to regionserver hsi or to send an exception.
protected  boolean checkFileSystem()
          Checks to see if the file system is still accessible.
static HMaster constructMaster(Class<? extends HMaster> masterClass, org.apache.hadoop.conf.Configuration conf)
          Utility for constructing an instance of the passed HMaster class.
protected  org.apache.hadoop.io.MapWritable createConfigurationSubset()
           
 void createTable(HTableDescriptor desc, byte[][] splitKeys)
          Creates a new table.
 void deleteColumn(byte[] tableName, byte[] c)
          Deletes a column from the specified table.
protected  void deleteEmptyMetaRows(HRegionInterface s, byte[] metaRegionName, List<byte[]> emptyRows)
           
 void deleteTable(byte[] tableName)
          Deletes a table
 void disableTable(byte[] tableName)
          Take table offline
protected static void doMain(String[] args, Class<? extends HMaster> masterClass)
           
 void enableTable(byte[] tableName)
          Puts the table on-line (only needed if table has been previously taken offline)
 double getAverageLoad()
           
 ClusterStatus getClusterStatus()
          Return cluster status.
 org.apache.hadoop.conf.Configuration getConfiguration()
           
protected  Result getFromMETA(byte[] row, byte[] family)
          Get row from meta table.
 HServerAddress getHServerAddress()
           
 InfoServer getInfoServer()
           
 HServerAddress getMasterAddress()
           
 MasterMetrics getMetrics()
           
 int getNumRetries()
           
 org.apache.hadoop.fs.Path getOldLogDir()
          Get the directory where old logs go
 long getProtocolVersion(String protocol, long clientVersion)
           
 RegionManager getRegionManager()
           
 RegionServerOperationQueue getRegionServerOperationQueue()
           
 org.apache.hadoop.fs.Path getRootDir()
           
 ServerManager getServerManager()
           
 Map<String,Integer> getTableFragmentation()
           
 ZooKeeperWrapper getZooKeeperWrapper()
          Get the ZK wrapper object
 boolean isClusterStartup()
          Returns true if this master process was responsible for starting the cluster.
 boolean isMasterRunning()
           
static void main(String[] args)
          Main program
 void modifyColumn(byte[] tableName, byte[] columnName, HColumnDescriptor descriptor)
          Modifies an existing column on the specified table
 void modifyTable(byte[] tableName, HConstants.Modify op, org.apache.hadoop.io.Writable[] args)
          Modify a table's metadata
 void process(org.apache.zookeeper.WatchedEvent event)
           
 HMsg[] regionServerReport(HServerInfo serverInfo, HMsg[] msgs, HRegionInfo[] mostLoadedRegions)
          Called to renew lease, tell master what the region server is doing and to receive new instructions from the master
 org.apache.hadoop.io.MapWritable regionServerStartup(HServerInfo serverInfo)
          Called when a region server first starts
 void resetClusterStartup()
           
 void run()
          Main processing loop
 void shutdown()
          Shutdown an HBase cluster.
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

MASTER

public static final String MASTER
See Also:
Constant Field Values
Constructor Detail

HMaster

public HMaster(org.apache.hadoop.conf.Configuration conf)
        throws IOException
Constructor

Parameters:
conf - configuration
Throws:
IOException
Method Detail

isClusterStartup

public boolean isClusterStartup()
Returns true if this master process was responsible for starting the cluster.


resetClusterStartup

public void resetClusterStartup()

getHServerAddress

public HServerAddress getHServerAddress()

checkFileSystem

protected boolean checkFileSystem()
Checks to see if the file system is still accessible. If not, sets closed

Returns:
false if file system is not available

getMasterAddress

public HServerAddress getMasterAddress()
Returns:
HServerAddress of the master server

getProtocolVersion

public long getProtocolVersion(String protocol,
                               long clientVersion)
Specified by:
getProtocolVersion in interface org.apache.hadoop.ipc.VersionedProtocol

getInfoServer

public InfoServer getInfoServer()
Returns:
InfoServer object. Maybe null.

getRootDir

public org.apache.hadoop.fs.Path getRootDir()
Returns:
HBase root dir.
Throws:
IOException

getNumRetries

public int getNumRetries()

getMetrics

public MasterMetrics getMetrics()
Returns:
Server metrics

getConfiguration

public org.apache.hadoop.conf.Configuration getConfiguration()
Returns:
Return configuration being used by this server.

getServerManager

public ServerManager getServerManager()

getRegionManager

public RegionManager getRegionManager()

getZooKeeperWrapper

public ZooKeeperWrapper getZooKeeperWrapper()
Get the ZK wrapper object

Returns:
the zookeeper wrapper

getAverageLoad

public double getAverageLoad()

getRegionServerOperationQueue

public RegionServerOperationQueue getRegionServerOperationQueue()

getOldLogDir

public org.apache.hadoop.fs.Path getOldLogDir()
Get the directory where old logs go

Returns:
the dir

run

public void run()
Main processing loop

Specified by:
run in interface Runnable
Overrides:
run in class Thread

regionServerStartup

public org.apache.hadoop.io.MapWritable regionServerStartup(HServerInfo serverInfo)
                                                     throws IOException
Description copied from interface: HMasterRegionInterface
Called when a region server first starts

Specified by:
regionServerStartup in interface HMasterRegionInterface
Parameters:
serverInfo - server info
Returns:
Configuration for the regionserver to use: e.g. filesystem, hbase rootdir, etc.
Throws:
IOException - e

createConfigurationSubset

protected org.apache.hadoop.io.MapWritable createConfigurationSubset()
Returns:
Subset of configuration to pass initializing regionservers: e.g. the filesystem to use and root directory to use.

regionServerReport

public HMsg[] regionServerReport(HServerInfo serverInfo,
                                 HMsg[] msgs,
                                 HRegionInfo[] mostLoadedRegions)
                          throws IOException
Description copied from interface: HMasterRegionInterface
Called to renew lease, tell master what the region server is doing and to receive new instructions from the master

Specified by:
regionServerReport in interface HMasterRegionInterface
Parameters:
serverInfo - server's address and start code
msgs - things the region server wants to tell the master
mostLoadedRegions - Array of HRegionInfos that should contain the reporting server's most loaded regions. These are candidates for being rebalanced.
Returns:
instructions from the master to the region server
Throws:
IOException - e

adornRegionServerAnswer

protected HMsg[] adornRegionServerAnswer(HServerInfo hsi,
                                         HMsg[] msgs)
                                  throws IOException
Override if you'd add messages to return to regionserver hsi or to send an exception.

Parameters:
msgs - Messages to add to
Returns:
Messages to return to
Throws:
IOException - exceptions that were injected for the region servers

isMasterRunning

public boolean isMasterRunning()
Specified by:
isMasterRunning in interface HMasterInterface
Returns:
true if master is available

shutdown

public void shutdown()
Description copied from interface: HMasterInterface
Shutdown an HBase cluster.

Specified by:
shutdown in interface HMasterInterface

createTable

public void createTable(HTableDescriptor desc,
                        byte[][] splitKeys)
                 throws IOException
Description copied from interface: HMasterInterface
Creates a new table. If splitKeys are specified, then the table will be created with an initial set of multiple regions. If splitKeys is null, the table will be created with a single region.

Specified by:
createTable in interface HMasterInterface
Parameters:
desc - table descriptor
Throws:
IOException

deleteTable

public void deleteTable(byte[] tableName)
                 throws IOException
Description copied from interface: HMasterInterface
Deletes a table

Specified by:
deleteTable in interface HMasterInterface
Parameters:
tableName - table to delete
Throws:
IOException - e

addColumn

public void addColumn(byte[] tableName,
                      HColumnDescriptor column)
               throws IOException
Description copied from interface: HMasterInterface
Adds a column to the specified table

Specified by:
addColumn in interface HMasterInterface
Parameters:
tableName - table to modify
column - column descriptor
Throws:
IOException - e

modifyColumn

public void modifyColumn(byte[] tableName,
                         byte[] columnName,
                         HColumnDescriptor descriptor)
                  throws IOException
Description copied from interface: HMasterInterface
Modifies an existing column on the specified table

Specified by:
modifyColumn in interface HMasterInterface
Parameters:
tableName - table name
columnName - name of the column to edit
descriptor - new column descriptor
Throws:
IOException - e

deleteColumn

public void deleteColumn(byte[] tableName,
                         byte[] c)
                  throws IOException
Description copied from interface: HMasterInterface
Deletes a column from the specified table. Table must be disabled.

Specified by:
deleteColumn in interface HMasterInterface
Parameters:
tableName - table to alter
c - column family to remove
Throws:
IOException - e

enableTable

public void enableTable(byte[] tableName)
                 throws IOException
Description copied from interface: HMasterInterface
Puts the table on-line (only needed if table has been previously taken offline)

Specified by:
enableTable in interface HMasterInterface
Parameters:
tableName - table to enable
Throws:
IOException - e

disableTable

public void disableTable(byte[] tableName)
                  throws IOException
Description copied from interface: HMasterInterface
Take table offline

Specified by:
disableTable in interface HMasterInterface
Parameters:
tableName - table to take offline
Throws:
IOException - e

getFromMETA

protected Result getFromMETA(byte[] row,
                             byte[] family)
                      throws IOException
Get row from meta table.

Parameters:
row -
family -
Returns:
Result
Throws:
IOException

modifyTable

public void modifyTable(byte[] tableName,
                        HConstants.Modify op,
                        org.apache.hadoop.io.Writable[] args)
                 throws IOException
Description copied from interface: HMasterInterface
Modify a table's metadata

Specified by:
modifyTable in interface HMasterInterface
Parameters:
tableName - table to modify
op - the operation to do
args - arguments for operation
Throws:
IOException - e

getClusterStatus

public ClusterStatus getClusterStatus()
Description copied from interface: HMasterInterface
Return cluster status.

Specified by:
getClusterStatus in interface HMasterInterface
Returns:
cluster status

deleteEmptyMetaRows

protected void deleteEmptyMetaRows(HRegionInterface s,
                                   byte[] metaRegionName,
                                   List<byte[]> emptyRows)

process

public void process(org.apache.zookeeper.WatchedEvent event)
Specified by:
process in interface org.apache.zookeeper.Watcher
See Also:
Watcher.process(org.apache.zookeeper.WatchedEvent)

constructMaster

public static HMaster constructMaster(Class<? extends HMaster> masterClass,
                                      org.apache.hadoop.conf.Configuration conf)
Utility for constructing an instance of the passed HMaster class.

Parameters:
masterClass -
conf -
Returns:
HMaster instance.

doMain

protected static void doMain(String[] args,
                             Class<? extends HMaster> masterClass)

getTableFragmentation

public Map<String,Integer> getTableFragmentation()
                                          throws IOException
Throws:
IOException

main

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

Parameters:
args -


Copyright © 2010 Apache Software Foundation. All Rights Reserved.