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
 void clearLastAssignment(HRegionInfo region)
           
 RegionState createRegionState(HRegionInfo hri)
          Add a region to RegionStates.
 RegionState createRegionState(HRegionInfo hri, RegionState.State newState, ServerName serverName)
          Add a region to RegionStates with the specified state.
 void createRegionStates(List<HRegionInfo> hris)
          Add a list of regions to RegionStates.
protected  Map<TableName,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()
           
 Map<RegionState.State,List<HRegionInfo>> getRegionByStateOfTable(TableName tableName)
          Gets current state of all regions of the table.
protected  HRegionInfo getRegionInfo(byte[] regionName)
          Get the HRegionInfo from cache, if not there, from the hbase:meta table.
 ServerName getRegionServerOfRegion(HRegionInfo hri)
           
 Map<String,RegionState> getRegionsInTransition()
          Get regions in transition and their states
 List<HRegionInfo> getRegionsOfTable(TableName tableName)
          Gets the online regions of the specified table.
protected  RegionState getRegionState(HRegionInfo hri)
           
protected  RegionState getRegionState(String encodedName)
           
 RegionState getRegionTransitionState(HRegionInfo hri)
          Get region transition state
 RegionState getRegionTransitionState(String encodedName)
          Get region transition state
 boolean isRegionInState(HRegionInfo hri, RegionState.State... states)
           
 boolean isRegionInState(String encodedName, RegionState.State... states)
           
 boolean isRegionInTransition(HRegionInfo hri)
           
 boolean isRegionInTransition(String encodedName)
           
 boolean isRegionOffline(HRegionInfo hri)
           
 boolean isRegionOnline(HRegionInfo hri)
           
 boolean isRegionsInTransition()
           
 void logSplit(HRegionInfo region)
          Log split is done for a given region, so it is assignable now.
 void logSplit(ServerName serverName)
          A dead server's hlogs have been split so that all the regions used to be open on it can be safely assigned now.
 void regionOffline(HRegionInfo hri)
          A region is offline, won't be in transition any more.
 void regionOffline(HRegionInfo hri, RegionState.State expectedState)
          A region is offline, won't be in transition any more.
 void regionOnline(HRegionInfo hri, ServerName serverName)
           
 void regionOnline(HRegionInfo hri, ServerName serverName, long openSeqNum)
          A region is online, won't be in transition any more.
 List<HRegionInfo> serverOffline(ZooKeeperWatcher watcher, ServerName sn)
          A server is offline, all regions on it are dead.
 void tableDeleted(TableName tableName)
          A table is deleted.
 RegionState transitionOpenFromPendingOpenOrOpeningOnServer(RegionTransition transition, RegionState fromState, ServerName sn)
          Transition a region state to OPEN from OPENING/PENDING_OPEN
 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 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 encodedName)
Returns:
True if specified region in transition.

isRegionsInTransition

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

isRegionOnline

public boolean isRegionOnline(HRegionInfo hri)
Returns:
True if specified region assigned, and not in transition.

isRegionOffline

public boolean isRegionOffline(HRegionInfo hri)
Returns:
True if specified region offline/closed, but not in transition. If the region is not in the map, it is offline to us too.

isRegionInState

public boolean isRegionInState(HRegionInfo hri,
                               RegionState.State... states)
Returns:
True if specified region is in one of the specified states.

isRegionInState

public boolean isRegionInState(String encodedName,
                               RegionState.State... states)
Returns:
True if specified region is in one of the specified states.

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 encodedName)
Get region transition state


createRegionStates

public void createRegionStates(List<HRegionInfo> hris)
Add a list of regions to RegionStates. If a region is split and offline, its state will be SPLIT. Otherwise, its state will be OFFLINE. Region already in RegionStates will be skipped.


createRegionState

public RegionState createRegionState(HRegionInfo hri)
Add a region to RegionStates. If the region is split and offline, its state will be SPLIT. Otherwise, its state will be OFFLINE. If it is already in RegionStates, this call has no effect, and the original state is returned.


createRegionState

public RegionState createRegionState(HRegionInfo hri,
                                     RegionState.State newState,
                                     ServerName serverName)
Add a region to RegionStates with the specified state. If the region 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. It will be put in transition if not already there.


updateRegionState

public RegionState updateRegionState(RegionTransition transition,
                                     RegionState.State state)
Update a region state. 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.


transitionOpenFromPendingOpenOrOpeningOnServer

public RegionState transitionOpenFromPendingOpenOrOpeningOnServer(RegionTransition transition,
                                                                  RegionState fromState,
                                                                  ServerName sn)
Transition a region state to OPEN from OPENING/PENDING_OPEN


updateRegionState

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


regionOnline

public void regionOnline(HRegionInfo hri,
                         ServerName serverName)

regionOnline

public void regionOnline(HRegionInfo hri,
                         ServerName serverName,
                         long openSeqNum)
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.


logSplit

public void logSplit(ServerName serverName)
A dead server's hlogs have been split so that all the regions used to be open on it can be safely assigned now. Mark them assignable.


logSplit

public void logSplit(HRegionInfo region)
Log split is done for a given region, so it is assignable now.


clearLastAssignment

public void clearLastAssignment(HRegionInfo region)

regionOffline

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


regionOffline

public void regionOffline(HRegionInfo hri,
                          RegionState.State expectedState)
A region is offline, won't be in transition any more. Its state should be the specified expected state, which can only be Split/Merged/Offline/null(=Offline)/SplittingNew/MergingNew.


serverOffline

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


getRegionsOfTable

public List<HRegionInfo> getRegionsOfTable(TableName tableName)
Gets the online regions of the specified table. This method looks at the in-memory state. It does not go to hbase: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

getRegionByStateOfTable

public Map<RegionState.State,List<HRegionInfo>> getRegionByStateOfTable(TableName tableName)
Gets current state of all regions of the table. This method looks at the in-memory state. It does not go to hbase:meta. Method guaranteed to return keys for all states in RegionState.State

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

tableDeleted

public void tableDeleted(TableName tableName)
A table is deleted. Remove its regions from all internal maps. We loop through all regions assuming we don't delete tables too much.


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<TableName,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 encodedName)

getRegionInfo

protected HRegionInfo getRegionInfo(byte[] regionName)
Get the HRegionInfo from cache, if not there, from the hbase:meta table. Be careful. Does RPC. Do not hold a lock or synchronize when you call this method.

Parameters:
regionName -
Returns:
HRegionInfo for the region


Copyright © 2007–2015 The Apache Software Foundation. All rights reserved.