From 4c4352c7277a7e7502793a32f3d56fca5ec2746d Mon Sep 17 00:00:00 2001 From: haxiaolin Date: Thu, 25 Jan 2018 18:47:29 +0800 Subject: [PATCH] HBASE-19861 - Avoid using RPCs when querying table infos for master status pages Signed-off-by: tedyu --- .../hbase/tmpl/master/MasterStatusTmpl.jamon | 60 ++++++++++----- .../hbase-webapps/master/tablesDetailed.jsp | 76 ++++++++++--------- 2 files changed, 80 insertions(+), 56 deletions(-) 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 d0342db333a..3253a576238 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; <%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> + public static String getUserTables(HMaster master, List tables){ + if (master.isInitialized()){ + try { + Map 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; + } + + @@ -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 sysTables = master.isInitialized() ? + master.listTableDescriptorsByNamespace(NamespaceDescriptor.SYSTEM_NAMESPACE_NAME_STR) : null; -<%if (sysTables != null && sysTables.length > 0)%> +<%if (sysTables != null && sysTables.size() > 0)%> @@ -378,7 +397,7 @@ AssignmentManager assignmentManager = master.getAssignmentManager(); -<%for HTableDescriptor systemTable : sysTables%> +<%for TableDescriptor systemTable : sysTables%> <%java>TableName tableName = systemTable.getTableName(); @@ -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 tables = new ArrayList(); + String errorMessage = getUserTables(master, tables); -<%if (tables != null && tables.length > 0)%> +<%if (tables.size() == 0 && errorMessage != null)%> +

<% errorMessage %>

+ + +<%if (tables != null && tables.size() > 0)%>
Table Name Description
<% tableName %>
@@ -437,8 +458,9 @@ AssignmentManager assignmentManager = master.getAssignmentManager(); - <%for HTableDescriptor htDesc : tables%> + <%for TableDescriptor desc : tables%> <%java> + HTableDescriptor htDesc = new HTableDescriptor(desc); TableName tableName = htDesc.getTableName(); Map> tableRegions = master.getAssignmentManager().getRegionStates() @@ -471,17 +493,15 @@ AssignmentManager assignmentManager = master.getAssignmentManager(); -

<% tables.length %> table(s) in set. [Details]

+

<% tables.size() %> table(s) in set. [Details]

NamespaceOther Regions Description
<% htDesc.toStringCustomizedValues() %>
<%def userSnapshots> <%java> - List snapshots = null; - try (Admin admin = master.getConnection().getAdmin()) { - snapshots = master.isInitialized() ? admin.listSnapshots() : null; - } + List snapshots = master.isInitialized() ? + master.getSnapshotManager().getCompletedSnapshots() : null; <%if (snapshots != null && snapshots.size() > 0)%> @@ -492,7 +512,7 @@ AssignmentManager assignmentManager = master.getAssignmentManager(); <%for SnapshotDescription snapshotDesc : snapshots%> <%java> - TableName snapshotTable = snapshotDesc.getTableName(); + TableName snapshotTable = TableName.valueOf(snapshotDesc.getTable()); 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 9201748d311..2ad44a3d68b 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()); %> - + -
-
- +
+
+ +
-<% HTableDescriptor[] tables; - Connection connection = master.getConnection(); - Admin admin = connection.getAdmin(); - try { - tables = admin.listTables(); - } finally { - admin.close(); - } - if(tables != null && tables.length > 0) { %> -
<% snapshotDesc.getName() %>
- - - - -<% for(HTableDescriptor htDesc : tables ) { %> - - - - -<% } %> + <% List tables = new ArrayList(); + String errorMessage = MasterStatusTmplImpl.getUserTables(master, tables); + if (tables.size() == 0 && errorMessage != null) { %> +

<%= errorMessage %>

+ <% } + if (tables != null && tables.size() > 0) { %> +
TableDescription
<%= escapeXml(htDesc.getTableName().getNameAsString()) %><%= htDesc.toString() %>
+ + + + + <% for (TableDescriptor htDesc : tables) { %> + + + + + <% } %> -

<%= tables.length %> table(s) in set.

-
TableDescription
+ <%= escapeXml( + htDesc.getTableName().getNameAsString()) %> + <%= htDesc.toString() %> +
-<% } %> +

<%= tables.size() %> table(s) in set.

+ + <% } %> - +