HBASE-12013 Support multiple regionservers per host in region_mover.rb
Signed-off-by: Elliott Clark <eclark@apache.org>
This commit is contained in:
parent
6813167423
commit
b26ec4e3df
|
@ -20,8 +20,6 @@
|
||||||
# not move a new region until successful confirm of region loading in new
|
# not move a new region until successful confirm of region loading in new
|
||||||
# location. Presumes balancer is disabled when we run (not harmful if its
|
# location. Presumes balancer is disabled when we run (not harmful if its
|
||||||
# on but this script and balancer will end up fighting each other).
|
# on but this script and balancer will end up fighting each other).
|
||||||
# Does not work for case of multiple regionservers all running on the
|
|
||||||
# one node.
|
|
||||||
require 'optparse'
|
require 'optparse'
|
||||||
require File.join(File.dirname(__FILE__), 'thread-pool')
|
require File.join(File.dirname(__FILE__), 'thread-pool')
|
||||||
include Java
|
include Java
|
||||||
|
@ -194,15 +192,9 @@ def move(admin, r, newServer, original)
|
||||||
java.lang.String.format("%.3f", (Time.now - start)))
|
java.lang.String.format("%.3f", (Time.now - start)))
|
||||||
end
|
end
|
||||||
|
|
||||||
# Return the hostname portion of a servername (all up to first ',')
|
# Return the hostname:port out of a servername (all up to second ',')
|
||||||
def getHostnamePortFromServerName(serverName)
|
def getHostPortFromServerName(serverName)
|
||||||
parts = serverName.split(',')
|
return serverName.split(',')[0..1]
|
||||||
return parts[0] + ":" + parts[1]
|
|
||||||
end
|
|
||||||
|
|
||||||
# Return the hostname:port out of a servername (all up to first ',')
|
|
||||||
def getHostnameFromServerName(serverName)
|
|
||||||
return serverName.split(',')[0]
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Return array of servernames where servername is hostname+port+startcode
|
# Return array of servernames where servername is hostname+port+startcode
|
||||||
|
@ -218,16 +210,17 @@ end
|
||||||
|
|
||||||
# Remove the servername whose hostname portion matches from the passed
|
# Remove the servername whose hostname portion matches from the passed
|
||||||
# array of servers. Returns as side-effect the servername removed.
|
# array of servers. Returns as side-effect the servername removed.
|
||||||
def stripServer(servers, hostname)
|
def stripServer(servers, hostname, port)
|
||||||
count = servers.length
|
count = servers.length
|
||||||
servername = nil
|
servername = nil
|
||||||
for server in servers
|
for server in servers
|
||||||
if getHostnameFromServerName(server) == hostname
|
hostFromServerName, portFromServerName = getHostPortFromServerName(server)
|
||||||
|
if hostFromServerName == hostname and portFromServerName == port
|
||||||
servername = servers.delete(server)
|
servername = servers.delete(server)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
# Check server to exclude is actually present
|
# Check server to exclude is actually present
|
||||||
raise RuntimeError, "Server %s not online" % hostname unless servers.length < count
|
raise RuntimeError, "Server %s:%d not online" % [hostname, port] unless servers.length < count
|
||||||
return servername
|
return servername
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -235,22 +228,25 @@ end
|
||||||
# matches from the passed array of servers.
|
# matches from the passed array of servers.
|
||||||
def stripExcludes(servers, excludefile)
|
def stripExcludes(servers, excludefile)
|
||||||
excludes = readExcludes(excludefile)
|
excludes = readExcludes(excludefile)
|
||||||
servers = servers.find_all{|server| !excludes.contains(getHostnameFromServerName(server)) }
|
servers = servers.find_all{|server|
|
||||||
|
!excludes.contains(getHostPortFromServerName(server).join(":"))
|
||||||
|
}
|
||||||
# return updated servers list
|
# return updated servers list
|
||||||
return servers
|
return servers
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
# Return servername that matches passed hostname
|
# Return servername that matches passed hostname and port
|
||||||
def getServerName(servers, hostname)
|
def getServerName(servers, hostname, port)
|
||||||
servername = nil
|
servername = nil
|
||||||
for server in servers
|
for server in servers
|
||||||
if getHostnameFromServerName(server) == hostname
|
hostFromServerName, portFromServerName = getHostPortFromServerName(server)
|
||||||
|
if hostFromServerName == hostname and portFromServerName == port
|
||||||
servername = server
|
servername = server
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
raise ArgumentError, "Server %s not online" % hostname unless servername
|
raise ArgumentError, "Server %s:%d not online" % [hostname, port] unless servername
|
||||||
return servername
|
return servername
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -321,19 +317,21 @@ def readFile(filename)
|
||||||
return regions
|
return regions
|
||||||
end
|
end
|
||||||
|
|
||||||
# Move regions off the passed hostname
|
# Move regions off the passed hostname:port
|
||||||
def unloadRegions(options, hostname)
|
def unloadRegions(options, hostname, port)
|
||||||
# Get configuration
|
# Get configuration
|
||||||
config = getConfiguration()
|
config = getConfiguration()
|
||||||
# Clean up any old files.
|
# Clean up any old files.
|
||||||
filename = getFilename(options, hostname)
|
filename = getFilename(options, hostname, port)
|
||||||
deleteFile(filename)
|
deleteFile(filename)
|
||||||
# Get an admin instance
|
# Get an admin instance
|
||||||
admin = HBaseAdmin.new(config)
|
admin = HBaseAdmin.new(config)
|
||||||
|
port = config.getInt(HConstants::REGIONSERVER_PORT, HConstants::DEFAULT_REGIONSERVER_PORT) \
|
||||||
|
unless port
|
||||||
servers = getServers(admin)
|
servers = getServers(admin)
|
||||||
# Remove the server we are unloading from from list of servers.
|
# Remove the server we are unloading from from list of servers.
|
||||||
# Side-effect is the servername that matches this hostname
|
# Side-effect is the servername that matches this hostname
|
||||||
servername = stripServer(servers, hostname)
|
servername = stripServer(servers, hostname, port)
|
||||||
|
|
||||||
# Remove the servers in our exclude list from list of servers.
|
# Remove the servers in our exclude list from list of servers.
|
||||||
servers = stripExcludes(servers, options[:excludesFile])
|
servers = stripExcludes(servers, options[:excludesFile])
|
||||||
|
@ -379,12 +377,14 @@ def unloadRegions(options, hostname)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Move regions to the passed hostname
|
# Move regions to the passed hostname
|
||||||
def loadRegions(options, hostname)
|
def loadRegions(options, hostname, port)
|
||||||
# Get configuration
|
# Get configuration
|
||||||
config = getConfiguration()
|
config = getConfiguration()
|
||||||
# Get an admin instance
|
# Get an admin instance
|
||||||
admin = HBaseAdmin.new(config)
|
admin = HBaseAdmin.new(config)
|
||||||
filename = getFilename(options, hostname)
|
port = config.getInt(HConstants::REGIONSERVER_PORT, HConstants::DEFAULT_REGIONSERVER_PORT) \
|
||||||
|
unless port
|
||||||
|
filename = getFilename(options, hostname, port)
|
||||||
regions = readFile(filename)
|
regions = readFile(filename)
|
||||||
return if regions.isEmpty()
|
return if regions.isEmpty()
|
||||||
servername = nil
|
servername = nil
|
||||||
|
@ -394,9 +394,9 @@ def loadRegions(options, hostname)
|
||||||
while Time.now < maxWait
|
while Time.now < maxWait
|
||||||
servers = getServers(admin)
|
servers = getServers(admin)
|
||||||
begin
|
begin
|
||||||
servername = getServerName(servers, hostname)
|
servername = getServerName(servers, hostname, port)
|
||||||
rescue ArgumentError => e
|
rescue ArgumentError => e
|
||||||
$LOG.info("hostname=" + hostname.to_s + " is not up yet, waiting");
|
$LOG.info("hostname=" + hostname.to_s + ":" + port.to_s + " is not up yet, waiting");
|
||||||
end
|
end
|
||||||
break if servername
|
break if servername
|
||||||
sleep 0.5
|
sleep 0.5
|
||||||
|
@ -458,10 +458,10 @@ def readExcludes(filename)
|
||||||
return excludes
|
return excludes
|
||||||
end
|
end
|
||||||
|
|
||||||
def getFilename(options, targetServer)
|
def getFilename(options, targetServer, port)
|
||||||
filename = options[:file]
|
filename = options[:file]
|
||||||
if not filename
|
if not filename
|
||||||
filename = "/tmp/" + ENV['USER'] + targetServer
|
filename = "/tmp/" + ENV['USER'] + targetServer + ":" + port
|
||||||
end
|
end
|
||||||
return filename
|
return filename
|
||||||
end
|
end
|
||||||
|
@ -470,11 +470,11 @@ end
|
||||||
# Do command-line parsing
|
# Do command-line parsing
|
||||||
options = {}
|
options = {}
|
||||||
optparse = OptionParser.new do |opts|
|
optparse = OptionParser.new do |opts|
|
||||||
opts.banner = "Usage: #{NAME}.rb [options] load|unload <hostname>"
|
opts.banner = "Usage: #{NAME}.rb [options] load|unload [<hostname>|<hostname:port>]"
|
||||||
opts.separator 'Load or unload regions by moving one at a time'
|
opts.separator 'Load or unload regions by moving one at a time'
|
||||||
options[:file] = nil
|
options[:file] = nil
|
||||||
options[:maxthreads] = 1
|
options[:maxthreads] = 1
|
||||||
opts.on('-f', '--filename=FILE', 'File to save regions list into unloading, or read from loading; default /tmp/<hostname>') do |file|
|
opts.on('-f', '--filename=FILE', 'File to save regions list into unloading, or read from loading; default /tmp/<hostname:port>') do |file|
|
||||||
options[:file] = file
|
options[:file] = file
|
||||||
end
|
end
|
||||||
opts.on('-h', '--help', 'Display usage information') do
|
opts.on('-h', '--help', 'Display usage information') do
|
||||||
|
@ -499,7 +499,7 @@ if ARGV.length < 2
|
||||||
puts optparse
|
puts optparse
|
||||||
exit 1
|
exit 1
|
||||||
end
|
end
|
||||||
hostname = ARGV[1]
|
hostname, port = ARGV[1].split(":")
|
||||||
if not hostname
|
if not hostname
|
||||||
opts optparse
|
opts optparse
|
||||||
exit 2
|
exit 2
|
||||||
|
@ -508,9 +508,9 @@ end
|
||||||
$LOG = configureLogging(options)
|
$LOG = configureLogging(options)
|
||||||
case ARGV[0]
|
case ARGV[0]
|
||||||
when 'load'
|
when 'load'
|
||||||
loadRegions(options, hostname)
|
loadRegions(options, hostname, port)
|
||||||
when 'unload'
|
when 'unload'
|
||||||
unloadRegions(options, hostname)
|
unloadRegions(options, hostname, port)
|
||||||
else
|
else
|
||||||
puts optparse
|
puts optparse
|
||||||
exit 3
|
exit 3
|
||||||
|
|
Loading…
Reference in New Issue