Skip to content

Commit

Permalink
NPE may occur when opening master-status or table.jsp or procedure.js…
Browse files Browse the repository at this point in the history
…p while Master is initializing
  • Loading branch information
guluo2016 committed Aug 13, 2024
1 parent 6788ff4 commit 27f8230
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 22 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

0 comments on commit 27f8230

Please sign in to comment.