From 9ad16aa3763d05e85807a5c81b42c03eb2dec4f5 Mon Sep 17 00:00:00 2001 From: xincunSong <365724453@qq.com> Date: Wed, 1 Jul 2020 08:49:51 +0800 Subject: [PATCH] HBASE-24624 Optimize table.jsp code (#1963) Signed-off-by: Guangxu Cheng --- .../resources/hbase-webapps/master/table.jsp | 391 ++++++++---------- 1 file changed, 161 insertions(+), 230 deletions(-) diff --git a/hbase-server/src/main/resources/hbase-webapps/master/table.jsp b/hbase-server/src/main/resources/hbase-webapps/master/table.jsp index ef173158f0c..1a34b7fe8d0 100644 --- a/hbase-server/src/main/resources/hbase-webapps/master/table.jsp +++ b/hbase-server/src/main/resources/hbase-webapps/master/table.jsp @@ -87,7 +87,7 @@ * its region server. * @return an anchor tag if one can be built, {@code null} otherwise. */ - private static String buildRegionServerLink(final ServerName serverName, final int rsInfoPort, + private static String buildRegionLink(final ServerName serverName, final int rsInfoPort, final RegionInfo regionInfo, final RegionState.State regionState) { if (serverName == null || regionInfo == null) { return null; } @@ -101,6 +101,45 @@ + "?name=" + regionInfo.getEncodedName(); return "" + serverName.getServerName() + ""; } + + /** + * Render an tag contents server name which the given region deploys. + * Links to the server rs-status page. + * not deployed instead if can not find the deploy message. + * @return an tag contents server name links to server rs-status page. + */ + private static String buildRegionDeployedServerTag(RegionInfo regionInfo, HMaster master, + Map regionsToServer) { + ServerName serverName = regionsToServer.get(regionInfo); + + if (serverName == null) { + return "not deployed"; + } + + String hostName = serverName.getHostname(); + String hostNameEncoded = URLEncoder.encode(hostName); + // This port might be wrong if RS actually ended up using something else. + int serverInfoPort = master.getRegionServerInfoPort(serverName); + String urlRegionServer = "//" + hostNameEncoded + ":" + serverInfoPort + "/rs-status"; + + return "" + StringEscapeUtils.escapeHtml4(hostName) + + ":" + serverInfoPort + ""; + } + + /** + * @return an

tag guide user to see all region messages. + */ + private static String moreRegionsToRender(int numRegionsRendered, int numRegions, String fqtn) { + if (numRegions > numRegionsRendered) { + String allRegionsUrl = "?name=" + URLEncoder.encode(fqtn) + "&numRegions=all"; + + return "This table has " + numRegions + + " regions in total, in order to improve the page load time, only " + + numRegionsRendered + " regions are displayed here, click here to see all regions.

"; + } + return ""; + } %> <% final String ZEROMB = "0 MB"; @@ -108,8 +147,7 @@ Configuration conf = master.getConfiguration(); String fqtn = request.getParameter("name"); final String escaped_fqtn = StringEscapeUtils.escapeHtml4(fqtn); - Table table; - boolean withReplica = false; + Table table = master.getConnection().getTable(TableName.valueOf(fqtn)); boolean showFragmentation = conf.getBoolean("hbase.master.ui.fragmentation.enabled", false); boolean readOnly = !InfoServer.canUserModifyUI(request, getServletContext(), conf); int numMetaReplicas = conf.getInt(HConstants.META_REPLICAS_NUM, @@ -160,31 +198,50 @@ -<% -if (fqtn != null && master.isInitialized()) { - try { - table = master.getConnection().getTable(TableName.valueOf(fqtn)); - if (table.getDescriptor().getRegionReplication() > 1) { - withReplica = true; - } - if ( !readOnly && action != null ) { -%> -
-
- +<% // handle the case for fqtn is null or master is not initialized with error message + redirect + if (fqtn == null || ! master.isInitialized()) { %> +
+
+ -


-<% - if (action.equals("split")) { +

+


+ +

+<% return; + } %> + +<% // unknow table + if (! admin.tableExists(TableName.valueOf(fqtn)).get()) { %> +
+
+ +
+


+ +

+<% return; + } %> + +<% // table split/compact/merge actions + if ( !readOnly && action != null ) { %> +
+
+ +
+


+<% if (action.equals("split")) { if (key != null && key.length() > 0) { admin.split(TableName.valueOf(fqtn), Bytes.toBytes(key)); } else { admin.split(TableName.valueOf(fqtn)); } - - %> Split request accepted. <% +%> Split request accepted. <% } else if (action.equals("compact")) { if (key != null && key.length() > 0) { List regions = admin.getRegions(TableName.valueOf(fqtn)).get(); @@ -198,45 +255,39 @@ if (fqtn != null && master.isInitialized()) { } else { admin.compact(TableName.valueOf(fqtn)); } - %> Compact request accepted. <% +%> Compact request accepted. <% } else if (action.equals("merge")) { - if (left != null && left.length() > 0 && right != null && right.length() > 0) { - admin.mergeRegions(Bytes.toBytesBinary(left), Bytes.toBytesBinary(right), false); - } - %> Merge request accepted. <% - } -%> - -

-<% - } else { -%> -
-
- + if (left != null && left.length() > 0 && right != null && right.length() > 0) { + admin.mergeRegions(Bytes.toBytesBinary(left), Bytes.toBytesBinary(right), false); + } +%> Merge request accepted. <% + } %> +
-
-<% - if(fqtn.equals(TableName.META_TABLE_NAME.getNameAsString())) { -%> +<% return; + } %> + +
+
+ +
+ +
+<% //Meta table. + if(fqtn.equals(TableName.META_TABLE_NAME.getNameAsString())) { %>

Table Regions

+
- +
@@ -248,13 +299,7 @@ if (fqtn != null && master.isInitialized()) { - <% - if (withReplica) { - %> - <% - } - %> @@ -305,13 +350,7 @@ if (fqtn != null && master.isInitialized()) { - <% - if (withReplica) { - %> - <% - } - %> <% } %> <%} %> @@ -319,7 +358,7 @@ if (fqtn != null && master.isInitialized()) {
NameMemSize Start Key End KeyReplicaID
<%= memSize%> <%= escapeXml(Bytes.toString(meta.getStartKey())) %> <%= escapeXml(Bytes.toString(meta.getEndKey())) %><%= meta.getReplicaId() %>
- +
@@ -421,6 +460,7 @@ if (fqtn != null && master.isInitialized()) { +

Meta Entries

<% if (!metaBrowser.getErrorMessages().isEmpty()) { @@ -512,7 +552,7 @@ if (fqtn != null && master.isInitialized()) { - + @@ -581,6 +621,7 @@ if (fqtn != null && master.isInitialized()) { <%} else { + //Common tables RegionStates states = master.getAssignmentManager().getRegionStates(); Map> regionStates = states.getRegionByStateOfTable(table.getName()); Map stateMap = new HashMap<>(); @@ -590,7 +631,9 @@ if (fqtn != null && master.isInitialized()) { } } RegionLocator r = master.getConnection().getRegionLocator(table.getName()); - try { %> + + try { +%>

Table Attributes

Name <%= endKeyDisplay %> <%= replicaIdDisplay %> <%= regionStateDisplay %>"><%= buildRegionServerLink(serverName, rsPort, regionInfo, regionState) %>"><%= buildRegionLink(serverName, rsPort, regionInfo, regionState) %> <%= seqNum %> <%= targetServerName %> <%= mergeRegionNames %>
@@ -820,19 +863,13 @@ if (fqtn != null && master.isInitialized()) {

Table Regions

+
@@ -845,13 +882,7 @@ if (fqtn != null && master.isInitialized()) { - <% - if (withReplica) { - %> - <% - } - %> @@ -867,7 +898,6 @@ if (fqtn != null && master.isInitialized()) { RegionInfo regionInfo = hriEntry.getKey(); ServerName addr = regionsToServer.get(regionInfo); RegionMetrics load = hriEntry.getValue(); - String urlRegionServer = null; String readReq = "N/A"; String writeReq = "N/A"; String regionSize = ZEROMB; @@ -894,14 +924,11 @@ if (fqtn != null && master.isInitialized()) { if (addr != null) { ServerMetrics sl = master.getServerManager().getLoad(addr); - // This port might be wrong if RS actually ended up using something else. - urlRegionServer = - "//" + URLEncoder.encode(addr.getHostname()) + ":" + master.getRegionServerInfoPort(addr) + "/rs-status"; if(sl != null) { Integer i = regDistribution.get(addr); if (null == i) i = Integer.valueOf(0); regDistribution.put(addr, i + 1); - if (withReplica && RegionReplicaUtil.isDefaultReplica(regionInfo.getReplicaId())) { + if (RegionReplicaUtil.isDefaultReplica(regionInfo.getReplicaId())) { i = primaryRegDistribution.get(addr); if (null == i) i = Integer.valueOf(0); primaryRegDistribution.put(addr, i+1); @@ -913,19 +940,7 @@ if (fqtn != null && master.isInitialized()) { %> - <% - if (urlRegionServer != null) { - %> - - <% - } else { - %> - - <% - } - %> + <%= buildRegionDeployedServerTag(regionInfo, master, regionsToServer) %> @@ -934,28 +949,16 @@ if (fqtn != null && master.isInitialized()) { - <% - if (withReplica) { - %> - <% - } - %> <% } %> <% } %>
Name(<%= String.format("%,1d", regions.size())%>)Start Key End Key Region StateReplicaID
<%= escapeXml(Bytes.toStringBinary(regionInfo.getRegionName())) %> - <%= addr == null? "-": StringEscapeUtils.escapeHtml4(addr.getHostname().toString()) + ":" + master.getRegionServerInfoPort(addr) %> - not deployed<%= readReq%> <%= writeReq%> <%= regionSize%><%= escapeXml(Bytes.toStringBinary(regionInfo.getStartKey()))%> <%= escapeXml(Bytes.toStringBinary(regionInfo.getEndKey()))%> <%= state%><%= regionInfo.getReplicaId() %>
- <% if (numRegions > numRegionsRendered) { - String allRegionsUrl = "?name=" + URLEncoder.encode(fqtn,"UTF-8") + "&numRegions=all"; - %> -

This table has <%= numRegions %> regions in total, in order to improve the page load time, - only <%= numRegionsRendered %> regions are displayed here, click - here to see all regions.

- <% } %> + <%= moreRegionsToRender(numRegionsRendered, numRegions, fqtn) %>
- +
@@ -971,7 +974,6 @@ if (fqtn != null && master.isInitialized()) { RegionInfo regionInfo = hriEntry.getKey(); ServerName addr = regionsToServer.get(regionInfo); RegionMetrics load = hriEntry.getValue(); - String urlRegionServer = null; float locality = 0.0f; float localityForSsd = 0.0f; String state = "N/A"; @@ -980,30 +982,12 @@ if (fqtn != null && master.isInitialized()) { localityForSsd = load.getDataLocalityForSsd(); } - if (addr != null) { - // This port might be wrong if RS actually ended up using something else. - urlRegionServer = - "//" + URLEncoder.encode(addr.getHostname()) + ":" + master.getRegionServerInfoPort(addr) + "/rs-status"; - } - if (numRegionsRendered < numRegionsToRender) { numRegionsRendered++; %> - <% - if (urlRegionServer != null) { - %> - - <% - } else { - %> - - <% - } - %> + <%= buildRegionDeployedServerTag(regionInfo, master, regionsToServer) %> @@ -1011,6 +995,7 @@ if (fqtn != null && master.isInitialized()) { <% } %>
Name(<%= String.format("%,1d", regions.size())%>)
<%= escapeXml(Bytes.toStringBinary(regionInfo.getRegionName())) %> - <%= addr == null? "-": StringEscapeUtils.escapeHtml4(addr.getHostname().toString()) + ":" + master.getRegionServerInfoPort(addr) %> - not deployed<%= locality%> <%= localityForSsd%>
+ <%= moreRegionsToRender(numRegionsRendered, numRegions, fqtn) %>
@@ -1031,7 +1016,6 @@ if (fqtn != null && master.isInitialized()) { RegionInfo regionInfo = hriEntry.getKey(); ServerName addr = regionsToServer.get(regionInfo); RegionMetrics load = hriEntry.getValue(); - String urlRegionServer = null; long compactingCells = 0; long compactedCells = 0; String compactionProgress = ""; @@ -1044,30 +1028,12 @@ if (fqtn != null && master.isInitialized()) { } } - if (addr != null) { - // This port might be wrong if RS actually ended up using something else. - urlRegionServer = - "//" + URLEncoder.encode(addr.getHostname()) + ":" + master.getRegionServerInfoPort(addr) + "/rs-status"; - } - if (numRegionsRendered < numRegionsToRender) { numRegionsRendered++; %> - <% - if (urlRegionServer != null) { - %> - - <% - } else { - %> - - <% - } - %> + <%= buildRegionDeployedServerTag(regionInfo, master, regionsToServer) %> @@ -1077,48 +1043,36 @@ if (fqtn != null && master.isInitialized()) { <% } %>
<%= escapeXml(Bytes.toStringBinary(regionInfo.getRegionName())) %> - <%= addr == null? "-": StringEscapeUtils.escapeHtml4(addr.getHostname().toString()) + ":" + master.getRegionServerInfoPort(addr) %> - not deployed<%= String.format("%,1d", compactingCells)%> <%= String.format("%,1d", compactedCells)%> <%= String.format("%,1d", compactingCells - compactedCells)%>
- <% if (numRegions > numRegionsRendered) { - String allRegionsUrl = "?name=" + URLEncoder.encode(fqtn,"UTF-8") + "&numRegions=all"; - %> -

This table has <%= numRegions %> regions in total, in order to improve the page load time, - only <%= numRegionsRendered %> regions are displayed here, click - here to see all regions.

- <% } %> + <%= moreRegionsToRender(numRegionsRendered, numRegions, fqtn) %>
+

Regions by Region Server

-<% -if (withReplica) { -%> - -<% -} else { -%> -
Region ServerRegion CountPrimary Region Count
- -<% -} -%> -<% - for (Map.Entry rdEntry : regDistribution.entrySet()) { - ServerName addr = rdEntry.getKey(); - String url = "//" + URLEncoder.encode(addr.getHostname()) + ":" + master.getRegionServerInfoPort(addr) + "/rs-status"; -%> - - - -<% -if (withReplica) { -%> - -<% -} -%> - -<% } %> - +
Region ServerRegion Count
<%= StringEscapeUtils.escapeHtml4(addr.getHostname().toString()) + ":" + master.getRegionServerInfoPort(addr) %><%= rdEntry.getValue()%><%= primaryRegDistribution.get(addr)%>
+ + + + + + + + <% + for (Map.Entry rdEntry : regDistribution.entrySet()) { + ServerName addr = rdEntry.getKey(); + String url = "//" + URLEncoder.encode(addr.getHostname()) + ":" + + master.getRegionServerInfoPort(addr) + "/rs-status"; + %> + + + + + + <% } %> +
Region ServerRegion CountPrimary Region Count
<%= StringEscapeUtils.escapeHtml4(addr.getHostname().toString()) + + ":" + master.getRegionServerInfoPort(addr) %><%= rdEntry.getValue()%><%= primaryRegDistribution.get(addr) == null ? 0 : primaryRegDistribution.get(addr)%>
+ <% } } catch(Exception ex) { for(StackTraceElement element : ex.getStackTrace()) { @@ -1218,41 +1172,6 @@ Actions: <% } %>
-<% } - } catch(TableNotFoundException e) { %> -
-
- -
-


-

Go Back -

<% - } catch(IllegalArgumentException e) { %> -
-
- -
-


-

Go Back -

<% - } -} - else { // handle the case for fqtn is null or master is not initialized with error message + redirect -%> -
-
- -
-


- -

-<% } %> @@ -1300,7 +1219,7 @@ $(document).ready(function() 1: {sorter: 'separator'} } }); - $("#regionServerDetailsTable").tablesorter({ + $("#tableBaseStatsTable").tablesorter({ headers: { 2: {sorter: 'separator'}, 3: {sorter: 'separator'}, @@ -1309,7 +1228,7 @@ $(document).ready(function() 6: {sorter: 'filesize'} } }); - $("#tableRegionTable").tablesorter({ + $("#metaTableBaseStatsTable").tablesorter({ headers: { 2: {sorter: 'separator'}, 3: {sorter: 'separator'}, @@ -1318,6 +1237,18 @@ $(document).ready(function() 6: {sorter: 'filesize'} } }); + $("#tableLocalityStatsTable").tablesorter({ + headers: { + 2: {sorter: 'separator'}, + 3: {sorter: 'separator'} + } + }); + $("#metaTableLocalityStatsTable").tablesorter({ + headers: { + 2: {sorter: 'separator'}, + 3: {sorter: 'separator'} + } + }); $("#tableCompactStatsTable").tablesorter({ headers: { 2: {sorter: 'separator'},