Search in sources :

Example 1 with RSGroupInfo

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;
}
Also used : TableName(org.apache.hadoop.hbase.TableName) RSGroupInfo(org.apache.hadoop.hbase.rsgroup.RSGroupInfo) RSGroupInfoManager(org.apache.hadoop.hbase.rsgroup.RSGroupInfoManager) HTableDescriptor(org.apache.hadoop.hbase.HTableDescriptor)

Example 2 with RSGroupInfo

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()));
                }
            }
        }
    }
}
Also used : HRegionInfo(org.apache.hadoop.hbase.HRegionInfo) TableName(org.apache.hadoop.hbase.TableName) RSGroupInfo(org.apache.hadoop.hbase.rsgroup.RSGroupInfo) TreeSet(java.util.TreeSet) ServerName(org.apache.hadoop.hbase.ServerName) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) TreeMap(java.util.TreeMap)

Example 3 with RSGroupInfo

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);
}
Also used : HRegionInfo(org.apache.hadoop.hbase.HRegionInfo) TableName(org.apache.hadoop.hbase.TableName) RSGroupInfo(org.apache.hadoop.hbase.rsgroup.RSGroupInfo) ServerName(org.apache.hadoop.hbase.ServerName) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Example 4 with RSGroupInfo

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()));
    }
}
Also used : HRegionInfo(org.apache.hadoop.hbase.HRegionInfo) TableName(org.apache.hadoop.hbase.TableName) RSGroupInfo(org.apache.hadoop.hbase.rsgroup.RSGroupInfo) ServerName(org.apache.hadoop.hbase.ServerName)

Example 5 with RSGroupInfo

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;
}
Also used : HRegionInfo(org.apache.hadoop.hbase.HRegionInfo) Address(org.apache.hadoop.hbase.net.Address) RSGroupInfo(org.apache.hadoop.hbase.rsgroup.RSGroupInfo) ServerName(org.apache.hadoop.hbase.ServerName)

Aggregations

RSGroupInfo (org.apache.hadoop.hbase.rsgroup.RSGroupInfo)6 HRegionInfo (org.apache.hadoop.hbase.HRegionInfo)4 ServerName (org.apache.hadoop.hbase.ServerName)4 TableName (org.apache.hadoop.hbase.TableName)4 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1 TreeSet (java.util.TreeSet)1 HTableDescriptor (org.apache.hadoop.hbase.HTableDescriptor)1 Address (org.apache.hadoop.hbase.net.Address)1 RSGroupInfoManager (org.apache.hadoop.hbase.rsgroup.RSGroupInfoManager)1 Test (org.junit.Test)1