HBASE-19861 - Avoid using RPCs when querying table infos for master status pages

Signed-off-by: tedyu <yuzhihong@gmail.com>
This commit is contained in:
haxiaolin 2018-01-25 18:47:29 +08:00 committed by tedyu
parent b8d6c99b6a
commit 4c4352c727
2 changed files with 80 additions and 56 deletions

View File

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

View File

@ -19,50 +19,54 @@
--%> --%>
<%@ page contentType="text/html;charset=UTF-8" <%@ page contentType="text/html;charset=UTF-8"
import="static org.apache.commons.lang3.StringEscapeUtils.escapeXml" import="static org.apache.commons.lang3.StringEscapeUtils.escapeXml"
import="org.apache.hadoop.hbase.master.HMaster" import="java.io.IOException"
import="org.apache.hadoop.hbase.client.Admin" import="java.util.ArrayList"
import="org.apache.hadoop.hbase.client.Connection" import="java.util.List"
import="org.apache.hadoop.hbase.HTableDescriptor" 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()); pageContext.setAttribute("pageTitle", "HBase Master: " + master.getServerName());
%> %>
<jsp:include page="header.jsp"> <jsp:include page="header.jsp">
<jsp:param name="pageTitle" value="${pageTitle}"/> <jsp:param name="pageTitle" value="${pageTitle}"/>
</jsp:include> </jsp:include>
<div class="container-fluid content"> <div class="container-fluid content">
<div class="row inner_header"> <div class="row inner_header">
<div class="page-header"> <div class="page-header">
<h1>User Tables</h1> <h1>User Tables</h1>
</div> </div>
</div> </div>
<% HTableDescriptor[] tables; <% List<TableDescriptor> tables = new ArrayList<TableDescriptor>();
Connection connection = master.getConnection(); String errorMessage = MasterStatusTmplImpl.getUserTables(master, tables);
Admin admin = connection.getAdmin(); if (tables.size() == 0 && errorMessage != null) { %>
try { <p> <%= errorMessage %> </p>
tables = admin.listTables(); <% }
} finally { if (tables != null && tables.size() > 0) { %>
admin.close(); <table class="table table-striped">
} <tr>
if(tables != null && tables.length > 0) { %>
<table class="table table-striped">
<tr>
<th>Table</th> <th>Table</th>
<th>Description</th> <th>Description</th>
</tr> </tr>
<% for(HTableDescriptor htDesc : tables ) { %> <% for (TableDescriptor htDesc : tables) { %>
<tr> <tr>
<td><a href="/table.jsp?name=<%= escapeXml(htDesc.getTableName().getNameAsString()) %>"><%= escapeXml(htDesc.getTableName().getNameAsString()) %></a></td> <td>
<td><%= htDesc.toString() %></td> <a href="/table.jsp?name=<%= escapeXml(htDesc.getTableName().getNameAsString()) %>"><%= escapeXml(
</tr> htDesc.getTableName().getNameAsString()) %>
<% } %> </a></td>
<td><%= htDesc.toString() %>
</td>
</tr>
<% } %>
<p> <%= tables.length %> table(s) in set.</p> <p><%= tables.size() %> table(s) in set.</p>
</table> </table>
<% } %> <% } %>
</div> </div>
<jsp:include page="footer.jsp" /> <jsp:include page="footer.jsp"/>