From bf0f90fedd1ec3751ed0cade2ab10afa21649d66 Mon Sep 17 00:00:00 2001 From: Peng Lu Date: Sat, 20 Jul 2024 17:54:15 +0800 Subject: [PATCH 1/2] FNFE may occur when accessing the region.jsp of the replica region --- .../hbase-webapps/regionserver/region.jsp | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) 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 3eeab8eb341c..635823b23134 100644 --- a/hbase-server/src/main/resources/hbase-webapps/regionserver/region.jsp +++ b/hbase-server/src/main/resources/hbase-webapps/regionserver/region.jsp @@ -22,9 +22,11 @@ import="java.util.Collection" import="java.util.Date" import="java.util.List" + import="org.apache.hadoop.fs.FileSystem" import="org.apache.hadoop.fs.FileStatus" import="org.apache.hadoop.fs.Path" import="org.apache.hadoop.hbase.HConstants" + import="org.apache.hadoop.hbase.client.RegionInfo" import="org.apache.hadoop.hbase.client.RegionInfoDisplay" import="org.apache.hadoop.hbase.mob.MobUtils" import="org.apache.hadoop.hbase.regionserver.HRegionServer" @@ -37,12 +39,17 @@ <% String regionName = request.getParameter("name"); HRegionServer rs = (HRegionServer) getServletContext().getAttribute(HRegionServer.REGIONSERVER); + FileSystem fs = rs.getFileSystem(); Region region = rs.getRegion(regionName); String displayName; + String note = ""; if (region != null) { displayName = RegionInfoDisplay.getRegionNameAsStringForDisplay(region.getRegionInfo(), rs.getConfiguration()); + if (region.getRegionInfo().getReplicaId() > RegionInfo.DEFAULT_REPLICA_ID) { + note = "The information about storefile(s) may not up-to-date because it's not the primary region."; + } } else { displayName = "region {" + regionName + "} is not currently online on this region server"; } @@ -79,17 +86,20 @@ Len Of Biggest Cell Key Of Biggest Cell - <% for(StoreFile sf : storeFiles) { %> + <% int count = 0; + for(StoreFile sf : storeFiles) { + if (!fs.exists(sf.getPath())) continue; + count ++; %> <%= sf.getPath() %> - <%= (int) (rs.getFileSystem().getLength(sf.getPath()) / 1024 / 1024) %> + <%= (int) (fs.getLength(sf.getPath()) / 1024 / 1024) %> <%= new Date(sf.getModificationTimestamp()) %> <%= String.format("%,1d", ((HStoreFile)sf).getFileInfo().getHFileInfo().getLenOfBiggestCell()) %> <%= ((HStoreFile)sf).getFileInfo().getHFileInfo().getKeyOfBiggestCell() %> <% } %> -

<%= storeFiles.size() %> StoreFile(s) in set.

+

<%= count %> StoreFile(s) in set. <%= note %>

<% if (store instanceof HMobStore) { %> From 084cc4b1b12f1c5cb404f974cb1301d3339a5348 Mon Sep 17 00:00:00 2001 From: Peng Lu Date: Fri, 26 Jul 2024 14:22:51 +0800 Subject: [PATCH 2/2] Add primary region check and fix the type conversion issue --- .../hbase-webapps/regionserver/region.jsp | 40 +++++++++---------- 1 file changed, 19 insertions(+), 21 deletions(-) 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 635823b23134..9cb432b326a2 100644 --- a/hbase-server/src/main/resources/hbase-webapps/regionserver/region.jsp +++ b/hbase-server/src/main/resources/hbase-webapps/regionserver/region.jsp @@ -32,24 +32,21 @@ import="org.apache.hadoop.hbase.regionserver.HRegionServer" import="org.apache.hadoop.hbase.regionserver.HMobStore" import="org.apache.hadoop.hbase.regionserver.HStoreFile" - import="org.apache.hadoop.hbase.regionserver.Region" - import="org.apache.hadoop.hbase.regionserver.Store" - import="org.apache.hadoop.hbase.regionserver.StoreFile" + import="org.apache.hadoop.hbase.regionserver.HRegion" + import="org.apache.hadoop.hbase.regionserver.HStore" %> <% String regionName = request.getParameter("name"); HRegionServer rs = (HRegionServer) getServletContext().getAttribute(HRegionServer.REGIONSERVER); FileSystem fs = rs.getFileSystem(); - Region region = rs.getRegion(regionName); + HRegion region = rs.getRegion(regionName); String displayName; - String note = ""; + boolean isReplicaRegion = false; if (region != null) { displayName = RegionInfoDisplay.getRegionNameAsStringForDisplay(region.getRegionInfo(), rs.getConfiguration()); - if (region.getRegionInfo().getReplicaId() > RegionInfo.DEFAULT_REPLICA_ID) { - note = "The information about storefile(s) may not up-to-date because it's not the primary region."; - } + isReplicaRegion = region.getRegionInfo().getReplicaId() > RegionInfo.DEFAULT_REPLICA_ID; } else { displayName = "region {" + regionName + "} is not currently online on this region server"; } @@ -66,11 +63,11 @@ -<% if(region != null) { // - List stores = region.getStores(); - for (Store store : stores) { +<% if(region != null) { + List stores = region.getStores(); + for (HStore store : stores) { String cf = store.getColumnFamilyName(); - Collection storeFiles = store.getStorefiles(); %> + Collection storeFiles = store.getStorefiles(); %>

Column Family: <%= cf %>

@@ -87,19 +84,19 @@ Key Of Biggest Cell <% int count = 0; - for(StoreFile sf : storeFiles) { - if (!fs.exists(sf.getPath())) continue; + for(HStoreFile sf : storeFiles) { + if (isReplicaRegion && !fs.exists(sf.getPath())) continue; count ++; %> <%= sf.getPath() %> <%= (int) (fs.getLength(sf.getPath()) / 1024 / 1024) %> <%= new Date(sf.getModificationTimestamp()) %> - <%= String.format("%,1d", ((HStoreFile)sf).getFileInfo().getHFileInfo().getLenOfBiggestCell()) %> - <%= ((HStoreFile)sf).getFileInfo().getHFileInfo().getKeyOfBiggestCell() %> + <%= String.format("%,1d", sf.getFileInfo().getHFileInfo().getLenOfBiggestCell()) %> + <%= sf.getFileInfo().getHFileInfo().getKeyOfBiggestCell() %> <% } %> -

<%= count %> StoreFile(s) in set. <%= note %>

+

<%= count %> StoreFile(s) in set. <%= isReplicaRegion ? "The information about storefile(s) may not up-to-date because it's not the primary region." : "" %>

<% if (store instanceof HMobStore) { %> @@ -113,17 +110,18 @@ <% int mobCnt = 0; - for (StoreFile sf : storeFiles) { + for (HStoreFile sf : storeFiles) { try { - byte[] value = ((HStoreFile)sf).getMetadataValue(HStoreFile.MOB_FILE_REFS); + byte[] value = sf.getMetadataValue(HStoreFile.MOB_FILE_REFS); if (value == null) { continue; } Collection fileNames = MobUtils.deserializeMobFileRefs(value).build().values(); - mobCnt += fileNames.size(); for (String fileName : fileNames) { Path mobPath = new Path(((HMobStore) store).getPath(), fileName); + if (isReplicaRegion && !fs.exists(mobPath)) continue; + mobCnt ++; FileStatus status = rs.getFileSystem().getFileStatus(mobPath); String mobPathStr = mobPath.toString(); String encodedStr = URLEncoder.encode(mobPathStr, HConstants.UTF8_ENCODING); %> @@ -142,7 +140,7 @@ <% } } %> -

<%= mobCnt %> MobFile(s) in set.

+

<%= mobCnt %> MobFile(s) in set. <%= isReplicaRegion ? "The information about MobFile(s) may not up-to-date because it's not the primary region." : "" %>

<% } }