Skip to content

Commit

Permalink
HBASE-24273 HBCK's "Orphan Regions on FileSystem" reports regions wit…
Browse files Browse the repository at this point in the history
…h referenced HFiles (apache#1613)

Signed-off-by: stack <stack@apache.org>
  • Loading branch information
huaxiangsun authored and Huaxiang Sun committed May 7, 2020
1 parent 9f46fcf commit 430fecf
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hbase.MetaTableAccessor;
import org.apache.hadoop.hbase.ScheduledChore;
import org.apache.hadoop.hbase.ServerName;
import org.apache.hadoop.hbase.client.RegionInfo;
Expand Down Expand Up @@ -134,7 +135,7 @@ protected synchronized void chore() {
loadRegionsFromInMemoryState();
loadRegionsFromRSReport();
try {
loadRegionsFromFS();
loadRegionsFromFS(scanForMergedParentRegions());
} catch (IOException e) {
LOG.warn("Failed to load the regions from filesystem", e);
}
Expand Down Expand Up @@ -187,6 +188,31 @@ private void saveCheckResultToSnapshot() {
}
}

/**
* Scan hbase:meta to get set of merged parent regions, this is a very heavy scan.
*
* @return Return generated {@link HashSet}
*/
private HashSet<String> scanForMergedParentRegions() throws IOException {
HashSet<String> mergedParentRegions = new HashSet<>();
// Null tablename means scan all of meta.
MetaTableAccessor.scanMetaForTableRegions(this.master.getConnection(),
r -> {
List<RegionInfo> mergeParents = MetaTableAccessor.getMergeRegions(r.rawCells());
if (mergeParents != null) {
for (RegionInfo mergeRegion : mergeParents) {
if (mergeRegion != null) {
// This region is already being merged
mergedParentRegions.add(mergeRegion.getEncodedName());
}
}
}
return true;
},
null);
return mergedParentRegions;
}

private void loadRegionsFromInMemoryState() {
List<RegionState> regionStates =
master.getAssignmentManager().getRegionStates().getRegionStates();
Expand Down Expand Up @@ -256,7 +282,7 @@ private void loadRegionsFromRSReport() {
}
}

private void loadRegionsFromFS() throws IOException {
private void loadRegionsFromFS(final HashSet<String> mergedParentRegions) throws IOException {
Path rootDir = master.getMasterFileSystem().getRootDir();
FileSystem fs = master.getMasterFileSystem().getFileSystem();

Expand All @@ -271,12 +297,12 @@ private void loadRegionsFromFS() throws IOException {
continue;
}
HbckRegionInfo hri = regionInfoMap.get(encodedRegionName);
if (hri == null) {
// If it is not in in-memory database and not a merged region,
// report it as an orphan region.
if (hri == null && !mergedParentRegions.contains(encodedRegionName)) {
orphanRegionsOnFS.put(encodedRegionName, regionDir);
continue;
}
HbckRegionInfo.HdfsEntry hdfsEntry = new HbckRegionInfo.HdfsEntry(regionDir);
hri.setHdfsEntry(hdfsEntry);
}
numRegions += regionDirs.size();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.RegionInfo;
import org.apache.hadoop.hbase.client.RegionInfoBuilder;
import org.apache.hadoop.hbase.client.Table;
import org.apache.hadoop.hbase.testclassification.LargeTests;
import org.apache.hadoop.hbase.testclassification.MasterTests;
import org.apache.hadoop.hbase.util.Threads;
Expand Down Expand Up @@ -146,10 +147,12 @@ private static void makeOverlap(MasterServices services, RegionInfo a, RegionInf
@Test
public void testOverlap() throws Exception {
TableName tn = TableName.valueOf(this.name.getMethodName());
TEST_UTIL.createMultiRegionTable(tn, HConstants.CATALOG_FAMILY);
Table t = TEST_UTIL.createMultiRegionTable(tn, HConstants.CATALOG_FAMILY);
TEST_UTIL.loadTable(t, HConstants.CATALOG_FAMILY);
List<RegionInfo> ris = MetaTableAccessor.getTableRegions(TEST_UTIL.getConnection(), tn);
assertTrue(ris.size() > 5);
MasterServices services = TEST_UTIL.getHBaseCluster().getMaster();
HMaster services = TEST_UTIL.getHBaseCluster().getMaster();
HbckChore hbckChore = services.getHbckChore();
services.getCatalogJanitor().scan();
CatalogJanitor.Report report = services.getCatalogJanitor().getLastReport();
assertTrue(report.isEmpty());
Expand All @@ -173,6 +176,9 @@ public void testOverlap() throws Exception {
throw new RuntimeException(e);
}
});

hbckChore.chore();
assertEquals(0, hbckChore.getOrphanRegionsOnFS().size());
}

/**
Expand Down

0 comments on commit 430fecf

Please sign in to comment.