org.apache.hadoop.hbase.master
Class RegionStates

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

@InterfaceAudience.Private
public class RegionStates
extends Object

Region state accountant. It holds the states of all regions in the memory. In normal scenario, it should match the meta table and the true region states. This map is used by AssignmentManager to track region states.


Method Summary
 RegionState createRegionState(HRegionInfo hri)
          Add a region to RegionStates.
 void createRegionStates(List<HRegionInfo> hris)
          Add a list of regions to RegionStates.
protected  Map<String,Map<ServerName,List<HRegionInfo>>> getAssignmentsByTable()
          This is an EXPENSIVE clone.
protected  double getAverageLoad()
          Compute the average load across all region servers.
 Map<HRegionInfo,ServerName> getRegionAssignments()
           
protected  HRegionInfo getRegionInfo(byte[] regionName)
          Get the HRegionInfo from cache, if not there, from the META table
 ServerName getRegionServerOfRegion(HRegionInfo hri)
           
 Map<String,RegionState> getRegionsInTransition()
          Get regions in transition and their states
 List<HRegionInfo> getRegionsOfTable(byte[] tableName)
          Gets the online regions of the specified table.
protected  RegionState getRegionState(HRegionInfo hri)
           
protected  RegionState getRegionState(String regionName)
           
 RegionState getRegionTransitionState(HRegionInfo hri)
          Get region transition state
 RegionState getRegionTransitionState(String regionName)
          Get region transition state
 boolean isRegionAssigned(HRegionInfo hri)
           
 boolean isRegionFailedToClose(HRegionInfo hri)
           
 boolean isRegionFailedToOpen(HRegionInfo hri)
           
 boolean isRegionInTransition(HRegionInfo hri)
           
 boolean isRegionInTransition(String regionName)
           
 boolean isRegionsInTransition()
           
 void regionOffline(HRegionInfo hri)
          A region is offline, won't be in transition any more.
 void regionOnline(HRegionInfo hri, ServerName serverName)
          A region is online, won't be in transition any more.
 List<HRegionInfo> serverOffline(ServerName sn)
          A server is offline, all regions on it are dead.
 RegionState updateRegionState(HRegionInfo hri, RegionState.State state)
          Update a region state.
 RegionState updateRegionState(HRegionInfo hri, RegionState.State state, ServerName serverName)
          Update a region state.
 RegionState updateRegionState(RegionTransition transition, RegionState.State state)
          Update a region state.
 void waitForAssignment(HRegionInfo hri)
          Waits until the specified region has completed assignment.
 void waitForUpdate(long timeout)
          Wait for the state map to be updated by assignment manager.
 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
 

Method Detail

getRegionAssignments

public Map<HRegionInfo,ServerName> getRegionAssignments()
Returns:
an unmodifiable the region assignment map

getRegionServerOfRegion

public ServerName getRegionServerOfRegion(HRegionInfo hri)

getRegionsInTransition

public Map<String,RegionState> getRegionsInTransition()
Get regions in transition and their states


isRegionInTransition

public boolean isRegionInTransition(HRegionInfo hri)
Returns:
True if specified region in transition.

isRegionInTransition

public boolean isRegionInTransition(String regionName)
Returns:
True if specified region in transition.

isRegionsInTransition

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

isRegionAssigned

public boolean isRegionAssigned(HRegionInfo hri)
Returns:
True if specified region assigned.

isRegionFailedToOpen

public boolean isRegionFailedToOpen(HRegionInfo hri)
Returns:
True if specified region failed to open.

isRegionFailedToClose

public boolean isRegionFailedToClose(HRegionInfo hri)
Returns:
True if specified region failed to close.

waitForUpdate

public void waitForUpdate(long timeout)
                   throws InterruptedException
Wait for the state map to be updated by assignment manager.

Throws:
InterruptedException

getRegionTransitionState

public RegionState getRegionTransitionState(HRegionInfo hri)
Get region transition state


getRegionTransitionState

public RegionState getRegionTransitionState(String regionName)
Get region transition state


createRegionStates

public void createRegionStates(List<HRegionInfo> hris)
Add a list of regions to RegionStates. The initial state is OFFLINE. If any region is already in RegionStates, that region will be skipped.


createRegionState

public RegionState createRegionState(HRegionInfo hri)
Add a region to RegionStates. The initial state is OFFLINE. If it is already in RegionStates, this call has no effect, and the original state is returned.


updateRegionState

public RegionState updateRegionState(HRegionInfo hri,
                                     RegionState.State state)
Update a region state. If it is not splitting, it will be put in transition if not already there.


updateRegionState

public RegionState updateRegionState(RegionTransition transition,
                                     RegionState.State state)
Update a region state. If it is not splitting, it will be put in transition if not already there. If we can't find the region info based on the region name in the transition, log a warning and return null.


updateRegionState

public RegionState updateRegionState(HRegionInfo hri,
                                     RegionState.State state,
                                     ServerName serverName)
Update a region state. If it is not splitting, it will be put in transition if not already there.


regionOnline

public void regionOnline(HRegionInfo hri,
                         ServerName serverName)
A region is online, won't be in transition any more. We can't confirm it is really online on specified region server because it hasn't been put in region server's online region list yet.


regionOffline

public void regionOffline(HRegionInfo hri)
A region is offline, won't be in transition any more.


serverOffline

public List<HRegionInfo> serverOffline(ServerName sn)
A server is offline, all regions on it are dead.


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

waitOnRegionToClearRegionsInTransition

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

If the region isn't in transition, returns immediately. Otherwise, method blocks until the region is out of transition.

Throws:
InterruptedException

waitForAssignment

public void waitForAssignment(HRegionInfo hri)
                       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.

Throws:
InterruptedException

getAverageLoad

protected double getAverageLoad()
Compute the average load across all region servers. Currently, this uses a very naive computation - just uses the number of regions being served, ignoring stats about number of requests.

Returns:
the average load

getAssignmentsByTable

protected Map<String,Map<ServerName,List<HRegionInfo>>> getAssignmentsByTable()
This is an EXPENSIVE clone. Cloning though is the safest thing to do. Can't let out original since it can change and at least the load balancer wants to iterate this exported list. We need to synchronize on regions since all access to this.servers is under a lock on this.regions.

Returns:
A clone of current assignments by table.

getRegionState

protected RegionState getRegionState(HRegionInfo hri)

getRegionState

protected RegionState getRegionState(String regionName)

getRegionInfo

protected HRegionInfo getRegionInfo(byte[] regionName)
Get the HRegionInfo from cache, if not there, from the META table

Parameters:
regionName -
Returns:
HRegionInfo for the region


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