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;
}
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());
}
}
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;
}
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);
}
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);
}
}
Aggregations