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
 class AssignmentManager.TimerUpdater
          Update timers for all regions in transition going against the server in the serversInUpdatingTimer.
 
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, LoadBalancer balancer, ExecutorService service)
          Constructs a new assignment manager.
 
Method Summary
 void addPlan(String encodedName, RegionPlan plan)
          Add a regionPlan for the specified region.
 void addPlans(Map<String,RegionPlan> plans)
          Add a map of region plans.
 void assign(HRegionInfo region, boolean setOfflineInZK)
          Assigns the specified region.
 void assign(HRegionInfo region, boolean setOfflineInZK, boolean forceNewPlan)
           
 void assign(HRegionInfo region, boolean setOfflineInZK, boolean forceNewPlan, boolean hijack)
           
 void assignAllUserRegions()
          Assigns all user regions, if any exist.
 void assignMeta()
          Assigns the META region.
 void assignRoot()
          Assigns the ROOT region.
 void assignUserRegions(List<HRegionInfo> regions, List<ServerName> servers)
          Assigns all user regions, if any.
 void assignUserRegionsToOnlineServers(List<HRegionInfo> regions)
          Assigns all user regions to online servers.
 void clearRegionFromTransition(HRegionInfo hri)
          Deprecated. This is a dupe of regionOffline(HRegionInfo). Please use that method instead.
 void deleteClosingOrClosedNode(HRegionInfo region)
           
 void deleteNodeAndOfflineRegion(HRegionInfo hri)
          Delete znode of region in transition if table is disabling/disabled and offline the region.
 List<HRegionInfo> getEnablingTableRegions(String tableName)
          Gives enabling table regions.
 ServerName getRegionServerOfRegion(HRegionInfo hri)
          Returns the RegionServer to which hri is assigned.
 NavigableMap<String,AssignmentManager.RegionState> getRegionsInTransition()
           
 List<HRegionInfo> getRegionsOfTable(byte[] tableName)
          Gets the online regions of the specified table.
 Pair<Integer,Integer> getReopenStatus(byte[] tableName)
          Used by the client to identify if all regions have the schema updates
 ZKTable getZKTable()
           
 void handleSplitReport(ServerName sn, HRegionInfo parent, HRegionInfo a, HRegionInfo b)
          Update inmemory structures.
 boolean isCarryingMeta(ServerName serverName)
           
 boolean isCarryingRegion(ServerName serverName, HRegionInfo hri)
          Check if the shutdown server carries the specific region.
 boolean isCarryingRoot(ServerName serverName)
           
 boolean isRegionAssigned(HRegionInfo hri)
          Checks whether the region is assigned.
 AssignmentManager.RegionState isRegionInTransition(HRegionInfo hri)
           
 boolean isRegionsInTransition()
           
 boolean isServerOnline(ServerName 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 nodeDeleted(String path)
          Called when a node has been deleted
 void offlineDisabledRegion(HRegionInfo regionInfo)
           
 Pair<Set<HRegionInfo>,List<AssignmentManager.RegionState>> processServerShutdown(ServerName sn)
          Start processing of shutdown server.
 void regionOffline(HRegionInfo regionInfo)
          Marks the region as offline.
 void removeClosedRegion(HRegionInfo hri)
          When a region is closed, it should be removed from the regionsToReopen
 void removeDeadNotExpiredServers(List<ServerName> servers)
          Loop through the deadNotExpired server list and remove them from the servers.
protected  void setEnabledTable(String tableName)
           
 void setOffline(HRegionInfo regionInfo)
          Sets the region as offline by removing in-memory assignment information but retaining transition information.
 void setRegionsToReopen(List<HRegionInfo> regions)
          Set the list of regions that will be reopened because of an update in table schema
 void shutdown()
          Shutdown the threadpool executor service
 void stop()
           
 void unassign(HRegionInfo region)
          Unassigns the specified region.
 void unassign(HRegionInfo region, boolean force)
          Unassigns the specified region.
 void unassign(List<HRegionInfo> regions)
          Unassign the list of regions.
 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 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,
                         LoadBalancer balancer,
                         ExecutorService service)
                  throws org.apache.zookeeper.KeeperException,
                         IOException
Constructs a new assignment manager.

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

getZKTable

public ZKTable getZKTable()
Returns:
Instance of ZKTable.

getRegionServerOfRegion

public ServerName getRegionServerOfRegion(HRegionInfo hri)
Returns the RegionServer to which hri is assigned.

Parameters:
hri - HRegion for which this function returns the region server
Returns:
HServerInfo The region server to which hri belongs

isRegionAssigned

public boolean isRegionAssigned(HRegionInfo hri)
Checks whether the region is assigned.

Parameters:
hri - HRegion for which this function returns the result
Returns:
True iff assigned.

getEnablingTableRegions

public List<HRegionInfo> getEnablingTableRegions(String tableName)
Gives enabling table regions.

Parameters:
tableName -
Returns:
list of regionInfos

addPlan

public void addPlan(String encodedName,
                    RegionPlan plan)
Add a regionPlan for the specified region.

Parameters:
encodedName -
plan -

addPlans

public void addPlans(Map<String,RegionPlan> plans)
Add a map of region plans.


setRegionsToReopen

public void setRegionsToReopen(List<HRegionInfo> regions)
Set the list of regions that will be reopened because of an update in table schema

Parameters:
regions - list of regions that should be tracked for reopen

getReopenStatus

public Pair<Integer,Integer> getReopenStatus(byte[] tableName)
                                      throws IOException
Used by the client to identify if all regions have the schema updates

Parameters:
tableName -
Returns:
Pair indicating the status of the alter command
Throws:
IOException

removeClosedRegion

public void removeClosedRegion(HRegionInfo hri)
When a region is closed, it should be removed from the regionsToReopen

Parameters:
hri - HRegionInfo of the region which was closed

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

nodeDeleted

public void nodeDeleted(String path)
Description copied from class: ZooKeeperListener
Called when a node has been deleted

Overrides:
nodeDeleted in class ZooKeeperListener
Parameters:
path - full path of the deleted node

nodeChildrenChanged

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

This happens when an RS begins the OPENING, SPLITTING or CLOSING of a region by creating a znode.

When this happens we must:

  1. Watch the node for further children changed events
  2. Watch all new children for changed events

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

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)

assign

public void assign(HRegionInfo region,
                   boolean setOfflineInZK,
                   boolean forceNewPlan,
                   boolean hijack)
Parameters:
region -
setOfflineInZK -
forceNewPlan -
hijack - - true new assignment is needed, false otherwise

removeDeadNotExpiredServers

public void removeDeadNotExpiredServers(List<ServerName> servers)
Loop through the deadNotExpired server list and remove them from the servers.

Parameters:
servers -

unassign

public void unassign(List<HRegionInfo> regions)
Unassign the list of regions. Configuration knobs: hbase.bulk.waitbetween.reopen indicates the number of milliseconds to wait before unassigning another region from this region server

Parameters:
regions -
Throws:
InterruptedException

unassign

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

Updates the RegionState and sends the CLOSE RPC unless region is being split by regionserver; then the unassign fails (silently) because we presume the region being unassigned no longer exists (its been split out of existence). TODO: What to do if split fails and is rolled back and parent is revivified?

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 unless region is being split by regionserver; then the unassign fails (silently) because we presume the region being unassigned no longer exists (its been split out of existence). TODO: What to do if split fails and is rolled back and parent is revivified?

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

deleteClosingOrClosedNode

public void deleteClosingOrClosedNode(HRegionInfo region)
Parameters:
region - regioninfo of znode to be deleted.

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.


assignUserRegionsToOnlineServers

public void assignUserRegionsToOnlineServers(List<HRegionInfo> regions)
                                      throws IOException,
                                             InterruptedException
Assigns all user regions to online servers. Use round-robin assignment.

Parameters:
regions -
Throws:
IOException
InterruptedException

assignUserRegions

public void assignUserRegions(List<HRegionInfo> regions,
                              List<ServerName> servers)
                       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

Throws:
InterruptedException
IOException

assignAllUserRegions

public void assignAllUserRegions()
                          throws IOException,
                                 InterruptedException
Assigns all user regions, if any exist. 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

deleteNodeAndOfflineRegion

public void deleteNodeAndOfflineRegion(HRegionInfo hri)
Delete znode of region in transition if table is disabling/disabled and offline the region.

Parameters:
hri - region to offline.

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)
Deprecated. This is a dupe of regionOffline(HRegionInfo). Please use that method instead.

Clears the specified region from being in transition.

Parameters:
hri - Region to remove.

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

isCarryingRoot

public boolean isCarryingRoot(ServerName serverName)

isCarryingMeta

public boolean isCarryingMeta(ServerName serverName)

isCarryingRegion

public boolean isCarryingRegion(ServerName serverName,
                                HRegionInfo hri)
Check if the shutdown server carries the specific region. We have a bunch of places that store region location Those values aren't consistent. There is a delay of notification. The location from zookeeper unassigned node has the most recent data; but the node could be deleted after the region is opened by AM. The AM's info could be old when OpenedRegionHandler processing hasn't finished yet when server shutdown occurs.

Returns:
whether the serverName currently hosts the region

processServerShutdown

public Pair<Set<HRegionInfo>,List<AssignmentManager.RegionState>> processServerShutdown(ServerName sn)
Start processing of shutdown server.

Parameters:
sn - Server that went down.
Returns:
Pair that has a set of regions in transition TO the dead server and a list of regions that were in transition, and also ON this server.

handleSplitReport

public void handleSplitReport(ServerName sn,
                              HRegionInfo parent,
                              HRegionInfo a,
                              HRegionInfo b)
Update inmemory structures.

Parameters:
sn - 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(ServerName serverName)
Check whether the RegionServer is online.

Parameters:
serverName -
Returns:
True if online.

shutdown

public void shutdown()
Shutdown the threadpool executor service


setEnabledTable

protected void setEnabledTable(String tableName)


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