@InterfaceAudience.Private public class RegionStates extends Object
Modifier and Type | Field and Description |
---|---|
private HashMap<String,Long> |
deadServers
Map a host port pair string to the latest start code
of a region server which is known to be dead.
|
(package private) static long |
DEFAULT_LOG_SPLIT_TIME |
private Map<HRegionInfo,Set<HRegionInfo>> |
defaultReplicaToOtherReplicas
Maintains the mapping from the default region to the replica regions.
|
private HashMap<String,ServerName> |
lastAssignments
Encoded region name to server assignment map for re-assignment
purpose.
|
private long |
lastProcessedServerCleanTime |
private static org.apache.commons.logging.Log |
LOG |
(package private) static String |
LOG_SPLIT_TIME |
private HashMap<String,ServerName> |
oldAssignments
Encoded region name to server assignment map for the
purpose to clean up serverHoldings when a region is online
on a new server.
|
private HashMap<ServerName,Long> |
processedServers
Map a dead servers to the time when log split is done.
|
private TreeMap<HRegionInfo,ServerName> |
regionAssignments
Region to server assignment map.
|
(package private) HashMap<String,RegionState> |
regionsInTransition
Regions currently in transition.
|
private Map<String,RegionState> |
regionStates
Region encoded name to state map.
|
private Map<TableName,Map<String,RegionState>> |
regionStatesTableIndex
Holds mapping of table -> region state
|
private RegionStateStore |
regionStateStore |
private Server |
server |
private Map<ServerName,Set<HRegionInfo>> |
serverHoldings
Server to regions assignment map.
|
private ServerManager |
serverManager |
private TableStateManager |
tableStateManager |
private boolean |
useZK |
Constructor and Description |
---|
RegionStates(Server master,
TableStateManager tableStateManager,
ServerManager serverManager,
RegionStateStore regionStateStore) |
Modifier and Type | Method and Description |
---|---|
private void |
addToReplicaMapping(HRegionInfo hri) |
private void |
addToServerHoldings(ServerName serverName,
HRegionInfo hri) |
private void |
cleanFailedSplitMergeRegions(Set<HRegionInfo> hris)
This method does an RPC to hbase:meta.
|
void |
clearLastAssignment(HRegionInfo region) |
(package private) Map<HRegionInfo,ServerName> |
closeAllUserRegions(Set<TableName> excludedTables)
At cluster clean re/start, mark all user regions closed except those of tables
that are excluded, such as disabled/disabling/enabling tables.
|
RegionState |
createRegionState(HRegionInfo hri)
Add a region to RegionStates.
|
RegionState |
createRegionState(HRegionInfo hri,
RegionState.State newState,
ServerName serverName,
ServerName lastHost)
Add a region to RegionStates with the specified state.
|
void |
createRegionStates(List<HRegionInfo> hris)
Add a list of regions to RegionStates.
|
void |
deleteRegion(HRegionInfo hri)
Remove a region from all state maps.
|
(package private) boolean |
existsInServerHoldings(ServerName serverName,
HRegionInfo hri)
Used in some unit tests
|
protected Map<TableName,Map<ServerName,List<HRegionInfo>>> |
getAssignmentsByTable()
This is an EXPENSIVE clone.
|
protected double |
getAverageLoad()
Compute the average load across all region servers.
|
(package private) ServerName |
getLastRegionServerOfRegion(String encodedName)
Get the last region server a region was on for purpose of re-assignment,
i.e.
|
Map<HRegionInfo,ServerName> |
getRegionAssignments() |
(package private) Map<ServerName,List<HRegionInfo>> |
getRegionAssignments(Collection<HRegionInfo> regions)
Return the replicas (including default) for the regions grouped by ServerName
|
protected Map<ServerName,List<HRegionInfo>> |
getRegionAssignmentsByServer()
Returns a clone of region assignments per server
|
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
|
private int |
getRegionReplication(HRegionInfo r) |
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
|
Set<HRegionInfo> |
getServerRegions(ServerName serverName)
Get a copy of all regions assigned to a server
|
(package private) static boolean |
isOneOfStates(RegionState regionState,
RegionState.State... states) |
boolean |
isRegionInRegionStates(HRegionInfo hri) |
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() |
(package private) boolean |
isServerDeadAndNotProcessed(ServerName server) |
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 wals have been split so that all the regions
used to be open on it can be safely assigned now.
|
(package private) void |
mergeRegions(HRegionInfo p,
HRegionInfo a,
HRegionInfo b,
ServerName sn) |
private RegionState |
putRegionState(RegionState regionState) |
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.
|
private void |
removeFromReplicaMapping(HRegionInfo hri) |
private void |
removeFromServerHoldings(ServerName serverName,
HRegionInfo hri) |
List<HRegionInfo> |
serverOffline(ZooKeeperWatcher watcher,
ServerName sn)
A server is offline, all regions on it are dead.
|
(package private) void |
setLastRegionServerOfRegion(ServerName serverName,
String encodedName) |
(package private) void |
setLastRegionServerOfRegions(ServerName serverName,
List<HRegionInfo> regionInfos) |
RegionState |
setRegionStateTOCLOSED(byte[] regionName,
ServerName serverName)
Set the region state to CLOSED
|
RegionState |
setRegionStateTOCLOSED(HRegionInfo regionInfo,
ServerName serverName)
Set the region state to CLOSED
|
(package private) void |
splitRegion(HRegionInfo p,
HRegionInfo a,
HRegionInfo b,
ServerName sn) |
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.
|
private RegionState |
updateRegionState(HRegionInfo hri,
RegionState.State state,
ServerName serverName,
long openSeqNum)
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.
|
(package private) boolean |
wasRegionOnDeadServer(String encodedName)
Checking if a region was assigned to a server which is not online now.
|
private static final org.apache.commons.logging.Log LOG
final HashMap<String,RegionState> regionsInTransition
private final Map<String,RegionState> regionStates
private final Map<TableName,Map<String,RegionState>> regionStatesTableIndex
private final Map<ServerName,Set<HRegionInfo>> serverHoldings
private final Map<HRegionInfo,Set<HRegionInfo>> defaultReplicaToOtherReplicas
private final TreeMap<HRegionInfo,ServerName> regionAssignments
private final HashMap<String,ServerName> lastAssignments
private final HashMap<String,ServerName> oldAssignments
private final HashMap<String,Long> deadServers
private final HashMap<ServerName,Long> processedServers
private long lastProcessedServerCleanTime
private final TableStateManager tableStateManager
private final RegionStateStore regionStateStore
private final ServerManager serverManager
private final Server server
private final boolean useZK
static final String LOG_SPLIT_TIME
static final long DEFAULT_LOG_SPLIT_TIME
RegionStates(Server master, TableStateManager tableStateManager, ServerManager serverManager, RegionStateStore regionStateStore)
public Map<HRegionInfo,ServerName> getRegionAssignments()
Map<ServerName,List<HRegionInfo>> getRegionAssignments(Collection<HRegionInfo> regions)
regions
- public ServerName getRegionServerOfRegion(HRegionInfo hri)
public Map<String,RegionState> getRegionsInTransition()
public boolean isRegionInTransition(HRegionInfo hri)
public boolean isRegionInTransition(String encodedName)
public boolean isRegionsInTransition()
public boolean isRegionOnline(HRegionInfo hri)
public boolean isRegionOffline(HRegionInfo hri)
public boolean isRegionInState(HRegionInfo hri, RegionState.State... states)
public boolean isRegionInState(String encodedName, RegionState.State... states)
public void waitForUpdate(long timeout) throws InterruptedException
InterruptedException
public RegionState getRegionTransitionState(HRegionInfo hri)
public RegionState getRegionTransitionState(String encodedName)
public void createRegionStates(List<HRegionInfo> hris)
public RegionState createRegionState(HRegionInfo hri)
public RegionState createRegionState(HRegionInfo hri, RegionState.State newState, ServerName serverName, ServerName lastHost)
hri
- the region info to create a state fornewState
- the state to the region in set toserverName
- the server the region is transitioning onlastHost
- the last server that hosts the regionprivate RegionState putRegionState(RegionState regionState)
public RegionState setRegionStateTOCLOSED(byte[] regionName, ServerName serverName)
public RegionState setRegionStateTOCLOSED(HRegionInfo regionInfo, ServerName serverName)
public RegionState updateRegionState(HRegionInfo hri, RegionState.State state)
public RegionState updateRegionState(RegionTransition transition, RegionState.State state)
public RegionState transitionOpenFromPendingOpenOrOpeningOnServer(RegionTransition transition, RegionState fromState, ServerName sn)
public RegionState updateRegionState(HRegionInfo hri, RegionState.State state, ServerName serverName)
public void regionOnline(HRegionInfo hri, ServerName serverName)
public void regionOnline(HRegionInfo hri, ServerName serverName, long openSeqNum)
private void addToServerHoldings(ServerName serverName, HRegionInfo hri)
private void addToReplicaMapping(HRegionInfo hri)
private void removeFromServerHoldings(ServerName serverName, HRegionInfo hri)
private void removeFromReplicaMapping(HRegionInfo hri)
boolean existsInServerHoldings(ServerName serverName, HRegionInfo hri)
public void logSplit(ServerName serverName)
public void logSplit(HRegionInfo region)
public void clearLastAssignment(HRegionInfo region)
public void regionOffline(HRegionInfo hri)
public void regionOffline(HRegionInfo hri, RegionState.State expectedState)
public List<HRegionInfo> serverOffline(ZooKeeperWatcher watcher, ServerName sn)
private void cleanFailedSplitMergeRegions(Set<HRegionInfo> hris)
hris
- The hris to check if empty in hbase:meta and if so, clean them up.public List<HRegionInfo> getRegionsOfTable(TableName tableName)
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.tableName
- tableName
public Map<RegionState.State,List<HRegionInfo>> getRegionByStateOfTable(TableName tableName)
hbase:meta
.
Method guaranteed to return keys for all states
in RegionState.State
tableName
- tableName
public void waitOnRegionToClearRegionsInTransition(HRegionInfo hri) throws InterruptedException
If the region isn't in transition, returns immediately. Otherwise, method blocks until the region is out of transition.
InterruptedException
public void tableDeleted(TableName tableName)
public Set<HRegionInfo> getServerRegions(ServerName serverName)
public void deleteRegion(HRegionInfo hri)
public boolean isRegionInRegionStates(HRegionInfo hri)
boolean wasRegionOnDeadServer(String encodedName)
boolean isServerDeadAndNotProcessed(ServerName server)
ServerName getLastRegionServerOfRegion(String encodedName)
void setLastRegionServerOfRegions(ServerName serverName, List<HRegionInfo> regionInfos)
void setLastRegionServerOfRegion(ServerName serverName, String encodedName)
void splitRegion(HRegionInfo p, HRegionInfo a, HRegionInfo b, ServerName sn) throws IOException
IOException
void mergeRegions(HRegionInfo p, HRegionInfo a, HRegionInfo b, ServerName sn) throws IOException
IOException
private int getRegionReplication(HRegionInfo r) throws IOException
IOException
Map<HRegionInfo,ServerName> closeAllUserRegions(Set<TableName> excludedTables)
protected double getAverageLoad()
protected Map<TableName,Map<ServerName,List<HRegionInfo>>> getAssignmentsByTable()
protected RegionState getRegionState(HRegionInfo hri)
protected Map<ServerName,List<HRegionInfo>> getRegionAssignmentsByServer()
protected RegionState getRegionState(String encodedName)
protected HRegionInfo getRegionInfo(byte[] regionName)
regionName
- static boolean isOneOfStates(RegionState regionState, RegionState.State... states)
private RegionState updateRegionState(HRegionInfo hri, RegionState.State state, ServerName serverName, long openSeqNum)
Copyright © 2007–2019 The Apache Software Foundation. All rights reserved.