use of org.apache.hadoop.hbase.ClusterMetrics in project hbase by apache.
the class RestartRsHoldingMetaAction method perform.
@Override
public void perform() throws Exception {
getLogger().info("Performing action: Restart regionserver holding META");
ServerName server = cluster.getServerHoldingMeta();
if (server == null) {
getLogger().warn("No server is holding hbase:meta right now.");
return;
}
ClusterMetrics clusterStatus = cluster.getClusterMetrics();
if (server.equals(clusterStatus.getMasterName())) {
// Master holds the meta, so restart the master.
restartMaster(server, sleepTime);
} else {
restartRs(server, sleepTime);
}
}
use of org.apache.hadoop.hbase.ClusterMetrics 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);
}
}
use of org.apache.hadoop.hbase.ClusterMetrics in project hbase by apache.
the class TestStochasticLoadBalancer method testCPRequestCost.
@Test
public void testCPRequestCost() {
// in order to pass needsBalance judgement
conf.setFloat("hbase.master.balancer.stochastic.cpRequestCost", 10000f);
loadBalancer.onConfigurationChange(conf);
// mock cluster State
Map<ServerName, List<RegionInfo>> clusterState = new HashMap<ServerName, List<RegionInfo>>();
ServerName serverA = randomServer(3).getServerName();
ServerName serverB = randomServer(3).getServerName();
ServerName serverC = randomServer(3).getServerName();
List<RegionInfo> regionsOnServerA = randomRegions(3);
List<RegionInfo> regionsOnServerB = randomRegions(3);
List<RegionInfo> regionsOnServerC = randomRegions(3);
clusterState.put(serverA, regionsOnServerA);
clusterState.put(serverB, regionsOnServerB);
clusterState.put(serverC, regionsOnServerC);
// mock ClusterMetrics
Map<ServerName, ServerMetrics> serverMetricsMap = new TreeMap<>();
serverMetricsMap.put(serverA, mockServerMetricsWithCpRequests(regionsOnServerA, 0));
serverMetricsMap.put(serverB, mockServerMetricsWithCpRequests(regionsOnServerB, 0));
serverMetricsMap.put(serverC, mockServerMetricsWithCpRequests(regionsOnServerC, 0));
ClusterMetrics clusterStatus = mock(ClusterMetrics.class);
when(clusterStatus.getLiveServerMetrics()).thenReturn(serverMetricsMap);
loadBalancer.updateClusterMetrics(clusterStatus);
// CPRequestCostFunction are Rate based, So doing setClusterMetrics again
// this time, regions on serverA with more cpRequestCount load
// serverA : 1000,1000,1000
// serverB : 0,0,0
// serverC : 0,0,0
// so should move two regions from serverA to serverB & serverC
serverMetricsMap = new TreeMap<>();
serverMetricsMap.put(serverA, mockServerMetricsWithCpRequests(regionsOnServerA, 1000));
serverMetricsMap.put(serverB, mockServerMetricsWithCpRequests(regionsOnServerB, 0));
serverMetricsMap.put(serverC, mockServerMetricsWithCpRequests(regionsOnServerC, 0));
clusterStatus = mock(ClusterMetrics.class);
when(clusterStatus.getLiveServerMetrics()).thenReturn(serverMetricsMap);
loadBalancer.updateClusterMetrics(clusterStatus);
List<RegionPlan> plans = loadBalancer.balanceTable(HConstants.ENSEMBLE_TABLE_NAME, clusterState);
Set<RegionInfo> regionsMoveFromServerA = new HashSet<>();
Set<ServerName> targetServers = new HashSet<>();
for (RegionPlan plan : plans) {
if (plan.getSource().equals(serverA)) {
regionsMoveFromServerA.add(plan.getRegionInfo());
targetServers.add(plan.getDestination());
}
}
// should move 2 regions from serverA, one moves to serverB, the other moves to serverC
assertEquals(2, regionsMoveFromServerA.size());
assertEquals(2, targetServers.size());
assertTrue(regionsOnServerA.containsAll(regionsMoveFromServerA));
// reset config
conf.setFloat("hbase.master.balancer.stochastic.cpRequestCost", 5f);
loadBalancer.onConfigurationChange(conf);
}
use of org.apache.hadoop.hbase.ClusterMetrics in project hbase by apache.
the class ClientModeStrategy method createRecords.
List<Record> createRecords(ClusterMetrics clusterMetrics) {
List<Record> ret = new ArrayList<>();
for (ServerMetrics serverMetrics : clusterMetrics.getLiveServerMetrics().values()) {
long lastReportTimestamp = serverMetrics.getLastReportTimestamp();
serverMetrics.getUserMetrics().values().forEach(um -> um.getClientMetrics().values().forEach(clientMetrics -> ret.add(createRecord(um.getNameAsString(), clientMetrics, lastReportTimestamp, serverMetrics.getServerName().getServerName()))));
}
return ret;
}
use of org.apache.hadoop.hbase.ClusterMetrics in project hbase by apache.
the class TopScreenModel method refreshMetricsData.
/*
* HBTop only calls this from a single thread, and if that ever changes, this needs
* synchronization
*/
public void refreshMetricsData() {
ClusterMetrics clusterMetrics;
try {
clusterMetrics = admin.getClusterMetrics();
} catch (Exception e) {
LOGGER.error("Unable to get cluster metrics", e);
return;
}
refreshSummary(clusterMetrics);
refreshRecords(clusterMetrics);
}
Aggregations