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);
}
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)));
}
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)));
}
Aggregations