From f380bd6189b77fd239f97d08cebbe63303a6c590 Mon Sep 17 00:00:00 2001 From: haxiaolin Date: Fri, 24 May 2019 16:32:42 +0800 Subject: [PATCH] HBASE-22411 Refactor codes of moving reigons in RSGroup --- .../hadoop/hbase/rsgroup/RSGroupAdminServer.java | 106 ++++++--------------- 1 file changed, 31 insertions(+), 75 deletions(-) diff --git a/hbase-rsgroup/src/main/java/org/apache/hadoop/hbase/rsgroup/RSGroupAdminServer.java b/hbase-rsgroup/src/main/java/org/apache/hadoop/hbase/rsgroup/RSGroupAdminServer.java index 20eb32700b..c595f33e1c 100644 --- a/hbase-rsgroup/src/main/java/org/apache/hadoop/hbase/rsgroup/RSGroupAdminServer.java +++ b/hbase-rsgroup/src/main/java/org/apache/hadoop/hbase/rsgroup/RSGroupAdminServer.java @@ -46,7 +46,6 @@ import org.apache.yetus.audience.InterfaceAudience; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.apache.hbase.thirdparty.com.google.common.collect.Lists; import org.apache.hbase.thirdparty.com.google.common.collect.Maps; /** @@ -61,8 +60,7 @@ public class RSGroupAdminServer implements RSGroupAdmin { private MasterServices master; private final RSGroupInfoManager rsGroupInfoManager; - public RSGroupAdminServer(MasterServices master, RSGroupInfoManager rsGroupInfoManager) - throws IOException { + public RSGroupAdminServer(MasterServices master, RSGroupInfoManager rsGroupInfoManager) { this.master = master; this.rsGroupInfoManager = rsGroupInfoManager; } @@ -199,11 +197,11 @@ public class RSGroupAdminServer implements RSGroupAdmin { * Moves every region from servers which are currently located on these servers, * but should not be located there. * @param servers the servers that will move to new group - * @param tables these tables will be kept on the servers, others will be moved + * @param tables regions of these tables will be kept on these servers, others will be moved * @param targetGroupName the target group name * @throws IOException if moving the server and tables fail */ - private void moveRegionsFromServers(Set
servers, Set tables, + private void moveRegionsFromServersExcludeTables(Set
servers, Set tables, String targetGroupName) throws IOException { boolean foundRegionsToMove; RSGroupInfo targetGrp = getRSGroupInfo(targetGroupName); @@ -215,7 +213,7 @@ public class RSGroupAdminServer implements RSGroupAdmin { // Get regions that are associated with this server and filter regions by tables. List regions = new ArrayList<>(); for (RegionInfo region : getRegions(rs)) { - if (!tables.contains(region.getTable())) { + if (tables == null || tables.isEmpty() || !tables.contains(region.getTable())) { regions.add(region); } } @@ -249,22 +247,29 @@ public class RSGroupAdminServer implements RSGroupAdmin { } /** - * Moves every region of tables which should be kept on the servers, - * but currently they are located on other servers. - * @param servers the regions of these servers will be kept on the servers, others will be moved + * Moves regions of tables which are not on target group servers. + * The passed server set is a part of target group servers. + * @param servers table regions on these severs will be kept, others will be moved; + * null or empty means all the regions of tables should be moved * @param tables the tables that will move to new group * @param targetGroupName the target group name * @throws IOException if moving the region fails */ private void moveRegionsToServers(Set
servers, Set tables, String targetGroupName) throws IOException { - for (TableName table: tables) { - LOG.info("Moving region(s) from " + table + " for table move to " + targetGroupName); + for (TableName table : tables) { + if (master.getAssignmentManager().isTableDisabled(table)) { + LOG.debug("Skipping move regions because the table" + table + " is disabled."); + continue; + } + LOG.info("Moving region(s) for table " + table + " to " + targetGroupName); for (RegionInfo region : master.getAssignmentManager().getRegionStates() - .getRegionsOfTable(table)) { - ServerName sn = master.getAssignmentManager().getRegionStates() - .getRegionServerOfRegion(region); - if (!servers.contains(sn.getAddress())) { + .getRegionsOfTable(table)) { + ServerName sn = + master.getAssignmentManager().getRegionStates().getRegionServerOfRegion(region); + if (servers == null || servers.isEmpty() || !servers.contains(sn.getAddress())) { + LOG.info("Moving region " + region.getShortNameToLog() + " to RSGroup " + + targetGroupName); master.getAssignmentManager().move(region); } } @@ -285,7 +290,8 @@ public class RSGroupAdminServer implements RSGroupAdmin { // TODO. Why? Stuff breaks if I equate them. return; } - RSGroupInfo targetGrp = getAndCheckRSGroupInfo(targetGroupName); + //check target group + getAndCheckRSGroupInfo(targetGroupName); // Hold a lock on the manager instance while moving servers to prevent // another writer changing our state while we are working. @@ -326,46 +332,7 @@ public class RSGroupAdminServer implements RSGroupAdmin { // MovedServers may be < passed in 'servers'. Set
movedServers = rsGroupInfoManager.moveServers(servers, srcGrp.getName(), targetGroupName); - List
editableMovedServers = Lists.newArrayList(movedServers); - boolean foundRegionsToMove; - do { - foundRegionsToMove = false; - for (Iterator
iter = editableMovedServers.iterator(); iter.hasNext();) { - Address rs = iter.next(); - // Get regions that are associated with this server. - List regions = getRegions(rs); - - LOG.info("Moving " + regions.size() + " region(s) from " + rs + - " for server move to " + targetGroupName); - - for (RegionInfo region: regions) { - // Regions might get assigned from tables of target group so we need to filter - if (targetGrp.containsTable(region.getTable())) { - continue; - } - LOG.info("Moving region " + region.getShortNameToLog()); - this.master.getAssignmentManager().move(region); - if (master.getAssignmentManager().getRegionStates(). - getRegionState(region).isFailedOpen()) { - // If region is in FAILED_OPEN state, it won't recover, not without - // operator intervention... in hbase-2.0.0 at least. Continue rather - // than mark region as 'foundRegionsToMove'. - continue; - } - foundRegionsToMove = true; - } - if (!foundRegionsToMove) { - iter.remove(); - } - } - try { - rsGroupInfoManager.wait(1000); - } catch (InterruptedException e) { - LOG.warn("Sleep interrupted", e); - Thread.currentThread().interrupt(); - } - } while (foundRegionsToMove); - + moveRegionsFromServersExcludeTables(movedServers, null, targetGroupName); LOG.info("Move server done: " + srcGrp.getName() + "=>" + targetGroupName); } } @@ -404,25 +371,14 @@ public class RSGroupAdminServer implements RSGroupAdmin { } rsGroupInfoManager.moveTables(tables, targetGroup); - // targetGroup is null when a table is being deleted. In this case no further - // action is required. - if (targetGroup != null) { - for (TableName table: tables) { - if (master.getAssignmentManager().isTableDisabled(table)) { - LOG.debug("Skipping move regions because the table" + table + " is disabled."); - continue; - } - for (RegionInfo region : - master.getAssignmentManager().getRegionStates().getRegionsOfTable(table)) { - LOG.info("Moving region " + region.getShortNameToLog() + - " to RSGroup " + targetGroup); - master.getAssignmentManager().move(region); - } - } - } + bulkMoveRegions(tables, targetGroup); } } + private void bulkMoveRegions(Set tables, String targetGroupName) throws IOException { + moveRegionsToServers(null, tables, targetGroupName); + } + @Override public void addRSGroup(String name) throws IOException { rsGroupInfoManager.addRSGroup(new RSGroupInfo(name)); @@ -550,9 +506,9 @@ public class RSGroupAdminServer implements RSGroupAdmin { String srcGroup = getRSGroupOfServer(servers.iterator().next()).getName(); rsGroupInfoManager.moveServersAndTables(servers, tables, srcGroup, targetGroup); - //move regions which should not belong to these tables - moveRegionsFromServers(servers, tables, targetGroup); - //move regions which should belong to these servers + //move regions on these servers which do not belong to these tables + moveRegionsFromServersExcludeTables(servers, tables, targetGroup); + //move regions of these tables which are not on these servers moveRegionsToServers(servers, tables, targetGroup); } LOG.info("Move servers and tables done. Severs :" -- 2.14.1