Skip to content

Commit

Permalink
HBASE-22658 region_mover.rb should choose same rsgroup servers as tar…
Browse files Browse the repository at this point in the history
…get servers

Co-authored-by: Reid Chan <[email protected]>
Signed-off-by: stack <[email protected]>
Signed-off-by: Andrew Purtell <[email protected]>
Signed-off-by: Reid Chan <[email protected]>
  • Loading branch information
carrey-feng and Reidddddd committed Jul 26, 2019
1 parent 2be03e1 commit 1930856
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions bin/region_mover.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@
import org.apache.hadoop.hbase.protobuf.ProtobufUtil
import org.apache.hadoop.hbase.ServerName
import org.apache.hadoop.hbase.HRegionInfo
import org.apache.hadoop.hbase.rsgroup.RSGroupAdmin
import org.apache.hadoop.hbase.rsgroup.RSGroupAdminClient
import org.apache.hadoop.hbase.client.ConnectionFactory
import org.apache.hadoop.hbase.net.Address

# Name of this script
NAME = "region_mover"
Expand Down Expand Up @@ -299,6 +303,17 @@ def unloadRegions(options, hostname, port)
# Get an admin instance
admin = HBaseAdmin.new(config)
servers = getServers(admin)
# If rsgroup enable, get servers belongs to the same rsgroup as given server
if isEnableRSGroup(admin)
$LOG.info("RegionServer group is enabled.")
begin
conn = ConnectionFactory.createConnection(config)
rsgroupAdmin = RSGroupAdminClient.new(conn)
servers = getSameRSGroupServers(servers, rsgroupAdmin, hostname, port)
ensure
conn.close()
end
end
# Remove the server we are unloading from from list of servers.
# Side-effect is the servername that matches this hostname
servername = stripServer(servers, hostname, port)
Expand Down Expand Up @@ -432,6 +447,29 @@ def getFilename(options, targetServer, port)
return filename
end

# Get servers in the same regionserver group as the given server
def getSameRSGroupServers(servers, rsgroupAdmin, hostname, port)
results = []
rsgroup = rsgroupAdmin.getRSGroupOfServer(Address.fromParts(hostname,
java.lang.Integer.parseInt(port)))
# rsgroup must be default or others, can't be nil
$LOG.info("Getting servers list from group: " + rsgroup.getName())
rsservers = rsgroup.getServers()
servers.each do |server|
servername = ServerName.parseServerName(server)
tmp = Address.fromParts(servername.getHostname(), servername.getPort())
if rsservers.contains(tmp)
results << servername.getServerName()
end
end
return results
end

# Determine whether rsgroup has been enabled
def isEnableRSGroup(admin)
coprocessors = java.util.Arrays.asList(admin.getMasterCoprocessors());
return coprocessors.contains("RSGroupAdminEndpoint")
end

# Do command-line parsing
options = {}
Expand Down

0 comments on commit 1930856

Please sign in to comment.