Search in sources :

Example 1 with FavoredNodeLoadBalancer

use of org.apache.hadoop.hbase.favored.FavoredNodeLoadBalancer in project hbase by apache.

the class TestRegionPlacement2 method testFavoredNodesPresentForRandomAssignment.

@Test
public void testFavoredNodesPresentForRandomAssignment() throws IOException {
    FavoredNodeLoadBalancer balancer = (FavoredNodeLoadBalancer) LoadBalancerFactory.getLoadBalancer(TEST_UTIL.getConfiguration());
    balancer.setClusterInfoProvider(new MasterClusterInfoProvider(TEST_UTIL.getMiniHBaseCluster().getMaster()));
    balancer.setFavoredNodesManager(TEST_UTIL.getMiniHBaseCluster().getMaster().getFavoredNodesManager());
    balancer.initialize();
    List<ServerName> servers = new ArrayList<>();
    for (int i = 0; i < SLAVES; i++) {
        ServerName server = TEST_UTIL.getMiniHBaseCluster().getRegionServer(i).getServerName();
        servers.add(server);
    }
    List<RegionInfo> regions = new ArrayList<>(1);
    RegionInfo region = RegionInfoBuilder.newBuilder(TableName.valueOf(name.getMethodName())).build();
    regions.add(region);
    ServerName serverBefore = balancer.randomAssignment(region, servers);
    List<ServerName> favoredNodesBefore = ((FavoredNodeLoadBalancer) balancer).getFavoredNodes(region);
    assertTrue(favoredNodesBefore.size() == FavoredNodeAssignmentHelper.FAVORED_NODES_NUM);
    // the primary RS should be the one that the balancer's assignment returns
    assertTrue(ServerName.isSameAddress(serverBefore, favoredNodesBefore.get(PRIMARY)));
    // now remove the primary from the list of servers
    removeMatchingServers(serverBefore, servers);
    // call randomAssignment with the modified servers list
    ServerName serverAfter = balancer.randomAssignment(region, servers);
    List<ServerName> favoredNodesAfter = ((FavoredNodeLoadBalancer) balancer).getFavoredNodes(region);
    assertTrue(favoredNodesAfter.size() == FavoredNodeAssignmentHelper.FAVORED_NODES_NUM);
    // We don't expect the favored nodes assignments to change in multiple calls
    // to the randomAssignment method in the balancer (relevant for AssignmentManager.assign
    // failures)
    assertTrue(favoredNodesAfter.containsAll(favoredNodesBefore));
    // We expect the new RegionServer assignee to be one of the favored nodes
    // chosen earlier.
    assertTrue(ServerName.isSameAddress(serverAfter, favoredNodesBefore.get(SECONDARY)) || ServerName.isSameAddress(serverAfter, favoredNodesBefore.get(TERTIARY)));
    // Make all the favored nodes unavailable for assignment
    removeMatchingServers(favoredNodesAfter, servers);
    // call randomAssignment with the modified servers list
    balancer.randomAssignment(region, servers);
    List<ServerName> favoredNodesNow = ((FavoredNodeLoadBalancer) balancer).getFavoredNodes(region);
    assertTrue(favoredNodesNow.size() == FavoredNodeAssignmentHelper.FAVORED_NODES_NUM);
    assertTrue(!favoredNodesNow.contains(favoredNodesAfter.get(PRIMARY)) && !favoredNodesNow.contains(favoredNodesAfter.get(SECONDARY)) && !favoredNodesNow.contains(favoredNodesAfter.get(TERTIARY)));
}
Also used : MasterClusterInfoProvider(org.apache.hadoop.hbase.master.balancer.MasterClusterInfoProvider) FavoredNodeLoadBalancer(org.apache.hadoop.hbase.favored.FavoredNodeLoadBalancer) ServerName(org.apache.hadoop.hbase.ServerName) ArrayList(java.util.ArrayList) RegionInfo(org.apache.hadoop.hbase.client.RegionInfo) Test(org.junit.Test)

Example 2 with FavoredNodeLoadBalancer

use of org.apache.hadoop.hbase.favored.FavoredNodeLoadBalancer in project hbase by apache.

the class TestRegionPlacement2 method testFavoredNodesPresentForRoundRobinAssignment.

@Test
public void testFavoredNodesPresentForRoundRobinAssignment() throws IOException {
    FavoredNodeLoadBalancer balancer = (FavoredNodeLoadBalancer) LoadBalancerFactory.getLoadBalancer(TEST_UTIL.getConfiguration());
    balancer.setClusterInfoProvider(new MasterClusterInfoProvider(TEST_UTIL.getMiniHBaseCluster().getMaster()));
    balancer.setFavoredNodesManager(TEST_UTIL.getMiniHBaseCluster().getMaster().getFavoredNodesManager());
    balancer.initialize();
    List<ServerName> servers = new ArrayList<>();
    for (int i = 0; i < SLAVES; i++) {
        ServerName server = TEST_UTIL.getMiniHBaseCluster().getRegionServer(i).getServerName();
        servers.add(server);
    }
    List<RegionInfo> regions = new ArrayList<>(1);
    RegionInfo region = RegionInfoBuilder.newBuilder(TableName.valueOf(name.getMethodName())).build();
    regions.add(region);
    Map<ServerName, List<RegionInfo>> assignmentMap = balancer.roundRobinAssignment(regions, servers);
    Set<ServerName> serverBefore = assignmentMap.keySet();
    List<ServerName> favoredNodesBefore = ((FavoredNodeLoadBalancer) balancer).getFavoredNodes(region);
    assertTrue(favoredNodesBefore.size() == FavoredNodeAssignmentHelper.FAVORED_NODES_NUM);
    // the primary RS should be the one that the balancer's assignment returns
    assertTrue(ServerName.isSameAddress(serverBefore.iterator().next(), favoredNodesBefore.get(PRIMARY)));
    // now remove the primary from the list of available servers
    List<ServerName> removedServers = removeMatchingServers(serverBefore, servers);
    // call roundRobinAssignment with the modified servers list
    assignmentMap = balancer.roundRobinAssignment(regions, servers);
    List<ServerName> favoredNodesAfter = ((FavoredNodeLoadBalancer) balancer).getFavoredNodes(region);
    assertTrue(favoredNodesAfter.size() == FavoredNodeAssignmentHelper.FAVORED_NODES_NUM);
    // We don't expect the favored nodes assignments to change in multiple calls
    // to the roundRobinAssignment method in the balancer (relevant for AssignmentManager.assign
    // failures)
    assertTrue(favoredNodesAfter.containsAll(favoredNodesBefore));
    Set<ServerName> serverAfter = assignmentMap.keySet();
    // We expect the new RegionServer assignee to be one of the favored nodes
    // chosen earlier.
    assertTrue(ServerName.isSameAddress(serverAfter.iterator().next(), favoredNodesBefore.get(SECONDARY)) || ServerName.isSameAddress(serverAfter.iterator().next(), favoredNodesBefore.get(TERTIARY)));
    // put back the primary in the list of available servers
    servers.addAll(removedServers);
    // now roundRobinAssignment with the modified servers list should return the primary
    // as the regionserver assignee
    assignmentMap = balancer.roundRobinAssignment(regions, servers);
    Set<ServerName> serverWithPrimary = assignmentMap.keySet();
    assertTrue(serverBefore.containsAll(serverWithPrimary));
    // Make all the favored nodes unavailable for assignment
    removeMatchingServers(favoredNodesAfter, servers);
    // call roundRobinAssignment with the modified servers list
    assignmentMap = balancer.roundRobinAssignment(regions, servers);
    List<ServerName> favoredNodesNow = ((FavoredNodeLoadBalancer) balancer).getFavoredNodes(region);
    assertTrue(favoredNodesNow.size() == FavoredNodeAssignmentHelper.FAVORED_NODES_NUM);
    assertTrue(!favoredNodesNow.contains(favoredNodesAfter.get(PRIMARY)) && !favoredNodesNow.contains(favoredNodesAfter.get(SECONDARY)) && !favoredNodesNow.contains(favoredNodesAfter.get(TERTIARY)));
}
Also used : MasterClusterInfoProvider(org.apache.hadoop.hbase.master.balancer.MasterClusterInfoProvider) FavoredNodeLoadBalancer(org.apache.hadoop.hbase.favored.FavoredNodeLoadBalancer) ServerName(org.apache.hadoop.hbase.ServerName) ArrayList(java.util.ArrayList) RegionInfo(org.apache.hadoop.hbase.client.RegionInfo) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Aggregations

ArrayList (java.util.ArrayList)2 ServerName (org.apache.hadoop.hbase.ServerName)2 RegionInfo (org.apache.hadoop.hbase.client.RegionInfo)2 FavoredNodeLoadBalancer (org.apache.hadoop.hbase.favored.FavoredNodeLoadBalancer)2 MasterClusterInfoProvider (org.apache.hadoop.hbase.master.balancer.MasterClusterInfoProvider)2 Test (org.junit.Test)2 List (java.util.List)1