Search in sources :

Example 11 with ConstraintException

use of org.apache.hadoop.hbase.constraint.ConstraintException in project hbase by apache.

the class RSGroupAdminServer method moveServers.

@edu.umd.cs.findbugs.annotations.SuppressWarnings(value = "RCN_REDUNDANT_NULLCHECK_WOULD_HAVE_BEEN_A_NPE", justification = "Ignoring complaint because don't know what it is complaining about")
@Override
public void moveServers(Set<Address> servers, String targetGroupName) throws IOException {
    if (servers == null) {
        throw new ConstraintException("The list of servers to move cannot be null.");
    }
    if (servers.isEmpty()) {
        // TODO. Why? Stuff breaks if I equate them.
        return;
    }
    RSGroupInfo targetGrp = getAndCheckRSGroupInfo(targetGroupName);
    // another writer changing our state while we are working.
    synchronized (rsGroupInfoManager) {
        if (master.getMasterCoprocessorHost() != null) {
            master.getMasterCoprocessorHost().preMoveServers(servers, targetGroupName);
        }
        // Presume first server's source group. Later ensure all servers are from this group.
        Address firstServer = servers.iterator().next();
        RSGroupInfo srcGrp = rsGroupInfoManager.getRSGroupOfServer(firstServer);
        if (srcGrp == null) {
            // Be careful. This exception message is tested for in TestRSGroupsBase...
            throw new ConstraintException("Source RSGroup for server " + firstServer + " does not exist.");
        }
        if (srcGrp.getName().equals(targetGroupName)) {
            throw new ConstraintException("Target RSGroup " + targetGroupName + " is same as source " + srcGrp + " RSGroup.");
        }
        // groups. This prevents bogus servers from entering groups
        if (RSGroupInfo.DEFAULT_GROUP.equals(srcGrp.getName())) {
            checkOnlineServersOnly(servers);
        }
        // Ensure all servers are of same rsgroup.
        for (Address server : servers) {
            String tmpGroup = rsGroupInfoManager.getRSGroupOfServer(server).getName();
            if (!tmpGroup.equals(srcGrp.getName())) {
                throw new ConstraintException("Move server request should only come from one source " + "RSGroup. Expecting only " + srcGrp.getName() + " but contains " + tmpGroup);
            }
        }
        if (srcGrp.getServers().size() <= servers.size() && srcGrp.getTables().size() > 0) {
            throw new ConstraintException("Cannot leave a RSGroup " + srcGrp.getName() + " that contains tables without servers to host them.");
        }
        // MovedServers may be < passed in 'servers'.
        Set<Address> movedServers = rsGroupInfoManager.moveServers(servers, srcGrp.getName(), targetGroupName);
        List<Address> editableMovedServers = Lists.newArrayList(movedServers);
        boolean foundRegionsToUnassign;
        do {
            foundRegionsToUnassign = false;
            for (Iterator<Address> iter = editableMovedServers.iterator(); iter.hasNext(); ) {
                Address rs = iter.next();
                // Get regions that are associated with this server.
                List<HRegionInfo> regions = getRegions(rs);
                // Unassign regions for a server
                // TODO: This is problematic especially if hbase:meta is in the mix.
                // We need to update state in hbase:meta on Master and if unassigned we hang
                // around in here. There is a silly sort on linked list done above
                // in getRegions putting hbase:meta last which helps but probably has holes.
                LOG.info("Unassigning " + regions.size() + " region(s) from " + rs + " for server move to " + targetGroupName);
                if (!regions.isEmpty()) {
                    // TODO bulk unassign or throttled unassign?
                    for (HRegionInfo region : regions) {
                        // Regions might get assigned from tables of target group so we need to filter
                        if (!targetGrp.containsTable(region.getTable())) {
                            this.master.getAssignmentManager().unassign(region);
                            if (master.getAssignmentManager().getRegionStates().getRegionState(region).isFailedOpen()) {
                                // than mark region as 'foundRegionsToUnassign'.
                                continue;
                            }
                            foundRegionsToUnassign = true;
                        }
                    }
                }
                if (!foundRegionsToUnassign) {
                    iter.remove();
                }
            }
            try {
                rsGroupInfoManager.wait(1000);
            } catch (InterruptedException e) {
                LOG.warn("Sleep interrupted", e);
                Thread.currentThread().interrupt();
            }
        } while (foundRegionsToUnassign);
        if (master.getMasterCoprocessorHost() != null) {
            master.getMasterCoprocessorHost().postMoveServers(servers, targetGroupName);
        }
        LOG.info("Move server done: " + srcGrp.getName() + "=>" + targetGroupName);
    }
}
Also used : HRegionInfo(org.apache.hadoop.hbase.HRegionInfo) Address(org.apache.hadoop.hbase.net.Address) ConstraintException(org.apache.hadoop.hbase.constraint.ConstraintException)

Example 12 with ConstraintException

use of org.apache.hadoop.hbase.constraint.ConstraintException in project hbase by apache.

the class RSGroupAdminServer method checkServersAndTables.

/**
   * Check servers and tables.
   * Fail if nulls or if servers and tables not belong to the same group
   * @param servers servers to move
   * @param tables tables to move
   * @param targetGroupName target group name
   * @throws IOException
   */
private void checkServersAndTables(Set<Address> servers, Set<TableName> tables, String targetGroupName) throws IOException {
    // Presume first server's source group. Later ensure all servers are from this group.
    Address firstServer = servers.iterator().next();
    RSGroupInfo tmpSrcGrp = rsGroupInfoManager.getRSGroupOfServer(firstServer);
    if (tmpSrcGrp == null) {
        // Be careful. This exception message is tested for in TestRSGroupsBase...
        throw new ConstraintException("Source RSGroup for server " + firstServer + " does not exist.");
    }
    RSGroupInfo srcGrp = new RSGroupInfo(tmpSrcGrp);
    if (srcGrp.getName().equals(targetGroupName)) {
        throw new ConstraintException("Target RSGroup " + targetGroupName + " is same as source " + srcGrp.getName() + " RSGroup.");
    }
    // Only move online servers
    checkOnlineServersOnly(servers);
    // Ensure all servers are of same rsgroup.
    for (Address server : servers) {
        String tmpGroup = rsGroupInfoManager.getRSGroupOfServer(server).getName();
        if (!tmpGroup.equals(srcGrp.getName())) {
            throw new ConstraintException("Move server request should only come from one source " + "RSGroup. Expecting only " + srcGrp.getName() + " but contains " + tmpGroup);
        }
    }
    // Ensure all tables and servers are of same rsgroup.
    for (TableName table : tables) {
        String tmpGroup = rsGroupInfoManager.getRSGroupOfTable(table);
        if (!tmpGroup.equals(srcGrp.getName())) {
            throw new ConstraintException("Move table request should only come from one source " + "RSGroup. Expecting only " + srcGrp.getName() + " but contains " + tmpGroup);
        }
    }
    if (srcGrp.getServers().size() <= servers.size() && srcGrp.getTables().size() > tables.size()) {
        throw new ConstraintException("Cannot leave a RSGroup " + srcGrp.getName() + " that contains tables without servers to host them.");
    }
}
Also used : TableName(org.apache.hadoop.hbase.TableName) Address(org.apache.hadoop.hbase.net.Address) ConstraintException(org.apache.hadoop.hbase.constraint.ConstraintException)

Example 13 with ConstraintException

use of org.apache.hadoop.hbase.constraint.ConstraintException in project hbase by apache.

the class RSGroupAdminServer method balanceRSGroup.

@Override
public boolean balanceRSGroup(String groupName) throws IOException {
    ServerManager serverManager = master.getServerManager();
    AssignmentManager assignmentManager = master.getAssignmentManager();
    LoadBalancer balancer = master.getLoadBalancer();
    boolean balancerRan;
    synchronized (balancer) {
        if (master.getMasterCoprocessorHost() != null) {
            master.getMasterCoprocessorHost().preBalanceRSGroup(groupName);
        }
        if (getRSGroupInfo(groupName) == null) {
            throw new ConstraintException("RSGroup does not exist: " + groupName);
        }
        // Only allow one balance run at at time.
        Map<String, RegionState> groupRIT = rsGroupGetRegionsInTransition(groupName);
        if (groupRIT.size() > 0) {
            LOG.debug("Not running balancer because " + groupRIT.size() + " region(s) in transition: " + StringUtils.abbreviate(master.getAssignmentManager().getRegionStates().getRegionsInTransition().toString(), 256));
            return false;
        }
        if (serverManager.areDeadServersInProgress()) {
            LOG.debug("Not running balancer because processing dead regionserver(s): " + serverManager.getDeadServers());
            return false;
        }
        //We balance per group instead of per table
        List<RegionPlan> plans = new ArrayList<>();
        for (Map.Entry<TableName, Map<ServerName, List<HRegionInfo>>> tableMap : getRSGroupAssignmentsByTable(groupName).entrySet()) {
            LOG.info("Creating partial plan for table " + tableMap.getKey() + ": " + tableMap.getValue());
            List<RegionPlan> partialPlans = balancer.balanceCluster(tableMap.getValue());
            LOG.info("Partial plan for table " + tableMap.getKey() + ": " + partialPlans);
            if (partialPlans != null) {
                plans.addAll(partialPlans);
            }
        }
        long startTime = System.currentTimeMillis();
        balancerRan = plans != null;
        if (plans != null && !plans.isEmpty()) {
            LOG.info("RSGroup balance " + groupName + " starting with plan count: " + plans.size());
            for (RegionPlan plan : plans) {
                LOG.info("balance " + plan);
                assignmentManager.balance(plan);
            }
            LOG.info("RSGroup balance " + groupName + " completed after " + (System.currentTimeMillis() - startTime) + " seconds");
        }
        if (master.getMasterCoprocessorHost() != null) {
            master.getMasterCoprocessorHost().postBalanceRSGroup(groupName, balancerRan);
        }
    }
    return balancerRan;
}
Also used : ServerManager(org.apache.hadoop.hbase.master.ServerManager) AssignmentManager(org.apache.hadoop.hbase.master.AssignmentManager) ArrayList(java.util.ArrayList) LoadBalancer(org.apache.hadoop.hbase.master.LoadBalancer) ConstraintException(org.apache.hadoop.hbase.constraint.ConstraintException) HRegionInfo(org.apache.hadoop.hbase.HRegionInfo) TableName(org.apache.hadoop.hbase.TableName) RegionState(org.apache.hadoop.hbase.master.RegionState) RegionPlan(org.apache.hadoop.hbase.master.RegionPlan) HashMap(java.util.HashMap) Map(java.util.Map)

Example 14 with ConstraintException

use of org.apache.hadoop.hbase.constraint.ConstraintException in project hbase by apache.

the class RSGroupBasedLoadBalancer method balanceCluster.

@Override
public List<RegionPlan> balanceCluster(Map<ServerName, List<HRegionInfo>> clusterState) throws HBaseIOException {
    if (!isOnline()) {
        throw new ConstraintException(RSGroupInfoManager.RSGROUP_TABLE_NAME + " is not online, unable to perform balance");
    }
    Map<ServerName, List<HRegionInfo>> correctedState = correctAssignments(clusterState);
    List<RegionPlan> regionPlans = new ArrayList<>();
    List<HRegionInfo> misplacedRegions = correctedState.get(LoadBalancer.BOGUS_SERVER_NAME);
    for (HRegionInfo regionInfo : misplacedRegions) {
        regionPlans.add(new RegionPlan(regionInfo, null, null));
    }
    try {
        List<RSGroupInfo> rsgi = rsGroupInfoManager.listRSGroups();
        for (RSGroupInfo info : rsgi) {
            Map<ServerName, List<HRegionInfo>> groupClusterState = new HashMap<>();
            Map<TableName, Map<ServerName, List<HRegionInfo>>> groupClusterLoad = new HashMap<>();
            for (Address sName : info.getServers()) {
                for (ServerName curr : clusterState.keySet()) {
                    if (curr.getAddress().equals(sName)) {
                        groupClusterState.put(curr, correctedState.get(curr));
                    }
                }
            }
            groupClusterLoad.put(TableName.valueOf(HConstants.ENSEMBLE_TABLE_NAME), groupClusterState);
            this.internalBalancer.setClusterLoad(groupClusterLoad);
            List<RegionPlan> groupPlans = this.internalBalancer.balanceCluster(groupClusterState);
            if (groupPlans != null) {
                regionPlans.addAll(groupPlans);
            }
        }
    } catch (IOException exp) {
        LOG.warn("Exception while balancing cluster.", exp);
        regionPlans.clear();
    }
    return regionPlans;
}
Also used : Address(org.apache.hadoop.hbase.net.Address) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) IOException(java.io.IOException) HBaseIOException(org.apache.hadoop.hbase.HBaseIOException) ConstraintException(org.apache.hadoop.hbase.constraint.ConstraintException) HRegionInfo(org.apache.hadoop.hbase.HRegionInfo) TableName(org.apache.hadoop.hbase.TableName) RegionPlan(org.apache.hadoop.hbase.master.RegionPlan) ServerName(org.apache.hadoop.hbase.ServerName) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) TreeMap(java.util.TreeMap)

Example 15 with ConstraintException

use of org.apache.hadoop.hbase.constraint.ConstraintException in project hbase by apache.

the class TestModifyNamespaceProcedure method testModifyNamespaceWithInvalidTableCount.

@Test(timeout = 60000)
public void testModifyNamespaceWithInvalidTableCount() throws Exception {
    final NamespaceDescriptor nsd = NamespaceDescriptor.create("testModifyNamespaceWithInvalidTableCount").build();
    final String nsKey = "hbase.namespace.quota.maxtables";
    final String nsValue = "-1";
    final ProcedureExecutor<MasterProcedureEnv> procExec = getMasterProcedureExecutor();
    createNamespaceForTesting(nsd);
    // Modify
    nsd.setConfiguration(nsKey, nsValue);
    long procId = procExec.submitProcedure(new ModifyNamespaceProcedure(procExec.getEnvironment(), nsd));
    // Wait the completion
    ProcedureTestingUtility.waitProcedure(procExec, procId);
    ProcedureInfo result = procExec.getResult(procId);
    assertTrue(result.isFailed());
    LOG.debug("Modify namespace failed with exception: " + result.getExceptionFullMessage());
    assertTrue(ProcedureTestingUtility.getExceptionCause(result) instanceof ConstraintException);
}
Also used : ProcedureInfo(org.apache.hadoop.hbase.ProcedureInfo) NamespaceDescriptor(org.apache.hadoop.hbase.NamespaceDescriptor) ConstraintException(org.apache.hadoop.hbase.constraint.ConstraintException) Test(org.junit.Test)

Aggregations

ConstraintException (org.apache.hadoop.hbase.constraint.ConstraintException)15 Test (org.junit.Test)8 ProcedureInfo (org.apache.hadoop.hbase.ProcedureInfo)6 NamespaceDescriptor (org.apache.hadoop.hbase.NamespaceDescriptor)5 TableName (org.apache.hadoop.hbase.TableName)4 HRegionInfo (org.apache.hadoop.hbase.HRegionInfo)3 Address (org.apache.hadoop.hbase.net.Address)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 HTableDescriptor (org.apache.hadoop.hbase.HTableDescriptor)2 RegionPlan (org.apache.hadoop.hbase.master.RegionPlan)2 TableId (co.cask.cdap.data2.util.TableId)1 NamespaceId (co.cask.cdap.proto.id.NamespaceId)1 FileNotFoundException (java.io.FileNotFoundException)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 TreeMap (java.util.TreeMap)1 HBaseIOException (org.apache.hadoop.hbase.HBaseIOException)1