Search in sources :

Example 21 with ClusterStatus

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

the class TestRSGroupsBase method getTableServerRegionMap.

public Map<TableName, Map<ServerName, List<String>>> getTableServerRegionMap() throws IOException {
    Map<TableName, Map<ServerName, List<String>>> map = Maps.newTreeMap();
    ClusterStatus status = TEST_UTIL.getHBaseClusterInterface().getClusterStatus();
    for (ServerName serverName : status.getServers()) {
        for (RegionLoad rl : status.getLoad(serverName).getRegionsLoad().values()) {
            TableName tableName = null;
            try {
                tableName = HRegionInfo.getTable(rl.getName());
            } catch (IllegalArgumentException e) {
                LOG.warn("Failed parse a table name from regionname=" + Bytes.toStringBinary(rl.getName()));
                continue;
            }
            if (!map.containsKey(tableName)) {
                map.put(tableName, new TreeMap<>());
            }
            if (!map.get(tableName).containsKey(serverName)) {
                map.get(tableName).put(serverName, new LinkedList<>());
            }
            map.get(tableName).get(serverName).add(rl.getNameAsString());
        }
    }
    return map;
}
Also used : TableName(org.apache.hadoop.hbase.TableName) RegionLoad(org.apache.hadoop.hbase.RegionLoad) ServerName(org.apache.hadoop.hbase.ServerName) Map(java.util.Map) TreeMap(java.util.TreeMap) ClusterStatus(org.apache.hadoop.hbase.ClusterStatus)

Example 22 with ClusterStatus

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

the class TestRSGroupsBase method getNumServers.

// return the real number of region servers, excluding the master embedded region server in 2.0+
public int getNumServers() throws IOException {
    ClusterStatus status = admin.getClusterStatus();
    ServerName master = status.getMaster();
    int count = 0;
    for (ServerName sn : status.getServers()) {
        if (!sn.equals(master)) {
            count++;
        }
    }
    return count;
}
Also used : ServerName(org.apache.hadoop.hbase.ServerName) ClusterStatus(org.apache.hadoop.hbase.ClusterStatus)

Example 23 with ClusterStatus

use of org.apache.hadoop.hbase.ClusterStatus in project cdap by caskdata.

the class HBaseTableUtil method getTableStats.

/**
   * Collects HBase table stats
   * //TODO: Explore the possiblitity of returning a {@code Map<TableId, TableStats>}
   * @param admin instance of {@link HBaseAdmin} to communicate with HBase
   * @return map of table name -> table stats
   * @throws IOException
   */
public Map<TableId, TableStats> getTableStats(HBaseAdmin admin) throws IOException {
    // The idea is to walk thru live region servers, collect table region stats and aggregate them towards table total
    // metrics.
    Map<TableId, TableStats> datasetStat = Maps.newHashMap();
    ClusterStatus clusterStatus = admin.getClusterStatus();
    for (ServerName serverName : clusterStatus.getServers()) {
        Map<byte[], RegionLoad> regionsLoad = clusterStatus.getLoad(serverName).getRegionsLoad();
        for (RegionLoad regionLoad : regionsLoad.values()) {
            TableName tableName = HRegionInfo.getTable(regionLoad.getName());
            HTableDescriptor tableDescriptor;
            try {
                tableDescriptor = admin.getTableDescriptor(tableName);
            } catch (TableNotFoundException exception) {
                // this can happen if the table has been deleted; the region stats get removed afterwards
                LOG.warn("Table not found for table name {}. Skipping collecting stats for it. Reason: {}", tableName, exception.getMessage());
                continue;
            }
            if (!isCDAPTable(tableDescriptor)) {
                continue;
            }
            TableId tableId = HTableNameConverter.from(tableDescriptor);
            TableStats stat = datasetStat.get(tableId);
            if (stat == null) {
                stat = new TableStats(regionLoad.getStorefileSizeMB(), regionLoad.getMemStoreSizeMB());
                datasetStat.put(tableId, stat);
            } else {
                stat.incStoreFileSizeMB(regionLoad.getStorefileSizeMB());
                stat.incMemStoreSizeMB(regionLoad.getMemStoreSizeMB());
            }
        }
    }
    return datasetStat;
}
Also used : TableId(co.cask.cdap.data2.util.TableId) TableName(org.apache.hadoop.hbase.TableName) TableNotFoundException(org.apache.hadoop.hbase.TableNotFoundException) RegionLoad(org.apache.hadoop.hbase.RegionLoad) ServerName(org.apache.hadoop.hbase.ServerName) ClusterStatus(org.apache.hadoop.hbase.ClusterStatus) HTableDescriptor(org.apache.hadoop.hbase.HTableDescriptor)

Aggregations

ClusterStatus (org.apache.hadoop.hbase.ClusterStatus)23 ServerName (org.apache.hadoop.hbase.ServerName)19 ServerLoad (org.apache.hadoop.hbase.ServerLoad)6 Test (org.junit.Test)6 ArrayList (java.util.ArrayList)4 RegionLoad (org.apache.hadoop.hbase.RegionLoad)4 HBaseTestingUtility (org.apache.hadoop.hbase.HBaseTestingUtility)3 MiniHBaseCluster (org.apache.hadoop.hbase.MiniHBaseCluster)3 HBaseAdmin (org.apache.hadoop.hbase.client.HBaseAdmin)3 IOException (java.io.IOException)2 LinkedList (java.util.LinkedList)2 List (java.util.List)2 TreeMap (java.util.TreeMap)2 TableName (org.apache.hadoop.hbase.TableName)2 Admin (org.apache.hadoop.hbase.client.Admin)2 RegionState (org.apache.hadoop.hbase.master.RegionState)2 ByteString (org.apache.hadoop.hbase.shaded.com.google.protobuf.ByteString)2 LiveServerInfo (org.apache.hadoop.hbase.shaded.protobuf.generated.ClusterStatusProtos.LiveServerInfo)2 RegionInTransition (org.apache.hadoop.hbase.shaded.protobuf.generated.ClusterStatusProtos.RegionInTransition)2 MasterThread (org.apache.hadoop.hbase.util.JVMClusterUtil.MasterThread)2