hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From st...@apache.org
Subject hbase git commit: HBASE-7332 [webui] HMaster webui should display the number of regions a table has. (Andrey Stepachev)
Date Tue, 03 Feb 2015 17:25:12 GMT
Repository: hbase
Updated Branches:
  refs/heads/master c812d13a4 -> 7861e518e


HBASE-7332 [webui] HMaster webui should display the number of regions a table has. (Andrey
Stepachev)


Project: http://git-wip-us.apache.org/repos/asf/hbase/repo
Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/7861e518
Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/7861e518
Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/7861e518

Branch: refs/heads/master
Commit: 7861e518efb2dc5d393b07079f4309a91b31dea3
Parents: c812d13
Author: stack <stack@apache.org>
Authored: Tue Feb 3 09:24:54 2015 -0800
Committer: stack <stack@apache.org>
Committed: Tue Feb 3 09:24:54 2015 -0800

----------------------------------------------------------------------
 .../hbase/tmpl/master/MasterStatusTmpl.jamon    | 31 +++++++++++-
 .../hadoop/hbase/master/RegionStates.java       | 53 +++++++++++++++++++-
 .../master/TestAssignmentManagerOnCluster.java  |  6 +--
 3 files changed, 83 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hbase/blob/7861e518/hbase-server/src/main/jamon/org/apache/hadoop/hbase/tmpl/master/MasterStatusTmpl.jamon
----------------------------------------------------------------------
diff --git a/hbase-server/src/main/jamon/org/apache/hadoop/hbase/tmpl/master/MasterStatusTmpl.jamon
b/hbase-server/src/main/jamon/org/apache/hadoop/hbase/tmpl/master/MasterStatusTmpl.jamon
index 9792126..c83f295 100644
--- a/hbase-server/src/main/jamon/org/apache/hadoop/hbase/tmpl/master/MasterStatusTmpl.jamon
+++ b/hbase-server/src/main/jamon/org/apache/hadoop/hbase/tmpl/master/MasterStatusTmpl.jamon
@@ -43,6 +43,8 @@ org.apache.hadoop.hbase.ServerLoad;
 org.apache.hadoop.hbase.ServerName;
 org.apache.hadoop.hbase.client.Admin;
 org.apache.hadoop.hbase.client.HConnectionManager;
+org.apache.hadoop.hbase.HRegionInfo;
+org.apache.hadoop.hbase.master.RegionState;
 org.apache.hadoop.hbase.HTableDescriptor;
 org.apache.hadoop.hbase.HBaseConfiguration;
 org.apache.hadoop.hbase.TableName;
@@ -363,17 +365,42 @@ AssignmentManager assignmentManager = master.getAssignmentManager();
             <th title="Fragmentation - Will be 0% after a major compaction and fluctuate
during normal usage.">Frag.</th>
         </%if>
         <th>Online Regions</th>
+        <th>Offline Regions</th>
+        <th>Failed Regions</th>
+        <th>Split Regions</th>
+        <th>Other Regions</th>
         <th>Description</th>
     </tr>
     <%for HTableDescriptor htDesc : tables%>
+    <%java>
+      Map<RegionState.State, List<HRegionInfo>> tableRegions =
+          master.getAssignmentManager().getRegionStates()
+            .getRegionByStateOfTable(htDesc.getTableName());
+      int openRegionsCount = tableRegions.get(RegionState.State.OPEN).size();
+      int offlineRegionsCount = tableRegions.get(RegionState.State.OFFLINE).size();
+      int splitRegionsCount = tableRegions.get(RegionState.State.SPLIT).size();
+      int failedRegionsCount = tableRegions.get(RegionState.State.FAILED_OPEN).size()
+             + tableRegions.get(RegionState.State.FAILED_CLOSE).size();
+      int otherRegionsCount = 0;
+      for (List<HRegionInfo> list: tableRegions.values()) {
+         otherRegionsCount += list.size();
+      }
+      // now subtract known states
+      otherRegionsCount = otherRegionsCount - openRegionsCount
+                     - failedRegionsCount - offlineRegionsCount
+                     - splitRegionsCount;
+    </%java>
     <tr>
         <td><% htDesc.getTableName().getNamespaceAsString() %></td>
         <td><a href=table.jsp?name=<% htDesc.getTableName().getNameAsString()
%>><% htDesc.getTableName().getQualifierAsString() %></a> </td>
         <%if (frags != null) %>
             <td align="center"><% frags.get(htDesc.getTableName().getNameAsString())
!= null ? frags.get(htDesc.getTableName().getQualifierAsString()).intValue() + "%" : "n/a"
%></td>
         </%if>
-        <td><% master.getAssignmentManager().getRegionStates().getRegionsOfTable(htDesc
-        .getTableName()).size() %>
+        <td><% openRegionsCount %></td>
+        <td><% offlineRegionsCount %></td>
+        <td><% failedRegionsCount %></td>
+        <td><% splitRegionsCount %></td>
+        <td><% otherRegionsCount %></td>
         <td><% htDesc.toStringCustomizedValues() %></td>
     </tr>
     </%for>

http://git-wip-us.apache.org/repos/asf/hbase/blob/7861e518/hbase-server/src/main/java/org/apache/hadoop/hbase/master/RegionStates.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/RegionStates.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/RegionStates.java
index c98a998..11139f6 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/RegionStates.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/RegionStates.java
@@ -75,6 +75,12 @@ public class RegionStates {
     new HashMap<String, RegionState>();
 
   /**
+   * Holds mapping of table -> region state
+   */
+  private final Map<TableName, Map<String, RegionState>> regionStatesTableIndex
=
+      new HashMap<TableName, Map<String, RegionState>>();
+
+  /**
    * Server to regions assignment map.
    * Contains the set of regions currently assigned to a given server.
    */
@@ -328,7 +334,7 @@ public class RegionStates {
         + "used existing: " + regionState + ", ignored new: " + newState);
     } else {
       regionState = new RegionState(hri, newState, serverName);
-      regionStates.put(encodedName, regionState);
+      putRegionState(regionState);
       if (newState == State.OPEN) {
         if (!serverName.equals(lastHost)) {
           LOG.warn("Open region's last host " + lastHost
@@ -351,6 +357,20 @@ public class RegionStates {
     return regionState;
   }
 
+  private RegionState putRegionState(RegionState regionState) {
+    HRegionInfo hri = regionState.getRegion();
+    String encodedName = hri.getEncodedName();
+    TableName table = hri.getTable();
+    RegionState oldState = regionStates.put(encodedName, regionState);
+    Map<String, RegionState> map = regionStatesTableIndex.get(table);
+    if (map == null) {
+      map = new HashMap<String, RegionState>();
+      regionStatesTableIndex.put(table, map);
+    }
+    map.put(encodedName, regionState);
+    return oldState;
+  }
+
   /**
    * Update a region state. It will be put in transition if not already there.
    */
@@ -637,6 +657,30 @@ public class RegionStates {
     return tableRegions;
   }
 
+  /**
+   * Gets current state of all regions of the table.
+   * This method looks at the in-memory state.  It does not go to <code>hbase:meta</code>.
+   * Method guaranteed to return keys for all states
+   * in {@link org.apache.hadoop.hbase.master.RegionState.State}
+   *
+   * @param tableName
+   * @return Online regions from <code>tableName</code>
+   */
+  public synchronized Map<RegionState.State, List<HRegionInfo>>
+  getRegionByStateOfTable(TableName tableName) {
+    Map<RegionState.State, List<HRegionInfo>> tableRegions =
+        new HashMap<State, List<HRegionInfo>>();
+    for (State state : State.values()) {
+      tableRegions.put(state, new ArrayList<HRegionInfo>());
+    }
+    Map<String, RegionState> indexMap = regionStatesTableIndex.get(tableName);
+    if (indexMap == null)
+      return tableRegions;
+    for (RegionState regionState : indexMap.values()) {
+      tableRegions.get(regionState.getState()).add(regionState.getRegion());
+    }
+    return tableRegions;
+  }
 
   /**
    * Wait on region to clear regions-in-transition.
@@ -696,6 +740,11 @@ public class RegionStates {
     String encodedName = hri.getEncodedName();
     regionsInTransition.remove(encodedName);
     regionStates.remove(encodedName);
+    TableName table = hri.getTable();
+    Map<String, RegionState> indexMap = regionStatesTableIndex.get(table);
+    indexMap.remove(encodedName);
+    if (indexMap.size() == 0)
+      regionStatesTableIndex.remove(table);
     lastAssignments.remove(encodedName);
     ServerName sn = regionAssignments.remove(hri);
     if (sn != null) {
@@ -1008,7 +1057,7 @@ public class RegionStates {
 
     synchronized (this) {
       regionsInTransition.put(encodedName, regionState);
-      regionStates.put(encodedName, regionState);
+      putRegionState(regionState);
 
       // For these states, region should be properly closed.
       // There should be no log splitting issue.

http://git-wip-us.apache.org/repos/asf/hbase/blob/7861e518/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestAssignmentManagerOnCluster.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestAssignmentManagerOnCluster.java
b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestAssignmentManagerOnCluster.java
index 5a0dffa..f1c080d 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestAssignmentManagerOnCluster.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestAssignmentManagerOnCluster.java
@@ -288,9 +288,9 @@ public class TestAssignmentManagerOnCluster {
 
       long timeoutTime = System.currentTimeMillis() + 800;
       while (true) {
-        List<HRegionInfo> regions =
-          regionStates.getRegionsOfTable(table);
-        if (!regions.contains(hri)) break;
+        if (regionStates.getRegionByStateOfTable(table)
+            .get(RegionState.State.OFFLINE).contains(hri))
+          break;
         long now = System.currentTimeMillis();
         if (now > timeoutTime) {
           fail("Failed to offline the region in time");


Mime
View raw message