-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "HBASE-22744 Removed deprecated status and load classes in cli…
…ent module" This reverts commit 4a61c8b.
- Loading branch information
1 parent
caa0535
commit 24b970e
Showing
11 changed files
with
1,784 additions
and
49 deletions.
There are no files selected for viewing
400 changes: 400 additions & 0 deletions
400
hbase-client/src/main/java/org/apache/hadoop/hbase/ClusterStatus.java
Large diffs are not rendered by default.
Oops, something went wrong.
421 changes: 421 additions & 0 deletions
421
hbase-client/src/main/java/org/apache/hadoop/hbase/RegionLoad.java
Large diffs are not rendered by default.
Oops, something went wrong.
596 changes: 596 additions & 0 deletions
596
hbase-client/src/main/java/org/apache/hadoop/hbase/ServerLoad.java
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
180 changes: 180 additions & 0 deletions
180
hbase-server/src/test/java/org/apache/hadoop/hbase/TestRegionLoad.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,180 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.apache.hadoop.hbase; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertNotNull; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
import java.io.IOException; | ||
import java.util.Collection; | ||
import java.util.EnumSet; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.TreeMap; | ||
import java.util.concurrent.TimeUnit; | ||
import java.util.stream.Collectors; | ||
import org.apache.hadoop.hbase.ClusterMetrics.Option; | ||
import org.apache.hadoop.hbase.client.Admin; | ||
import org.apache.hadoop.hbase.client.RegionInfo; | ||
import org.apache.hadoop.hbase.client.Table; | ||
import org.apache.hadoop.hbase.testclassification.MediumTests; | ||
import org.apache.hadoop.hbase.testclassification.MiscTests; | ||
import org.apache.hadoop.hbase.util.Bytes; | ||
import org.junit.AfterClass; | ||
import org.junit.BeforeClass; | ||
import org.junit.ClassRule; | ||
import org.junit.Test; | ||
import org.junit.experimental.categories.Category; | ||
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; | ||
|
||
@Category({MiscTests.class, MediumTests.class}) | ||
public class TestRegionLoad { | ||
|
||
@ClassRule | ||
public static final HBaseClassTestRule CLASS_RULE = | ||
HBaseClassTestRule.forClass(TestRegionLoad.class); | ||
|
||
private static final Logger LOG = LoggerFactory.getLogger(TestRegionLoad.class); | ||
private static final HBaseTestingUtility UTIL = new HBaseTestingUtility(); | ||
private static Admin admin; | ||
|
||
private static final TableName TABLE_1 = TableName.valueOf("table_1"); | ||
private static final TableName TABLE_2 = TableName.valueOf("table_2"); | ||
private static final TableName TABLE_3 = TableName.valueOf("table_3"); | ||
private static final TableName[] tables = new TableName[]{TABLE_1, TABLE_2, TABLE_3}; | ||
private static final int MSG_INTERVAL = 500; // ms | ||
|
||
@BeforeClass | ||
public static void beforeClass() throws Exception { | ||
// Make servers report eagerly. This test is about looking at the cluster status reported. | ||
// Make it so we don't have to wait around too long to see change. | ||
UTIL.getConfiguration().setInt("hbase.regionserver.msginterval", MSG_INTERVAL); | ||
UTIL.startMiniCluster(4); | ||
admin = UTIL.getAdmin(); | ||
admin.balancerSwitch(false, true); | ||
createTables(); | ||
} | ||
|
||
@AfterClass | ||
public static void afterClass() throws Exception { | ||
UTIL.shutdownMiniCluster(); | ||
} | ||
|
||
private static void createTables() throws IOException, InterruptedException { | ||
byte[][] FAMILIES = new byte [][] {Bytes.toBytes("f")}; | ||
for (TableName tableName : tables) { | ||
Table table = | ||
UTIL.createTable(tableName, FAMILIES, HBaseTestingUtility.KEYS_FOR_HBA_CREATE_TABLE); | ||
UTIL.waitTableAvailable(tableName); | ||
UTIL.loadTable(table, FAMILIES[0]); | ||
} | ||
} | ||
|
||
@Test | ||
public void testRegionLoad() throws Exception { | ||
|
||
// Check if regions match with the regionLoad from the server | ||
for (ServerName serverName : admin | ||
.getClusterMetrics(EnumSet.of(Option.LIVE_SERVERS)).getLiveServerMetrics().keySet()) { | ||
List<RegionInfo> regions = admin.getRegions(serverName); | ||
LOG.info("serverName=" + serverName + ", regions=" + | ||
regions.stream().map(r -> r.getRegionNameAsString()).collect(Collectors.toList())); | ||
Collection<RegionLoad> regionLoads = admin.getRegionMetrics(serverName) | ||
.stream().map(r -> new RegionLoad(r)).collect(Collectors.toList()); | ||
LOG.info("serverName=" + serverName + ", regionLoads=" + | ||
regionLoads.stream().map(r -> Bytes.toString(r.getRegionName())). | ||
collect(Collectors.toList())); | ||
checkRegionsAndRegionLoads(regions, regionLoads); | ||
} | ||
|
||
// Check if regionLoad matches the table's regions and nothing is missed | ||
for (TableName table : new TableName[]{TABLE_1, TABLE_2, TABLE_3}) { | ||
List<RegionInfo> tableRegions = admin.getRegions(table); | ||
|
||
List<RegionLoad> regionLoads = Lists.newArrayList(); | ||
for (ServerName serverName : admin | ||
.getClusterMetrics(EnumSet.of(Option.LIVE_SERVERS)).getLiveServerMetrics().keySet()) { | ||
regionLoads.addAll(admin.getRegionMetrics(serverName, table) | ||
.stream().map(r -> new RegionLoad(r)).collect(Collectors.toList())); | ||
} | ||
checkRegionsAndRegionLoads(tableRegions, regionLoads); | ||
} | ||
|
||
// Just wait here. If this fixes the test, come back and do a better job. | ||
// Would have to redo the below so can wait on cluster status changing. | ||
// Admin#getClusterMetrics retrieves data from HMaster. Admin#getRegionMetrics, by contrast, | ||
// get the data from RS. Hence, it will fail if we do the assert check before RS has done | ||
// the report. | ||
TimeUnit.MILLISECONDS.sleep(3 * MSG_INTERVAL); | ||
|
||
// Check RegionLoad matches the regionLoad from ClusterStatus | ||
ClusterStatus clusterStatus | ||
= new ClusterStatus(admin.getClusterMetrics(EnumSet.of(Option.LIVE_SERVERS))); | ||
for (ServerName serverName : clusterStatus.getServers()) { | ||
ServerLoad serverLoad = clusterStatus.getLoad(serverName); | ||
Map<byte[], RegionLoad> regionLoads = admin.getRegionMetrics(serverName).stream() | ||
.collect(Collectors.toMap(e -> e.getRegionName(), e -> new RegionLoad(e), | ||
(v1, v2) -> { | ||
throw new RuntimeException("impossible!!"); | ||
}, () -> new TreeMap<>(Bytes.BYTES_COMPARATOR))); | ||
LOG.debug("serverName=" + serverName + ", getRegionLoads=" + | ||
serverLoad.getRegionsLoad().keySet().stream().map(r -> Bytes.toString(r)). | ||
collect(Collectors.toList())); | ||
LOG.debug("serverName=" + serverName + ", regionLoads=" + | ||
regionLoads.keySet().stream().map(r -> Bytes.toString(r)). | ||
collect(Collectors.toList())); | ||
compareRegionLoads(serverLoad.getRegionsLoad(), regionLoads); | ||
} | ||
} | ||
|
||
private void compareRegionLoads(Map<byte[], RegionLoad> regionLoadCluster, | ||
Map<byte[], RegionLoad> regionLoads) { | ||
|
||
assertEquals("No of regionLoads from clusterStatus and regionloads from RS doesn't match", | ||
regionLoadCluster.size(), regionLoads.size()); | ||
|
||
// The contents of region load from cluster and server should match | ||
for (byte[] regionName : regionLoadCluster.keySet()) { | ||
regionLoads.remove(regionName); | ||
} | ||
assertEquals("regionLoads from SN should be empty", 0, regionLoads.size()); | ||
} | ||
|
||
private void checkRegionsAndRegionLoads(Collection<RegionInfo> regions, | ||
Collection<RegionLoad> regionLoads) { | ||
for (RegionLoad load : regionLoads) { | ||
assertNotNull(load.regionLoadPB); | ||
} | ||
|
||
assertEquals("No of regions and regionloads doesn't match", regions.size(), regionLoads.size()); | ||
|
||
Map<byte[], RegionLoad> regionLoadMap = Maps.newTreeMap(Bytes.BYTES_COMPARATOR); | ||
for (RegionLoad regionLoad : regionLoads) { | ||
regionLoadMap.put(regionLoad.getName(), regionLoad); | ||
} | ||
for (RegionInfo info : regions) { | ||
assertTrue("Region not in regionLoadMap region:" + info.getRegionNameAsString() + | ||
" regionMap: " + regionLoadMap, regionLoadMap.containsKey(info.getRegionName())); | ||
} | ||
} | ||
} |
Oops, something went wrong.