Search in sources :

Example 1 with Address

use of org.apache.hadoop.hbase.net.Address in project hbase by apache.

the class RSGroupInfoManagerImpl method moveServers.

@Override
public synchronized Set<Address> moveServers(Set<Address> servers, String srcGroup, String dstGroup) throws IOException {
    RSGroupInfo src = getRSGroupInfo(srcGroup);
    RSGroupInfo dst = getRSGroupInfo(dstGroup);
    // If destination is 'default' rsgroup, only add servers that are online. If not online, drop
    // it. If not 'default' group, add server to 'dst' rsgroup EVEN IF IT IS NOT online (could be a
    // rsgroup of dead servers that are to come back later).
    Set<Address> onlineServers = dst.getName().equals(RSGroupInfo.DEFAULT_GROUP) ? Utility.getOnlineServers(this.masterServices) : null;
    for (Address el : servers) {
        src.removeServer(el);
        if (onlineServers != null) {
            if (!onlineServers.contains(el)) {
                if (LOG.isDebugEnabled()) {
                    LOG.debug("Dropping " + el + " during move-to-default rsgroup because not online");
                }
                continue;
            }
        }
        dst.addServer(el);
    }
    Map<String, RSGroupInfo> newGroupMap = Maps.newHashMap(rsGroupMap);
    newGroupMap.put(src.getName(), src);
    newGroupMap.put(dst.getName(), dst);
    flushConfig(newGroupMap);
    return dst.getServers();
}
Also used : Address(org.apache.hadoop.hbase.net.Address)

Example 2 with Address

use of org.apache.hadoop.hbase.net.Address 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 3 with Address

use of org.apache.hadoop.hbase.net.Address in project hbase by apache.

the class TestRSGroupsBase method addGroup.

protected RSGroupInfo addGroup(String groupName, int serverCount) throws IOException, InterruptedException {
    RSGroupInfo defaultInfo = rsGroupAdmin.getRSGroupInfo(RSGroupInfo.DEFAULT_GROUP);
    assertTrue(defaultInfo != null);
    assertTrue(defaultInfo.getServers().size() >= serverCount);
    rsGroupAdmin.addRSGroup(groupName);
    Set<Address> set = new HashSet<>();
    for (Address server : defaultInfo.getServers()) {
        if (set.size() == serverCount) {
            break;
        }
        set.add(server);
    }
    rsGroupAdmin.moveServers(set, groupName);
    RSGroupInfo result = rsGroupAdmin.getRSGroupInfo(groupName);
    assertTrue(result.getServers().size() >= serverCount);
    return result;
}
Also used : Address(org.apache.hadoop.hbase.net.Address) HashSet(java.util.HashSet)

Example 4 with Address

use of org.apache.hadoop.hbase.net.Address in project hbase by apache.

the class TestRSGroupsBase method testKillRS.

@Test
public void testKillRS() throws Exception {
    RSGroupInfo appInfo = addGroup("appInfo", 1);
    final TableName tableName = TableName.valueOf(tablePrefix + "_ns", name.getMethodName());
    admin.createNamespace(NamespaceDescriptor.create(tableName.getNamespaceAsString()).addConfiguration(RSGroupInfo.NAMESPACE_DESC_PROP_GROUP, appInfo.getName()).build());
    final HTableDescriptor desc = new HTableDescriptor(tableName);
    desc.addFamily(new HColumnDescriptor("f"));
    admin.createTable(desc);
    //wait for created table to be assigned
    TEST_UTIL.waitFor(WAIT_TIMEOUT, new Waiter.Predicate<Exception>() {

        @Override
        public boolean evaluate() throws Exception {
            return getTableRegionMap().get(desc.getTableName()) != null;
        }
    });
    ServerName targetServer = ServerName.parseServerName(appInfo.getServers().iterator().next().toString());
    AdminProtos.AdminService.BlockingInterface targetRS = ((ClusterConnection) admin.getConnection()).getAdmin(targetServer);
    HRegionInfo targetRegion = ProtobufUtil.getOnlineRegions(targetRS).get(0);
    Assert.assertEquals(1, ProtobufUtil.getOnlineRegions(targetRS).size());
    try {
        //stopping may cause an exception
        //due to the connection loss
        targetRS.stopServer(null, AdminProtos.StopServerRequest.newBuilder().setReason("Die").build());
    } catch (Exception e) {
    }
    assertFalse(cluster.getClusterStatus().getServers().contains(targetServer));
    //wait for created table to be assigned
    TEST_UTIL.waitFor(WAIT_TIMEOUT, new Waiter.Predicate<Exception>() {

        @Override
        public boolean evaluate() throws Exception {
            return cluster.getClusterStatus().getRegionsInTransition().isEmpty();
        }
    });
    Set<Address> newServers = Sets.newHashSet();
    newServers.add(rsGroupAdmin.getRSGroupInfo(RSGroupInfo.DEFAULT_GROUP).getServers().iterator().next());
    rsGroupAdmin.moveServers(newServers, appInfo.getName());
    //Make sure all the table's regions get reassigned
    //disabling the table guarantees no conflicting assign/unassign (ie SSH) happens
    admin.disableTable(tableName);
    admin.enableTable(tableName);
    //wait for region to be assigned
    TEST_UTIL.waitFor(WAIT_TIMEOUT, new Waiter.Predicate<Exception>() {

        @Override
        public boolean evaluate() throws Exception {
            return cluster.getClusterStatus().getRegionsInTransition().isEmpty();
        }
    });
    targetServer = ServerName.parseServerName(newServers.iterator().next().toString());
    targetRS = ((ClusterConnection) admin.getConnection()).getAdmin(targetServer);
    Assert.assertEquals(1, ProtobufUtil.getOnlineRegions(targetRS).size());
    Assert.assertEquals(tableName, ProtobufUtil.getOnlineRegions(targetRS).get(0).getTable());
}
Also used : Address(org.apache.hadoop.hbase.net.Address) HColumnDescriptor(org.apache.hadoop.hbase.HColumnDescriptor) IOException(java.io.IOException) ConstraintException(org.apache.hadoop.hbase.constraint.ConstraintException) HTableDescriptor(org.apache.hadoop.hbase.HTableDescriptor) HRegionInfo(org.apache.hadoop.hbase.HRegionInfo) TableName(org.apache.hadoop.hbase.TableName) ClusterConnection(org.apache.hadoop.hbase.client.ClusterConnection) ServerName(org.apache.hadoop.hbase.ServerName) Waiter(org.apache.hadoop.hbase.Waiter) Test(org.junit.Test)

Example 5 with Address

use of org.apache.hadoop.hbase.net.Address in project hbase by apache.

the class RSGroupAdminClient method moveServers.

@Override
public void moveServers(Set<Address> servers, String targetGroup) throws IOException {
    Set<HBaseProtos.ServerName> hostPorts = Sets.newHashSet();
    for (Address el : servers) {
        hostPorts.add(HBaseProtos.ServerName.newBuilder().setHostName(el.getHostname()).setPort(el.getPort()).build());
    }
    MoveServersRequest request = MoveServersRequest.newBuilder().setTargetGroup(targetGroup).addAllServers(hostPorts).build();
    try {
        stub.moveServers(null, request);
    } catch (ServiceException e) {
        throw ProtobufUtil.handleRemoteException(e);
    }
}
Also used : Address(org.apache.hadoop.hbase.net.Address) ServiceException(com.google.protobuf.ServiceException) MoveServersRequest(org.apache.hadoop.hbase.protobuf.generated.RSGroupAdminProtos.MoveServersRequest)

Aggregations

Address (org.apache.hadoop.hbase.net.Address)13 TableName (org.apache.hadoop.hbase.TableName)6 HRegionInfo (org.apache.hadoop.hbase.HRegionInfo)5 ServerName (org.apache.hadoop.hbase.ServerName)5 ConstraintException (org.apache.hadoop.hbase.constraint.ConstraintException)5 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)2 LinkedList (java.util.LinkedList)2 List (java.util.List)2 Waiter (org.apache.hadoop.hbase.Waiter)2 Test (org.junit.Test)2 ServiceException (com.google.protobuf.ServiceException)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1 HBaseIOException (org.apache.hadoop.hbase.HBaseIOException)1 HColumnDescriptor (org.apache.hadoop.hbase.HColumnDescriptor)1 HTableDescriptor (org.apache.hadoop.hbase.HTableDescriptor)1 ClusterConnection (org.apache.hadoop.hbase.client.ClusterConnection)1