HBASE-21439 RegionLoads aren't being used in RegionLoad cost functions

Signed-off-by: tedyu <yuzhihong@gmail.com>
Signed-off-by: Andrew Purtell <apurtell@apache.org>

Conflicts:
	hbase-server/src/test/java/org/apache/hadoop/hbase/master/balancer/TestStochasticLoadBalancer.java
This commit is contained in:
Ben Lau 2018-11-05 15:34:08 -08:00 committed by Andrew Purtell
parent 3a13088a2e
commit 0875fa0634
No known key found for this signature in database
GPG Key ID: 8597754DD5365CCD
4 changed files with 31 additions and 15 deletions

View File

@ -18,6 +18,8 @@
*/
package org.apache.hadoop.hbase.client;
import edu.umd.cs.findbugs.annotations.CheckForNull;
import java.io.DataInputStream;
import java.io.IOException;
import java.util.ArrayList;
@ -271,6 +273,26 @@ public interface RegionInfo {
return encodedName;
}
@InterfaceAudience.Private
static String getRegionNameAsString(byte[] regionName) {
return getRegionNameAsString(null, regionName);
}
@InterfaceAudience.Private
static String getRegionNameAsString(@CheckForNull RegionInfo ri, byte[] regionName) {
if (RegionInfo.hasEncodedName(regionName)) {
// new format region names already have their encoded name.
return Bytes.toStringBinary(regionName);
}
// old format. regionNameStr doesn't have the region name.
if (ri == null) {
return Bytes.toStringBinary(regionName) + "." + RegionInfo.encodeRegionName(regionName);
} else {
return Bytes.toStringBinary(regionName) + "." + ri.getEncodedName();
}
}
/**
* @return Return a String of short, printable names for <code>hris</code>
* (usually encoded name) for us logging.

View File

@ -287,15 +287,7 @@ public class RegionInfoBuilder {
*/
@Override
public String getRegionNameAsString() {
if (RegionInfo.hasEncodedName(this.regionName)) {
// new format region names already have their encoded name.
return Bytes.toStringBinary(this.regionName);
}
// old format. regionNameStr doesn't have the region name.
//
//
return Bytes.toStringBinary(this.regionName) + "." + this.getEncodedName();
return RegionInfo.getRegionNameAsString(this, this.regionName);
}
/** @return the encoded region name */

View File

@ -45,7 +45,6 @@ import org.apache.hadoop.hbase.master.balancer.BaseLoadBalancer.Cluster.AssignRe
import org.apache.hadoop.hbase.master.balancer.BaseLoadBalancer.Cluster.LocalityType;
import org.apache.hadoop.hbase.master.balancer.BaseLoadBalancer.Cluster.MoveRegionAction;
import org.apache.hadoop.hbase.master.balancer.BaseLoadBalancer.Cluster.SwapRegionsAction;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;
import org.apache.yetus.audience.InterfaceAudience;
import org.slf4j.Logger;
@ -531,14 +530,15 @@ public class StochasticLoadBalancer extends BaseLoadBalancer {
clusterStatus.getLiveServerMetrics().forEach((ServerName sn, ServerMetrics sm) -> {
sm.getRegionMetrics().forEach((byte[] regionName, RegionMetrics rm) -> {
Deque<BalancerRegionLoad> rLoads = oldLoads.get(Bytes.toString(regionName));
String regionNameAsString = RegionInfo.getRegionNameAsString(regionName);
Deque<BalancerRegionLoad> rLoads = oldLoads.get(regionNameAsString);
if (rLoads == null) {
rLoads = new ArrayDeque<>(numRegionLoadsToRemember + 1);
} else if (rLoads.size() >= numRegionLoadsToRemember) {
rLoads.remove();
}
rLoads.add(new BalancerRegionLoad(rm));
loads.put(Bytes.toString(regionName), rLoads);
loads.put(regionNameAsString, rLoads);
});
});

View File

@ -142,10 +142,12 @@ public class TestStochasticLoadBalancer extends BalancerTestBase {
loadBalancer.setClusterMetrics(clusterStatus);
}
assertTrue(loadBalancer.loads.get(REGION_KEY) != null);
assertTrue(loadBalancer.loads.get(REGION_KEY).size() == 15);
Queue<BalancerRegionLoad> loads = loadBalancer.loads.get(REGION_KEY);
String regionNameAsString = RegionInfo.getRegionNameAsString(Bytes.toBytes(REGION_KEY));
assertTrue(loadBalancer.loads.get(regionNameAsString) != null);
assertTrue(loadBalancer.loads.get(regionNameAsString).size() == 15);
Queue<BalancerRegionLoad> loads = loadBalancer.loads.get(regionNameAsString);
int i = 0;
while(loads.size() > 0) {
BalancerRegionLoad rl = loads.remove();