Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HBASE-28778 NPE may occur when opening master-status or table.jsp or procedure.js… #6152

Merged
merged 2 commits into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why we move this page here? Because we may add some elements in the below code block and it should be placed after header?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the below code block should be placed after header,as shown below.

image

If we don't do this, it will display as follows.

image

<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);
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We input directly into the browser http://localhost:16030/region.json, without specifying a region name (http://localhost:16030/region.json?name=123456789), we would get NPE in here.

Although this situation does not occur frequently, it is best to handle it.

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