Search in sources :

Example 31 with HRegionInfo

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

the class FavoredNodeAssignmentHelper method updateMetaWithFavoredNodesInfo.

/**
   * Update meta table with favored nodes info
   * @param regionToFavoredNodes map of HRegionInfo's to their favored nodes
   * @param connection connection to be used
   * @throws IOException
   */
public static void updateMetaWithFavoredNodesInfo(Map<HRegionInfo, List<ServerName>> regionToFavoredNodes, Connection connection) throws IOException {
    List<Put> puts = new ArrayList<>();
    for (Map.Entry<HRegionInfo, List<ServerName>> entry : regionToFavoredNodes.entrySet()) {
        Put put = makePutFromRegionInfo(entry.getKey(), entry.getValue());
        if (put != null) {
            puts.add(put);
        }
    }
    MetaTableAccessor.putsToMetaTable(connection, puts);
    LOG.info("Added " + puts.size() + " regions in META");
}
Also used : HRegionInfo(org.apache.hadoop.hbase.HRegionInfo) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) Put(org.apache.hadoop.hbase.client.Put)

Example 32 with HRegionInfo

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

the class FavoredNodeLoadBalancer method segregateRegionsAndAssignRegionsWithFavoredNodes.

private Pair<Map<ServerName, List<HRegionInfo>>, List<HRegionInfo>> segregateRegionsAndAssignRegionsWithFavoredNodes(List<HRegionInfo> regions, List<ServerName> availableServers) {
    Map<ServerName, List<HRegionInfo>> assignmentMapForFavoredNodes = new HashMap<>(regions.size() / 2);
    List<HRegionInfo> regionsWithNoFavoredNodes = new ArrayList<>(regions.size() / 2);
    for (HRegionInfo region : regions) {
        List<ServerName> favoredNodes = fnm.getFavoredNodes(region);
        ServerName primaryHost = null;
        ServerName secondaryHost = null;
        ServerName tertiaryHost = null;
        if (favoredNodes != null) {
            for (ServerName s : favoredNodes) {
                ServerName serverWithLegitStartCode = availableServersContains(availableServers, s);
                if (serverWithLegitStartCode != null) {
                    FavoredNodesPlan.Position position = FavoredNodesPlan.getFavoredServerPosition(favoredNodes, s);
                    if (Position.PRIMARY.equals(position)) {
                        primaryHost = serverWithLegitStartCode;
                    } else if (Position.SECONDARY.equals(position)) {
                        secondaryHost = serverWithLegitStartCode;
                    } else if (Position.TERTIARY.equals(position)) {
                        tertiaryHost = serverWithLegitStartCode;
                    }
                }
            }
            assignRegionToAvailableFavoredNode(assignmentMapForFavoredNodes, region, primaryHost, secondaryHost, tertiaryHost);
        }
        if (primaryHost == null && secondaryHost == null && tertiaryHost == null) {
            //all favored nodes unavailable
            regionsWithNoFavoredNodes.add(region);
        }
    }
    return new Pair<>(assignmentMapForFavoredNodes, regionsWithNoFavoredNodes);
}
Also used : HRegionInfo(org.apache.hadoop.hbase.HRegionInfo) HashMap(java.util.HashMap) ServerName(org.apache.hadoop.hbase.ServerName) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Position(org.apache.hadoop.hbase.favored.FavoredNodesPlan.Position) Pair(org.apache.hadoop.hbase.util.Pair)

Example 33 with HRegionInfo

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

the class FavoredNodesManager method updateFavoredNodes.

public synchronized void updateFavoredNodes(Map<HRegionInfo, List<ServerName>> regionFNMap) throws IOException {
    Map<HRegionInfo, List<ServerName>> regionToFavoredNodes = new HashMap<>();
    for (Map.Entry<HRegionInfo, List<ServerName>> entry : regionFNMap.entrySet()) {
        HRegionInfo regionInfo = entry.getKey();
        List<ServerName> servers = entry.getValue();
        /*
       * None of the following error conditions should happen. If it does, there is an issue with
       * favored nodes generation or the regions its called on.
       */
        if (servers.size() != Sets.newHashSet(servers).size()) {
            throw new IOException("Duplicates found: " + servers);
        }
        if (!isFavoredNodeApplicable(regionInfo)) {
            throw new IOException("Can't update FN for a un-applicable region: " + regionInfo.getRegionNameAsString() + " with " + servers);
        }
        if (servers.size() != FavoredNodeAssignmentHelper.FAVORED_NODES_NUM) {
            throw new IOException("At least " + FavoredNodeAssignmentHelper.FAVORED_NODES_NUM + " favored nodes should be present for region : " + regionInfo.getEncodedName() + " current FN servers:" + servers);
        }
        List<ServerName> serversWithNoStartCodes = Lists.newArrayList();
        for (ServerName sn : servers) {
            if (sn.getStartcode() == ServerName.NON_STARTCODE) {
                serversWithNoStartCodes.add(sn);
            } else {
                serversWithNoStartCodes.add(ServerName.valueOf(sn.getHostname(), sn.getPort(), ServerName.NON_STARTCODE));
            }
        }
        regionToFavoredNodes.put(regionInfo, serversWithNoStartCodes);
    }
    // Lets do a bulk update to meta since that reduces the RPC's
    FavoredNodeAssignmentHelper.updateMetaWithFavoredNodesInfo(regionToFavoredNodes, masterServices.getConnection());
    deleteFavoredNodesForRegions(regionToFavoredNodes.keySet());
    for (Map.Entry<HRegionInfo, List<ServerName>> entry : regionToFavoredNodes.entrySet()) {
        HRegionInfo regionInfo = entry.getKey();
        List<ServerName> serversWithNoStartCodes = entry.getValue();
        globalFavoredNodesAssignmentPlan.updateFavoredNodesMap(regionInfo, serversWithNoStartCodes);
        addToReplicaLoad(regionInfo, serversWithNoStartCodes);
    }
}
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) IOException(java.io.IOException) HBaseIOException(org.apache.hadoop.hbase.HBaseIOException) HashMap(java.util.HashMap) Map(java.util.Map)

Example 34 with HRegionInfo

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

the class MobUtils method getMobRegionPath.

/**
   * Gets the region dir of the mob files.
   * It's {HBASE_DIR}/mobdir/{namespace}/{tableName}/{regionEncodedName}.
   * @param conf The current configuration.
   * @param tableName The current table name.
   * @return The region dir of the mob files.
   */
public static Path getMobRegionPath(Configuration conf, TableName tableName) {
    Path tablePath = FSUtils.getTableDir(getMobHome(conf), tableName);
    HRegionInfo regionInfo = getMobRegionInfo(tableName);
    return new Path(tablePath, regionInfo.getEncodedName());
}
Also used : Path(org.apache.hadoop.fs.Path) HRegionInfo(org.apache.hadoop.hbase.HRegionInfo)

Example 35 with HRegionInfo

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

the class DisabledTableSnapshotHandler method snapshotRegions.

// TODO consider parallelizing these operations since they are independent. Right now its just
// easier to keep them serial though
@Override
public void snapshotRegions(List<Pair<HRegionInfo, ServerName>> regionsAndLocations) throws IOException, KeeperException {
    try {
        // 1. get all the regions hosting this table.
        // extract each pair to separate lists
        Set<HRegionInfo> regions = new HashSet<>();
        for (Pair<HRegionInfo, ServerName> p : regionsAndLocations) {
            // Don't include non-default regions
            HRegionInfo hri = p.getFirst();
            if (RegionReplicaUtil.isDefaultReplica(hri)) {
                regions.add(hri);
            }
        }
        // handle the mob files if any.
        boolean mobEnabled = MobUtils.hasMobColumns(htd);
        if (mobEnabled) {
            // snapshot the mob files as a offline region.
            HRegionInfo mobRegionInfo = MobUtils.getMobRegionInfo(htd.getTableName());
            regions.add(mobRegionInfo);
        }
        // 2. for each region, write all the info to disk
        String msg = "Starting to write region info and WALs for regions for offline snapshot:" + ClientSnapshotDescriptionUtils.toString(snapshot);
        LOG.info(msg);
        status.setStatus(msg);
        ThreadPoolExecutor exec = SnapshotManifest.createExecutor(conf, "DisabledTableSnapshot");
        try {
            ModifyRegionUtils.editRegions(exec, regions, new ModifyRegionUtils.RegionEditTask() {

                @Override
                public void editRegion(final HRegionInfo regionInfo) throws IOException {
                    snapshotManifest.addRegion(FSUtils.getTableDir(rootDir, snapshotTable), regionInfo);
                }
            });
        } finally {
            exec.shutdown();
        }
    } catch (Exception e) {
        // make sure we capture the exception to propagate back to the client later
        String reason = "Failed snapshot " + ClientSnapshotDescriptionUtils.toString(snapshot) + " due to exception:" + e.getMessage();
        ForeignException ee = new ForeignException(reason, e);
        monitor.receive(ee);
        status.abort("Snapshot of table: " + snapshotTable + " failed because " + e.getMessage());
    } finally {
        LOG.debug("Marking snapshot" + ClientSnapshotDescriptionUtils.toString(snapshot) + " as finished.");
    }
}
Also used : IOException(java.io.IOException) KeeperException(org.apache.zookeeper.KeeperException) IOException(java.io.IOException) ForeignException(org.apache.hadoop.hbase.errorhandling.ForeignException) HRegionInfo(org.apache.hadoop.hbase.HRegionInfo) ServerName(org.apache.hadoop.hbase.ServerName) ForeignException(org.apache.hadoop.hbase.errorhandling.ForeignException) ModifyRegionUtils(org.apache.hadoop.hbase.util.ModifyRegionUtils) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) HashSet(java.util.HashSet)

Aggregations

HRegionInfo (org.apache.hadoop.hbase.HRegionInfo)408 ServerName (org.apache.hadoop.hbase.ServerName)153 Test (org.junit.Test)141 TableName (org.apache.hadoop.hbase.TableName)118 ArrayList (java.util.ArrayList)86 IOException (java.io.IOException)83 HTableDescriptor (org.apache.hadoop.hbase.HTableDescriptor)75 Path (org.apache.hadoop.fs.Path)63 List (java.util.List)59 HashMap (java.util.HashMap)57 HColumnDescriptor (org.apache.hadoop.hbase.HColumnDescriptor)49 Table (org.apache.hadoop.hbase.client.Table)47 Map (java.util.Map)43 HRegionServer (org.apache.hadoop.hbase.regionserver.HRegionServer)41 FileSystem (org.apache.hadoop.fs.FileSystem)40 Configuration (org.apache.hadoop.conf.Configuration)38 HRegionLocation (org.apache.hadoop.hbase.HRegionLocation)35 TreeMap (java.util.TreeMap)26 HashSet (java.util.HashSet)23 HBaseIOException (org.apache.hadoop.hbase.HBaseIOException)22