Search in sources :

Example 21 with ServerMetrics

use of org.apache.hadoop.hbase.ServerMetrics 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 22 with ServerMetrics

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

the class MasterDumpServlet method dumpServers.

private void dumpServers(HMaster master, PrintWriter out) {
    ServerManager sm = master.getServerManager();
    if (sm == null) {
        out.println("ServerManager is not initialized");
        return;
    }
    Map<ServerName, ServerMetrics> servers = sm.getOnlineServers();
    for (Map.Entry<ServerName, ServerMetrics> e : servers.entrySet()) {
        out.println(e.getKey() + ": " + e.getValue());
    }
}
Also used : ServerManager(org.apache.hadoop.hbase.master.ServerManager) ServerName(org.apache.hadoop.hbase.ServerName) ServerMetrics(org.apache.hadoop.hbase.ServerMetrics) Map(java.util.Map)

Example 23 with ServerMetrics

use of org.apache.hadoop.hbase.ServerMetrics 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 24 with ServerMetrics

use of org.apache.hadoop.hbase.ServerMetrics 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 25 with ServerMetrics

use of org.apache.hadoop.hbase.ServerMetrics 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

ServerMetrics (org.apache.hadoop.hbase.ServerMetrics)37 ServerName (org.apache.hadoop.hbase.ServerName)27 RegionMetrics (org.apache.hadoop.hbase.RegionMetrics)19 ClusterMetrics (org.apache.hadoop.hbase.ClusterMetrics)18 HashMap (java.util.HashMap)13 List (java.util.List)11 ArrayList (java.util.ArrayList)10 Map (java.util.Map)10 RegionInfo (org.apache.hadoop.hbase.client.RegionInfo)10 Test (org.junit.Test)10 IOException (java.io.IOException)7 TreeMap (java.util.TreeMap)6 TableName (org.apache.hadoop.hbase.TableName)6 Configuration (org.apache.hadoop.conf.Configuration)5 Collections (java.util.Collections)4 Collectors (java.util.stream.Collectors)4 InterfaceAudience (org.apache.yetus.audience.InterfaceAudience)4 InterruptedIOException (java.io.InterruptedIOException)3 Arrays (java.util.Arrays)3 HashSet (java.util.HashSet)3