Search in sources :

Example 6 with ServerName

use of org.apache.hadoop.hbase.ServerName in project hbase by apache.

the class RSGroupInfoManagerImpl method getDefaultServers.

// Called by ServerEventsListenerThread. Presume it has lock on this manager when it runs.
private SortedSet<Address> getDefaultServers() throws IOException {
    SortedSet<Address> defaultServers = Sets.newTreeSet();
    for (ServerName serverName : getOnlineRS()) {
        Address server = Address.fromParts(serverName.getHostname(), serverName.getPort());
        boolean found = false;
        for (RSGroupInfo rsgi : listRSGroups()) {
            if (!RSGroupInfo.DEFAULT_GROUP.equals(rsgi.getName()) && rsgi.containsServer(server)) {
                found = true;
                break;
            }
        }
        if (!found) {
            defaultServers.add(server);
        }
    }
    return defaultServers;
}
Also used : Address(org.apache.hadoop.hbase.net.Address) ServerName(org.apache.hadoop.hbase.ServerName)

Example 7 with ServerName

use of org.apache.hadoop.hbase.ServerName in project hbase by apache.

the class TestRSGroupBasedLoadBalancer method testRetainAssignment.

/**
   * Test the cluster startup bulk assignment which attempts to retain
   * assignment info.
   *
   * @throws Exception
   */
@Test
public void testRetainAssignment() throws Exception {
    // Test simple case where all same servers are there
    Map<ServerName, List<HRegionInfo>> currentAssignments = mockClusterServers();
    Map<HRegionInfo, ServerName> inputForTest = new HashMap<>();
    for (ServerName sn : currentAssignments.keySet()) {
        for (HRegionInfo region : currentAssignments.get(sn)) {
            inputForTest.put(region, sn);
        }
    }
    //verify region->null server assignment is handled
    inputForTest.put(randomRegions(1).get(0), null);
    Map<ServerName, List<HRegionInfo>> newAssignment = loadBalancer.retainAssignment(inputForTest, servers);
    assertRetainedAssignment(inputForTest, servers, newAssignment);
}
Also used : HRegionInfo(org.apache.hadoop.hbase.HRegionInfo) HashMap(java.util.HashMap) ServerName(org.apache.hadoop.hbase.ServerName) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Example 8 with ServerName

use of org.apache.hadoop.hbase.ServerName in project hbase by apache.

the class TestRSGroupBasedLoadBalancer method reconcile.

private ArrayListMultimap<String, ServerAndLoad> reconcile(ArrayListMultimap<String, ServerAndLoad> previousLoad, List<RegionPlan> plans) {
    ArrayListMultimap<String, ServerAndLoad> result = ArrayListMultimap.create();
    result.putAll(previousLoad);
    if (plans != null) {
        for (RegionPlan plan : plans) {
            ServerName source = plan.getSource();
            updateLoad(result, source, -1);
            ServerName destination = plan.getDestination();
            updateLoad(result, destination, +1);
        }
    }
    return result;
}
Also used : RegionPlan(org.apache.hadoop.hbase.master.RegionPlan) ServerName(org.apache.hadoop.hbase.ServerName)

Example 9 with ServerName

use of org.apache.hadoop.hbase.ServerName 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 10 with ServerName

use of org.apache.hadoop.hbase.ServerName in project hbase by apache.

the class TestRSGroups method testMisplacedRegions.

@Test
public void testMisplacedRegions() throws Exception {
    final TableName tableName = TableName.valueOf(tablePrefix + "_testMisplacedRegions");
    LOG.info("testMisplacedRegions");
    final RSGroupInfo RSGroupInfo = addGroup("testMisplacedRegions", 1);
    TEST_UTIL.createMultiRegionTable(tableName, new byte[] { 'f' }, 15);
    TEST_UTIL.waitUntilAllRegionsAssigned(tableName);
    rsGroupAdminEndpoint.getGroupInfoManager().moveTables(Sets.newHashSet(tableName), RSGroupInfo.getName());
    assertTrue(rsGroupAdmin.balanceRSGroup(RSGroupInfo.getName()));
    TEST_UTIL.waitFor(60000, new Predicate<Exception>() {

        @Override
        public boolean evaluate() throws Exception {
            ServerName serverName = ServerName.valueOf(RSGroupInfo.getServers().iterator().next().toString(), 1);
            return admin.getConnection().getAdmin().getOnlineRegions(serverName).size() == 15;
        }
    });
}
Also used : TableName(org.apache.hadoop.hbase.TableName) ServerName(org.apache.hadoop.hbase.ServerName) IOException(java.io.IOException) Test(org.junit.Test)

Aggregations

ServerName (org.apache.hadoop.hbase.ServerName)426 HRegionInfo (org.apache.hadoop.hbase.HRegionInfo)202 Test (org.junit.Test)163 ArrayList (java.util.ArrayList)97 TableName (org.apache.hadoop.hbase.TableName)89 IOException (java.io.IOException)87 HashMap (java.util.HashMap)81 List (java.util.List)72 Map (java.util.Map)54 HRegionLocation (org.apache.hadoop.hbase.HRegionLocation)45 HTableDescriptor (org.apache.hadoop.hbase.HTableDescriptor)34 Table (org.apache.hadoop.hbase.client.Table)33 HashSet (java.util.HashSet)32 TreeMap (java.util.TreeMap)31 HColumnDescriptor (org.apache.hadoop.hbase.HColumnDescriptor)29 Configuration (org.apache.hadoop.conf.Configuration)26 HRegionServer (org.apache.hadoop.hbase.regionserver.HRegionServer)26 Pair (org.apache.hadoop.hbase.util.Pair)24 KeeperException (org.apache.zookeeper.KeeperException)23 InterruptedIOException (java.io.InterruptedIOException)22