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:
parent
dcdebbffdc
commit
13b68abb58
|
@ -18,6 +18,8 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.hadoop.hbase.client;
|
package org.apache.hadoop.hbase.client;
|
||||||
|
|
||||||
|
import edu.umd.cs.findbugs.annotations.CheckForNull;
|
||||||
|
|
||||||
import java.io.DataInputStream;
|
import java.io.DataInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
@ -271,6 +273,26 @@ public interface RegionInfo {
|
||||||
return encodedName;
|
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>
|
* @return Return a String of short, printable names for <code>hris</code>
|
||||||
* (usually encoded name) for us logging.
|
* (usually encoded name) for us logging.
|
||||||
|
|
|
@ -287,15 +287,7 @@ public class RegionInfoBuilder {
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String getRegionNameAsString() {
|
public String getRegionNameAsString() {
|
||||||
if (RegionInfo.hasEncodedName(this.regionName)) {
|
return RegionInfo.getRegionNameAsString(this, 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 the encoded region name */
|
/** @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.LocalityType;
|
||||||
import org.apache.hadoop.hbase.master.balancer.BaseLoadBalancer.Cluster.MoveRegionAction;
|
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.master.balancer.BaseLoadBalancer.Cluster.SwapRegionsAction;
|
||||||
import org.apache.hadoop.hbase.util.Bytes;
|
|
||||||
import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;
|
import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;
|
||||||
import org.apache.yetus.audience.InterfaceAudience;
|
import org.apache.yetus.audience.InterfaceAudience;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
|
@ -531,14 +530,15 @@ public class StochasticLoadBalancer extends BaseLoadBalancer {
|
||||||
|
|
||||||
clusterStatus.getLiveServerMetrics().forEach((ServerName sn, ServerMetrics sm) -> {
|
clusterStatus.getLiveServerMetrics().forEach((ServerName sn, ServerMetrics sm) -> {
|
||||||
sm.getRegionMetrics().forEach((byte[] regionName, RegionMetrics rm) -> {
|
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) {
|
if (rLoads == null) {
|
||||||
rLoads = new ArrayDeque<>(numRegionLoadsToRemember + 1);
|
rLoads = new ArrayDeque<>(numRegionLoadsToRemember + 1);
|
||||||
} else if (rLoads.size() >= numRegionLoadsToRemember) {
|
} else if (rLoads.size() >= numRegionLoadsToRemember) {
|
||||||
rLoads.remove();
|
rLoads.remove();
|
||||||
}
|
}
|
||||||
rLoads.add(new BalancerRegionLoad(rm));
|
rLoads.add(new BalancerRegionLoad(rm));
|
||||||
loads.put(Bytes.toString(regionName), rLoads);
|
loads.put(regionNameAsString, rLoads);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -142,10 +142,12 @@ public class TestStochasticLoadBalancer extends BalancerTestBase {
|
||||||
|
|
||||||
loadBalancer.setClusterMetrics(clusterStatus);
|
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;
|
int i = 0;
|
||||||
while(loads.size() > 0) {
|
while(loads.size() > 0) {
|
||||||
BalancerRegionLoad rl = loads.remove();
|
BalancerRegionLoad rl = loads.remove();
|
||||||
|
|
Loading…
Reference in New Issue