use of org.apache.hadoop.hbase.rsgroup.RSGroupInfo in project hbase by apache.
the class TestRSGroupBasedLoadBalancer method getTableName.
private TableName getTableName(ServerName sn) throws IOException {
TableName tableName = null;
RSGroupInfoManager gm = getMockedGroupInfoManager();
RSGroupInfo groupOfServer = null;
for (RSGroupInfo gInfo : gm.listRSGroups()) {
if (gInfo.containsServer(sn.getAddress())) {
groupOfServer = gInfo;
break;
}
}
for (HTableDescriptor desc : tableDescs) {
if (gm.getRSGroupOfTable(desc.getTableName()).endsWith(groupOfServer.getName())) {
tableName = desc.getTableName();
}
}
return tableName;
}
use of org.apache.hadoop.hbase.rsgroup.RSGroupInfo in project hbase by apache.
the class TestRSGroupBasedLoadBalancer method assertRetainedAssignment.
/**
* Asserts a valid retained assignment plan.
* <p>
* Must meet the following conditions:
* <ul>
* <li>Every input region has an assignment, and to an online server
* <li>If a region had an existing assignment to a server with the same
* address a a currently online server, it will be assigned to it
* </ul>
*
* @param existing
* @param assignment
* @throws java.io.IOException
* @throws java.io.FileNotFoundException
*/
private void assertRetainedAssignment(Map<HRegionInfo, ServerName> existing, List<ServerName> servers, Map<ServerName, List<HRegionInfo>> assignment) throws FileNotFoundException, IOException {
// Verify condition 1, every region assigned, and to online server
Set<ServerName> onlineServerSet = new TreeSet<>(servers);
Set<HRegionInfo> assignedRegions = new TreeSet<>();
for (Map.Entry<ServerName, List<HRegionInfo>> a : assignment.entrySet()) {
assertTrue("Region assigned to server that was not listed as online", onlineServerSet.contains(a.getKey()));
for (HRegionInfo r : a.getValue()) assignedRegions.add(r);
}
assertEquals(existing.size(), assignedRegions.size());
// Verify condition 2, every region must be assigned to correct server.
Set<String> onlineHostNames = new TreeSet<>();
for (ServerName s : servers) {
onlineHostNames.add(s.getHostname());
}
for (Map.Entry<ServerName, List<HRegionInfo>> a : assignment.entrySet()) {
ServerName currentServer = a.getKey();
for (HRegionInfo r : a.getValue()) {
ServerName oldAssignedServer = existing.get(r);
TableName tableName = r.getTable();
String groupName = getMockedGroupInfoManager().getRSGroupOfTable(tableName);
assertTrue(StringUtils.isNotEmpty(groupName));
RSGroupInfo gInfo = getMockedGroupInfoManager().getRSGroup(groupName);
assertTrue("Region is not correctly assigned to group servers.", gInfo.containsServer(currentServer.getAddress()));
if (oldAssignedServer != null && onlineHostNames.contains(oldAssignedServer.getHostname())) {
// different group.
if (!oldAssignedServer.getAddress().equals(currentServer.getAddress())) {
assertFalse(gInfo.containsServer(oldAssignedServer.getAddress()));
}
}
}
}
}
use of org.apache.hadoop.hbase.rsgroup.RSGroupInfo in project hbase by apache.
the class TestRSGroupBasedLoadBalancer method testBulkAssignment.
/**
* Tests the bulk assignment used during cluster startup.
*
* Round-robin. Should yield a balanced cluster so same invariant as the
* load balancer holds, all servers holding either floor(avg) or
* ceiling(avg).
*
* @throws Exception
*/
@Test
public void testBulkAssignment() throws Exception {
List<HRegionInfo> regions = randomRegions(25);
Map<ServerName, List<HRegionInfo>> assignments = loadBalancer.roundRobinAssignment(regions, servers);
//test empty region/servers scenario
//this should not throw an NPE
loadBalancer.roundRobinAssignment(regions, Collections.EMPTY_LIST);
//test regular scenario
assertTrue(assignments.keySet().size() == servers.size());
for (ServerName sn : assignments.keySet()) {
List<HRegionInfo> regionAssigned = assignments.get(sn);
for (HRegionInfo region : regionAssigned) {
TableName tableName = region.getTable();
String groupName = getMockedGroupInfoManager().getRSGroupOfTable(tableName);
assertTrue(StringUtils.isNotEmpty(groupName));
RSGroupInfo gInfo = getMockedGroupInfoManager().getRSGroup(groupName);
assertTrue("Region is not correctly assigned to group servers.", gInfo.containsServer(sn.getAddress()));
}
}
ArrayListMultimap<String, ServerAndLoad> loadMap = convertToGroupBasedMap(assignments);
assertClusterAsBalanced(loadMap);
}
use of org.apache.hadoop.hbase.rsgroup.RSGroupInfo in project hbase by apache.
the class TestRSGroupBasedLoadBalancer method assertImmediateAssignment.
/**
* All regions have an assignment.
*
* @param regions
* @param servers
* @param assignments
* @throws java.io.IOException
* @throws java.io.FileNotFoundException
*/
private void assertImmediateAssignment(List<HRegionInfo> regions, List<ServerName> servers, Map<HRegionInfo, ServerName> assignments) throws IOException {
for (HRegionInfo region : regions) {
assertTrue(assignments.containsKey(region));
ServerName server = assignments.get(region);
TableName tableName = region.getTable();
String groupName = getMockedGroupInfoManager().getRSGroupOfTable(tableName);
assertTrue(StringUtils.isNotEmpty(groupName));
RSGroupInfo gInfo = getMockedGroupInfoManager().getRSGroup(groupName);
assertTrue("Region is not correctly assigned to group servers.", gInfo.containsServer(server.getAddress()));
}
}
use of org.apache.hadoop.hbase.rsgroup.RSGroupInfo in project hbase by apache.
the class TestRSGroupBasedLoadBalancer method convertToGroupBasedMap.
private ArrayListMultimap<String, ServerAndLoad> convertToGroupBasedMap(final Map<ServerName, List<HRegionInfo>> serversMap) throws IOException {
ArrayListMultimap<String, ServerAndLoad> loadMap = ArrayListMultimap.create();
for (RSGroupInfo gInfo : getMockedGroupInfoManager().listRSGroups()) {
Set<Address> groupServers = gInfo.getServers();
for (Address hostPort : groupServers) {
ServerName actual = null;
for (ServerName entry : servers) {
if (entry.getAddress().equals(hostPort)) {
actual = entry;
break;
}
}
List<HRegionInfo> regions = serversMap.get(actual);
assertTrue("No load for " + actual, regions != null);
loadMap.put(gInfo.getName(), new ServerAndLoad(actual, regions.size()));
}
}
return loadMap;
}
Aggregations