From c797583d613bac648f974e1301f8bfc8c788d8a0 Mon Sep 17 00:00:00 2001 From: haxiaolin Date: Thu, 16 May 2019 11:08:59 +0800 Subject: [PATCH] HBASE-22411 Refactor codes of moving reigons in RSGroup --- .../hadoop/hbase/rsgroup/RSGroupAdminServer.java | 97 ++++++++++------------ 1 file changed, 43 insertions(+), 54 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..e937a31318 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 @@ -61,8 +61,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,7 +198,7 @@ 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 */ @@ -210,7 +209,7 @@ public class RSGroupAdminServer implements RSGroupAdmin { Set
allSevers = new HashSet<>(servers); do { foundRegionsToMove = false; - for (Iterator
iter = allSevers.iterator(); iter.hasNext();) { + for (Iterator
iter = allSevers.iterator(); iter.hasNext(); ) { Address rs = iter.next(); // Get regions that are associated with this server and filter regions by tables. List regions = new ArrayList<>(); @@ -220,21 +219,9 @@ public class RSGroupAdminServer implements RSGroupAdmin { } } - LOG.info("Moving " + regions.size() + " region(s) from " + rs + - " for server move to " + targetGroupName); - if (!regions.isEmpty()) { - for (RegionInfo region: regions) { - // Regions might get assigned from tables of target group so we need to filter - if (!targetGrp.containsTable(region.getTable())) { - this.master.getAssignmentManager().move(region); - if (master.getAssignmentManager().getRegionStates(). - getRegionState(region).isFailedOpen()) { - continue; - } - foundRegionsToMove = true; - } - } - } + LOG.info("Moving " + regions.size() + " region(s) from " + rs + " for server move to " + + targetGroupName); + foundRegionsToMove = bulkMoveRegions(regions, targetGrp); if (!foundRegionsToMove) { iter.remove(); } @@ -248,23 +235,41 @@ public class RSGroupAdminServer implements RSGroupAdmin { } while (foundRegionsToMove); } + private boolean bulkMoveRegions(List regions, RSGroupInfo targetGroup) + throws IOException { + for (RegionInfo region : regions) { + // Regions might get assigned from tables of target group so we need to filter + if (!targetGroup.containsTable(region.getTable())) { + this.master.getAssignmentManager().move(region); + if (!master.getAssignmentManager().getRegionStates(). + getRegionState(region).isFailedOpen()) { + return true; + } + } + } + return false; + } + /** - * 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, + private void moveTableRegionsNotOnServers(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) { + 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); } } @@ -338,22 +343,7 @@ public class RSGroupAdminServer implements RSGroupAdmin { 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; - } + foundRegionsToMove = bulkMoveRegions(regions, targetGrp); if (!foundRegionsToMove) { iter.remove(); } @@ -412,17 +402,16 @@ public class RSGroupAdminServer implements RSGroupAdmin { 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 { + moveTableRegionsNotOnServers(null, tables, targetGroupName); + } + @Override public void addRSGroup(String name) throws IOException { rsGroupInfoManager.addRSGroup(new RSGroupInfo(name)); @@ -550,10 +539,10 @@ 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 + //move regions on these servers which do not belong to these tables moveRegionsFromServers(servers, tables, targetGroup); - //move regions which should belong to these servers - moveRegionsToServers(servers, tables, targetGroup); + //move regions of these tables which are not on these servers + moveTableRegionsNotOnServers(servers, tables, targetGroup); } LOG.info("Move servers and tables done. Severs :" + servers + " , Tables : " + tables + " => " + targetGroup); -- 2.14.1