From aaa9d937150eb1bac284513b6347e48f9853d10d Mon Sep 17 00:00:00 2001 From: Guanghao Zhang Date: Fri, 9 Aug 2019 02:07:14 -0500 Subject: [PATCH] HBASE-22824 Show filesystem path for the orphans regions on filesystem (#469) Signed-off-by: Duo Zhang --- .../apache/hadoop/hbase/master/HbckChore.java | 23 ++++++++++++------- .../resources/hbase-webapps/master/hbck.jsp | 16 +++++++------ .../master/assignment/TestHbckChore.java | 2 +- 3 files changed, 25 insertions(+), 16 deletions(-) diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/HbckChore.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/HbckChore.java index 64da15d1e88..5bb4e9524fc 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/HbckChore.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/HbckChore.java @@ -61,6 +61,8 @@ public class HbckChore extends ScheduledChore { */ private final Map regionInfoMap = new HashMap<>(); + private final Set disabledTableRegions = new HashSet<>(); + /** * The regions only opened on RegionServers, but no region info in meta. */ @@ -68,7 +70,7 @@ public class HbckChore extends ScheduledChore { /** * The regions have directory on FileSystem, but no region info in meta. */ - private final Set orphanRegionsOnFS = new HashSet<>(); + private final Map orphanRegionsOnFS = new HashMap<>(); /** * The inconsistent regions. There are three case: * case 1. Master thought this region opened, but no regionserver reported it. @@ -82,7 +84,7 @@ public class HbckChore extends ScheduledChore { * The "snapshot" is used to save the last round's HBCK checking report. */ private final Map orphanRegionsOnRSSnapshot = new HashMap<>(); - private final Set orphanRegionsOnFSSnapshot = new HashSet<>(); + private final Map orphanRegionsOnFSSnapshot = new HashMap<>(); private final Map>> inconsistentRegionsSnapshot = new HashMap<>(); @@ -121,6 +123,7 @@ public class HbckChore extends ScheduledChore { } running = true; regionInfoMap.clear(); + disabledTableRegions.clear(); orphanRegionsOnRS.clear(); orphanRegionsOnFS.clear(); inconsistentRegions.clear(); @@ -167,7 +170,8 @@ public class HbckChore extends ScheduledChore { orphanRegionsOnRS.entrySet() .forEach(e -> orphanRegionsOnRSSnapshot.put(e.getKey(), e.getValue())); orphanRegionsOnFSSnapshot.clear(); - orphanRegionsOnFSSnapshot.addAll(orphanRegionsOnFS); + orphanRegionsOnFS.entrySet() + .forEach(e -> orphanRegionsOnFSSnapshot.put(e.getKey(), e.getValue())); inconsistentRegionsSnapshot.clear(); inconsistentRegions.entrySet() .forEach(e -> inconsistentRegionsSnapshot.put(e.getKey(), e.getValue())); @@ -182,11 +186,9 @@ public class HbckChore extends ScheduledChore { master.getAssignmentManager().getRegionStates().getRegionStates(); for (RegionState regionState : regionStates) { RegionInfo regionInfo = regionState.getRegion(); - // Because the inconsistent regions are not absolutely right, only skip the offline regions - // which belong to disabled table. if (master.getTableStateManager() .isTableState(regionInfo.getTable(), TableState.State.DISABLED)) { - continue; + disabledTableRegions.add(regionInfo.getEncodedName()); } HbckRegionInfo.MetaEntry metaEntry = new HbckRegionInfo.MetaEntry(regionInfo, regionState.getServerName(), @@ -220,6 +222,11 @@ public class HbckChore extends ScheduledChore { HbckRegionInfo hri = entry.getValue(); ServerName locationInMeta = hri.getMetaEntry().getRegionServer(); if (hri.getDeployedOn().size() == 0) { + // Because the inconsistent regions are not absolutely right, only skip the offline regions + // which belong to disabled table. + if (disabledTableRegions.contains(encodedRegionName)) { + continue; + } // Master thought this region opened, but no regionserver reported it. inconsistentRegions.put(encodedRegionName, new Pair<>(locationInMeta, new LinkedList<>())); } else if (hri.getDeployedOn().size() > 1) { @@ -244,7 +251,7 @@ public class HbckChore extends ScheduledChore { String encodedRegionName = regionDir.getName(); HbckRegionInfo hri = regionInfoMap.get(encodedRegionName); if (hri == null) { - orphanRegionsOnFS.add(encodedRegionName); + orphanRegionsOnFS.put(encodedRegionName, regionDir); continue; } HbckRegionInfo.HdfsEntry hdfsEntry = new HbckRegionInfo.HdfsEntry(regionDir); @@ -279,7 +286,7 @@ public class HbckChore extends ScheduledChore { /** * @return the regions have directory on FileSystem, but no region info in meta. */ - public Set getOrphanRegionsOnFS() { + public Map getOrphanRegionsOnFS() { // Need synchronized here, as this "snapshot" may be changed after checking. rwLock.readLock().lock(); try { diff --git a/hbase-server/src/main/resources/hbase-webapps/master/hbck.jsp b/hbase-server/src/main/resources/hbase-webapps/master/hbck.jsp index 1da84ac815b..a003e5fe096 100644 --- a/hbase-server/src/main/resources/hbase-webapps/master/hbck.jsp +++ b/hbase-server/src/main/resources/hbase-webapps/master/hbck.jsp @@ -23,11 +23,11 @@ import="java.util.Date" import="java.util.List" import="java.util.Map" - import="java.util.Set" import="java.util.stream.Collectors" import="java.time.ZonedDateTime" import="java.time.format.DateTimeFormatter" %> +<%@ page import="org.apache.hadoop.fs.Path" %> <%@ page import="org.apache.hadoop.hbase.client.RegionInfo" %> <%@ page import="org.apache.hadoop.hbase.master.HbckChore" %> <%@ page import="org.apache.hadoop.hbase.master.HMaster" %> @@ -42,7 +42,7 @@ HbckChore hbckChore = master.getHbckChore(); Map>> inconsistentRegions = null; Map orphanRegionsOnRS = null; - Set orphanRegionsOnFS = null; + Map orphanRegionsOnFS = null; long startTimestamp = 0; long endTimestamp = 0; if (hbckChore != null) { @@ -110,7 +110,7 @@ - + @@ -136,7 +136,7 @@ <% if (orphanRegionsOnRS != null && orphanRegionsOnRS.size() > 0) { %>
RegionRegion Encoded Name Location in META Reported Online RegionServers
- + <% for (Map.Entry entry : orphanRegionsOnRS.entrySet()) { %> @@ -159,11 +159,13 @@ <% if (orphanRegionsOnFS != null && orphanRegionsOnFS.size() > 0) { %>
RegionRegion Encoded Name Reported Online RegionServer
- + + - <% for (String region : orphanRegionsOnFS) { %> + <% for (Map.Entry entry : orphanRegionsOnFS.entrySet()) { %> - + + <% } %> diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/assignment/TestHbckChore.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/assignment/TestHbckChore.java index 845c43a2759..616e19ea73b 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/assignment/TestHbckChore.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/assignment/TestHbckChore.java @@ -192,7 +192,7 @@ public class TestHbckChore extends TestAssignmentManagerBase { HRegion.createRegionDir(conf, regionInfo, FSUtils.getRootDir(conf)); hbckChore.choreForTesting(); assertEquals(1, hbckChore.getOrphanRegionsOnFS().size()); - assertTrue(hbckChore.getOrphanRegionsOnFS().contains(regionInfo.getEncodedName())); + assertTrue(hbckChore.getOrphanRegionsOnFS().containsKey(regionInfo.getEncodedName())); FSUtils.deleteRegionDir(conf, new HRegionInfo(regionInfo)); hbckChore.choreForTesting();
RegionRegion Encoded NameFileSystem Path
<%= region %><%= entry.getKey() %><%= entry.getValue() %>