diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java index ae739b380a3..bb796a549d9 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java @@ -115,6 +115,7 @@ import org.apache.hadoop.hbase.protobuf.generated.ClusterStatusProtos; import org.apache.hadoop.hbase.protobuf.generated.ClusterStatusProtos.RegionLoad; import org.apache.hadoop.hbase.protobuf.generated.ClusterStatusProtos.RegionStoreSequenceIds; import org.apache.hadoop.hbase.protobuf.generated.HBaseProtos.Coprocessor; +import org.apache.hadoop.hbase.protobuf.generated.HBaseProtos.Coprocessor.Builder; import org.apache.hadoop.hbase.protobuf.generated.HBaseProtos.NameStringPair; import org.apache.hadoop.hbase.protobuf.generated.HBaseProtos.RegionServerInfo; import org.apache.hadoop.hbase.protobuf.generated.HBaseProtos.RegionSpecifier; @@ -1174,17 +1175,22 @@ public class HRegionServer extends HasThread implements serverLoad.setUsedHeapMB((int)(memory.getUsed() / 1024 / 1024)); serverLoad.setMaxHeapMB((int) (memory.getMax() / 1024 / 1024)); Set coprocessors = getWAL(null).getCoprocessorHost().getCoprocessors(); + Builder coprocessorBuilder = Coprocessor.newBuilder(); for (String coprocessor : coprocessors) { - serverLoad.addCoprocessors( - Coprocessor.newBuilder().setName(coprocessor).build()); + serverLoad.addCoprocessors(coprocessorBuilder.setName(coprocessor).build()); } RegionLoad.Builder regionLoadBldr = RegionLoad.newBuilder(); RegionSpecifier.Builder regionSpecifier = RegionSpecifier.newBuilder(); for (Region region : regions) { + Set regionCoprocessors = region.getCoprocessorHost().getCoprocessors(); + Iterator iterator = regionCoprocessors.iterator(); + while (iterator.hasNext()) { + serverLoad.addCoprocessors(coprocessorBuilder.setName(iterator.next()).build()); + } serverLoad.addRegionLoads(createRegionLoad(region, regionLoadBldr, regionSpecifier)); - for (String coprocessor : - getWAL(region.getRegionInfo()).getCoprocessorHost().getCoprocessors()) { - serverLoad.addCoprocessors(Coprocessor.newBuilder().setName(coprocessor).build()); + for (String coprocessor : getWAL(region.getRegionInfo()).getCoprocessorHost() + .getCoprocessors()) { + serverLoad.addCoprocessors(coprocessorBuilder.setName(coprocessor).build()); } } serverLoad.setReportStartTime(reportStartTime); diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestClassLoading.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestClassLoading.java index 6a5080bf3c1..f5d2a204d44 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestClassLoading.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestClassLoading.java @@ -75,6 +75,10 @@ public class TestClassLoading { regionServerCoprocessor.getSimpleName() }; + private static final String[] masterRegionServerSystemCoprocessors = new String[] { + regionCoprocessor1.getSimpleName(), MultiRowMutationEndpoint.class.getSimpleName(), + regionServerCoprocessor.getSimpleName() }; + @BeforeClass public static void setUpBeforeClass() throws Exception { Configuration conf = TEST_UTIL.getConfiguration(); @@ -447,7 +451,7 @@ public class TestClassLoading { // This was a test for HBASE-4070. // We are removing coprocessors from region load in HBASE-5258. // Therefore, this test now only checks system coprocessors. - assertAllRegionServers(regionServerSystemCoprocessors,null); + assertAllRegionServers(null); } /** @@ -478,20 +482,18 @@ public class TestClassLoading { return serverLoadHashMap; } - void assertAllRegionServers(String[] expectedCoprocessors, String tableName) - throws InterruptedException { + void assertAllRegionServers(String tableName) throws InterruptedException { Map servers; String[] actualCoprocessors = null; boolean success = false; - for(int i = 0; i < 5; i++) { - if (tableName == null) { - //if no tableName specified, use all servers. - servers = - TEST_UTIL.getMiniHBaseCluster().getMaster().getServerManager(). - getOnlineServers(); - } else { - servers = serversForTable(tableName); - } + String[] expectedCoprocessors = regionServerSystemCoprocessors; + if (tableName == null) { + // if no tableName specified, use all servers. + servers = TEST_UTIL.getMiniHBaseCluster().getMaster().getServerManager().getOnlineServers(); + } else { + servers = serversForTable(tableName); + } + for (int i = 0; i < 5; i++) { boolean any_failed = false; for(Map.Entry server: servers.entrySet()) { actualCoprocessors = server.getValue().getRsCoprocessors(); @@ -500,8 +502,10 @@ public class TestClassLoading { Arrays.toString(actualCoprocessors) + " ; expected: " + Arrays.toString(expectedCoprocessors)); any_failed = true; + expectedCoprocessors = switchExpectedCoprocessors(expectedCoprocessors); break; } + expectedCoprocessors = switchExpectedCoprocessors(expectedCoprocessors); } if (any_failed == false) { success = true; @@ -513,6 +517,15 @@ public class TestClassLoading { assertTrue(success); } + private String[] switchExpectedCoprocessors(String[] expectedCoprocessors) { + if (Arrays.equals(regionServerSystemCoprocessors, expectedCoprocessors)) { + expectedCoprocessors = masterRegionServerSystemCoprocessors; + } else { + expectedCoprocessors = regionServerSystemCoprocessors; + } + return expectedCoprocessors; + } + @Test public void testMasterCoprocessorsReported() { // HBASE 4070: Improve region server metrics to report loaded coprocessors