org.apache.hadoop.hbase.master
Class RegionManager

java.lang.Object
  extended by org.apache.hadoop.hbase.master.RegionManager

public class RegionManager
extends Object

Class to manage assigning regions to servers, state of root and meta, etc.


Field Summary
protected static org.apache.commons.logging.Log LOG
           
 
Method Summary
 void addMetaRegionToScan(MetaRegion m)
          Add a meta region to the scan queue
 void applyActions(HServerInfo serverInfo, ArrayList<HMsg> returnMsgs)
          Send messages to the given region server asking it to split any regions in 'regionsToSplit', etc.
 boolean areAllMetaRegionsOnline()
          Block until meta regions are online or we're shutting down.
 int countRegionsOnFS()
           
 void createRegion(HRegionInfo newRegion, HRegionInterface server, byte[] metaRegionName)
          Create a new HRegion, put a row for it into META (or ROOT), and mark the new region unassigned so that it will get assigned to a region server.
 void endAction(byte[] regionName, HConstants.Modify op)
           
 void endActions(byte[] regionName)
           
 MetaRegion getFirstMetaRegionForRegion(HRegionInfo newRegion)
          Search our map of online meta regions to find the first meta region that should contain a pointer to newRegion.
 List<MetaRegion> getListOfOnlineMetaRegions()
          Get a list of online MetaRegions
 Set<HRegionInfo> getMarkedToClose(String serverName)
          Remove the map of region names to region infos waiting to be offlined for a given server
 MetaRegion getMetaRegionForRow(byte[] row)
          Get metaregion that would host passed in row.
 Set<MetaRegion> getMetaRegionsForTable(byte[] tableName)
          Get a set of all the meta regions that contain info about a given table.
 HRegionInfo getMetaServerRegionInfo(String server)
          Is this server assigned to transition a META table.
 Map<byte[],MetaRegion> getOnlineMetaRegions()
           
 HServerAddress getRootRegionLocation()
          Get the root region location.
 void incrementNumMetaRegions()
          Bump the count of meta regions up one
 boolean isInitialMetaScanComplete()
          Check if the initial meta scan has been completed.
 boolean isInitialRootScanComplete()
          Check if the initial root scan has been completed.
 boolean isMetaRegionOnline(byte[] startKey)
          Check if a meta region is online by its name
 boolean isMetaServer(HServerAddress server)
          Does this server have any META regions open on it, or any meta regions being assigned to it?
 boolean isOfflined(String regionName)
           
 boolean isPendingOpen(String regionName)
          Check if a region has been assigned and we're waiting for a response from the region server.
 boolean isRootInTransitionOnThisServer(String server)
          Is this server assigned to transition the ROOT table.
 boolean isRootServer(HServerAddress server)
           
 boolean isUnassigned(HRegionInfo info)
          Check if a region is on the unassigned list
 List<byte[]> listMetaRegionsForServer(HServerAddress server)
          Returns the list of byte[] start-keys for any .META.
 boolean metaRegionsInTransition()
           
 int numMetaRegions()
          Return the number of meta regions.
 int numOnlineMetaRegions()
          Count of online meta regions
 MetaRegion offlineMetaRegionWithStartKey(byte[] startKey)
          Set an online MetaRegion offline - remove it from the map.
 boolean offlineMetaServer(HServerAddress server)
          Call to take this metaserver offline for immediate reassignment.
 void putMetaRegionOnline(MetaRegion metaRegion)
          Set a MetaRegion as online.
 boolean regionIsInTransition(String regionName)
           
 boolean regionIsOpening(String regionName)
           
 void removeRegion(HRegionInfo info)
          Remove a region from the region state map.
 void setClosed(String regionName)
           
 void setClosing(String serverName, HRegionInfo regionInfo, boolean setOffline)
          Mark a region as closing
 void setNumMetaRegions(int num)
          Set the number of meta regions.
 void setOpen(String regionName)
          Region has been assigned to a server and the server has told us it is open
 void setPendingClose(String regionName)
          Called when we have told a region server to close the region
 void setRootRegionLocation(HServerAddress address)
          Set the root region location.
 void setUnassigned(HRegionInfo info, boolean force)
          Set a region to unassigned
 void startAction(byte[] regionName, HRegionInfo info, HServerAddress server, HConstants.Modify op)
           
 void stop()
          Stop the region assigner
 void stopScanners()
          Stop the root and meta scanners so that the region servers serving meta regions can shut down.
 void waitForRootRegionLocation()
          Block until either the root region location is available or we're shutting down.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOG

protected static final org.apache.commons.logging.Log LOG
Method Detail

countRegionsOnFS

public int countRegionsOnFS()
                     throws IOException
Returns:
the rough number of the regions on fs Note: this method simply counts the regions on fs by accumulating all the dirs in each table dir (${HBASE_ROOT}/$TABLE) and skipping logfiles, compaction dirs.
Throws:
IOException

getOnlineMetaRegions

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

metaRegionsInTransition

public boolean metaRegionsInTransition()

stopScanners

public void stopScanners()
Stop the root and meta scanners so that the region servers serving meta regions can shut down.


stop

public void stop()
Stop the region assigner


areAllMetaRegionsOnline

public boolean areAllMetaRegionsOnline()
Block until meta regions are online or we're shutting down.

Returns:
true if we found meta regions, false if we're closing.

getFirstMetaRegionForRegion

public MetaRegion getFirstMetaRegionForRegion(HRegionInfo newRegion)
Search our map of online meta regions to find the first meta region that should contain a pointer to newRegion.

Parameters:
newRegion -
Returns:
MetaRegion where the newRegion should live

getMetaRegionsForTable

public Set<MetaRegion> getMetaRegionsForTable(byte[] tableName)
                                       throws NotAllMetaRegionsOnlineException
Get a set of all the meta regions that contain info about a given table.

Parameters:
tableName - Table you need to know all the meta regions for
Returns:
set of MetaRegion objects that contain the table
Throws:
NotAllMetaRegionsOnlineException

getMetaRegionForRow

public MetaRegion getMetaRegionForRow(byte[] row)
                               throws NotAllMetaRegionsOnlineException
Get metaregion that would host passed in row.

Parameters:
row - Row need to know all the meta regions for
Returns:
MetaRegion for passed row.
Throws:
NotAllMetaRegionsOnlineException

createRegion

public void createRegion(HRegionInfo newRegion,
                         HRegionInterface server,
                         byte[] metaRegionName)
                  throws IOException
Create a new HRegion, put a row for it into META (or ROOT), and mark the new region unassigned so that it will get assigned to a region server.

Parameters:
newRegion - HRegionInfo for the region to create
server - server hosting the META (or ROOT) region where the new region needs to be noted
metaRegionName - name of the meta region where new region is to be written
Throws:
IOException

putMetaRegionOnline

public void putMetaRegionOnline(MetaRegion metaRegion)
Set a MetaRegion as online.

Parameters:
metaRegion -

getListOfOnlineMetaRegions

public List<MetaRegion> getListOfOnlineMetaRegions()
Get a list of online MetaRegions

Returns:
list of MetaRegion objects

numOnlineMetaRegions

public int numOnlineMetaRegions()
Count of online meta regions

Returns:
count of online meta regions

isMetaRegionOnline

public boolean isMetaRegionOnline(byte[] startKey)
Check if a meta region is online by its name

Parameters:
startKey - name of the meta region to check
Returns:
true if the region is online, false otherwise

offlineMetaRegionWithStartKey

public MetaRegion offlineMetaRegionWithStartKey(byte[] startKey)
Set an online MetaRegion offline - remove it from the map.

Parameters:
startKey - Startkey to use finding region to remove.
Returns:
the MetaRegion that was taken offline.

isRootServer

public boolean isRootServer(HServerAddress server)

listMetaRegionsForServer

public List<byte[]> listMetaRegionsForServer(HServerAddress server)
Returns the list of byte[] start-keys for any .META. regions hosted on the indicated server.

Parameters:
server - server address
Returns:
list of meta region start-keys.

isMetaServer

public boolean isMetaServer(HServerAddress server)
Does this server have any META regions open on it, or any meta regions being assigned to it?

Parameters:
server - Server IP:port
Returns:
true if server has meta region assigned

isRootInTransitionOnThisServer

public boolean isRootInTransitionOnThisServer(String server)
Is this server assigned to transition the ROOT table. HBASE-1928

Parameters:
server - Server
Returns:
true if server is transitioning the ROOT table

getMetaServerRegionInfo

public HRegionInfo getMetaServerRegionInfo(String server)
Is this server assigned to transition a META table. HBASE-1928

Parameters:
server - Server
Returns:
if this server was transitioning a META table then a not null HRegionInfo pointing to it

offlineMetaServer

public boolean offlineMetaServer(HServerAddress server)
Call to take this metaserver offline for immediate reassignment. Used only when we know a region has shut down cleanly. A meta server is a server that hosts either -ROOT- or any .META. regions. If you are considering a unclean shutdown potentially, use ProcessServerShutdown which calls other methods to immediately unassign root/meta but delay the reassign until the log has been split.

Parameters:
server - the server that went down
Returns:
true if this was in fact a meta server, false if it did not carry meta regions.

removeRegion

public void removeRegion(HRegionInfo info)
Remove a region from the region state map.

Parameters:
info -

regionIsInTransition

public boolean regionIsInTransition(String regionName)
Parameters:
regionName -
Returns:
true if the named region is in a transition state

regionIsOpening

public boolean regionIsOpening(String regionName)
Parameters:
regionName -
Returns:
true if the region is unassigned, pendingOpen or open

setUnassigned

public void setUnassigned(HRegionInfo info,
                          boolean force)
Set a region to unassigned

Parameters:
info - Region to set unassigned
force - if true mark region unassigned whatever its current state

isUnassigned

public boolean isUnassigned(HRegionInfo info)
Check if a region is on the unassigned list

Parameters:
info - HRegionInfo to check for
Returns:
true if on the unassigned list, false if it isn't. Note that this means a region could not be on the unassigned list AND not be assigned, if it happens to be between states.

isPendingOpen

public boolean isPendingOpen(String regionName)
Check if a region has been assigned and we're waiting for a response from the region server.

Parameters:
regionName - name of the region
Returns:
true if open, false otherwise

setOpen

public void setOpen(String regionName)
Region has been assigned to a server and the server has told us it is open

Parameters:
regionName -

isOfflined

public boolean isOfflined(String regionName)
Parameters:
regionName -
Returns:
true if region is marked to be offlined.

setClosing

public void setClosing(String serverName,
                       HRegionInfo regionInfo,
                       boolean setOffline)
Mark a region as closing

Parameters:
serverName -
regionInfo -
setOffline -

getMarkedToClose

public Set<HRegionInfo> getMarkedToClose(String serverName)
Remove the map of region names to region infos waiting to be offlined for a given server

Parameters:
serverName -
Returns:
set of infos to close

setPendingClose

public void setPendingClose(String regionName)
Called when we have told a region server to close the region

Parameters:
regionName -

setClosed

public void setClosed(String regionName)
Parameters:
regionName -

addMetaRegionToScan

public void addMetaRegionToScan(MetaRegion m)
Add a meta region to the scan queue

Parameters:
m - MetaRegion that needs to get scanned

isInitialRootScanComplete

public boolean isInitialRootScanComplete()
Check if the initial root scan has been completed.

Returns:
true if scan completed, false otherwise

isInitialMetaScanComplete

public boolean isInitialMetaScanComplete()
Check if the initial meta scan has been completed.

Returns:
true if meta completed, false otherwise

getRootRegionLocation

public HServerAddress getRootRegionLocation()
Get the root region location.

Returns:
HServerAddress describing root region server.

waitForRootRegionLocation

public void waitForRootRegionLocation()
Block until either the root region location is available or we're shutting down.


numMetaRegions

public int numMetaRegions()
Return the number of meta regions.

Returns:
number of meta regions

incrementNumMetaRegions

public void incrementNumMetaRegions()
Bump the count of meta regions up one


setRootRegionLocation

public void setRootRegionLocation(HServerAddress address)
Set the root region location.

Parameters:
address - Address of the region server where the root lives

setNumMetaRegions

public void setNumMetaRegions(int num)
Set the number of meta regions.

Parameters:
num - Number of meta regions

startAction

public void startAction(byte[] regionName,
                        HRegionInfo info,
                        HServerAddress server,
                        HConstants.Modify op)
Parameters:
regionName -
info -
server -
op -

endAction

public void endAction(byte[] regionName,
                      HConstants.Modify op)
Parameters:
regionName -
op -

endActions

public void endActions(byte[] regionName)
Parameters:
regionName -

applyActions

public void applyActions(HServerInfo serverInfo,
                         ArrayList<HMsg> returnMsgs)
Send messages to the given region server asking it to split any regions in 'regionsToSplit', etc.

Parameters:
serverInfo -
returnMsgs -


Copyright © 2010 Apache Software Foundation. All Rights Reserved.