Package org.apache.hadoop.hbase.rsgroup
Class RSGroupInfoManagerImpl
java.lang.Object
org.apache.hadoop.hbase.rsgroup.RSGroupInfoManagerImpl
- All Implemented Interfaces:
RSGroupInfoManager
This is an implementation of
RSGroupInfoManager
which makes use of an HBase table as the
persistence store for the group information. It also makes use of zookeeper to store group
information needed for bootstrapping during offline mode.
Concurrency
RSGroup state is kept locally in Maps. There is a rsgroup name to cached RSGroupInfo Map atRSGroupInfoManagerImpl.RSGroupInfoHolder.groupName2Group
. These Maps are persisted to the
hbase:rsgroup table (and cached in zk) on each modification.
Mutations on state are synchronized but reads can continue without having to wait on an instance
monitor, mutations do wholesale replace of the Maps on update -- Copy-On-Write; the local Maps of
state are read-only, just-in-case (see flushConfig).
Reads must not block else there is a danger we'll deadlock.
Clients of this class, the RSGroupAdminEndpoint
for example, want to query and then act
on the results of the query modifying cache in zookeeper without another thread making
intermediate modifications. These clients synchronize on the 'this' instance so no other has
access concurrently. Reads must be able to continue concurrently.-
Nested Class Summary
Modifier and TypeClassDescriptionprivate static final class
(package private) static class
private class
-
Field Summary
Modifier and TypeFieldDescriptionprivate final AsyncClusterConnection
(package private) static final int
Define the default number of retries(package private) static final String
Define the config key of retries threshold when movements failed(package private) static final String
private static final org.slf4j.Logger
private final MasterServices
(package private) static final byte[]
(package private) static final byte[]
(package private) static final String
private static final byte[]
private static final String
private static final TableDescriptor
Table descriptor forhbase:rsgroup
catalog table(package private) static final TableName
private final RSGroupInfoManagerImpl.RSGroupStartupWorker
private final ZKWatcher
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprivate void
addRegion
(LinkedList<RegionInfo> regions, RegionInfo hri) void
addRSGroup
(RSGroupInfo rsGroupInfo) Add given RSGroupInfo to existing list of group infos.balanceRSGroup
(String groupName, BalanceRequest request) Balance a region server group.private void
checkForDeadOrOnlineServers
(Set<Address> servers) Check if the set of servers are belong to dead servers list or online servers list.private void
checkGroupName
(String groupName) private void
checkOnlineServersOnly
(Set<Address> servers) determineRSGroupInfoForTable
(TableName tableName) DetermineRSGroupInfo
for the given table.private void
private void
flushConfig
(Map<String, RSGroupInfo> newGroupMap) private void
flushConfigTable
(Map<String, RSGroupInfo> groupMap) getDefaultServers
(List<RSGroupInfo> rsGroupInfoList) (package private) static RSGroupInfoManager
getInstance
(MasterServices masterServices) Returns Set of online Servers named for their hostname and port (not ServerName).private List<RegionInfo>
getRegions
(Address server) Returns List of Regions associated with thisserver
.getRSGroup
(String groupName) GetsRSGroupInfo
for the given group name.(package private) Map<TableName,
Map<ServerName, List<RegionInfo>>> getRSGroupAssignmentsByTable
(TableStateManager tableStateManager, String groupName) This is an EXPENSIVE clone.getRSGroupForTable
(TableName tableName) GetRSGroupInfo
for the given table.private RSGroupInfo
getRSGroupInfo
(String groupName) getRSGroupOfServer
(Address serverHostPort) Gets the group info of server.private void
init()
private static boolean
isMasterRunning
(MasterServices masterServices) boolean
isOnline()
Whether the manager is able to fully return group metadataprivate boolean
isTableInGroup
(TableName tableName, String groupName, Set<TableName> tablesInGroupCache) List the existingRSGroupInfo
s.private void
migrate()
private void
migrate
(Collection<RSGroupInfo> groupList) private <T> void
moveRegionsBetweenGroups
(Set<T> regionsOwners, Set<Address> newRegionsOwners, String targetGroupName, String sourceGroupName, Function<T, List<RegionInfo>> getRegionsInfo, Function<RegionInfo, Boolean> validation) private void
moveServerRegionsFromGroup
(Set<Address> movedServers, Set<Address> srcGrpServers, String targetGroupName, String sourceGroupName) Move every region from servers which are currently located on these servers, but should not be located there.void
moveServers
(Set<Address> servers, String targetGroupName) Move servers to a new group.moveServers
(Set<Address> servers, String srcGroup, String dstGroup) private void
moveTablesAndWait
(Set<TableName> tables, String targetGroup) private void
multiMutate
(List<Mutation> mutations) private void
refresh
(boolean forceOnline) Read rsgroup info from the source of truth, the hbase:rsgroup table.void
removeRSGroup
(String groupName) Remove a region server group.void
removeServers
(Set<Address> servers) Remove decommissioned servers from rsgroupvoid
renameRSGroup
(String oldName, String newName) Rename rsgroupprivate void
resetRSGroupMap
(Map<String, RSGroupInfo> newRSGroupMap) Make changes visible.private List<RSGroupInfo>
private List<RSGroupInfo>
private Map<String,
RegionState> rsGroupGetRegionsInTransition
(String groupName) private void
saveRSGroupMapToZK
(Map<String, RSGroupInfo> newGroupMap) void
setRSGroup
(Set<TableName> tables, String groupName) Set group for tables.void
start()
private void
updateCacheOfRSGroups
(Set<String> currentGroups) Update cache of rsgroups.private void
void
updateRSGroupConfig
(String groupName, Map<String, String> configuration) Update RSGroup configurationprivate void
waitForRegionMovement
(List<Pair<RegionInfo, Future<byte[]>>> regionMoveFutures, Set<String> failedRegions, String sourceGroupName, int retryCount) Wait for all the region move to complete.
-
Field Details
-
LOG
-
RSGROUP_TABLE_NAME
-
KEEP_ONE_SERVER_IN_DEFAULT_ERROR_MESSAGE
- See Also:
-
FAILED_MOVE_MAX_RETRY
Define the config key of retries threshold when movements failed- See Also:
-
DEFAULT_MAX_RETRY_VALUE
Define the default number of retries- See Also:
-
RS_GROUP_ZNODE
- See Also:
-
META_FAMILY_BYTES
-
META_QUALIFIER_BYTES
-
MIGRATE_THREAD_NAME
- See Also:
-
ROW_KEY
-
RSGROUP_TABLE_DESC
Table descriptor forhbase:rsgroup
catalog table -
holder
-
masterServices
-
conn
-
watcher
-
rsGroupStartupWorker
-
prevRSGroups
-
script
-
-
Constructor Details
-
RSGroupInfoManagerImpl
-
-
Method Details
-
updateDefaultServers
-
init
- Throws:
IOException
-
getInstance
- Throws:
IOException
-
start
- Specified by:
start
in interfaceRSGroupInfoManager
-
addRSGroup
Description copied from interface:RSGroupInfoManager
Add given RSGroupInfo to existing list of group infos.- Specified by:
addRSGroup
in interfaceRSGroupInfoManager
- Throws:
IOException
-
getRSGroupInfo
- Throws:
ConstraintException
-
getOnlineServers
Returns Set of online Servers named for their hostname and port (not ServerName). -
moveServers
public Set<Address> moveServers(Set<Address> servers, String srcGroup, String dstGroup) throws IOException - Throws:
IOException
-
getRSGroupOfServer
Description copied from interface:RSGroupInfoManager
Gets the group info of server.- Specified by:
getRSGroupOfServer
in interfaceRSGroupInfoManager
-
getRSGroup
Description copied from interface:RSGroupInfoManager
GetsRSGroupInfo
for the given group name.- Specified by:
getRSGroup
in interfaceRSGroupInfoManager
-
removeRSGroup
Description copied from interface:RSGroupInfoManager
Remove a region server group.- Specified by:
removeRSGroup
in interfaceRSGroupInfoManager
- Throws:
IOException
-
listRSGroups
Description copied from interface:RSGroupInfoManager
List the existingRSGroupInfo
s.- Specified by:
listRSGroups
in interfaceRSGroupInfoManager
-
isOnline
Description copied from interface:RSGroupInfoManager
Whether the manager is able to fully return group metadata- Specified by:
isOnline
in interfaceRSGroupInfoManager
- Returns:
- whether the manager is in online mode
-
removeServers
Description copied from interface:RSGroupInfoManager
Remove decommissioned servers from rsgroup- Specified by:
removeServers
in interfaceRSGroupInfoManager
- Parameters:
servers
- set of servers to remove- Throws:
IOException
-
retrieveGroupListFromGroupTable
- Throws:
IOException
-
retrieveGroupListFromZookeeper
- Throws:
IOException
-
migrate
-
migrate
-
refresh
Read rsgroup info from the source of truth, the hbase:rsgroup table. Update zk cache. Called on startup of the manager.- Throws:
IOException
-
flushConfigTable
- Throws:
IOException
-
flushConfig
- Throws:
IOException
-
flushConfig
- Throws:
IOException
-
saveRSGroupMapToZK
- Throws:
IOException
-
resetRSGroupMap
Make changes visible. Caller must be synchronized on 'this'. -
updateCacheOfRSGroups
Update cache of rsgroups. Caller must be synchronized on 'this'.- Parameters:
currentGroups
- Current list of Groups.
-
getDefaultServers
-
getDefaultServers
-
isMasterRunning
-
multiMutate
- Throws:
IOException
-
checkGroupName
- Throws:
ConstraintException
-
getRSGroupForTable
Description copied from interface:RSGroupInfoManager
GetRSGroupInfo
for the given table.- Specified by:
getRSGroupForTable
in interfaceRSGroupInfoManager
- Throws:
IOException
-
checkForDeadOrOnlineServers
Check if the set of servers are belong to dead servers list or online servers list.- Parameters:
servers
- servers to remove- Throws:
IOException
-
checkOnlineServersOnly
- Throws:
IOException
-
getRegions
Returns List of Regions associated with thisserver
. -
addRegion
-
moveServerRegionsFromGroup
private void moveServerRegionsFromGroup(Set<Address> movedServers, Set<Address> srcGrpServers, String targetGroupName, String sourceGroupName) throws IOException Move every region from servers which are currently located on these servers, but should not be located there.- Parameters:
movedServers
- the servers that are moved to new groupsrcGrpServers
- all servers in the source group, excluding the movedServerstargetGroupName
- the target groupsourceGroupName
- the source group- Throws:
IOException
- if moving the server and tables fail
-
moveRegionsBetweenGroups
private <T> void moveRegionsBetweenGroups(Set<T> regionsOwners, Set<Address> newRegionsOwners, String targetGroupName, String sourceGroupName, Function<T, List<RegionInfo>> getRegionsInfo, Function<RegionInfo, throws IOExceptionBoolean> validation) - Throws:
IOException
-
waitForRegionMovement
private void waitForRegionMovement(List<Pair<RegionInfo, Future<byte[]>>> regionMoveFutures, Set<String> failedRegions, String sourceGroupName, int retryCount) Wait for all the region move to complete. Keep waiting for other region movement completion even if some region movement fails. -
isTableInGroup
private boolean isTableInGroup(TableName tableName, String groupName, Set<TableName> tablesInGroupCache) throws IOException - Throws:
IOException
-
rsGroupGetRegionsInTransition
- Throws:
IOException
-
getRSGroupAssignmentsByTable
Map<TableName,Map<ServerName, getRSGroupAssignmentsByTableList<RegionInfo>>> (TableStateManager tableStateManager, String groupName) throws IOException 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. Load balancer should iterate over this list because cloned list will ignore disabled table and split parent region cases. This method is invoked bybalanceRSGroup(java.lang.String, org.apache.hadoop.hbase.client.BalanceRequest)
- Returns:
- A clone of current assignments for this group.
- Throws:
IOException
-
balanceRSGroup
Description copied from interface:RSGroupInfoManager
Balance a region server group.- Specified by:
balanceRSGroup
in interfaceRSGroupInfoManager
- Throws:
IOException
-
moveTablesAndWait
- Throws:
IOException
-
setRSGroup
Description copied from interface:RSGroupInfoManager
Set group for tables.- Specified by:
setRSGroup
in interfaceRSGroupInfoManager
- Throws:
IOException
-
moveServers
Description copied from interface:RSGroupInfoManager
Move servers to a new group.- Specified by:
moveServers
in interfaceRSGroupInfoManager
- Throws:
IOException
-
determineRSGroupInfoForTable
Description copied from interface:RSGroupInfoManager
DetermineRSGroupInfo
for the given table.- Specified by:
determineRSGroupInfoForTable
in interfaceRSGroupInfoManager
- Parameters:
tableName
- table name- Returns:
- rsgroup name
-
renameRSGroup
Description copied from interface:RSGroupInfoManager
Rename rsgroup- Specified by:
renameRSGroup
in interfaceRSGroupInfoManager
- Parameters:
oldName
- old rsgroup namenewName
- new rsgroup name- Throws:
IOException
-
updateRSGroupConfig
public void updateRSGroupConfig(String groupName, Map<String, String> configuration) throws IOExceptionDescription copied from interface:RSGroupInfoManager
Update RSGroup configuration- Specified by:
updateRSGroupConfig
in interfaceRSGroupInfoManager
- Parameters:
groupName
- the group nameconfiguration
- new configuration of the group name to be set- Throws:
IOException
- if a remote or network exception occurs
-