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, HConstants, HBaseRPCProtocolVersion, HMasterInterface, HMasterRegionInterface, org.apache.hadoop.ipc.VersionedProtocol, org.apache.zookeeper.Watcher

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

HMaster is the "master server" for a HBase. There is only one HMaster for a single HBase deployment. NOTE: This class extends Thread rather than Chore because the sleep time can be interrupted when there is something to do, rather than the Chore sleep time which is invariant.


Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
Thread.State, Thread.UncaughtExceptionHandler
 
Nested classes/interfaces inherited from interface org.apache.hadoop.hbase.HConstants
HConstants.Modify
 
Nested classes/interfaces inherited from interface org.apache.zookeeper.Watcher
org.apache.zookeeper.Watcher.Event
 
Field Summary
static String MASTER
          Name of master server
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Fields inherited from interface org.apache.hadoop.hbase.HConstants
ALL_VERSIONS, CATALOG_FAMILY, CATALOG_FAMILY_STR, CATALOG_HISTORIAN_FAMILY, CLUSTER_DISTRIBUTED, CLUSTER_IS_DISTRIBUTED, CLUSTER_IS_LOCAL, DEFAULT_HBASE_CLIENT_SCANNER_MAX_RESULT_SIZE, DEFAULT_HOST, DEFAULT_MASTER_INFOPORT, DEFAULT_MASTER_PORT, DEFAULT_MAX_FILE_SIZE, DEFAULT_REGION_SERVER_CLASS, DEFAULT_REGIONSERVER_INFOPORT, DEFAULT_REGIONSERVER_PORT, DEFAULT_SIZE_RESERVATION_BLOCK, DEFAULT_ZOOKEEPER_PAUSE, DEFAULT_ZOOKEEPER_RETRIES, EMPTY_BYTE_ARRAY, EMPTY_END_ROW, EMPTY_START_ROW, FILE_SYSTEM_VERSION, FOREVER, HBASE_CLIENT_RETRIES_NUMBER_KEY, HBASE_CLIENT_SCANNER_MAX_RESULT_SIZE_KEY, HBASE_DIR, HREGION_COMPACTIONDIR_NAME, HREGION_LOGDIR_NAME, HREGION_OLDLOGFILE_NAME, IN_MEMORY, LAST_ROW, LATEST_TIMESTAMP, LATEST_TIMESTAMP_BYTES, MAJOR_COMPACTION_PERIOD, MASTER_PORT, MAX_ROW_LENGTH, MAXIMUM_VALUE_LENGTH, META_ROW_DELIMITER, META_TABLE_NAME, NAME, NINES, REGION_IMPL, REGION_SERVER_CLASS, REGION_SERVER_IMPL, REGIONINFO_QUALIFIER, REGIONSERVER_PORT, RETRY_BACKOFF, ROOT_TABLE_NAME, SERVER_QUALIFIER, SPLITA_QUALIFIER, SPLITB_QUALIFIER, STARTCODE_QUALIFIER, THREAD_WAKE_FREQUENCY, UTF8_ENCODING, VERSION_FILE_NAME, VERSIONS, WEEK_IN_SECONDS, ZERO_L, ZEROES, ZOOKEEPER_CONFIG_NAME, ZOOKEEPER_PAUSE, ZOOKEEPER_QUORUM, ZOOKEEPER_RETRIES
 
Fields inherited from interface org.apache.hadoop.hbase.ipc.HBaseRPCProtocolVersion
versionID
 
Constructor Summary
HMaster(HBaseConfiguration conf)
          Build the HMaster out of a raw configuration item.
 
Method Summary
 void addColumn(byte[] tableName, HColumnDescriptor column)
          Adds a column to the specified table
protected  boolean checkFileSystem()
          Checks to see if the file system is still accessible.
 int countRegionsOnFS()
           
protected  org.apache.hadoop.io.MapWritable createConfigurationSubset()
           
 void createTable(HTableDescriptor desc)
          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.
 HBaseConfiguration getConfiguration()
           
protected  Result getFromMETA(byte[] row, byte[] family)
          Get row from meta table.
 InfoServer getInfoServer()
           
 HServerAddress getMasterAddress()
           
 MasterMetrics getMetrics()
           
 Map<byte[],MetaRegion> getOnlineMetaRegions()
           
 long getProtocolVersion(String protocol, long clientVersion)
           
 org.apache.hadoop.fs.Path getRootDir()
           
 HServerAddress getRootRegionLocation()
           
 Map<HServerAddress,HServerInfo> getServerAddressToServerInfo()
           
 org.apache.hadoop.hbase.master.ServerManager getServerManager()
           
 Map<String,HServerLoad> getServersToLoad()
           
 Map<String,HServerInfo> getServersToServerInfo()
           
 ZooKeeperWrapper getZooKeeperWrapper()
          Get the ZK wrapper object
 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 run()
          Main processing loop
 void shutdown()
          Shutdown an HBase cluster.
 void waitForRootRegionLocation()
          Wait until root region is available
 
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
Name of master server

See Also:
Constant Field Values
Constructor Detail

HMaster

public HMaster(HBaseConfiguration conf)
        throws IOException
Build the HMaster out of a raw configuration item.

Parameters:
conf - configuration
Throws:
IOException
Method Detail

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

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

getRootDir

public org.apache.hadoop.fs.Path getRootDir()
Returns:
Hbase root dir.

getServersToServerInfo

public Map<String,HServerInfo> getServersToServerInfo()
Returns:
Read-only map of servers to serverinfo.

getServerAddressToServerInfo

public Map<HServerAddress,HServerInfo> getServerAddressToServerInfo()

getServersToLoad

public Map<String,HServerLoad> getServersToLoad()
Returns:
Read-only map of servers to load.

getAverageLoad

public double getAverageLoad()
Returns:
The average load

countRegionsOnFS

public int countRegionsOnFS()
Returns:
the number of regions on filesystem

getRootRegionLocation

public HServerAddress getRootRegionLocation()
Returns:
Location of the -ROOT- region.

waitForRootRegionLocation

public void waitForRootRegionLocation()
Wait until root region is available


getOnlineMetaRegions

public Map<byte[],MetaRegion> getOnlineMetaRegions()
Returns:
Read-only map of online regions.

getServerManager

public org.apache.hadoop.hbase.master.ServerManager getServerManager()
Returns:
the server manager instance

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
Returns:
Configuration for the regionserver to use: e.g. filesystem, hbase rootdir, etc.
Throws:
IOException

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

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)
                 throws IOException
Description copied from interface: HMasterInterface
Creates a new table

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
Throws:
IOException

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
column - column descriptor
Throws:
IOException

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
columnName - name of the column to edit
descriptor - new column descriptor
Throws:
IOException

deleteColumn

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

Specified by:
deleteColumn in interface HMasterInterface
Throws:
IOException

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
Throws:
IOException

disableTable

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

Specified by:
disableTable in interface HMasterInterface
Throws:
IOException

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
Throws:
IOException

getClusterStatus

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

Specified by:
getClusterStatus in interface HMasterInterface
Returns:
cluster status

getMetrics

public MasterMetrics getMetrics()
Returns:
Server metrics

getConfiguration

public HBaseConfiguration getConfiguration()
Returns:
Return configuration being used by this server.

deleteEmptyMetaRows

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

getZooKeeperWrapper

public ZooKeeperWrapper getZooKeeperWrapper()
Get the ZK wrapper object

Returns:
the zookeeper wrapper

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)

doMain

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

main

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

Parameters:
args -


Copyright © 2010 The Apache Software Foundation