From 3caaf2d739106b56ab94a0561e730ff35802610d Mon Sep 17 00:00:00 2001 From: Peng Lu Date: Thu, 5 Sep 2024 20:07:36 +0800 Subject: [PATCH] HBASE-28778 NPE may occur when opening master-status or table.jsp or procedure.jsp while Master is initializing (#6152) Signed-off-by: Duo Zhang --- .../master/http/MasterStatusServlet.java | 5 ++- .../hbase-webapps/master/procedures.jsp | 23 +++++++++-- .../resources/hbase-webapps/master/table.jsp | 39 ++++++++++--------- .../hbase-webapps/regionserver/region.jsp | 12 ++++-- 4 files changed, 54 insertions(+), 25 deletions(-) diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/http/MasterStatusServlet.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/http/MasterStatusServlet.java index e46621d7b521..09bb5375a5d5 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/http/MasterStatusServlet.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/http/MasterStatusServlet.java @@ -77,7 +77,10 @@ public void doGet(HttpServletRequest request, HttpServletResponse response) thro private ServerName getMetaLocationOrNull(HMaster master) { RegionStateNode rsn = master.getAssignmentManager().getRegionStates() .getRegionStateNode(RegionInfoBuilder.FIRST_META_REGIONINFO); - return rsn.isInState(RegionState.State.OPEN) ? rsn.getRegionLocation() : null; + if (rsn != null) { + return rsn.isInState(RegionState.State.OPEN) ? rsn.getRegionLocation() : null; + } + return null; } private Map getFragmentationInfo(HMaster master, Configuration conf) diff --git a/hbase-server/src/main/resources/hbase-webapps/master/procedures.jsp b/hbase-server/src/main/resources/hbase-webapps/master/procedures.jsp index 0ac2ff3908d3..c25c5c3886ba 100644 --- a/hbase-server/src/main/resources/hbase-webapps/master/procedures.jsp +++ b/hbase-server/src/main/resources/hbase-webapps/master/procedures.jsp @@ -47,8 +47,28 @@ <%@ page import="org.apache.hadoop.hbase.metrics.Histogram" %> <%@ page import="java.util.TreeMap" %> <%@ page import="org.apache.hadoop.hbase.metrics.impl.HistogramImpl" %> + + + + + <% HMaster master = (HMaster) getServletContext().getAttribute(HMaster.MASTER); + if (!master.isInitialized()) { +%> +
+
+ +
+


+ +

+<% return; + } %> + +<% ProcedureExecutor procExecutor = master.getMasterProcedureExecutor(); List> procedures = procExecutor.getProcedures(); Collections.sort(procedures, new Comparator() { @@ -63,9 +83,6 @@ List lockedResources = master.getLocks(); pageContext.setAttribute("pageTitle", "HBase Master Procedures: " + master.getServerName()); %> - - -
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 f0599b7aa64a..f0b8ad651171 100644 --- a/hbase-server/src/main/resources/hbase-webapps/master/table.jsp +++ b/hbase-server/src/main/resources/hbase-webapps/master/table.jsp @@ -148,11 +148,32 @@ return ""; } %> + + + + + <% final String ZEROMB = "0 MB"; HMaster master = (HMaster)getServletContext().getAttribute(HMaster.MASTER); Configuration conf = master.getConfiguration(); String fqtn = request.getParameter("name"); + // handle the case for fqtn is null or master is not initialized with error message + redirect + if (fqtn == null || !master.isInitialized()) { +%> +
+
+ +
+


+ +

+<% return; + } %> + +<% final String escaped_fqtn = StringEscapeUtils.escapeHtml4(fqtn); Table table = master.getConnection().getTable(TableName.valueOf(fqtn)); boolean showFragmentation = conf.getBoolean("hbase.master.ui.fragmentation.enabled", false); @@ -201,24 +222,6 @@ final MetaBrowser metaBrowser = new MetaBrowser(connection, request); %> - - - - -<% // handle the case for fqtn is null or master is not initialized with error message + redirect - if (fqtn == null || ! master.isInitialized()) { %> -
-
- -
-


- -

-<% return; - } %> - <% // unknow table if (! admin.tableExists(TableName.valueOf(fqtn)).get()) { %>
diff --git a/hbase-server/src/main/resources/hbase-webapps/regionserver/region.jsp b/hbase-server/src/main/resources/hbase-webapps/regionserver/region.jsp index 9cb432b326a2..c6084f74e904 100644 --- a/hbase-server/src/main/resources/hbase-webapps/regionserver/region.jsp +++ b/hbase-server/src/main/resources/hbase-webapps/regionserver/region.jsp @@ -39,8 +39,10 @@ String regionName = request.getParameter("name"); HRegionServer rs = (HRegionServer) getServletContext().getAttribute(HRegionServer.REGIONSERVER); FileSystem fs = rs.getFileSystem(); - - HRegion region = rs.getRegion(regionName); + HRegion region = null; + if (regionName != null) { + region = rs.getRegion(regionName); + } String displayName; boolean isReplicaRegion = false; if (region != null) { @@ -48,7 +50,11 @@ rs.getConfiguration()); isReplicaRegion = region.getRegionInfo().getReplicaId() > RegionInfo.DEFAULT_REPLICA_ID; } else { - displayName = "region {" + regionName + "} is not currently online on this region server"; + if (regionName != null) { + displayName = "region {" + regionName + "} is not currently online on this region server"; + } else { + displayName = "you must specify a region name when accessing this page"; + } } pageContext.setAttribute("pageTitle", "HBase RegionServer: " + rs.getServerName()); %>