Skip to content

Commit

Permalink
HBASE-28778 NPE may occur when opening master-status or table.jsp or …
Browse files Browse the repository at this point in the history
…procedure.jsp while Master is initializing (#6152)

Signed-off-by: Duo Zhang <zhangduo@apache.org>
(cherry picked from commit 3caaf2d)
  • Loading branch information
guluo2016 authored and Apache9 committed Sep 5, 2024
1 parent a1fc641 commit 52eae69
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, Integer> getFragmentationInfo(HMaster master, Configuration conf)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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" %>

<jsp:include page="header.jsp">
<jsp:param name="pageTitle" value="${pageTitle}"/>
</jsp:include>

<%
HMaster master = (HMaster) getServletContext().getAttribute(HMaster.MASTER);
if (!master.isInitialized()) {
%>
<div class="container-fluid content">
<div class="row inner_header">
<div class="page-header">
<h1>Master is initializing</h1>
</div>
</div>
<p><hr><p>
<jsp:include page="redirect.jsp" />
</div>
<% return;
} %>

<%
ProcedureExecutor<MasterProcedureEnv> procExecutor = master.getMasterProcedureExecutor();
List<Procedure<MasterProcedureEnv>> procedures = procExecutor.getProcedures();
Collections.sort(procedures, new Comparator<Procedure>() {
Expand All @@ -63,9 +83,6 @@
List<LockedResource> lockedResources = master.getLocks();
pageContext.setAttribute("pageTitle", "HBase Master Procedures: " + master.getServerName());
%>
<jsp:include page="header.jsp">
<jsp:param name="pageTitle" value="${pageTitle}"/>
</jsp:include>

<div class="container-fluid content">
<div class="row top_header">
Expand Down
39 changes: 21 additions & 18 deletions hbase-server/src/main/resources/hbase-webapps/master/table.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,32 @@
return "";
}
%>

<jsp:include page="header.jsp">
<jsp:param name="pageTitle" value="${pageTitle}"/>
</jsp:include>

<%
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()) {
%>
<div class="container-fluid content">
<div class="row inner_header">
<div class="page-header">
<h1>Table not ready</h1>
</div>
</div>
<p><hr><p>
<jsp:include page="redirect.jsp" />
</div>
<% 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);
Expand Down Expand Up @@ -201,24 +222,6 @@
final MetaBrowser metaBrowser = new MetaBrowser(connection, request);
%>

<jsp:include page="header.jsp">
<jsp:param name="pageTitle" value="${pageTitle}"/>
</jsp:include>

<% // handle the case for fqtn is null or master is not initialized with error message + redirect
if (fqtn == null || ! master.isInitialized()) { %>
<div class="container-fluid content">
<div class="row inner_header">
<div class="page-header">
<h1>Table not ready</h1>
</div>
</div>
<p><hr><p>
<jsp:include page="redirect.jsp" />
</div>
<% return;
} %>

<% // unknow table
if (! admin.tableExists(TableName.valueOf(fqtn)).get()) { %>
<div class="container-fluid content">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,22 @@
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) {
displayName = RegionInfoDisplay.getRegionNameAsStringForDisplay(region.getRegionInfo(),
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());
%>
Expand Down

0 comments on commit 52eae69

Please sign in to comment.