HBASE-12664 TestDefaultLoadBalancer.testBalanceCluster fails in CachedDNSToSwitchMapping

Conflicts:
	hbase-server/src/test/java/org/apache/hadoop/hbase/master/balancer/TestDefaultLoadBalancer.java
	hbase-server/src/test/java/org/apache/hadoop/hbase/master/balancer/TestStochasticLoadBalancer.java
This commit is contained in:
stack 2014-12-09 11:06:23 -08:00
parent 9a128b94d5
commit d7f2ac796f
4 changed files with 29 additions and 24 deletions

View File

@ -33,6 +33,7 @@ import java.util.SortedSet;
import java.util.TreeMap;
import java.util.TreeSet;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HRegionInfo;
import org.apache.hadoop.hbase.ServerName;
import org.apache.hadoop.hbase.TableName;
@ -40,6 +41,7 @@ import org.apache.hadoop.hbase.client.RegionReplicaUtil;
import org.apache.hadoop.hbase.master.RackManager;
import org.apache.hadoop.hbase.master.RegionPlan;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.net.DNSToSwitchMapping;
import org.junit.Assert;
/**
@ -53,6 +55,28 @@ public class BalancerTestBase {
protected static Random rand = new Random();
static int regionId = 0;
// This class is introduced because IP to rack resolution can be lengthy.
static class MockMapping implements DNSToSwitchMapping {
public MockMapping(Configuration conf) {
}
public List<String> resolve(List<String> names) {
List<String> ret = new ArrayList<String>(names.size());
for (String name : names) {
ret.add("rack");
}
return ret;
}
// do not add @Override annotations here. It mighty break compilation with earlier Hadoops
public void reloadCachedMappings() {
}
// do not add @Override annotations here. It mighty break compilation with earlier Hadoops
public void reloadCachedMappings(List<String> arg0) {
}
}
/**
* Invariant is that all servers have between floor(avg) and ceiling(avg)
* number of regions.

View File

@ -72,30 +72,6 @@ public class TestBaseLoadBalancer extends BalancerTestBase {
new int[] { 1, 3 }, new int[] { 2, 3 }, new int[] { 3, 3 }, new int[] { 25, 3 },
new int[] { 2, 10 }, new int[] { 2, 100 }, new int[] { 12, 10 }, new int[] { 12, 100 }, };
// This class is introduced because IP to rack resolution can be lengthy.
public static class MockMapping implements DNSToSwitchMapping {
public MockMapping(Configuration conf) {
}
private static String RACK = "rack";
public List<String> resolve(List<String> names) {
List<String> ret = new ArrayList<String>(names.size());
for (String name : names) {
ret.add(RACK);
}
return ret;
}
// do not add @Override annotations here. It mighty break compilation with earlier Hadoops
public void reloadCachedMappings() {
}
// do not add @Override annotations here. It mighty break compilation with earlier Hadoops
public void reloadCachedMappings(List<String> arg0) {
}
}
@BeforeClass
public static void beforeAllTests() throws Exception {
Configuration conf = HBaseConfiguration.create();

View File

@ -45,6 +45,7 @@ public class TestDefaultLoadBalancer extends BalancerTestBase {
@BeforeClass
public static void beforeAllTests() throws Exception {
Configuration conf = HBaseConfiguration.create();
conf.setClass("hbase.util.ip.to.rack.determiner", MockMapping.class, DNSToSwitchMapping.class);
conf.set("hbase.regions.slop", "0");
loadBalancer = new SimpleLoadBalancer();
loadBalancer.setConf(conf);

View File

@ -48,7 +48,10 @@ import org.apache.hadoop.hbase.client.RegionReplicaUtil;
import org.apache.hadoop.hbase.master.RackManager;
import org.apache.hadoop.hbase.master.RegionPlan;
import org.apache.hadoop.hbase.master.balancer.BaseLoadBalancer.Cluster;
import org.apache.hadoop.hbase.testclassification.FlakeyTests;
import org.apache.hadoop.hbase.testclassification.MediumTests;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.net.DNSToSwitchMapping;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;
@ -63,6 +66,7 @@ public class TestStochasticLoadBalancer extends BalancerTestBase {
@BeforeClass
public static void beforeAllTests() throws Exception {
conf = HBaseConfiguration.create();
conf.setClass("hbase.util.ip.to.rack.determiner", MockMapping.class, DNSToSwitchMapping.class);
conf.setFloat("hbase.master.balancer.stochastic.maxMovePercent", 0.75f);
conf.setFloat("hbase.regions.slop", 0.0f);
loadBalancer = new StochasticLoadBalancer();