Search in sources :

Example 26 with ClusterMetrics

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);
    }
}
Also used : ClusterMetrics(org.apache.hadoop.hbase.ClusterMetrics) ServerName(org.apache.hadoop.hbase.ServerName)

Example 27 with ClusterMetrics

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

Example 28 with ClusterMetrics

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);
}
Also used : HashMap(java.util.HashMap) RegionInfo(org.apache.hadoop.hbase.client.RegionInfo) TreeMap(java.util.TreeMap) ClusterMetrics(org.apache.hadoop.hbase.ClusterMetrics) RegionPlan(org.apache.hadoop.hbase.master.RegionPlan) ServerName(org.apache.hadoop.hbase.ServerName) ArrayList(java.util.ArrayList) List(java.util.List) ServerMetrics(org.apache.hadoop.hbase.ServerMetrics) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 29 with ClusterMetrics

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;
}
Also used : RecordFilter(org.apache.hadoop.hbase.hbtop.RecordFilter) Arrays(java.util.Arrays) UserMetrics(org.apache.hadoop.hbase.UserMetrics) Set(java.util.Set) ServerMetrics(org.apache.hadoop.hbase.ServerMetrics) HashMap(java.util.HashMap) ClusterMetrics(org.apache.hadoop.hbase.ClusterMetrics) Collectors(java.util.stream.Collectors) FieldValueType(org.apache.hadoop.hbase.hbtop.field.FieldValueType) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) List(java.util.List) InterfaceAudience(org.apache.yetus.audience.InterfaceAudience) Field(org.apache.hadoop.hbase.hbtop.field.Field) FieldInfo(org.apache.hadoop.hbase.hbtop.field.FieldInfo) FieldValue(org.apache.hadoop.hbase.hbtop.field.FieldValue) Map(java.util.Map) Record(org.apache.hadoop.hbase.hbtop.Record) Collections(java.util.Collections) ArrayList(java.util.ArrayList) Record(org.apache.hadoop.hbase.hbtop.Record) ServerMetrics(org.apache.hadoop.hbase.ServerMetrics)

Example 30 with ClusterMetrics

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);
}
Also used : ClusterMetrics(org.apache.hadoop.hbase.ClusterMetrics)

Aggregations

ClusterMetrics (org.apache.hadoop.hbase.ClusterMetrics)39 ServerName (org.apache.hadoop.hbase.ServerName)30 Test (org.junit.Test)19 ServerMetrics (org.apache.hadoop.hbase.ServerMetrics)18 ArrayList (java.util.ArrayList)13 List (java.util.List)12 HashMap (java.util.HashMap)9 RegionMetrics (org.apache.hadoop.hbase.RegionMetrics)8 Admin (org.apache.hadoop.hbase.client.Admin)8 IOException (java.io.IOException)7 Map (java.util.Map)7 TableName (org.apache.hadoop.hbase.TableName)7 RegionInfo (org.apache.hadoop.hbase.client.RegionInfo)7 HashSet (java.util.HashSet)6 Configuration (org.apache.hadoop.conf.Configuration)6 TreeMap (java.util.TreeMap)5 Collections (java.util.Collections)4 LinkedList (java.util.LinkedList)4 Collectors (java.util.stream.Collectors)4 Put (org.apache.hadoop.hbase.client.Put)4