Search in sources :

Example 1 with MasterClusterInfoProvider

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

the class RSGroupBasedLoadBalancer method initialize.

@Override
public void initialize() throws IOException {
    if (rsGroupInfoManager == null) {
        rsGroupInfoManager = masterServices.getRSGroupInfoManager();
        if (rsGroupInfoManager == null) {
            String msg = "RSGroupInfoManager hasn't been initialized";
            LOG.error(msg);
            throw new HBaseIOException(msg);
        }
        rsGroupInfoManager.start();
    }
    // Create the balancer
    Configuration conf = masterServices.getConfiguration();
    Class<? extends LoadBalancer> balancerClass;
    @SuppressWarnings("deprecation") String balancerClassName = conf.get(HBASE_RSGROUP_LOADBALANCER_CLASS);
    if (balancerClassName == null) {
        balancerClass = conf.getClass(HConstants.HBASE_MASTER_LOADBALANCER_CLASS, LoadBalancerFactory.getDefaultLoadBalancerClass(), LoadBalancer.class);
    } else {
        try {
            balancerClass = Class.forName(balancerClassName).asSubclass(LoadBalancer.class);
        } catch (ClassNotFoundException e) {
            throw new IOException(e);
        }
    }
    this.provider = new MasterClusterInfoProvider(masterServices);
    // avoid infinite nesting
    if (getClass().isAssignableFrom(balancerClass)) {
        balancerClass = LoadBalancerFactory.getDefaultLoadBalancerClass();
    }
    internalBalancer = ReflectionUtils.newInstance(balancerClass);
    internalBalancer.setClusterInfoProvider(provider);
    // special handling for favor node balancers
    if (internalBalancer instanceof FavoredNodesPromoter) {
        favoredNodesManager = new FavoredNodesManager(provider);
        ((FavoredNodesPromoter) internalBalancer).setFavoredNodesManager(favoredNodesManager);
    }
    internalBalancer.initialize();
    // init fallback groups
    this.fallbackEnabled = conf.getBoolean(FALLBACK_GROUP_ENABLE_KEY, false);
}
Also used : MasterClusterInfoProvider(org.apache.hadoop.hbase.master.balancer.MasterClusterInfoProvider) Configuration(org.apache.hadoop.conf.Configuration) HBaseIOException(org.apache.hadoop.hbase.HBaseIOException) FavoredNodesPromoter(org.apache.hadoop.hbase.favored.FavoredNodesPromoter) LoadBalancer(org.apache.hadoop.hbase.master.LoadBalancer) FavoredNodesManager(org.apache.hadoop.hbase.favored.FavoredNodesManager) IOException(java.io.IOException) HBaseIOException(org.apache.hadoop.hbase.HBaseIOException)

Example 2 with MasterClusterInfoProvider

use of org.apache.hadoop.hbase.master.balancer.MasterClusterInfoProvider 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 3 with MasterClusterInfoProvider

use of org.apache.hadoop.hbase.master.balancer.MasterClusterInfoProvider 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

MasterClusterInfoProvider (org.apache.hadoop.hbase.master.balancer.MasterClusterInfoProvider)3 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 Test (org.junit.Test)2 IOException (java.io.IOException)1 List (java.util.List)1 Configuration (org.apache.hadoop.conf.Configuration)1 HBaseIOException (org.apache.hadoop.hbase.HBaseIOException)1 FavoredNodesManager (org.apache.hadoop.hbase.favored.FavoredNodesManager)1 FavoredNodesPromoter (org.apache.hadoop.hbase.favored.FavoredNodesPromoter)1 LoadBalancer (org.apache.hadoop.hbase.master.LoadBalancer)1