Package org.apache.hadoop.hbase.util
Class RegionMover
java.lang.Object
org.apache.hadoop.hbase.util.AbstractHBaseTool
org.apache.hadoop.hbase.util.RegionMover
- All Implemented Interfaces:
Closeable
,AutoCloseable
,org.apache.hadoop.conf.Configurable
,org.apache.hadoop.util.Tool
Tool for loading/unloading regions to/from given regionserver This tool can be run from Command
line directly as a utility. Supports Ack/No Ack mode for loading/unloading operations.Ack mode
acknowledges if regions are online after movement while noAck mode is best effort mode that
improves performance but will still move on if region is stuck/not moved. Motivation behind noAck
mode being RS shutdown where even if a Region is stuck, upon shutdown master will move it
anyways. This can also be used by constructiong an Object using the builder and then calling
load()
or unload()
methods for the desired operations.-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
Builder for Region mover.Nested classes/interfaces inherited from class org.apache.hadoop.hbase.util.AbstractHBaseTool
AbstractHBaseTool.OptionsOrderComparator
-
Field Summary
Modifier and TypeFieldDescriptionprivate boolean
private Admin
private Connection
static final int
static final int
static final int
private String
private String
private String
private String
private String
private static final org.slf4j.Logger
private int
static final String
static final String
private int
private RackManager
private RegionMover.RegionMoverBuilder
static final String
private int
Fields inherited from class org.apache.hadoop.hbase.util.AbstractHBaseTool
cmdLineArgs, conf, EXIT_FAILURE, EXIT_SUCCESS, LONG_HELP_OPTION, options, SHORT_HELP_OPTION
-
Constructor Summary
ModifierConstructorDescriptionprivate
private
-
Method Summary
Modifier and TypeMethodDescriptionprotected void
Override this to add command-line options usingAbstractHBaseTool.addOptWithArg(java.lang.String, java.lang.String)
and similar methods.void
close()
private void
deleteFile
(String filename) protected int
doWork()
The "main function" of the tool(package private) Collection<ServerName>
filterRSGroupServers
(RSGroupInfo rsgroup, Collection<ServerName> onlineServers) private Optional<RegionInfo>
getMetaRegionInfoIfToBeMoved
(List<RegionInfo> regionsToMove) getRegionsMovePlan
(boolean moveMetaRegion) private ServerName
private boolean
private void
includeExcludeRegionServers
(String fileName, List<ServerName> regionServers, boolean isInclude) Designates or excludes the servername whose hostname and port portion matches the list given in the file.boolean
Isolated regions specified inisolateRegionIdArray
onhostname
in ack Mode and Unload regions from givenhostname
using ack/noAck mode andmaxthreads
.boolean
load()
Loads the specifiedhostname
with regions listed in thefilename
RegionMover Object has to be created usingRegionMover(RegionMoverBuilder)
private void
loadRegions
(List<RegionInfo> regionsToMove) static void
protected void
processOptions
(org.apache.hbase.thirdparty.org.apache.commons.cli.CommandLine cmd) This method is called to process the options after they have been parsed.private List<RegionInfo>
readRegionsFromFile
(String filename) readServersFromFile
(String filename) private void
stripMaster
(List<ServerName> regionServers) Exclude master from list of RSs to move regions toprivate ServerName
stripServer
(List<ServerName> regionServers, String hostname, int port) Remove the servername whose hostname and port portion matches from the passed array of servers.private void
submitRegionMovesWhileUnloading
(ServerName server, List<ServerName> regionServers, List<RegionInfo> movedRegions, List<RegionInfo> regionsToMove, boolean forceMoveRegionByAck) boolean
unload()
Unload regions from givenhostname
using ack/noAck mode andmaxthreads
.In noAck mode we do not make sure that region is successfully online on the target region server,hence it is best effort.We do not unload regions to hostnames given inexcludeFile
.boolean
Unload regions from givenhostname
using ack/noAck mode andmaxthreads
.In noAck mode we do not make sure that region is successfully online on the target region server,hence it is best effort.We do not unload regions to hostnames given inexcludeFile
.private boolean
unloadRegions
(boolean unloadFromRack) private boolean
unloadRegions
(boolean unloadFromRack, List<String> isolateRegionIdArray) private void
unloadRegions
(ServerName server, List<ServerName> regionServers, List<RegionInfo> movedRegions, List<String> isolateRegionIdArray) private void
waitMoveTasksToFinish
(ExecutorService moveRegionsPool, List<Future<Boolean>> taskList, long timeoutInSeconds) private boolean
waitTaskToFinish
(ExecutorService pool, Future<Boolean> task, String operation) private void
writeFile
(String filename, List<RegionInfo> movedRegions) Write the number of regions moved in the first line followed by regions moved in subsequent linesMethods inherited from class org.apache.hadoop.hbase.util.AbstractHBaseTool
addOption, addOptNoArg, addOptNoArg, addOptWithArg, addOptWithArg, addRequiredOption, addRequiredOptWithArg, addRequiredOptWithArg, doStaticMain, getConf, getOptionAsDouble, getOptionAsInt, getOptionAsInt, getOptionAsLong, getOptionAsLong, newParser, parseArgs, parseInt, parseLong, printUsage, printUsage, processOldArgs, run, setConf
-
Field Details
-
MOVE_RETRIES_MAX_KEY
- See Also:
-
MOVE_WAIT_MAX_KEY
- See Also:
-
SERVERSTART_WAIT_MAX_KEY
- See Also:
-
DEFAULT_MOVE_RETRIES_MAX
- See Also:
-
DEFAULT_MOVE_WAIT_MAX
- See Also:
-
DEFAULT_SERVERSTART_WAIT_MAX
- See Also:
-
LOG
-
rmbuilder
-
ack
-
maxthreads
-
timeout
-
isolateRegionIdArray
-
loadUnload
-
hostname
-
filename
-
excludeFile
-
designatedFile
-
port
-
conn
-
admin
-
rackManager
-
-
Constructor Details
-
RegionMover
- Throws:
IOException
-
RegionMover
private RegionMover()
-
-
Method Details
-
close
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
-
load
Loads the specifiedhostname
with regions listed in thefilename
RegionMover Object has to be created usingRegionMover(RegionMoverBuilder)
- Returns:
- true if loading succeeded, false otherwise
- Throws:
ExecutionException
InterruptedException
TimeoutException
-
getMetaRegionMovePlan
-
getNonMetaRegionsMovePlan
-
getRegionsMovePlan
-
getMetaRegionInfoIfToBeMoved
-
loadRegions
- Throws:
Exception
-
unload
Unload regions from givenhostname
using ack/noAck mode andmaxthreads
.In noAck mode we do not make sure that region is successfully online on the target region server,hence it is best effort.We do not unload regions to hostnames given inexcludeFile
. If designatedFile is present with some contents, we will unload regions to hostnames provided indesignatedFile
- Returns:
- true if unloading succeeded, false otherwise
- Throws:
InterruptedException
ExecutionException
TimeoutException
-
unloadFromRack
Unload regions from givenhostname
using ack/noAck mode andmaxthreads
.In noAck mode we do not make sure that region is successfully online on the target region server,hence it is best effort.We do not unload regions to hostnames given inexcludeFile
. If designatedFile is present with some contents, we will unload regions to hostnames provided indesignatedFile
. While unloading regions, destination RegionServers are selected from different rack i.e regions should not move to any RegionServers that belong to same rack as source RegionServer.- Returns:
- true if unloading succeeded, false otherwise
- Throws:
InterruptedException
ExecutionException
TimeoutException
-
unloadRegions
private boolean unloadRegions(boolean unloadFromRack) throws ExecutionException, InterruptedException, TimeoutException -
isolateRegions
Isolated regions specified inisolateRegionIdArray
onhostname
in ack Mode and Unload regions from givenhostname
using ack/noAck mode andmaxthreads
. In noAck mode we do not make sure that region is successfully online on the target region server,hence it is the best effort. We do not unload regions to hostnames given inexcludeFile
. If designatedFile is present with some contents, we will unload regions to hostnames provided indesignatedFile
- Returns:
- true if region isolation succeeded, false otherwise
- Throws:
ExecutionException
InterruptedException
TimeoutException
-
unloadRegions
private boolean unloadRegions(boolean unloadFromRack, List<String> isolateRegionIdArray) throws InterruptedException, ExecutionException, TimeoutException -
filterRSGroupServers
@Private Collection<ServerName> filterRSGroupServers(RSGroupInfo rsgroup, Collection<ServerName> onlineServers) -
unloadRegions
private void unloadRegions(ServerName server, List<ServerName> regionServers, List<RegionInfo> movedRegions, List<String> isolateRegionIdArray) throws Exception - Throws:
Exception
-
submitRegionMovesWhileUnloading
private void submitRegionMovesWhileUnloading(ServerName server, List<ServerName> regionServers, List<RegionInfo> movedRegions, List<RegionInfo> regionsToMove, boolean forceMoveRegionByAck) throws Exception - Throws:
Exception
-
waitTaskToFinish
private boolean waitTaskToFinish(ExecutorService pool, Future<Boolean> task, String operation) throws TimeoutException, InterruptedException, ExecutionException -
waitMoveTasksToFinish
private void waitMoveTasksToFinish(ExecutorService moveRegionsPool, List<Future<Boolean>> taskList, long timeoutInSeconds) throws Exception - Throws:
Exception
-
ignoreRegionMoveFailure
-
getTargetServer
- Throws:
Exception
-
readRegionsFromFile
- Throws:
IOException
-
writeFile
Write the number of regions moved in the first line followed by regions moved in subsequent lines- Throws:
IOException
-
deleteFile
-
readServersFromFile
- Parameters:
filename
- The file should have 'host:port' per line- Returns:
- List of servers from the file in format 'hostname:port'.
- Throws:
IOException
-
includeExcludeRegionServers
private void includeExcludeRegionServers(String fileName, List<ServerName> regionServers, boolean isInclude) throws IOException Designates or excludes the servername whose hostname and port portion matches the list given in the file. Example:
If you want to designated RSs, suppose designatedFile has RS1, regionServers has RS1, RS2 and RS3. When we call includeExcludeRegionServers(designatedFile, regionServers, true), RS2 and RS3 are removed from regionServers list so that regions can move to only RS1. If you want to exclude RSs, suppose excludeFile has RS1, regionServers has RS1, RS2 and RS3. When we call includeExcludeRegionServers(excludeFile, servers, false), RS1 is removed from regionServers list so that regions can move to only RS2 and RS3.- Throws:
IOException
-
stripMaster
Exclude master from list of RSs to move regions to- Throws:
IOException
-
stripServer
Remove the servername whose hostname and port portion matches from the passed array of servers. Returns as side-effect the servername removed.- Returns:
- server removed from list of Region Servers
-
addOptions
Description copied from class:AbstractHBaseTool
Override this to add command-line options usingAbstractHBaseTool.addOptWithArg(java.lang.String, java.lang.String)
and similar methods.- Specified by:
addOptions
in classAbstractHBaseTool
-
processOptions
Description copied from class:AbstractHBaseTool
This method is called to process the options after they have been parsed.- Specified by:
processOptions
in classAbstractHBaseTool
-
doWork
Description copied from class:AbstractHBaseTool
The "main function" of the tool- Specified by:
doWork
in classAbstractHBaseTool
- Throws:
Exception
-
main
-