Search in sources :

Example 6 with Cluster

use of org.apache.hadoop.hbase.master.balancer.BaseLoadBalancer.Cluster in project hbase by apache.

the class TestStochasticLoadBalancer method testReplicaCost.

@Test
public void testReplicaCost() {
    Configuration conf = HBaseConfiguration.create();
    StochasticLoadBalancer.CostFunction costFunction = new StochasticLoadBalancer.RegionReplicaHostCostFunction(conf);
    for (int[] mockCluster : clusterStateMocks) {
        BaseLoadBalancer.Cluster cluster = mockCluster(mockCluster);
        costFunction.init(cluster);
        double cost = costFunction.cost();
        assertTrue(cost >= 0);
        assertTrue(cost <= 1.01);
    }
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) HBaseConfiguration(org.apache.hadoop.hbase.HBaseConfiguration) Cluster(org.apache.hadoop.hbase.master.balancer.BaseLoadBalancer.Cluster) Test(org.junit.Test)

Example 7 with Cluster

use of org.apache.hadoop.hbase.master.balancer.BaseLoadBalancer.Cluster in project hbase by apache.

the class TestStochasticLoadBalancer method testReplicaCostForReplicas.

@Test
public void testReplicaCostForReplicas() {
    Configuration conf = HBaseConfiguration.create();
    StochasticLoadBalancer.CostFunction costFunction = new StochasticLoadBalancer.RegionReplicaHostCostFunction(conf);
    int[] servers = new int[] { 3, 3, 3, 3, 3 };
    TreeMap<ServerName, List<HRegionInfo>> clusterState = mockClusterServers(servers);
    BaseLoadBalancer.Cluster cluster;
    cluster = new BaseLoadBalancer.Cluster(clusterState, null, null, null);
    costFunction.init(cluster);
    double costWithoutReplicas = costFunction.cost();
    assertEquals(0, costWithoutReplicas, 0);
    // replicate the region from first server to the last server
    HRegionInfo replica1 = RegionReplicaUtil.getRegionInfoForReplica(clusterState.firstEntry().getValue().get(0), 1);
    clusterState.lastEntry().getValue().add(replica1);
    cluster = new BaseLoadBalancer.Cluster(clusterState, null, null, null);
    costFunction.init(cluster);
    double costWith1ReplicaDifferentServer = costFunction.cost();
    assertEquals(0, costWith1ReplicaDifferentServer, 0);
    // add a third replica to the last server
    HRegionInfo replica2 = RegionReplicaUtil.getRegionInfoForReplica(replica1, 2);
    clusterState.lastEntry().getValue().add(replica2);
    cluster = new BaseLoadBalancer.Cluster(clusterState, null, null, null);
    costFunction.init(cluster);
    double costWith1ReplicaSameServer = costFunction.cost();
    assertTrue(costWith1ReplicaDifferentServer < costWith1ReplicaSameServer);
    // test with replication = 4 for following:
    HRegionInfo replica3;
    Iterator<Entry<ServerName, List<HRegionInfo>>> it;
    Entry<ServerName, List<HRegionInfo>> entry;
    clusterState = mockClusterServers(servers);
    it = clusterState.entrySet().iterator();
    //first server
    entry = it.next();
    HRegionInfo hri = entry.getValue().get(0);
    replica1 = RegionReplicaUtil.getRegionInfoForReplica(hri, 1);
    replica2 = RegionReplicaUtil.getRegionInfoForReplica(hri, 2);
    replica3 = RegionReplicaUtil.getRegionInfoForReplica(hri, 3);
    entry.getValue().add(replica1);
    entry.getValue().add(replica2);
    //2nd server
    it.next().getValue().add(replica3);
    cluster = new BaseLoadBalancer.Cluster(clusterState, null, null, null);
    costFunction.init(cluster);
    double costWith3ReplicasSameServer = costFunction.cost();
    clusterState = mockClusterServers(servers);
    hri = clusterState.firstEntry().getValue().get(0);
    replica1 = RegionReplicaUtil.getRegionInfoForReplica(hri, 1);
    replica2 = RegionReplicaUtil.getRegionInfoForReplica(hri, 2);
    replica3 = RegionReplicaUtil.getRegionInfoForReplica(hri, 3);
    clusterState.firstEntry().getValue().add(replica1);
    clusterState.lastEntry().getValue().add(replica2);
    clusterState.lastEntry().getValue().add(replica3);
    cluster = new BaseLoadBalancer.Cluster(clusterState, null, null, null);
    costFunction.init(cluster);
    double costWith2ReplicasOnTwoServers = costFunction.cost();
    assertTrue(costWith2ReplicasOnTwoServers < costWith3ReplicasSameServer);
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) HBaseConfiguration(org.apache.hadoop.hbase.HBaseConfiguration) HRegionInfo(org.apache.hadoop.hbase.HRegionInfo) Entry(java.util.Map.Entry) ServerName(org.apache.hadoop.hbase.ServerName) ArrayList(java.util.ArrayList) List(java.util.List) Cluster(org.apache.hadoop.hbase.master.balancer.BaseLoadBalancer.Cluster) Test(org.junit.Test)

Example 8 with Cluster

use of org.apache.hadoop.hbase.master.balancer.BaseLoadBalancer.Cluster in project hbase by apache.

the class TestBaseLoadBalancer method testClusterServersWithSameHostPort.

@Test(timeout = 180000)
public void testClusterServersWithSameHostPort() {
    // tests whether the BaseLoadBalancer.Cluster can be constructed with servers
    // sharing same host and port
    List<ServerName> servers = getListOfServerNames(randomServers(10, 10));
    List<HRegionInfo> regions = randomRegions(101);
    Map<ServerName, List<HRegionInfo>> clusterState = new HashMap<>();
    assignRegions(regions, servers, clusterState);
    // construct another list of servers, but sharing same hosts and ports
    List<ServerName> oldServers = new ArrayList<>(servers.size());
    for (ServerName sn : servers) {
        // The old server would have had same host and port, but different start code!
        oldServers.add(ServerName.valueOf(sn.getHostname(), sn.getPort(), sn.getStartcode() - 10));
    }
    // some more regions
    regions = randomRegions(9);
    assignRegions(regions, oldServers, clusterState);
    // should not throw exception:
    BaseLoadBalancer.Cluster cluster = new Cluster(clusterState, null, null, null);
    assertEquals(101 + 9, cluster.numRegions);
    // only 10 servers because they share the same host + port
    assertEquals(10, cluster.numServers);
}
Also used : HRegionInfo(org.apache.hadoop.hbase.HRegionInfo) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ServerName(org.apache.hadoop.hbase.ServerName) ArrayList(java.util.ArrayList) Cluster(org.apache.hadoop.hbase.master.balancer.BaseLoadBalancer.Cluster) ArrayList(java.util.ArrayList) List(java.util.List) Cluster(org.apache.hadoop.hbase.master.balancer.BaseLoadBalancer.Cluster) Test(org.junit.Test)

Example 9 with Cluster

use of org.apache.hadoop.hbase.master.balancer.BaseLoadBalancer.Cluster in project hbase by apache.

the class TestStochasticLoadBalancer method testMoveCost.

@Test
public void testMoveCost() throws Exception {
    Configuration conf = HBaseConfiguration.create();
    StochasticLoadBalancer.CostFunction costFunction = new StochasticLoadBalancer.MoveCostFunction(conf);
    for (int[] mockCluster : clusterStateMocks) {
        BaseLoadBalancer.Cluster cluster = mockCluster(mockCluster);
        costFunction.init(cluster);
        double cost = costFunction.cost();
        assertEquals(0.0f, cost, 0.001);
        // cluster region number is smaller than maxMoves=600
        cluster.setNumRegions(200);
        cluster.setNumMovedRegions(10);
        cost = costFunction.cost();
        assertEquals(0.05f, cost, 0.001);
        cluster.setNumMovedRegions(100);
        cost = costFunction.cost();
        assertEquals(0.5f, cost, 0.001);
        cluster.setNumMovedRegions(200);
        cost = costFunction.cost();
        assertEquals(1.0f, cost, 0.001);
        // cluster region number is bigger than maxMoves=2500
        cluster.setNumRegions(10000);
        cluster.setNumMovedRegions(250);
        cost = costFunction.cost();
        assertEquals(0.1f, cost, 0.001);
        cluster.setNumMovedRegions(1250);
        cost = costFunction.cost();
        assertEquals(0.5f, cost, 0.001);
        cluster.setNumMovedRegions(2500);
        cost = costFunction.cost();
        assertEquals(1.0f, cost, 0.01);
    }
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) HBaseConfiguration(org.apache.hadoop.hbase.HBaseConfiguration) Cluster(org.apache.hadoop.hbase.master.balancer.BaseLoadBalancer.Cluster) Test(org.junit.Test)

Aggregations

Cluster (org.apache.hadoop.hbase.master.balancer.BaseLoadBalancer.Cluster)9 Test (org.junit.Test)9 ArrayList (java.util.ArrayList)6 List (java.util.List)6 HRegionInfo (org.apache.hadoop.hbase.HRegionInfo)6 ServerName (org.apache.hadoop.hbase.ServerName)6 LinkedHashMap (java.util.LinkedHashMap)4 Configuration (org.apache.hadoop.conf.Configuration)4 HBaseConfiguration (org.apache.hadoop.hbase.HBaseConfiguration)4 HashMap (java.util.HashMap)3 Entry (java.util.Map.Entry)1 MoveRegionAction (org.apache.hadoop.hbase.master.balancer.BaseLoadBalancer.Cluster.MoveRegionAction)1