Search in sources :

Example 16 with RegionMetrics

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

the class TestRSGroupBasedLoadBalancerWithStochasticLoadBalancerAsInternal method mockServerMetricsWithReadRequests.

private ServerMetrics mockServerMetricsWithReadRequests(ServerName server, List<RegionInfo> regionsOnServer, long readRequestCount) {
    ServerMetrics serverMetrics = mock(ServerMetrics.class);
    Map<byte[], RegionMetrics> regionLoadMap = new TreeMap<>(Bytes.BYTES_COMPARATOR);
    for (RegionInfo info : regionsOnServer) {
        RegionMetrics rl = mock(RegionMetrics.class);
        when(rl.getReadRequestCount()).thenReturn(readRequestCount);
        when(rl.getCpRequestCount()).thenReturn(0L);
        when(rl.getWriteRequestCount()).thenReturn(0L);
        when(rl.getMemStoreSize()).thenReturn(Size.ZERO);
        when(rl.getStoreFileSize()).thenReturn(Size.ZERO);
        regionLoadMap.put(info.getRegionName(), rl);
    }
    when(serverMetrics.getRegionMetrics()).thenReturn(regionLoadMap);
    return serverMetrics;
}
Also used : ServerMetrics(org.apache.hadoop.hbase.ServerMetrics) RegionInfo(org.apache.hadoop.hbase.client.RegionInfo) TreeMap(java.util.TreeMap) RegionMetrics(org.apache.hadoop.hbase.RegionMetrics)

Example 17 with RegionMetrics

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

the class RegionSizeCalculator method init.

private void init(RegionLocator regionLocator, Admin admin) throws IOException {
    if (!enabled(admin.getConfiguration())) {
        LOG.info("Region size calculation disabled.");
        return;
    }
    if (regionLocator.getName().isSystemTable()) {
        LOG.info("Region size calculation disabled for system tables.");
        return;
    }
    LOG.info("Calculating region sizes for table \"" + regionLocator.getName() + "\".");
    // Get the servers which host regions of the table
    Set<ServerName> tableServers = getRegionServersOfTable(regionLocator);
    for (ServerName tableServerName : tableServers) {
        for (RegionMetrics regionLoad : admin.getRegionMetrics(tableServerName, regionLocator.getName())) {
            byte[] regionId = regionLoad.getRegionName();
            long regionSizeBytes = ((long) regionLoad.getStoreFileSize().get(Size.Unit.MEGABYTE)) * MEGABYTE;
            sizeMap.put(regionId, regionSizeBytes);
            if (LOG.isDebugEnabled()) {
                LOG.debug("Region " + regionLoad.getNameAsString() + " has size " + regionSizeBytes);
            }
        }
    }
    LOG.debug("Region sizes calculated");
}
Also used : ServerName(org.apache.hadoop.hbase.ServerName) RegionMetrics(org.apache.hadoop.hbase.RegionMetrics)

Example 18 with RegionMetrics

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

the class HMaster method getCompactionState.

/**
 * Get the compaction state of the table
 *
 * @param tableName The table name
 * @return CompactionState Compaction state of the table
 */
public CompactionState getCompactionState(final TableName tableName) {
    CompactionState compactionState = CompactionState.NONE;
    try {
        List<RegionInfo> regions = assignmentManager.getRegionStates().getRegionsOfTable(tableName);
        for (RegionInfo regionInfo : regions) {
            ServerName serverName = assignmentManager.getRegionStates().getRegionServerOfRegion(regionInfo);
            if (serverName == null) {
                continue;
            }
            ServerMetrics sl = serverManager.getLoad(serverName);
            if (sl == null) {
                continue;
            }
            RegionMetrics regionMetrics = sl.getRegionMetrics().get(regionInfo.getRegionName());
            if (regionMetrics.getCompactionState() == CompactionState.MAJOR) {
                if (compactionState == CompactionState.MINOR) {
                    compactionState = CompactionState.MAJOR_AND_MINOR;
                } else {
                    compactionState = CompactionState.MAJOR;
                }
            } else if (regionMetrics.getCompactionState() == CompactionState.MINOR) {
                if (compactionState == CompactionState.MAJOR) {
                    compactionState = CompactionState.MAJOR_AND_MINOR;
                } else {
                    compactionState = CompactionState.MINOR;
                }
            }
        }
    } catch (Exception e) {
        compactionState = null;
        LOG.error("Exception when get compaction state for " + tableName.getNameAsString(), e);
    }
    return compactionState;
}
Also used : ServerName(org.apache.hadoop.hbase.ServerName) CompactionState(org.apache.hadoop.hbase.client.CompactionState) RegionInfo(org.apache.hadoop.hbase.client.RegionInfo) ServerMetrics(org.apache.hadoop.hbase.ServerMetrics) AccessDeniedException(org.apache.hadoop.hbase.security.AccessDeniedException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) ExecutionException(java.util.concurrent.ExecutionException) TableNotDisabledException(org.apache.hadoop.hbase.TableNotDisabledException) RemoteProcedureException(org.apache.hadoop.hbase.procedure2.RemoteProcedureException) NoSuchColumnFamilyException(org.apache.hadoop.hbase.regionserver.NoSuchColumnFamilyException) PleaseHoldException(org.apache.hadoop.hbase.PleaseHoldException) ReplicationException(org.apache.hadoop.hbase.replication.ReplicationException) DoNotRetryIOException(org.apache.hadoop.hbase.DoNotRetryIOException) UnknownRegionException(org.apache.hadoop.hbase.UnknownRegionException) HBaseIOException(org.apache.hadoop.hbase.HBaseIOException) MasterStoppedException(org.apache.hadoop.hbase.exceptions.MasterStoppedException) KeeperException(org.apache.zookeeper.KeeperException) ServerNotRunningYetException(org.apache.hadoop.hbase.ipc.ServerNotRunningYetException) InvalidFamilyOperationException(org.apache.hadoop.hbase.InvalidFamilyOperationException) InvocationTargetException(java.lang.reflect.InvocationTargetException) InterruptedIOException(java.io.InterruptedIOException) TableNotFoundException(org.apache.hadoop.hbase.TableNotFoundException) TimeoutException(java.util.concurrent.TimeoutException) ReplicationPeerNotFoundException(org.apache.hadoop.hbase.ReplicationPeerNotFoundException) PleaseRestartMasterException(org.apache.hadoop.hbase.PleaseRestartMasterException) MasterNotRunningException(org.apache.hadoop.hbase.MasterNotRunningException) RegionMetrics(org.apache.hadoop.hbase.RegionMetrics)

Example 19 with RegionMetrics

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

the class SimpleRegionNormalizer method getRegionSizeMB.

/**
 * @return size of region in MB and if region is not found than -1
 */
private long getRegionSizeMB(RegionInfo hri) {
    ServerName sn = masterServices.getAssignmentManager().getRegionStates().getRegionServerOfRegion(hri);
    if (sn == null) {
        LOG.debug("{} region was not found on any Server", hri.getRegionNameAsString());
        return -1;
    }
    ServerMetrics serverMetrics = masterServices.getServerManager().getLoad(sn);
    if (serverMetrics == null) {
        LOG.debug("server {} was not found in ServerManager", sn.getServerName());
        return -1;
    }
    RegionMetrics regionLoad = serverMetrics.getRegionMetrics().get(hri.getRegionName());
    if (regionLoad == null) {
        LOG.debug("{} was not found in RegionsLoad", hri.getRegionNameAsString());
        return -1;
    }
    return (long) regionLoad.getStoreFileSize().get(Size.Unit.MEGABYTE);
}
Also used : ServerName(org.apache.hadoop.hbase.ServerName) ServerMetrics(org.apache.hadoop.hbase.ServerMetrics) RegionMetrics(org.apache.hadoop.hbase.RegionMetrics)

Example 20 with RegionMetrics

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

the class TestAsyncClusterAdminApi method testGetRegionLoads.

@Test
public void testGetRegionLoads() throws Exception {
    // Turn off the balancer
    admin.balancerSwitch(false).join();
    TableName[] tables = new TableName[] { TableName.valueOf(tableName.getNameAsString() + "1"), TableName.valueOf(tableName.getNameAsString() + "2"), TableName.valueOf(tableName.getNameAsString() + "3") };
    createAndLoadTable(tables);
    // Sleep to wait region server report
    Thread.sleep(TEST_UTIL.getConfiguration().getInt("hbase.regionserver.msginterval", 3 * 1000) * 2);
    // Check if regions match with the regionLoad from the server
    Collection<ServerName> servers = admin.getRegionServers().get();
    for (ServerName serverName : servers) {
        List<RegionInfo> regions = admin.getRegions(serverName).get();
        checkRegionsAndRegionLoads(regions, admin.getRegionMetrics(serverName).get());
    }
    // Check if regionLoad matches the table's regions and nothing is missed
    for (TableName table : tables) {
        List<RegionInfo> tableRegions = admin.getRegions(table).get();
        List<RegionMetrics> regionLoads = Lists.newArrayList();
        for (ServerName serverName : servers) {
            regionLoads.addAll(admin.getRegionMetrics(serverName, table).get());
        }
        checkRegionsAndRegionLoads(tableRegions, regionLoads);
    }
    // Check RegionLoad matches the regionLoad from ClusterStatus
    ClusterMetrics clusterStatus = admin.getClusterMetrics(EnumSet.of(Option.LIVE_SERVERS)).get();
    assertEquals(servers.size(), clusterStatus.getLiveServerMetrics().size());
    for (Map.Entry<ServerName, ServerMetrics> entry : clusterStatus.getLiveServerMetrics().entrySet()) {
        ServerName sn = entry.getKey();
        ServerMetrics sm = entry.getValue();
        compareRegionLoads(sm.getRegionMetrics().values(), admin.getRegionMetrics(sn).get());
    }
    for (ServerName serverName : clusterStatus.getLiveServerMetrics().keySet()) {
        ServerMetrics serverLoad = clusterStatus.getLiveServerMetrics().get(serverName);
    }
}
Also used : TableName(org.apache.hadoop.hbase.TableName) ClusterMetrics(org.apache.hadoop.hbase.ClusterMetrics) ServerName(org.apache.hadoop.hbase.ServerName) ServerMetrics(org.apache.hadoop.hbase.ServerMetrics) Map(java.util.Map) RegionMetrics(org.apache.hadoop.hbase.RegionMetrics) Test(org.junit.Test)

Aggregations

RegionMetrics (org.apache.hadoop.hbase.RegionMetrics)25 ServerMetrics (org.apache.hadoop.hbase.ServerMetrics)18 ServerName (org.apache.hadoop.hbase.ServerName)16 ClusterMetrics (org.apache.hadoop.hbase.ClusterMetrics)7 HashMap (java.util.HashMap)6 RegionInfo (org.apache.hadoop.hbase.client.RegionInfo)5 Test (org.junit.Test)5 Map (java.util.Map)4 TreeMap (java.util.TreeMap)4 Size (org.apache.hadoop.hbase.Size)4 ArrayList (java.util.ArrayList)3 Configuration (org.apache.hadoop.conf.Configuration)3 Stoppable (org.apache.hadoop.hbase.Stoppable)3 IOException (java.io.IOException)2 List (java.util.List)2 TableName (org.apache.hadoop.hbase.TableName)2 UserMetrics (org.apache.hadoop.hbase.UserMetrics)2 InterruptedIOException (java.io.InterruptedIOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 UnknownHostException (java.net.UnknownHostException)1