use of org.apache.hadoop.hbase.master.balancer.BaseLoadBalancer.Cluster.MoveRegionAction in project hbase by apache.
the class TestBaseLoadBalancer method testRegionAvailabilityWithRegionMoves.
@Test(timeout = 180000)
public void testRegionAvailabilityWithRegionMoves() throws Exception {
List<HRegionInfo> list0 = new ArrayList<>();
List<HRegionInfo> list1 = new ArrayList<>();
List<HRegionInfo> list2 = new ArrayList<>();
// create a region (region1)
HRegionInfo hri1 = new HRegionInfo(TableName.valueOf(name.getMethodName()), "key1".getBytes(), "key2".getBytes(), false, 100);
// create a replica of the region (replica_of_region1)
HRegionInfo hri2 = RegionReplicaUtil.getRegionInfoForReplica(hri1, 1);
// create a second region (region2)
HRegionInfo hri3 = new HRegionInfo(TableName.valueOf(name.getMethodName()), "key2".getBytes(), "key3".getBytes(), false, 101);
//only region1
list0.add(hri1);
//only replica_of_region1
list1.add(hri2);
//only region2
list2.add(hri3);
Map<ServerName, List<HRegionInfo>> clusterState = new LinkedHashMap<>();
//servers[0] hosts region1
clusterState.put(servers[0], list0);
//servers[1] hosts replica_of_region1
clusterState.put(servers[1], list1);
//servers[2] hosts region2
clusterState.put(servers[2], list2);
// create a cluster with the above clusterState. The way in which the
// cluster is created (constructor code) would make sure the indices of
// the servers are in the order in which it is inserted in the clusterState
// map (linkedhashmap is important).
Cluster cluster = new Cluster(clusterState, null, null, rackManager);
// check whether moving region1 from servers[1] to servers[2] would lower availability
assertTrue(!cluster.wouldLowerAvailability(hri1, servers[2]));
// now move region1 from servers[0] to servers[2]
cluster.doAction(new MoveRegionAction(0, 0, 2));
// check that the numMaxRegionsPerTable for "table" has increased to 2
assertEquals(2, cluster.numMaxRegionsPerTable[0]);
// now repeat check whether moving region1 from servers[1] to servers[2]
// would lower availability
assertTrue(cluster.wouldLowerAvailability(hri1, servers[2]));
// start over again
clusterState.clear();
List<HRegionInfo> list3 = new ArrayList<>();
HRegionInfo hri4 = RegionReplicaUtil.getRegionInfoForReplica(hri3, 1);
list3.add(hri4);
//servers[0], rack1 hosts region1
clusterState.put(servers[0], list0);
//servers[5], rack2 hosts replica_of_region1
clusterState.put(servers[5], list1);
//servers[6], rack2 hosts region2
clusterState.put(servers[6], list2);
//servers[12], rack3 hosts replica_of_region2
clusterState.put(servers[12], list3);
// create a cluster with the above clusterState
cluster = new Cluster(clusterState, null, null, rackManager);
// check whether a move of replica_of_region2 from servers[12],rack3 to servers[0],rack1 would
// lower the availability
assertTrue(!cluster.wouldLowerAvailability(hri4, servers[0]));
// now move region2 from servers[6],rack2 to servers[0],rack1
cluster.doAction(new MoveRegionAction(2, 2, 0));
// now repeat check if replica_of_region2 from servers[12],rack3 to servers[0],rack1 would
// lower the availability
assertTrue(cluster.wouldLowerAvailability(hri3, servers[0]));
}
Aggregations