org.apache.hadoop.hbase.master
Class AssignmentManager

java.lang.Object
  extended by org.apache.hadoop.hbase.zookeeper.ZooKeeperListener
      extended by org.apache.hadoop.hbase.master.AssignmentManager

public class AssignmentManager
extends ZooKeeperListener

Manages and performs region assignment.

Monitors ZooKeeper for events related to regions in transition.

Handles existing regions in transition during master failover.


Nested Class Summary
static class AssignmentManager.RegionState
          State of a Region while undergoing transitions.
 class AssignmentManager.TimeoutMonitor
          Monitor to check for time outs on region transition operations
 
Field Summary
protected  Server master
           
 
Fields inherited from class org.apache.hadoop.hbase.zookeeper.ZooKeeperListener
watcher
 
Constructor Summary
AssignmentManager(Server master, ServerManager serverManager, CatalogTracker catalogTracker, ExecutorService service)
          Constructs a new assignment manager.
 
Method Summary
 void assign(HRegionInfo region, boolean setOfflineInZK)
          Assigns the specified region.
 void assign(HRegionInfo region, boolean setOfflineInZK, boolean forceNewPlan)
           
 void assignAllUserRegions()
          Assigns all user regions, if any.
 void assignMeta()
          Assigns the META region.
 void assignRoot()
          Assigns the ROOT region.
 void clearRegionFromTransition(HRegionInfo hri)
          Clears the specified region from being in transition.
 NavigableMap<String,AssignmentManager.RegionState> getRegionsInTransition()
           
 List<HRegionInfo> getRegionsOfTable(byte[] tableName)
          Gets the online regions of the specified table.
 ZKTable getZKTable()
           
 void handleSplitReport(HServerInfo hsi, HRegionInfo parent, HRegionInfo a, HRegionInfo b)
          Update inmemory structures.
 AssignmentManager.RegionState isRegionInTransition(HRegionInfo hri)
           
 boolean isRegionsInTransition()
           
 boolean isServerOnline(String serverName)
          Check whether the RegionServer is online.
 void nodeChildrenChanged(String path)
          New unassigned node has been created.
 void nodeCreated(String path)
          New unassigned node has been created.
 void nodeDataChanged(String path)
          Existing unassigned node has had data changed.
 void offlineDisabledRegion(HRegionInfo regionInfo)
           
 List<AssignmentManager.RegionState> processServerShutdown(HServerInfo hsi)
          Process shutdown server removing any assignments.
 void regionOffline(HRegionInfo regionInfo)
          Marks the region as offline.
 void regionOnline(HRegionInfo regionInfo, HServerInfo serverInfo)
          Marks the region as online.
 void setOffline(HRegionInfo regionInfo)
          Sets the region as offline by removing in-memory assignment information but retaining transition information.
 void stop()
           
 void unassign(HRegionInfo region)
          Unassigns the specified region.
 void unassign(HRegionInfo region, boolean force)
          Unassigns the specified region.
 void waitForAssignment(HRegionInfo regionInfo)
          Waits until the specified region has completed assignment.
 void waitOnRegionToClearRegionsInTransition(HRegionInfo hri)
          Wait on region to clear regions-in-transition.
 
Methods inherited from class org.apache.hadoop.hbase.zookeeper.ZooKeeperListener
nodeDeleted
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

master

protected Server master
Constructor Detail

AssignmentManager

public AssignmentManager(Server master,
                         ServerManager serverManager,
                         CatalogTracker catalogTracker,
                         ExecutorService service)
                  throws org.apache.zookeeper.KeeperException
Constructs a new assignment manager.

Parameters:
master -
serverManager -
catalogTracker -
service -
Throws:
org.apache.zookeeper.KeeperException
Method Detail

getZKTable

public ZKTable getZKTable()
Returns:
Instance of ZKTable.

nodeCreated

public void nodeCreated(String path)
New unassigned node has been created.

This happens when an RS begins the OPENING or CLOSING of a region by creating an unassigned node.

When this happens we must:

  1. Watch the node for further events
  2. Read and handle the state in the node

Overrides:
nodeCreated in class ZooKeeperListener
Parameters:
path - full path of the new node

nodeDataChanged

public void nodeDataChanged(String path)
Existing unassigned node has had data changed.

This happens when an RS transitions from OFFLINE to OPENING, or between OPENING/OPENED and CLOSING/CLOSED.

When this happens we must:

  1. Watch the node for further events
  2. Read and handle the state in the node

Overrides:
nodeDataChanged in class ZooKeeperListener
Parameters:
path - full path of the updated node

nodeChildrenChanged

public void nodeChildrenChanged(String path)
New unassigned node has been created.

This happens when an RS begins the OPENING or CLOSING of a region by creating an unassigned node.

When this happens we must:

  1. Watch the node for further children changed events
  2. Watch all new children for changed events
  3. Read all children and handle them

Overrides:
nodeChildrenChanged in class ZooKeeperListener
Parameters:
path - full path of the node whose children have changed

regionOnline

public void regionOnline(HRegionInfo regionInfo,
                         HServerInfo serverInfo)
Marks the region as online. Removes it from regions in transition and updates the in-memory assignment information.

Used when a region has been successfully opened on a region server.

Parameters:
regionInfo -
serverInfo -

regionOffline

public void regionOffline(HRegionInfo regionInfo)
Marks the region as offline. Removes it from regions in transition and removes in-memory assignment information.

Used when a region has been closed and should remain closed.

Parameters:
regionInfo -

setOffline

public void setOffline(HRegionInfo regionInfo)
Sets the region as offline by removing in-memory assignment information but retaining transition information.

Used when a region has been closed but should be reassigned.

Parameters:
regionInfo -

offlineDisabledRegion

public void offlineDisabledRegion(HRegionInfo regionInfo)

assign

public void assign(HRegionInfo region,
                   boolean setOfflineInZK)
Assigns the specified region.

If a RegionPlan is available with a valid destination then it will be used to determine what server region is assigned to. If no RegionPlan is available, region will be assigned to a random available server.

Updates the RegionState and sends the OPEN RPC.

This will only succeed if the region is in transition and in a CLOSED or OFFLINE state or not in transition (in-memory not zk), and of course, the chosen server is up and running (It may have just crashed!). If the in-memory checks pass, the zk node is forced to OFFLINE before assigning.

Parameters:
region - server to be assigned
setOfflineInZK - whether ZK node should be created/transitioned to an OFFLINE state before assigning the region

assign

public void assign(HRegionInfo region,
                   boolean setOfflineInZK,
                   boolean forceNewPlan)

unassign

public void unassign(HRegionInfo region)
Unassigns the specified region.

Updates the RegionState and sends the CLOSE RPC.

If a RegionPlan is already set, it will remain.

Parameters:
region - server to be unassigned

unassign

public void unassign(HRegionInfo region,
                     boolean force)
Unassigns the specified region.

Updates the RegionState and sends the CLOSE RPC.

If a RegionPlan is already set, it will remain.

Parameters:
region - server to be unassigned
force - if region should be closed even if already closing

waitForAssignment

public void waitForAssignment(HRegionInfo regionInfo)
                       throws InterruptedException
Waits until the specified region has completed assignment.

If the region is already assigned, returns immediately. Otherwise, method blocks until the region is assigned.

Parameters:
regionInfo - region to wait on assignment for
Throws:
InterruptedException

assignRoot

public void assignRoot()
                throws org.apache.zookeeper.KeeperException
Assigns the ROOT region.

Assumes that ROOT is currently closed and is not being actively served by any RegionServer.

Forcibly unsets the current root region location in ZooKeeper and assigns ROOT to a random RegionServer.

Throws:
org.apache.zookeeper.KeeperException

assignMeta

public void assignMeta()
Assigns the META region.

Assumes that META is currently closed and is not being actively served by any RegionServer.

Forcibly assigns META to a random RegionServer.


assignAllUserRegions

public void assignAllUserRegions()
                          throws IOException,
                                 InterruptedException
Assigns all user regions, if any. Used during cluster startup.

This is a synchronous call and will return once every region has been assigned. If anything fails, an exception is thrown and the cluster should be shutdown.

Throws:
InterruptedException
IOException

getRegionsInTransition

public NavigableMap<String,AssignmentManager.RegionState> getRegionsInTransition()
Returns:
A copy of the Map of regions currently in transition.

isRegionsInTransition

public boolean isRegionsInTransition()
Returns:
True if regions in transition.

isRegionInTransition

public AssignmentManager.RegionState isRegionInTransition(HRegionInfo hri)
Parameters:
hri - Region to check.
Returns:
Returns null if passed region is not in transition else the current RegionState

clearRegionFromTransition

public void clearRegionFromTransition(HRegionInfo hri)
Clears the specified region from being in transition.

Used only by HBCK tool.

Parameters:
hri -

waitOnRegionToClearRegionsInTransition

public void waitOnRegionToClearRegionsInTransition(HRegionInfo hri)
                                            throws IOException
Wait on region to clear regions-in-transition.

Parameters:
hri - Region to wait on.
Throws:
IOException

getRegionsOfTable

public List<HRegionInfo> getRegionsOfTable(byte[] tableName)
Gets the online regions of the specified table. This method looks at the in-memory state. It does not go to .META.. Only returns online regions. If a region on this table has been closed during a disable, etc., it will be included in the returned list. So, the returned list may not necessarily be ALL regions in this table, its all the ONLINE regions in the table.

Parameters:
tableName -
Returns:
Online regions from tableName

processServerShutdown

public List<AssignmentManager.RegionState> processServerShutdown(HServerInfo hsi)
Process shutdown server removing any assignments.

Parameters:
hsi - Server that went down.
Returns:
list of regions in transition on this server

handleSplitReport

public void handleSplitReport(HServerInfo hsi,
                              HRegionInfo parent,
                              HRegionInfo a,
                              HRegionInfo b)
Update inmemory structures.

Parameters:
hsi - Server that reported the split
parent - Parent region that was split
a - Daughter region A
b - Daughter region B

stop

public void stop()

isServerOnline

public boolean isServerOnline(String serverName)
Check whether the RegionServer is online.



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