HBASE-21439 RegionLoads aren't being used in RegionLoad cost functions
Signed-off-by: tedyu <yuzhihong@gmail.com>
This commit is contained in:
parent
a8ad61ec88
commit
d9f32137b6
|
@ -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.
|
||||
|
|
|
@ -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 */
|
||||
|
|
|
@ -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;
|
||||
|
@ -533,14 +532,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);
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -131,7 +131,7 @@ public class TestStochasticLoadBalancer extends BalancerTestBase {
|
|||
when(rl.getWriteRequestCount()).thenReturn(0L);
|
||||
when(rl.getMemStoreSize()).thenReturn(Size.ZERO);
|
||||
when(rl.getStoreFileSize()).thenReturn(Size.ZERO);
|
||||
regionLoadMap.put(info.getEncodedNameAsBytes(), rl);
|
||||
regionLoadMap.put(info.getRegionName(), rl);
|
||||
}
|
||||
when(serverMetrics.getRegionMetrics()).thenReturn(regionLoadMap);
|
||||
return serverMetrics;
|
||||
|
@ -222,10 +222,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();
|
||||
|
|
Loading…
Reference in New Issue