HBASE-21439 RegionLoads aren't being used in RegionLoad cost functions
Amend HBASE-21439 Update RSGroup Test too Signed-off-by: tedyu <yuzhihong@gmail.com> Signed-off-by: Andrew Purtell <apurtell@apache.org> Amending-Author: Andrew Purtell <apurtell@apache.org>
This commit is contained in:
parent
36178f7443
commit
68c9396685
|
@ -48,6 +48,8 @@ import org.apache.hadoop.hbase.util.Pair;
|
|||
import org.apache.hadoop.hbase.util.PairOfSameType;
|
||||
import org.apache.hadoop.io.DataInputBuffer;
|
||||
|
||||
import edu.umd.cs.findbugs.annotations.CheckForNull;
|
||||
|
||||
/**
|
||||
* Information about a region. A region is a range of keys in the whole keyspace of a table, an
|
||||
* identifier (a timestamp) for differentiating between subset ranges (after region split)
|
||||
|
@ -189,6 +191,26 @@ public class HRegionInfo implements Comparable<HRegionInfo> {
|
|||
return encodedName;
|
||||
}
|
||||
|
||||
@InterfaceAudience.Private
|
||||
public static String getRegionNameAsString(byte[] regionName) {
|
||||
return getRegionNameAsString(null, regionName);
|
||||
}
|
||||
|
||||
@InterfaceAudience.Private
|
||||
public static String getRegionNameAsString(@CheckForNull HRegionInfo ri, byte[] regionName) {
|
||||
if (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) + "." + encodeRegionName(regionName);
|
||||
} else {
|
||||
return Bytes.toStringBinary(regionName) + "." + ri.getEncodedName();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Return a short, printable name for this region (usually encoded name) for us logging.
|
||||
*/
|
||||
|
|
|
@ -84,7 +84,7 @@ public class TestRSGroupBasedLoadBalancerWithStochasticLoadBalancerAsInternal
|
|||
when(rl.getWriteRequestsCount()).thenReturn(0L);
|
||||
when(rl.getMemStoreSizeMB()).thenReturn(0);
|
||||
when(rl.getStorefileSizeMB()).thenReturn(0);
|
||||
regionLoadMap.put(info.getEncodedNameAsBytes(), rl);
|
||||
regionLoadMap.put(info.getRegionName(), rl);
|
||||
}
|
||||
when(serverMetrics.getRegionsLoad()).thenReturn(regionLoadMap);
|
||||
return serverMetrics;
|
||||
|
|
|
@ -51,7 +51,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 com.google.common.base.Optional;
|
||||
|
@ -545,7 +544,8 @@ public class StochasticLoadBalancer extends BaseLoadBalancer {
|
|||
continue;
|
||||
}
|
||||
for (Entry<byte[], RegionLoad> entry : sl.getRegionsLoad().entrySet()) {
|
||||
Deque<RegionLoad> rLoads = oldLoads.get(Bytes.toString(entry.getKey()));
|
||||
String regionNameAsString = HRegionInfo.getRegionNameAsString(entry.getKey());
|
||||
Deque<RegionLoad> rLoads = oldLoads.get(regionNameAsString);
|
||||
if (rLoads == null) {
|
||||
// There was nothing there
|
||||
rLoads = new ArrayDeque<RegionLoad>();
|
||||
|
@ -553,8 +553,7 @@ public class StochasticLoadBalancer extends BaseLoadBalancer {
|
|||
rLoads.remove();
|
||||
}
|
||||
rLoads.add(entry.getValue());
|
||||
loads.put(Bytes.toString(entry.getKey()), rLoads);
|
||||
|
||||
loads.put(regionNameAsString, rLoads);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -142,10 +142,12 @@ public class TestStochasticLoadBalancer extends BalancerTestBase {
|
|||
|
||||
loadBalancer.setClusterStatus(clusterStatus);
|
||||
}
|
||||
assertTrue(loadBalancer.loads.get(REGION_KEY) != null);
|
||||
assertTrue(loadBalancer.loads.get(REGION_KEY).size() == 15);
|
||||
|
||||
Queue<RegionLoad> loads = loadBalancer.loads.get(REGION_KEY);
|
||||
String regionNameAsString = HRegionInfo.getRegionNameAsString(Bytes.toBytes(REGION_KEY));
|
||||
assertTrue(loadBalancer.loads.get(regionNameAsString) != null);
|
||||
assertTrue(loadBalancer.loads.get(regionNameAsString).size() == 15);
|
||||
|
||||
Queue<RegionLoad> loads = loadBalancer.loads.get(regionNameAsString);
|
||||
int i = 0;
|
||||
while(loads.size() > 0) {
|
||||
RegionLoad rl = loads.remove();
|
||||
|
|
Loading…
Reference in New Issue