Skip to content

Commit 24b970e

Browse files
committed
Revert "HBASE-22744 Removed deprecated status and load classes in client module"
This reverts commit 4a61c8b.
1 parent caa0535 commit 24b970e

File tree

11 files changed

+1784
-49
lines changed

11 files changed

+1784
-49
lines changed

hbase-client/src/main/java/org/apache/hadoop/hbase/ClusterStatus.java

Lines changed: 400 additions & 0 deletions
Large diffs are not rendered by default.

hbase-client/src/main/java/org/apache/hadoop/hbase/RegionLoad.java

Lines changed: 421 additions & 0 deletions
Large diffs are not rendered by default.

hbase-client/src/main/java/org/apache/hadoop/hbase/ServerLoad.java

Lines changed: 596 additions & 0 deletions
Large diffs are not rendered by default.

hbase-client/src/main/java/org/apache/hadoop/hbase/shaded/protobuf/ProtobufUtil.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@
131131
import org.apache.hadoop.hbase.shaded.protobuf.generated.AdminProtos.GetOnlineRegionResponse;
132132
import org.apache.hadoop.hbase.shaded.protobuf.generated.AdminProtos.GetRegionInfoRequest;
133133
import org.apache.hadoop.hbase.shaded.protobuf.generated.AdminProtos.GetRegionInfoResponse;
134+
import org.apache.hadoop.hbase.shaded.protobuf.generated.AdminProtos.GetRegionLoadResponse;
134135
import org.apache.hadoop.hbase.shaded.protobuf.generated.AdminProtos.GetServerInfoRequest;
135136
import org.apache.hadoop.hbase.shaded.protobuf.generated.AdminProtos.GetServerInfoResponse;
136137
import org.apache.hadoop.hbase.shaded.protobuf.generated.AdminProtos.GetStoreFileRequest;
@@ -1733,6 +1734,16 @@ public static org.apache.hadoop.hbase.client.RegionInfo getRegionInfo(final RpcC
17331734
}
17341735
}
17351736

1737+
public static List<org.apache.hadoop.hbase.RegionLoad> getRegionLoadInfo(
1738+
GetRegionLoadResponse regionLoadResponse) {
1739+
List<org.apache.hadoop.hbase.RegionLoad> regionLoadList =
1740+
new ArrayList<>(regionLoadResponse.getRegionLoadsCount());
1741+
for (RegionLoad regionLoad : regionLoadResponse.getRegionLoadsList()) {
1742+
regionLoadList.add(new org.apache.hadoop.hbase.RegionLoad(regionLoad));
1743+
}
1744+
return regionLoadList;
1745+
}
1746+
17361747
/**
17371748
* A helper to close a region given a region name
17381749
* using admin protocol.

hbase-rest/src/test/java/org/apache/hadoop/hbase/rest/TestStatusResource.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public static void setUpBeforeClass() throws Exception {
100100
TEST_UTIL.waitFor(6000, new Waiter.Predicate<IOException>() {
101101
@Override
102102
public boolean evaluate() throws IOException {
103-
return TEST_UTIL.getMiniHBaseCluster().getClusterMetrics().getAverageLoad() > 0;
103+
return TEST_UTIL.getMiniHBaseCluster().getClusterStatus().getAverageLoad() > 0;
104104
}
105105
});
106106
}

hbase-server/src/test/java/org/apache/hadoop/hbase/MiniHBaseCluster.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ public MiniHBaseCluster(Configuration conf, int numMasters, int numRegionServers
110110
CompatibilityFactory.getInstance(MetricsAssertHelper.class).init();
111111

112112
init(numMasters, numRegionServers, rsPorts, masterClass, regionserverClass);
113-
this.initialClusterStatus = getClusterMetrics();
113+
this.initialClusterStatus = getClusterStatus();
114114
}
115115

116116
public Configuration getConfiguration() {
@@ -435,9 +435,9 @@ public JVMClusterUtil.RegionServerThread startRegionServerAndWait(long timeout)
435435
ServerName rsServerName = t.getRegionServer().getServerName();
436436

437437
long start = System.currentTimeMillis();
438-
ClusterMetrics clusterStatus = getClusterMetrics();
438+
ClusterStatus clusterStatus = getClusterStatus();
439439
while ((System.currentTimeMillis() - start) < timeout) {
440-
if (clusterStatus != null && clusterStatus.getLiveServerMetrics().containsKey(rsServerName)) {
440+
if (clusterStatus != null && clusterStatus.getServers().contains(rsServerName)) {
441441
return t;
442442
}
443443
Threads.sleep(100);
@@ -659,6 +659,16 @@ public void shutdown() throws IOException {
659659
public void close() throws IOException {
660660
}
661661

662+
/**
663+
* @deprecated As of release 2.0.0, this will be removed in HBase 3.0.0
664+
* Use {@link #getClusterMetrics()} instead.
665+
*/
666+
@Deprecated
667+
public ClusterStatus getClusterStatus() throws IOException {
668+
HMaster master = getMaster();
669+
return master == null ? null : new ClusterStatus(master.getClusterMetrics());
670+
}
671+
662672
@Override
663673
public ClusterMetrics getClusterMetrics() throws IOException {
664674
HMaster master = getMaster();

hbase-server/src/test/java/org/apache/hadoop/hbase/TestClientClusterStatus.java

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ public void testNone() throws Exception {
8989
// or more requests than expected.
9090
Assert.assertEquals(status0.getLiveServerMetrics().size(),
9191
status1.getLiveServerMetrics().size());
92+
checkPbObjectNotNull(new ClusterStatus(status0));
93+
checkPbObjectNotNull(new ClusterStatus(status1));
9294
}
9395

9496
@Test
@@ -107,26 +109,28 @@ public void testLiveAndDeadServersStatus() throws Exception {
107109
Waiter.waitFor(CLUSTER.getConfiguration(), 10 * 1000, 100, new Predicate<Exception>() {
108110
@Override
109111
public boolean evaluate() throws Exception {
110-
ClusterMetrics status = ADMIN.getClusterMetrics(EnumSet.of(Option.LIVE_SERVERS));
112+
ClusterStatus status
113+
= new ClusterStatus(ADMIN.getClusterMetrics(EnumSet.of(Option.LIVE_SERVERS)));
111114
Assert.assertNotNull(status);
112-
return status.getRegionCount() > 0;
115+
return status.getRegionsCount() > 0;
113116
}
114117
});
115118
// Retrieve live servers and dead servers info.
116119
EnumSet<Option> options =
117120
EnumSet.of(Option.LIVE_SERVERS, Option.DEAD_SERVERS, Option.SERVERS_NAME);
118-
ClusterMetrics status = ADMIN.getClusterMetrics(options);
121+
ClusterStatus status = new ClusterStatus(ADMIN.getClusterMetrics(options));
122+
checkPbObjectNotNull(status);
119123
Assert.assertNotNull(status);
120-
Assert.assertNotNull(status.getLiveServerMetrics().keySet());
124+
Assert.assertNotNull(status.getServers());
121125
// exclude a dead region server
122126
Assert.assertEquals(SLAVES -1, numRs);
123127
// live servers = nums of regionservers
124128
// By default, HMaster don't carry any regions so it won't report its load.
125129
// Hence, it won't be in the server list.
126-
Assert.assertEquals(status.getLiveServerMetrics().keySet().size(), numRs);
127-
Assert.assertTrue(status.getRegionCount() > 0);
130+
Assert.assertEquals(status.getServers().size(), numRs);
131+
Assert.assertTrue(status.getRegionsCount() > 0);
128132
Assert.assertNotNull(status.getDeadServerNames());
129-
Assert.assertEquals(1, status.getDeadServerNames().size());
133+
Assert.assertEquals(1, status.getDeadServersSize());
130134
ServerName deadServerName = status.getDeadServerNames().iterator().next();
131135
Assert.assertEquals(DEAD.getServerName(), deadServerName);
132136
Assert.assertNotNull(status.getServersName());
@@ -154,18 +158,18 @@ public void testMasterAndBackupMastersStatus() throws Exception {
154158
Assert.assertEquals(MASTERS, masterThreads.size());
155159
// Retrieve master and backup masters infos only.
156160
EnumSet<Option> options = EnumSet.of(Option.MASTER, Option.BACKUP_MASTERS);
157-
ClusterMetrics status = ADMIN.getClusterMetrics(options);
158-
Assert.assertTrue(status.getMasterName().equals(activeName));
159-
Assert.assertEquals(MASTERS - 1, status.getBackupMasterNames().size());
161+
ClusterStatus status = new ClusterStatus(ADMIN.getClusterMetrics(options));
162+
Assert.assertTrue(status.getMaster().equals(activeName));
163+
Assert.assertEquals(MASTERS - 1, status.getBackupMastersSize());
160164
}
161165

162166
@Test
163167
public void testOtherStatusInfos() throws Exception {
164168
EnumSet<Option> options =
165169
EnumSet.of(Option.MASTER_COPROCESSORS, Option.HBASE_VERSION,
166170
Option.CLUSTER_ID, Option.BALANCER_ON);
167-
ClusterMetrics status = ADMIN.getClusterMetrics(options);
168-
Assert.assertTrue(status.getMasterCoprocessorNames().size() == 1);
171+
ClusterStatus status = new ClusterStatus(ADMIN.getClusterMetrics(options));
172+
Assert.assertTrue(status.getMasterCoprocessors().length == 1);
169173
Assert.assertNotNull(status.getHBaseVersion());
170174
Assert.assertNotNull(status.getClusterId());
171175
Assert.assertTrue(status.getAverageLoad() == 0.0);
@@ -188,6 +192,21 @@ public void testObserver() throws IOException {
188192
Assert.assertEquals(postCount + 1, MyObserver.POST_COUNT.get());
189193
}
190194

195+
/**
196+
* HBASE-19496 do the refactor for ServerLoad and RegionLoad so the inner pb object is useless
197+
* now. However, they are Public classes, and consequently we must make sure the all pb objects
198+
* have initialized.
199+
*/
200+
private static void checkPbObjectNotNull(ClusterStatus status) {
201+
for (ServerName name : status.getLiveServerMetrics().keySet()) {
202+
ServerLoad load = status.getLoad(name);
203+
Assert.assertNotNull(load.obtainServerLoadPB());
204+
for (RegionLoad rl : load.getRegionsLoad().values()) {
205+
Assert.assertNotNull(rl.regionLoadPB);
206+
}
207+
}
208+
}
209+
191210
public static class MyObserver implements MasterCoprocessor, MasterObserver {
192211
private static final AtomicInteger PRE_COUNT = new AtomicInteger(0);
193212
private static final AtomicInteger POST_COUNT = new AtomicInteger(0);
Lines changed: 180 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
package org.apache.hadoop.hbase;
19+
20+
import static org.junit.Assert.assertEquals;
21+
import static org.junit.Assert.assertNotNull;
22+
import static org.junit.Assert.assertTrue;
23+
24+
import java.io.IOException;
25+
import java.util.Collection;
26+
import java.util.EnumSet;
27+
import java.util.List;
28+
import java.util.Map;
29+
import java.util.TreeMap;
30+
import java.util.concurrent.TimeUnit;
31+
import java.util.stream.Collectors;
32+
import org.apache.hadoop.hbase.ClusterMetrics.Option;
33+
import org.apache.hadoop.hbase.client.Admin;
34+
import org.apache.hadoop.hbase.client.RegionInfo;
35+
import org.apache.hadoop.hbase.client.Table;
36+
import org.apache.hadoop.hbase.testclassification.MediumTests;
37+
import org.apache.hadoop.hbase.testclassification.MiscTests;
38+
import org.apache.hadoop.hbase.util.Bytes;
39+
import org.junit.AfterClass;
40+
import org.junit.BeforeClass;
41+
import org.junit.ClassRule;
42+
import org.junit.Test;
43+
import org.junit.experimental.categories.Category;
44+
import org.slf4j.Logger;
45+
import org.slf4j.LoggerFactory;
46+
47+
import org.apache.hbase.thirdparty.com.google.common.collect.Lists;
48+
import org.apache.hbase.thirdparty.com.google.common.collect.Maps;
49+
50+
@Category({MiscTests.class, MediumTests.class})
51+
public class TestRegionLoad {
52+
53+
@ClassRule
54+
public static final HBaseClassTestRule CLASS_RULE =
55+
HBaseClassTestRule.forClass(TestRegionLoad.class);
56+
57+
private static final Logger LOG = LoggerFactory.getLogger(TestRegionLoad.class);
58+
private static final HBaseTestingUtility UTIL = new HBaseTestingUtility();
59+
private static Admin admin;
60+
61+
private static final TableName TABLE_1 = TableName.valueOf("table_1");
62+
private static final TableName TABLE_2 = TableName.valueOf("table_2");
63+
private static final TableName TABLE_3 = TableName.valueOf("table_3");
64+
private static final TableName[] tables = new TableName[]{TABLE_1, TABLE_2, TABLE_3};
65+
private static final int MSG_INTERVAL = 500; // ms
66+
67+
@BeforeClass
68+
public static void beforeClass() throws Exception {
69+
// Make servers report eagerly. This test is about looking at the cluster status reported.
70+
// Make it so we don't have to wait around too long to see change.
71+
UTIL.getConfiguration().setInt("hbase.regionserver.msginterval", MSG_INTERVAL);
72+
UTIL.startMiniCluster(4);
73+
admin = UTIL.getAdmin();
74+
admin.balancerSwitch(false, true);
75+
createTables();
76+
}
77+
78+
@AfterClass
79+
public static void afterClass() throws Exception {
80+
UTIL.shutdownMiniCluster();
81+
}
82+
83+
private static void createTables() throws IOException, InterruptedException {
84+
byte[][] FAMILIES = new byte [][] {Bytes.toBytes("f")};
85+
for (TableName tableName : tables) {
86+
Table table =
87+
UTIL.createTable(tableName, FAMILIES, HBaseTestingUtility.KEYS_FOR_HBA_CREATE_TABLE);
88+
UTIL.waitTableAvailable(tableName);
89+
UTIL.loadTable(table, FAMILIES[0]);
90+
}
91+
}
92+
93+
@Test
94+
public void testRegionLoad() throws Exception {
95+
96+
// Check if regions match with the regionLoad from the server
97+
for (ServerName serverName : admin
98+
.getClusterMetrics(EnumSet.of(Option.LIVE_SERVERS)).getLiveServerMetrics().keySet()) {
99+
List<RegionInfo> regions = admin.getRegions(serverName);
100+
LOG.info("serverName=" + serverName + ", regions=" +
101+
regions.stream().map(r -> r.getRegionNameAsString()).collect(Collectors.toList()));
102+
Collection<RegionLoad> regionLoads = admin.getRegionMetrics(serverName)
103+
.stream().map(r -> new RegionLoad(r)).collect(Collectors.toList());
104+
LOG.info("serverName=" + serverName + ", regionLoads=" +
105+
regionLoads.stream().map(r -> Bytes.toString(r.getRegionName())).
106+
collect(Collectors.toList()));
107+
checkRegionsAndRegionLoads(regions, regionLoads);
108+
}
109+
110+
// Check if regionLoad matches the table's regions and nothing is missed
111+
for (TableName table : new TableName[]{TABLE_1, TABLE_2, TABLE_3}) {
112+
List<RegionInfo> tableRegions = admin.getRegions(table);
113+
114+
List<RegionLoad> regionLoads = Lists.newArrayList();
115+
for (ServerName serverName : admin
116+
.getClusterMetrics(EnumSet.of(Option.LIVE_SERVERS)).getLiveServerMetrics().keySet()) {
117+
regionLoads.addAll(admin.getRegionMetrics(serverName, table)
118+
.stream().map(r -> new RegionLoad(r)).collect(Collectors.toList()));
119+
}
120+
checkRegionsAndRegionLoads(tableRegions, regionLoads);
121+
}
122+
123+
// Just wait here. If this fixes the test, come back and do a better job.
124+
// Would have to redo the below so can wait on cluster status changing.
125+
// Admin#getClusterMetrics retrieves data from HMaster. Admin#getRegionMetrics, by contrast,
126+
// get the data from RS. Hence, it will fail if we do the assert check before RS has done
127+
// the report.
128+
TimeUnit.MILLISECONDS.sleep(3 * MSG_INTERVAL);
129+
130+
// Check RegionLoad matches the regionLoad from ClusterStatus
131+
ClusterStatus clusterStatus
132+
= new ClusterStatus(admin.getClusterMetrics(EnumSet.of(Option.LIVE_SERVERS)));
133+
for (ServerName serverName : clusterStatus.getServers()) {
134+
ServerLoad serverLoad = clusterStatus.getLoad(serverName);
135+
Map<byte[], RegionLoad> regionLoads = admin.getRegionMetrics(serverName).stream()
136+
.collect(Collectors.toMap(e -> e.getRegionName(), e -> new RegionLoad(e),
137+
(v1, v2) -> {
138+
throw new RuntimeException("impossible!!");
139+
}, () -> new TreeMap<>(Bytes.BYTES_COMPARATOR)));
140+
LOG.debug("serverName=" + serverName + ", getRegionLoads=" +
141+
serverLoad.getRegionsLoad().keySet().stream().map(r -> Bytes.toString(r)).
142+
collect(Collectors.toList()));
143+
LOG.debug("serverName=" + serverName + ", regionLoads=" +
144+
regionLoads.keySet().stream().map(r -> Bytes.toString(r)).
145+
collect(Collectors.toList()));
146+
compareRegionLoads(serverLoad.getRegionsLoad(), regionLoads);
147+
}
148+
}
149+
150+
private void compareRegionLoads(Map<byte[], RegionLoad> regionLoadCluster,
151+
Map<byte[], RegionLoad> regionLoads) {
152+
153+
assertEquals("No of regionLoads from clusterStatus and regionloads from RS doesn't match",
154+
regionLoadCluster.size(), regionLoads.size());
155+
156+
// The contents of region load from cluster and server should match
157+
for (byte[] regionName : regionLoadCluster.keySet()) {
158+
regionLoads.remove(regionName);
159+
}
160+
assertEquals("regionLoads from SN should be empty", 0, regionLoads.size());
161+
}
162+
163+
private void checkRegionsAndRegionLoads(Collection<RegionInfo> regions,
164+
Collection<RegionLoad> regionLoads) {
165+
for (RegionLoad load : regionLoads) {
166+
assertNotNull(load.regionLoadPB);
167+
}
168+
169+
assertEquals("No of regions and regionloads doesn't match", regions.size(), regionLoads.size());
170+
171+
Map<byte[], RegionLoad> regionLoadMap = Maps.newTreeMap(Bytes.BYTES_COMPARATOR);
172+
for (RegionLoad regionLoad : regionLoads) {
173+
regionLoadMap.put(regionLoad.getName(), regionLoad);
174+
}
175+
for (RegionInfo info : regions) {
176+
assertTrue("Region not in regionLoadMap region:" + info.getRegionNameAsString() +
177+
" regionMap: " + regionLoadMap, regionLoadMap.containsKey(info.getRegionName()));
178+
}
179+
}
180+
}

0 commit comments

Comments
 (0)