From c24cf2d55ecd479c89b0613b6ebbdaba4eb793ad Mon Sep 17 00:00:00 2001 From: Jan Hentschel Date: Sat, 23 Dec 2017 00:52:08 +0100 Subject: [PATCH] HBASE-19601 Fixed Checkstyle errors in hbase-rsgroup and enabled Checkstyle to fail on violations --- .../hbase/checkstyle-suppressions.xml | 1 + hbase-rsgroup/pom.xml | 16 +++++++ .../hadoop/hbase/rsgroup/RSGroupAdmin.java | 4 +- .../hbase/rsgroup/RSGroupAdminClient.java | 5 +- .../hbase/rsgroup/RSGroupAdminEndpoint.java | 17 ++++--- .../hbase/rsgroup/RSGroupAdminServer.java | 48 +++++++++++-------- .../rsgroup/RSGroupBasedLoadBalancer.java | 17 ++++--- .../hbase/rsgroup/RSGroupInfoManager.java | 3 +- .../hbase/rsgroup/RSGroupInfoManagerImpl.java | 7 +-- .../hbase/rsgroup/RSGroupProtobufUtil.java | 9 ++-- .../hbase/rsgroup/RSGroupableBalancer.java | 2 +- .../apache/hadoop/hbase/rsgroup/Utility.java | 14 ++++-- .../TestRSGroupBasedLoadBalancer.java | 29 ++--------- .../hadoop/hbase/rsgroup/TestRSGroups.java | 5 +- .../hbase/rsgroup/TestRSGroupsBase.java | 32 +++++++++---- .../rsgroup/VerifyingRSGroupAdminClient.java | 25 +++++----- 16 files changed, 137 insertions(+), 97 deletions(-) diff --git a/hbase-checkstyle/src/main/resources/hbase/checkstyle-suppressions.xml b/hbase-checkstyle/src/main/resources/hbase/checkstyle-suppressions.xml index 1ecae86f4ed..b9c9b212ef5 100644 --- a/hbase-checkstyle/src/main/resources/hbase/checkstyle-suppressions.xml +++ b/hbase-checkstyle/src/main/resources/hbase/checkstyle-suppressions.xml @@ -35,4 +35,5 @@ + diff --git a/hbase-rsgroup/pom.xml b/hbase-rsgroup/pom.xml index dba581046ee..16c198b69a7 100644 --- a/hbase-rsgroup/pom.xml +++ b/hbase-rsgroup/pom.xml @@ -68,6 +68,22 @@ + + org.apache.maven.plugins + maven-checkstyle-plugin + + + checkstyle + validate + + check + + + true + + + + diff --git a/hbase-rsgroup/src/main/java/org/apache/hadoop/hbase/rsgroup/RSGroupAdmin.java b/hbase-rsgroup/src/main/java/org/apache/hadoop/hbase/rsgroup/RSGroupAdmin.java index 453ef54f24c..9ea996be1cc 100644 --- a/hbase-rsgroup/src/main/java/org/apache/hadoop/hbase/rsgroup/RSGroupAdmin.java +++ b/hbase-rsgroup/src/main/java/org/apache/hadoop/hbase/rsgroup/RSGroupAdmin.java @@ -22,8 +22,8 @@ import java.util.List; import java.util.Set; import org.apache.hadoop.hbase.TableName; -import org.apache.yetus.audience.InterfaceAudience; import org.apache.hadoop.hbase.net.Address; +import org.apache.yetus.audience.InterfaceAudience; /** * Group user API interface used between client and server. @@ -84,7 +84,7 @@ public interface RSGroupAdmin { * @param servers set of servers to move * @param tables set of tables to move * @param targetGroup the target group name - * @throws IOException + * @throws IOException if moving the server and tables fail */ void moveServersAndTables(Set
servers, Set tables, String targetGroup) throws IOException; diff --git a/hbase-rsgroup/src/main/java/org/apache/hadoop/hbase/rsgroup/RSGroupAdminClient.java b/hbase-rsgroup/src/main/java/org/apache/hadoop/hbase/rsgroup/RSGroupAdminClient.java index be83a7b1e93..e39fe761dd1 100644 --- a/hbase-rsgroup/src/main/java/org/apache/hadoop/hbase/rsgroup/RSGroupAdminClient.java +++ b/hbase-rsgroup/src/main/java/org/apache/hadoop/hbase/rsgroup/RSGroupAdminClient.java @@ -17,13 +17,14 @@ */ package org.apache.hadoop.hbase.rsgroup; +import com.google.protobuf.ServiceException; + import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.util.Set; import org.apache.hadoop.hbase.TableName; -import org.apache.yetus.audience.InterfaceAudience; import org.apache.hadoop.hbase.client.Connection; import org.apache.hadoop.hbase.net.Address; import org.apache.hadoop.hbase.protobuf.ProtobufUtil; @@ -44,9 +45,9 @@ import org.apache.hadoop.hbase.protobuf.generated.RSGroupAdminProtos.RSGroupAdmi import org.apache.hadoop.hbase.protobuf.generated.RSGroupAdminProtos.RemoveRSGroupRequest; import org.apache.hadoop.hbase.protobuf.generated.RSGroupAdminProtos.RemoveServersRequest; import org.apache.hadoop.hbase.protobuf.generated.RSGroupProtos; +import org.apache.yetus.audience.InterfaceAudience; import org.apache.hadoop.hbase.shaded.com.google.common.collect.Sets; -import com.google.protobuf.ServiceException; /** * Client used for managing region server group information. diff --git a/hbase-rsgroup/src/main/java/org/apache/hadoop/hbase/rsgroup/RSGroupAdminEndpoint.java b/hbase-rsgroup/src/main/java/org/apache/hadoop/hbase/rsgroup/RSGroupAdminEndpoint.java index 75588408e40..4ee6a17147f 100644 --- a/hbase-rsgroup/src/main/java/org/apache/hadoop/hbase/rsgroup/RSGroupAdminEndpoint.java +++ b/hbase-rsgroup/src/main/java/org/apache/hadoop/hbase/rsgroup/RSGroupAdminEndpoint.java @@ -18,6 +18,10 @@ package org.apache.hadoop.hbase.rsgroup; +import com.google.protobuf.RpcCallback; +import com.google.protobuf.RpcController; +import com.google.protobuf.Service; + import java.io.IOException; import java.util.Collections; import java.util.HashSet; @@ -26,10 +30,6 @@ import java.util.Optional; import java.util.Set; import java.util.stream.Collectors; -import com.google.protobuf.RpcCallback; -import com.google.protobuf.RpcController; -import com.google.protobuf.Service; - import org.apache.hadoop.hbase.CoprocessorEnvironment; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.NamespaceDescriptor; @@ -74,11 +74,12 @@ import org.apache.hadoop.hbase.protobuf.generated.RSGroupAdminProtos.RemoveRSGro import org.apache.hadoop.hbase.protobuf.generated.RSGroupAdminProtos.RemoveRSGroupResponse; import org.apache.hadoop.hbase.protobuf.generated.RSGroupAdminProtos.RemoveServersRequest; import org.apache.hadoop.hbase.protobuf.generated.RSGroupAdminProtos.RemoveServersResponse; -import org.apache.hadoop.hbase.shaded.com.google.common.collect.Sets; import org.apache.yetus.audience.InterfaceAudience; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.apache.hadoop.hbase.shaded.com.google.common.collect.Sets; + // TODO: Encapsulate MasterObserver functions into separate subclass. @CoreCoprocessor @InterfaceAudience.Private @@ -231,7 +232,8 @@ public class RSGroupAdminEndpoint implements MasterCoprocessor, MasterObserver { public void balanceRSGroup(RpcController controller, BalanceRSGroupRequest request, RpcCallback done) { BalanceRSGroupResponse.Builder builder = BalanceRSGroupResponse.newBuilder(); - LOG.info(master.getClientIdAuditPrefix() + " balance rsgroup, group=" + request.getRSGroupName()); + LOG.info(master.getClientIdAuditPrefix() + " balance rsgroup, group=" + + request.getRSGroupName()); try { builder.setBalanceRan(groupAdminServer.balanceRSGroup(request.getRSGroupName())); } catch (IOException e) { @@ -263,7 +265,8 @@ public class RSGroupAdminEndpoint implements MasterCoprocessor, MasterObserver { try { Address hp = Address.fromParts(request.getServer().getHostName(), request.getServer().getPort()); - LOG.info(master.getClientIdAuditPrefix() + " initiates rsgroup info retrieval, server=" + hp); + LOG.info(master.getClientIdAuditPrefix() + " initiates rsgroup info retrieval, server=" + + hp); RSGroupInfo RSGroupInfo = groupAdminServer.getRSGroupOfServer(hp); if (RSGroupInfo != null) { builder.setRSGroupInfo(RSGroupProtobufUtil.toProtoGroupInfo(RSGroupInfo)); 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 b4d35e306c8..df30709fb64 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 @@ -43,12 +43,13 @@ import org.apache.hadoop.hbase.master.ServerManager; import org.apache.hadoop.hbase.master.assignment.AssignmentManager; import org.apache.hadoop.hbase.master.assignment.RegionStates.RegionStateNode; import org.apache.hadoop.hbase.net.Address; -import org.apache.hadoop.hbase.shaded.com.google.common.collect.Lists; -import org.apache.hadoop.hbase.shaded.com.google.common.collect.Maps; import org.apache.yetus.audience.InterfaceAudience; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.apache.hadoop.hbase.shaded.com.google.common.collect.Lists; +import org.apache.hadoop.hbase.shaded.com.google.common.collect.Maps; + /** * Service to support Region Server Grouping (HBase-6721). */ @@ -116,7 +117,10 @@ public class RSGroupAdminServer implements RSGroupAdmin { LinkedList regions = new LinkedList<>(); for (Map.Entry el : master.getAssignmentManager().getRegionStates().getRegionAssignments().entrySet()) { - if (el.getValue() == null) continue; + if (el.getValue() == null) { + continue; + } + if (el.getValue().getAddress().equals(server)) { addRegion(regions, el.getKey()); } @@ -133,17 +137,20 @@ public class RSGroupAdminServer implements RSGroupAdmin { // If meta, move it last otherwise other unassigns fail because meta is not // online for them to update state in. This is dodgy. Needs to be made more // robust. See TODO below. - if (hri.isMetaRegion()) regions.addLast(hri); - else regions.addFirst(hri); + if (hri.isMetaRegion()) { + regions.addLast(hri); + } else { + regions.addFirst(hri); + } } /** * Check servers and tables. - * Fail if nulls or if servers and tables not belong to the same group + * * @param servers servers to move * @param tables tables to move * @param targetGroupName target group name - * @throws IOException + * @throws IOException if nulls or if servers and tables not belong to the same group */ private void checkServersAndTables(Set
servers, Set tables, String targetGroupName) throws IOException { @@ -157,7 +164,7 @@ public class RSGroupAdminServer implements RSGroupAdmin { } RSGroupInfo srcGrp = new RSGroupInfo(tmpSrcGrp); if (srcGrp.getName().equals(targetGroupName)) { - throw new ConstraintException( "Target RSGroup " + targetGroupName + + throw new ConstraintException("Target RSGroup " + targetGroupName + " is same as source " + srcGrp.getName() + " RSGroup."); } // Only move online servers @@ -181,8 +188,7 @@ public class RSGroupAdminServer implements RSGroupAdmin { } } - if (srcGrp.getServers().size() <= servers.size() - && srcGrp.getTables().size() > tables.size() ) { + if (srcGrp.getServers().size() <= servers.size() && srcGrp.getTables().size() > tables.size()) { throw new ConstraintException("Cannot leave a RSGroup " + srcGrp.getName() + " that contains tables without servers to host them."); } @@ -194,7 +200,7 @@ public class RSGroupAdminServer implements RSGroupAdmin { * @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 targetGroupName the target group name - * @throws IOException + * @throws IOException if moving the server and tables fail */ private void moveRegionsFromServers(Set
servers, Set tables, String targetGroupName) throws IOException { @@ -244,18 +250,19 @@ 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 + * @param servers the regions of these servers will be kept on the servers, others will be moved * @param tables the tables that will move to new group * @param targetGroupName the target group name - * @throws IOException + * @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 (RegionInfo region : master.getAssignmentManager().getRegionStates().getRegionsOfTable(table)) { - ServerName sn = master.getAssignmentManager().getRegionStates().getRegionServerOfRegion(region); + for (RegionInfo region : master.getAssignmentManager().getRegionStates() + .getRegionsOfTable(table)) { + ServerName sn = master.getAssignmentManager().getRegionStates() + .getRegionServerOfRegion(region); if (!servers.contains(sn.getAddress())) { master.getAssignmentManager().move(region); } @@ -294,7 +301,7 @@ public class RSGroupAdminServer implements RSGroupAdmin { + " does not exist."); } if (srcGrp.getName().equals(targetGroupName)) { - throw new ConstraintException( "Target RSGroup " + targetGroupName + + throw new ConstraintException("Target RSGroup " + targetGroupName + " is same as source " + srcGrp + " RSGroup."); } // Only move online servers (when moving from 'default') or servers from other @@ -482,7 +489,10 @@ public class RSGroupAdminServer implements RSGroupAdmin { synchronized (balancer) { // If balance not true, don't run balancer. - if (!((HMaster) master).isBalancerOn()) return false; + if (!((HMaster) master).isBalancerOn()) { + return false; + } + if (master.getMasterCoprocessorHost() != null) { master.getMasterCoprocessorHost().preBalanceRSGroup(groupName); } @@ -547,7 +557,7 @@ public class RSGroupAdminServer implements RSGroupAdmin { @Override public void moveServersAndTables(Set
servers, Set tables, String targetGroup) throws IOException { - if (servers == null || servers.isEmpty() ) { + if (servers == null || servers.isEmpty()) { throw new ConstraintException("The list of servers to move cannot be null or empty."); } if (tables == null || tables.isEmpty()) { diff --git a/hbase-rsgroup/src/main/java/org/apache/hadoop/hbase/rsgroup/RSGroupBasedLoadBalancer.java b/hbase-rsgroup/src/main/java/org/apache/hadoop/hbase/rsgroup/RSGroupBasedLoadBalancer.java index a228a768e51..9579257b3d0 100644 --- a/hbase-rsgroup/src/main/java/org/apache/hadoop/hbase/rsgroup/RSGroupBasedLoadBalancer.java +++ b/hbase-rsgroup/src/main/java/org/apache/hadoop/hbase/rsgroup/RSGroupBasedLoadBalancer.java @@ -43,16 +43,17 @@ import org.apache.hadoop.hbase.master.MasterServices; import org.apache.hadoop.hbase.master.RegionPlan; import org.apache.hadoop.hbase.master.balancer.StochasticLoadBalancer; import org.apache.hadoop.hbase.net.Address; +import org.apache.hadoop.util.ReflectionUtils; +import org.apache.yetus.audience.InterfaceAudience; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import org.apache.hadoop.hbase.shaded.com.google.common.annotations.VisibleForTesting; import org.apache.hadoop.hbase.shaded.com.google.common.collect.ArrayListMultimap; import org.apache.hadoop.hbase.shaded.com.google.common.collect.LinkedListMultimap; import org.apache.hadoop.hbase.shaded.com.google.common.collect.ListMultimap; import org.apache.hadoop.hbase.shaded.com.google.common.collect.Lists; import org.apache.hadoop.hbase.shaded.com.google.common.collect.Maps; -import org.apache.hadoop.util.ReflectionUtils; -import org.apache.yetus.audience.InterfaceAudience; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; /** * GroupBasedLoadBalancer, used when Region Server Grouping is configured (HBase-6721) @@ -324,8 +325,7 @@ public class RSGroupBasedLoadBalancer implements RSGroupableBalancer { } private ServerName findServerForRegion( - Map> existingAssignments, RegionInfo region) - { + Map> existingAssignments, RegionInfo region) { for (Map.Entry> entry : existingAssignments.entrySet()) { if (entry.getValue().contains(region)) { return entry.getKey(); @@ -392,7 +392,10 @@ public class RSGroupBasedLoadBalancer implements RSGroupableBalancer { } public boolean isOnline() { - if (this.rsGroupInfoManager == null) return false; + if (this.rsGroupInfoManager == null) { + return false; + } + return this.rsGroupInfoManager.isOnline(); } diff --git a/hbase-rsgroup/src/main/java/org/apache/hadoop/hbase/rsgroup/RSGroupInfoManager.java b/hbase-rsgroup/src/main/java/org/apache/hadoop/hbase/rsgroup/RSGroupInfoManager.java index 5eee236f297..77aefbd903d 100644 --- a/hbase-rsgroup/src/main/java/org/apache/hadoop/hbase/rsgroup/RSGroupInfoManager.java +++ b/hbase-rsgroup/src/main/java/org/apache/hadoop/hbase/rsgroup/RSGroupInfoManager.java @@ -18,16 +18,15 @@ package org.apache.hadoop.hbase.rsgroup; - import java.io.IOException; import java.util.List; import java.util.Set; import org.apache.hadoop.hbase.NamespaceDescriptor; import org.apache.hadoop.hbase.TableName; +import org.apache.hadoop.hbase.net.Address; import org.apache.hadoop.hbase.util.Bytes; import org.apache.yetus.audience.InterfaceAudience; -import org.apache.hadoop.hbase.net.Address; /** * Interface used to manage RSGroupInfo storage. An implementation diff --git a/hbase-rsgroup/src/main/java/org/apache/hadoop/hbase/rsgroup/RSGroupInfoManagerImpl.java b/hbase-rsgroup/src/main/java/org/apache/hadoop/hbase/rsgroup/RSGroupInfoManagerImpl.java index 67dfde729f4..56867bf8686 100644 --- a/hbase-rsgroup/src/main/java/org/apache/hadoop/hbase/rsgroup/RSGroupInfoManagerImpl.java +++ b/hbase-rsgroup/src/main/java/org/apache/hadoop/hbase/rsgroup/RSGroupInfoManagerImpl.java @@ -18,6 +18,8 @@ package org.apache.hadoop.hbase.rsgroup; +import com.google.protobuf.ServiceException; + import java.io.ByteArrayInputStream; import java.io.IOException; import java.util.ArrayList; @@ -81,14 +83,13 @@ import org.apache.yetus.audience.InterfaceAudience; import org.apache.zookeeper.KeeperException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; + import org.apache.hadoop.hbase.shaded.com.google.common.collect.Lists; import org.apache.hadoop.hbase.shaded.com.google.common.collect.Maps; import org.apache.hadoop.hbase.shaded.com.google.common.collect.Sets; import org.apache.hadoop.hbase.shaded.protobuf.RequestConverter; import org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos; -import com.google.protobuf.ServiceException; - /** * This is an implementation of {@link RSGroupInfoManager} which makes * use of an HBase table as the persistence store for the group information. @@ -114,7 +115,7 @@ import com.google.protobuf.ServiceException; * no other has access concurrently. Reads must be able to continue concurrently. */ @InterfaceAudience.Private -class RSGroupInfoManagerImpl implements RSGroupInfoManager { +final class RSGroupInfoManagerImpl implements RSGroupInfoManager { private static final Logger LOG = LoggerFactory.getLogger(RSGroupInfoManagerImpl.class); /** Table descriptor for hbase:rsgroup catalog table */ diff --git a/hbase-rsgroup/src/main/java/org/apache/hadoop/hbase/rsgroup/RSGroupProtobufUtil.java b/hbase-rsgroup/src/main/java/org/apache/hadoop/hbase/rsgroup/RSGroupProtobufUtil.java index 30f64272f39..56e35e76197 100644 --- a/hbase-rsgroup/src/main/java/org/apache/hadoop/hbase/rsgroup/RSGroupProtobufUtil.java +++ b/hbase-rsgroup/src/main/java/org/apache/hadoop/hbase/rsgroup/RSGroupProtobufUtil.java @@ -21,15 +21,18 @@ package org.apache.hadoop.hbase.rsgroup; import java.util.ArrayList; import java.util.List; -import org.apache.yetus.audience.InterfaceAudience; import org.apache.hadoop.hbase.TableName; import org.apache.hadoop.hbase.net.Address; -import org.apache.hadoop.hbase.protobuf.generated.HBaseProtos; import org.apache.hadoop.hbase.protobuf.ProtobufUtil; +import org.apache.hadoop.hbase.protobuf.generated.HBaseProtos; import org.apache.hadoop.hbase.protobuf.generated.RSGroupProtos; +import org.apache.yetus.audience.InterfaceAudience; @InterfaceAudience.Private -class RSGroupProtobufUtil { +final class RSGroupProtobufUtil { + private RSGroupProtobufUtil() { + } + static RSGroupInfo toGroupInfo(RSGroupProtos.RSGroupInfo proto) { RSGroupInfo RSGroupInfo = new RSGroupInfo(proto.getName()); for(HBaseProtos.ServerName el: proto.getServersList()) { diff --git a/hbase-rsgroup/src/main/java/org/apache/hadoop/hbase/rsgroup/RSGroupableBalancer.java b/hbase-rsgroup/src/main/java/org/apache/hadoop/hbase/rsgroup/RSGroupableBalancer.java index 90f45ac29af..d091b3cfbde 100644 --- a/hbase-rsgroup/src/main/java/org/apache/hadoop/hbase/rsgroup/RSGroupableBalancer.java +++ b/hbase-rsgroup/src/main/java/org/apache/hadoop/hbase/rsgroup/RSGroupableBalancer.java @@ -18,8 +18,8 @@ package org.apache.hadoop.hbase.rsgroup; -import org.apache.yetus.audience.InterfaceAudience; import org.apache.hadoop.hbase.master.LoadBalancer; +import org.apache.yetus.audience.InterfaceAudience; /** * Marker Interface. RSGroups feature will check for a LoadBalancer diff --git a/hbase-rsgroup/src/main/java/org/apache/hadoop/hbase/rsgroup/Utility.java b/hbase-rsgroup/src/main/java/org/apache/hadoop/hbase/rsgroup/Utility.java index f0c699828ad..4d7bf43ba5d 100644 --- a/hbase-rsgroup/src/main/java/org/apache/hadoop/hbase/rsgroup/Utility.java +++ b/hbase-rsgroup/src/main/java/org/apache/hadoop/hbase/rsgroup/Utility.java @@ -23,22 +23,28 @@ import java.util.HashSet; import java.util.Set; import org.apache.hadoop.hbase.ServerName; -import org.apache.yetus.audience.InterfaceAudience; import org.apache.hadoop.hbase.master.MasterServices; import org.apache.hadoop.hbase.net.Address; +import org.apache.yetus.audience.InterfaceAudience; /** * Utility for this RSGroup package in hbase-rsgroup. */ @InterfaceAudience.Private -class Utility { +final class Utility { + private Utility() { + } + /** - * @param master + * @param master the master to get online servers for * @return Set of online Servers named for their hostname and port (not ServerName). */ static Set
getOnlineServers(final MasterServices master) { Set
onlineServers = new HashSet
(); - if (master == null) return onlineServers; + if (master == null) { + return onlineServers; + } + for(ServerName server: master.getServerManager().getOnlineServers().keySet()) { onlineServers.add(server.getAddress()); } diff --git a/hbase-rsgroup/src/test/java/org/apache/hadoop/hbase/master/balancer/TestRSGroupBasedLoadBalancer.java b/hbase-rsgroup/src/test/java/org/apache/hadoop/hbase/master/balancer/TestRSGroupBasedLoadBalancer.java index 797022c169a..da74e7d1b42 100644 --- a/hbase-rsgroup/src/test/java/org/apache/hadoop/hbase/master/balancer/TestRSGroupBasedLoadBalancer.java +++ b/hbase-rsgroup/src/test/java/org/apache/hadoop/hbase/master/balancer/TestRSGroupBasedLoadBalancer.java @@ -74,8 +74,7 @@ public class TestRSGroupBasedLoadBalancer { private static RSGroupBasedLoadBalancer loadBalancer; private static SecureRandom rand; - static String[] groups = new String[] { RSGroupInfo.DEFAULT_GROUP, "dg2", "dg3", - "dg4" }; + static String[] groups = new String[] { RSGroupInfo.DEFAULT_GROUP, "dg2", "dg3", "dg4" }; static TableName[] tables = new TableName[] { TableName.valueOf("dt1"), TableName.valueOf("dt2"), @@ -110,8 +109,6 @@ public class TestRSGroupBasedLoadBalancer { * * Invariant is that all servers of the group should be hosting either floor(average) or * ceiling(average) - * - * @throws Exception */ @Test public void testBalanceCluster() throws Exception { @@ -163,12 +160,6 @@ public class TestRSGroupBasedLoadBalancer { /** * All regions have an assignment. - * - * @param regions - * @param servers - * @param assignments - * @throws java.io.IOException - * @throws java.io.FileNotFoundException */ private void assertImmediateAssignment(List regions, List servers, @@ -193,8 +184,6 @@ public class TestRSGroupBasedLoadBalancer { * Round-robin. Should yield a balanced cluster so same invariant as the * load balancer holds, all servers holding either floor(avg) or * ceiling(avg). - * - * @throws Exception */ @Test public void testBulkAssignment() throws Exception { @@ -226,10 +215,7 @@ public class TestRSGroupBasedLoadBalancer { } /** - * Test the cluster startup bulk assignment which attempts to retain - * assignment info. - * - * @throws Exception + * Test the cluster startup bulk assignment which attempts to retain assignment info. */ @Test public void testRetainAssignment() throws Exception { @@ -249,8 +235,7 @@ public class TestRSGroupBasedLoadBalancer { } /** - * Test BOGUS_SERVER_NAME among groups do not overwrite each other - * @throws Exception + * Test BOGUS_SERVER_NAME among groups do not overwrite each other. */ @Test public void testRoundRobinAssignment() throws Exception { @@ -288,11 +273,6 @@ public class TestRSGroupBasedLoadBalancer { *
  • If a region had an existing assignment to a server with the same * address a a currently online server, it will be assigned to it * - * - * @param existing - * @param assignment - * @throws java.io.IOException - * @throws java.io.FileNotFoundException */ private void assertRetainedAssignment( Map existing, List servers, @@ -305,8 +285,9 @@ public class TestRSGroupBasedLoadBalancer { assertTrue( "Region assigned to server that was not listed as online", onlineServerSet.contains(a.getKey())); - for (RegionInfo r : a.getValue()) + for (RegionInfo r : a.getValue()) { assignedRegions.add(r); + } } assertEquals(existing.size(), assignedRegions.size()); diff --git a/hbase-rsgroup/src/test/java/org/apache/hadoop/hbase/rsgroup/TestRSGroups.java b/hbase-rsgroup/src/test/java/org/apache/hadoop/hbase/rsgroup/TestRSGroups.java index 378c1ab0a99..cbd862d322d 100644 --- a/hbase-rsgroup/src/test/java/org/apache/hadoop/hbase/rsgroup/TestRSGroups.java +++ b/hbase-rsgroup/src/test/java/org/apache/hadoop/hbase/rsgroup/TestRSGroups.java @@ -40,8 +40,6 @@ import org.apache.hadoop.hbase.master.HMaster; import org.apache.hadoop.hbase.master.ServerManager; import org.apache.hadoop.hbase.master.snapshot.SnapshotManager; import org.apache.hadoop.hbase.net.Address; -import org.apache.hadoop.hbase.shaded.protobuf.ProtobufUtil; -import org.apache.hadoop.hbase.shaded.protobuf.generated.AdminProtos; import org.apache.hadoop.hbase.testclassification.MediumTests; import org.apache.hadoop.hbase.util.Bytes; import org.junit.After; @@ -53,7 +51,10 @@ import org.junit.Test; import org.junit.experimental.categories.Category; import org.slf4j.Logger; import org.slf4j.LoggerFactory; + import org.apache.hadoop.hbase.shaded.com.google.common.collect.Sets; +import org.apache.hadoop.hbase.shaded.protobuf.ProtobufUtil; +import org.apache.hadoop.hbase.shaded.protobuf.generated.AdminProtos; @Category({MediumTests.class}) public class TestRSGroups extends TestRSGroupsBase { diff --git a/hbase-rsgroup/src/test/java/org/apache/hadoop/hbase/rsgroup/TestRSGroupsBase.java b/hbase-rsgroup/src/test/java/org/apache/hadoop/hbase/rsgroup/TestRSGroupsBase.java index e4386bc9a1f..7fa264b8ab1 100644 --- a/hbase-rsgroup/src/test/java/org/apache/hadoop/hbase/rsgroup/TestRSGroupsBase.java +++ b/hbase-rsgroup/src/test/java/org/apache/hadoop/hbase/rsgroup/TestRSGroupsBase.java @@ -343,8 +343,10 @@ public abstract class TestRSGroupsBase { @Override public boolean evaluate() throws Exception { List regions = getTableRegionMap().get(tableName); - if (regions == null) + if (regions == null) { return false; + } + return getTableRegionMap().get(tableName).size() >= 5; } }); @@ -476,8 +478,10 @@ public abstract class TestRSGroupsBase { @Override public boolean evaluate() throws Exception { List regions = getTableRegionMap().get(tableName); - if (regions == null) + if (regions == null) { return false; + } + return getTableRegionMap().get(tableName).size() >= 6; } }); @@ -516,8 +520,8 @@ public abstract class TestRSGroupsBase { }); // Lets move this region to the new group. - TEST_UTIL.getAdmin().move(Bytes.toBytes(RegionInfo.encodeRegionName(Bytes.toBytes(targetRegion))), - Bytes.toBytes(targetServer.getServerName())); + TEST_UTIL.getAdmin().move(Bytes.toBytes(RegionInfo.encodeRegionName( + Bytes.toBytes(targetRegion))), Bytes.toBytes(targetServer.getServerName())); TEST_UTIL.waitFor(WAIT_TIMEOUT, new Waiter.Predicate() { @Override public boolean evaluate() throws Exception { @@ -676,11 +680,14 @@ public abstract class TestRSGroupsBase { @Override public boolean evaluate() throws Exception { List regionsA = getTableRegionMap().get(tableNameA); - if (regionsA == null) + if (regionsA == null) { return false; + } + List regionsB = getTableRegionMap().get(tableNameB); - if (regionsB == null) + if (regionsB == null) { return false; + } return getTableRegionMap().get(tableNameA).size() >= 1 && getTableRegionMap().get(tableNameB).size() >= 1; @@ -704,7 +711,8 @@ public abstract class TestRSGroupsBase { rsGroupAdmin.getRSGroupInfoOfTable(tableNameB).getName()); //verify tables' not exist in old group - Set DefaultTables = rsGroupAdmin.getRSGroupInfo(RSGroupInfo.DEFAULT_GROUP).getTables(); + Set DefaultTables = rsGroupAdmin.getRSGroupInfo(RSGroupInfo.DEFAULT_GROUP) + .getTables(); assertFalse(DefaultTables.contains(tableNameA)); assertFalse(DefaultTables.contains(tableNameB)); @@ -758,8 +766,10 @@ public abstract class TestRSGroupsBase { @Override public boolean evaluate() throws Exception { List regions = getTableRegionMap().get(tableName); - if (regions == null) + if (regions == null) { return false; + } + return getTableRegionMap().get(tableName).size() >= 5; } }); @@ -847,7 +857,8 @@ public abstract class TestRSGroupsBase { rsGroupAdmin.getRSGroupInfoOfTable(tableName).getName()); //verify servers' not exist in old group - Set
    defaultServers = rsGroupAdmin.getRSGroupInfo(RSGroupInfo.DEFAULT_GROUP).getServers(); + Set
    defaultServers = rsGroupAdmin.getRSGroupInfo(RSGroupInfo.DEFAULT_GROUP) + .getServers(); assertFalse(defaultServers.contains(targetServer.getAddress())); //verify servers' exist in new group @@ -855,7 +866,8 @@ public abstract class TestRSGroupsBase { assertTrue(newGroupServers.contains(targetServer.getAddress())); //verify tables' not exist in old group - Set defaultTables = rsGroupAdmin.getRSGroupInfo(RSGroupInfo.DEFAULT_GROUP).getTables(); + Set defaultTables = rsGroupAdmin.getRSGroupInfo(RSGroupInfo.DEFAULT_GROUP) + .getTables(); assertFalse(defaultTables.contains(tableName)); //verify tables' exist in new group diff --git a/hbase-rsgroup/src/test/java/org/apache/hadoop/hbase/rsgroup/VerifyingRSGroupAdminClient.java b/hbase-rsgroup/src/test/java/org/apache/hadoop/hbase/rsgroup/VerifyingRSGroupAdminClient.java index 0a26a355c10..5a466a789ae 100644 --- a/hbase-rsgroup/src/test/java/org/apache/hadoop/hbase/rsgroup/VerifyingRSGroupAdminClient.java +++ b/hbase-rsgroup/src/test/java/org/apache/hadoop/hbase/rsgroup/VerifyingRSGroupAdminClient.java @@ -17,12 +17,14 @@ */ package org.apache.hadoop.hbase.rsgroup; -import org.apache.hadoop.hbase.shaded.com.google.common.collect.Maps; -import org.apache.hadoop.hbase.shaded.com.google.common.collect.Sets; +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.util.List; +import java.util.Map; +import java.util.Set; + import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hbase.TableName; -import org.apache.hadoop.hbase.zookeeper.ZKWatcher; -import org.apache.yetus.audience.InterfaceAudience; import org.apache.hadoop.hbase.client.ConnectionFactory; import org.apache.hadoop.hbase.client.Result; import org.apache.hadoop.hbase.client.Scan; @@ -32,15 +34,14 @@ import org.apache.hadoop.hbase.net.Address; import org.apache.hadoop.hbase.protobuf.ProtobufUtil; import org.apache.hadoop.hbase.protobuf.generated.RSGroupProtos; import org.apache.hadoop.hbase.zookeeper.ZKUtil; +import org.apache.hadoop.hbase.zookeeper.ZKWatcher; import org.apache.hadoop.hbase.zookeeper.ZNodePaths; +import org.apache.yetus.audience.InterfaceAudience; import org.apache.zookeeper.KeeperException; import org.junit.Assert; -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.util.List; -import java.util.Map; -import java.util.Set; +import org.apache.hadoop.hbase.shaded.com.google.common.collect.Maps; +import org.apache.hadoop.hbase.shaded.com.google.common.collect.Sets; @InterfaceAudience.Private public class VerifyingRSGroupAdminClient implements RSGroupAdmin { @@ -51,7 +52,8 @@ public class VerifyingRSGroupAdminClient implements RSGroupAdmin { public VerifyingRSGroupAdminClient(RSGroupAdmin RSGroupAdmin, Configuration conf) throws IOException { wrapped = RSGroupAdmin; - table = ConnectionFactory.createConnection(conf).getTable(RSGroupInfoManager.RSGROUP_TABLE_NAME); + table = ConnectionFactory.createConnection(conf) + .getTable(RSGroupInfoManager.RSGROUP_TABLE_NAME); zkw = new ZKWatcher(conf, this.getClass().getSimpleName(), null); } @@ -105,7 +107,8 @@ public class VerifyingRSGroupAdminClient implements RSGroupAdmin { } @Override - public void moveServersAndTables(Set
    servers, Set tables, String targetGroup) throws IOException { + public void moveServersAndTables(Set
    servers, Set tables, String targetGroup) + throws IOException { wrapped.moveServersAndTables(servers, tables, targetGroup); verify(); }