hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From zhang...@apache.org
Subject [05/14] hbase git commit: HBASE-19861 - Avoid using RPCs when querying table infos for master status pages
Date Sat, 27 Jan 2018 06:39:47 GMT
HBASE-19861 - Avoid using RPCs when querying table infos for master status pages

Signed-off-by: tedyu <yuzhihong@gmail.com>


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

Branch: refs/heads/HBASE-19064
Commit: 94a1c051ba64bf490b2cc65e5b813176f1d0bb45
Parents: 39b912a
Author: haxiaolin <haxiaolin@xiaomi.com>
Authored: Thu Jan 25 18:47:29 2018 +0800
Committer: tedyu <yuzhihong@gmail.com>
Committed: Fri Jan 26 08:02:14 2018 -0800

----------------------------------------------------------------------
 .../hbase/tmpl/master/MasterStatusTmpl.jamon    | 60 ++++++++++------
 .../hbase-webapps/master/tablesDetailed.jsp     | 76 ++++++++++----------
 2 files changed, 80 insertions(+), 56 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hbase/blob/94a1c051/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 d0342db..3253a57 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
@@ -30,7 +30,9 @@ AssignmentManager assignmentManager = null;
 </%args>
 <%import>
 java.util.*;
+java.io.IOException;
 org.apache.hadoop.hbase.client.RegionInfo;
+org.apache.hadoop.hbase.client.TableDescriptor;
 org.apache.hadoop.hbase.HBaseConfiguration;
 org.apache.hadoop.hbase.HConstants;
 org.apache.hadoop.hbase.HTableDescriptor;
@@ -40,7 +42,6 @@ org.apache.hadoop.hbase.ServerName;
 org.apache.hadoop.hbase.TableName;
 org.apache.hadoop.hbase.client.Admin;
 org.apache.hadoop.hbase.client.MasterSwitchType;
-org.apache.hadoop.hbase.client.SnapshotDescription;
 org.apache.hadoop.hbase.master.assignment.AssignmentManager;
 org.apache.hadoop.hbase.master.DeadServer;
 org.apache.hadoop.hbase.master.HMaster;
@@ -50,6 +51,7 @@ org.apache.hadoop.hbase.protobuf.ProtobufUtil;
 org.apache.hadoop.hbase.quotas.QuotaUtil;
 org.apache.hadoop.hbase.security.access.AccessControlLists;
 org.apache.hadoop.hbase.security.visibility.VisibilityConstants;
+org.apache.hadoop.hbase.shaded.protobuf.generated.SnapshotProtos.SnapshotDescription;
 org.apache.hadoop.hbase.tool.Canary;
 org.apache.hadoop.hbase.util.Bytes;
 org.apache.hadoop.hbase.util.FSUtils;
@@ -93,6 +95,26 @@ AssignmentManager assignmentManager = master.getAssignmentManager();
   }
 </%class>
 
+<%class>
+  public static String getUserTables(HMaster master, List<TableDescriptor> tables){
+    if (master.isInitialized()){
+      try {
+        Map<String, TableDescriptor> descriptorMap = master.getTableDescriptors().getAll();
+        if (descriptorMap != null) {
+          for (TableDescriptor desc : descriptorMap.values()) {
+            if (!desc.getTableName().isSystemTable()) {
+             tables.add(desc);
+            }
+          }
+        }
+      } catch (IOException e) {
+        return "Got user tables error, " + e.getMessage();
+      }
+    }
+    return null;
+  }
+</%class>
+
 <!DOCTYPE html>
 <?xml version="1.0" encoding="UTF-8" ?>
 <html lang="en">
@@ -363,13 +385,10 @@ AssignmentManager assignmentManager = master.getAssignmentManager();
 
 <%def catalogTables>
 <%java>
- HTableDescriptor[] sysTables = null;
- try (Admin admin = master.getConnection().getAdmin()) {
-   sysTables = master.isInitialized() ? admin.listTableDescriptorsByNamespace(
-     NamespaceDescriptor.SYSTEM_NAMESPACE_NAME_STR) : null;
- }
+ List<TableDescriptor> sysTables = master.isInitialized() ?
+   master.listTableDescriptorsByNamespace(NamespaceDescriptor.SYSTEM_NAMESPACE_NAME_STR)
: null;
 </%java>
-<%if (sysTables != null && sysTables.length > 0)%>
+<%if (sysTables != null && sysTables.size() > 0)%>
 <table class="table table-striped">
 <tr>
     <th>Table Name</th>
@@ -378,7 +397,7 @@ AssignmentManager assignmentManager = master.getAssignmentManager();
     </%if>
     <th>Description</th>
 </tr>
-<%for HTableDescriptor systemTable : sysTables%>
+<%for TableDescriptor systemTable : sysTables%>
 <tr>
 <%java>TableName tableName = systemTable.getTableName();</%java>
     <td><a href="table.jsp?name=<% tableName %>"><% tableName %></a></td>
@@ -417,12 +436,14 @@ AssignmentManager assignmentManager = master.getAssignmentManager();
 
 <%def userTables>
 <%java>
-   HTableDescriptor[] tables = null;
-   try (Admin admin = master.getConnection().getAdmin()) {
-     tables = master.isInitialized() ? admin.listTables() : null;
-   }
+   List<TableDescriptor> tables = new ArrayList<TableDescriptor>();
+   String errorMessage = getUserTables(master, tables);
 </%java>
-<%if (tables != null && tables.length > 0)%>
+<%if (tables.size() == 0 && errorMessage != null)%>
+<p> <% errorMessage %> </p>
+</%if>
+
+<%if (tables != null && tables.size() > 0)%>
 <table class="table table-striped">
     <tr>
         <th>Namespace</th>
@@ -437,8 +458,9 @@ AssignmentManager assignmentManager = master.getAssignmentManager();
         <th>Other Regions</th>
         <th>Description</th>
     </tr>
-    <%for HTableDescriptor htDesc : tables%>
+    <%for TableDescriptor desc : tables%>
     <%java>
+      HTableDescriptor htDesc = new HTableDescriptor(desc);
       TableName tableName = htDesc.getTableName();
       Map<RegionState.State, List<RegionInfo>> tableRegions =
           master.getAssignmentManager().getRegionStates()
@@ -471,17 +493,15 @@ AssignmentManager assignmentManager = master.getAssignmentManager();
         <td><% htDesc.toStringCustomizedValues() %></td>
     </tr>
     </%for>
-    <p><% tables.length %> table(s) in set. [<a href=tablesDetailed.jsp>Details</a>]</p>
+    <p><% tables.size() %> table(s) in set. [<a href=tablesDetailed.jsp>Details</a>]</p>
 </table>
 </%if>
 </%def>
 
 <%def userSnapshots>
 <%java>
-   List<SnapshotDescription> snapshots = null;
-   try (Admin admin = master.getConnection().getAdmin()) {
-     snapshots = master.isInitialized() ? admin.listSnapshots() : null;
-   }
+   List<SnapshotDescription> snapshots = master.isInitialized() ?
+     master.getSnapshotManager().getCompletedSnapshots() : null;
 </%java>
 <%if (snapshots != null && snapshots.size() > 0)%>
 <table class="table table-striped">
@@ -492,7 +512,7 @@ AssignmentManager assignmentManager = master.getAssignmentManager();
     </tr>
     <%for SnapshotDescription snapshotDesc : snapshots%>
     <%java>
-        TableName snapshotTable = snapshotDesc.getTableName();
+        TableName snapshotTable = TableName.valueOf(snapshotDesc.getTable());
     </%java>
     <tr>
         <td><a href="snapshot.jsp?name=<% snapshotDesc.getName() %>"><%
snapshotDesc.getName() %></a> </td>

http://git-wip-us.apache.org/repos/asf/hbase/blob/94a1c051/hbase-server/src/main/resources/hbase-webapps/master/tablesDetailed.jsp
----------------------------------------------------------------------
diff --git a/hbase-server/src/main/resources/hbase-webapps/master/tablesDetailed.jsp b/hbase-server/src/main/resources/hbase-webapps/master/tablesDetailed.jsp
index 9201748..2ad44a3 100644
--- a/hbase-server/src/main/resources/hbase-webapps/master/tablesDetailed.jsp
+++ b/hbase-server/src/main/resources/hbase-webapps/master/tablesDetailed.jsp
@@ -18,51 +18,55 @@
  */
 --%>
 <%@ page contentType="text/html;charset=UTF-8"
-  import="static org.apache.commons.lang3.StringEscapeUtils.escapeXml"
-  import="org.apache.hadoop.hbase.master.HMaster"
-  import="org.apache.hadoop.hbase.client.Admin"
-  import="org.apache.hadoop.hbase.client.Connection"
-  import="org.apache.hadoop.hbase.HTableDescriptor"
+         import="static org.apache.commons.lang3.StringEscapeUtils.escapeXml"
+         import="java.io.IOException"
+         import="java.util.ArrayList"
+         import="java.util.List"
+         import="java.util.Map"
 %>
+<%@ page import="org.apache.hadoop.hbase.client.TableDescriptor" %>
+<%@ page import="org.apache.hadoop.hbase.master.HMaster" %>
+<%@ page import="org.apache.hadoop.hbase.tmpl.master.MasterStatusTmplImpl" %>
 <%
-  HMaster master = (HMaster)getServletContext().getAttribute(HMaster.MASTER);
+  HMaster master = (HMaster) getServletContext().getAttribute(HMaster.MASTER);
   pageContext.setAttribute("pageTitle", "HBase Master: " + master.getServerName());
 %>
 <jsp:include page="header.jsp">
-    <jsp:param name="pageTitle" value="${pageTitle}"/>
+  <jsp:param name="pageTitle" value="${pageTitle}"/>
 </jsp:include>
 
-  <div class="container-fluid content">
-    <div class="row inner_header">
-        <div class="page-header">
-            <h1>User Tables</h1>
-        </div>
+<div class="container-fluid content">
+  <div class="row inner_header">
+    <div class="page-header">
+      <h1>User Tables</h1>
     </div>
+  </div>
 
-<% HTableDescriptor[] tables;
-   Connection connection = master.getConnection();
-   Admin admin = connection.getAdmin();
-   try {
-     tables = admin.listTables();
-   } finally {
-     admin.close();
-   }
-   if(tables != null && tables.length > 0) { %>
-<table class="table table-striped">
-<tr>
-    <th>Table</th>
-    <th>Description</th>
-</tr>
-<%   for(HTableDescriptor htDesc : tables ) { %>
-<tr>
-    <td><a href="/table.jsp?name=<%= escapeXml(htDesc.getTableName().getNameAsString())
%>"><%= escapeXml(htDesc.getTableName().getNameAsString()) %></a></td>
-    <td><%= htDesc.toString() %></td>
-</tr>
-<%   }  %>
+  <% List<TableDescriptor> tables = new ArrayList<TableDescriptor>();
+     String errorMessage = MasterStatusTmplImpl.getUserTables(master, tables);
+  if (tables.size() == 0 && errorMessage != null) { %>
+  <p> <%= errorMessage %> </p>
+  <% }
+  if (tables != null && tables.size() > 0) { %>
+  <table class="table table-striped">
+    <tr>
+      <th>Table</th>
+      <th>Description</th>
+    </tr>
+    <% for (TableDescriptor htDesc : tables) { %>
+    <tr>
+      <td>
+        <a href="/table.jsp?name=<%= escapeXml(htDesc.getTableName().getNameAsString())
%>"><%= escapeXml(
+            htDesc.getTableName().getNameAsString()) %>
+        </a></td>
+      <td><%= htDesc.toString() %>
+      </td>
+    </tr>
+    <% } %>
 
-<p> <%= tables.length %> table(s) in set.</p>
-</table>
-<% } %>
+    <p><%= tables.size() %> table(s) in set.</p>
+  </table>
+  <% } %>
 </div>
 
-<jsp:include page="footer.jsp" />
+<jsp:include page="footer.jsp"/>


Mime
View raw message