HBASE-22824 Show filesystem path for the orphans regions on filesystem (#469)

Signed-off-by: Duo Zhang <zhangduo@apache.org>
This commit is contained in:
Guanghao Zhang 2019-08-09 02:07:14 -05:00 committed by GitHub
parent c05ee7c9fe
commit 989e09a2d5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 25 additions and 16 deletions

View File

@ -61,6 +61,8 @@ public class HbckChore extends ScheduledChore {
*/ */
private final Map<String, HbckRegionInfo> regionInfoMap = new HashMap<>(); private final Map<String, HbckRegionInfo> regionInfoMap = new HashMap<>();
private final Set<String> disabledTableRegions = new HashSet<>();
/** /**
* The regions only opened on RegionServers, but no region info in meta. * 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. * The regions have directory on FileSystem, but no region info in meta.
*/ */
private final Set<String> orphanRegionsOnFS = new HashSet<>(); private final Map<String, Path> orphanRegionsOnFS = new HashMap<>();
/** /**
* The inconsistent regions. There are three case: * The inconsistent regions. There are three case:
* case 1. Master thought this region opened, but no regionserver reported it. * 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. * The "snapshot" is used to save the last round's HBCK checking report.
*/ */
private final Map<String, ServerName> orphanRegionsOnRSSnapshot = new HashMap<>(); private final Map<String, ServerName> orphanRegionsOnRSSnapshot = new HashMap<>();
private final Set<String> orphanRegionsOnFSSnapshot = new HashSet<>(); private final Map<String, Path> orphanRegionsOnFSSnapshot = new HashMap<>();
private final Map<String, Pair<ServerName, List<ServerName>>> inconsistentRegionsSnapshot = private final Map<String, Pair<ServerName, List<ServerName>>> inconsistentRegionsSnapshot =
new HashMap<>(); new HashMap<>();
@ -121,6 +123,7 @@ public class HbckChore extends ScheduledChore {
} }
running = true; running = true;
regionInfoMap.clear(); regionInfoMap.clear();
disabledTableRegions.clear();
orphanRegionsOnRS.clear(); orphanRegionsOnRS.clear();
orphanRegionsOnFS.clear(); orphanRegionsOnFS.clear();
inconsistentRegions.clear(); inconsistentRegions.clear();
@ -167,7 +170,8 @@ public class HbckChore extends ScheduledChore {
orphanRegionsOnRS.entrySet() orphanRegionsOnRS.entrySet()
.forEach(e -> orphanRegionsOnRSSnapshot.put(e.getKey(), e.getValue())); .forEach(e -> orphanRegionsOnRSSnapshot.put(e.getKey(), e.getValue()));
orphanRegionsOnFSSnapshot.clear(); orphanRegionsOnFSSnapshot.clear();
orphanRegionsOnFSSnapshot.addAll(orphanRegionsOnFS); orphanRegionsOnFS.entrySet()
.forEach(e -> orphanRegionsOnFSSnapshot.put(e.getKey(), e.getValue()));
inconsistentRegionsSnapshot.clear(); inconsistentRegionsSnapshot.clear();
inconsistentRegions.entrySet() inconsistentRegions.entrySet()
.forEach(e -> inconsistentRegionsSnapshot.put(e.getKey(), e.getValue())); .forEach(e -> inconsistentRegionsSnapshot.put(e.getKey(), e.getValue()));
@ -182,11 +186,9 @@ public class HbckChore extends ScheduledChore {
master.getAssignmentManager().getRegionStates().getRegionStates(); master.getAssignmentManager().getRegionStates().getRegionStates();
for (RegionState regionState : regionStates) { for (RegionState regionState : regionStates) {
RegionInfo regionInfo = regionState.getRegion(); 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() if (master.getTableStateManager()
.isTableState(regionInfo.getTable(), TableState.State.DISABLED)) { .isTableState(regionInfo.getTable(), TableState.State.DISABLED)) {
continue; disabledTableRegions.add(regionInfo.getEncodedName());
} }
HbckRegionInfo.MetaEntry metaEntry = HbckRegionInfo.MetaEntry metaEntry =
new HbckRegionInfo.MetaEntry(regionInfo, regionState.getServerName(), new HbckRegionInfo.MetaEntry(regionInfo, regionState.getServerName(),
@ -220,6 +222,11 @@ public class HbckChore extends ScheduledChore {
HbckRegionInfo hri = entry.getValue(); HbckRegionInfo hri = entry.getValue();
ServerName locationInMeta = hri.getMetaEntry().getRegionServer(); ServerName locationInMeta = hri.getMetaEntry().getRegionServer();
if (hri.getDeployedOn().size() == 0) { 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. // Master thought this region opened, but no regionserver reported it.
inconsistentRegions.put(encodedRegionName, new Pair<>(locationInMeta, new LinkedList<>())); inconsistentRegions.put(encodedRegionName, new Pair<>(locationInMeta, new LinkedList<>()));
} else if (hri.getDeployedOn().size() > 1) { } else if (hri.getDeployedOn().size() > 1) {
@ -244,7 +251,7 @@ public class HbckChore extends ScheduledChore {
String encodedRegionName = regionDir.getName(); String encodedRegionName = regionDir.getName();
HbckRegionInfo hri = regionInfoMap.get(encodedRegionName); HbckRegionInfo hri = regionInfoMap.get(encodedRegionName);
if (hri == null) { if (hri == null) {
orphanRegionsOnFS.add(encodedRegionName); orphanRegionsOnFS.put(encodedRegionName, regionDir);
continue; continue;
} }
HbckRegionInfo.HdfsEntry hdfsEntry = new HbckRegionInfo.HdfsEntry(regionDir); 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. * @return the regions have directory on FileSystem, but no region info in meta.
*/ */
public Set<String> getOrphanRegionsOnFS() { public Map<String, Path> getOrphanRegionsOnFS() {
// Need synchronized here, as this "snapshot" may be changed after checking. // Need synchronized here, as this "snapshot" may be changed after checking.
rwLock.readLock().lock(); rwLock.readLock().lock();
try { try {

View File

@ -23,11 +23,11 @@
import="java.util.Date" import="java.util.Date"
import="java.util.List" import="java.util.List"
import="java.util.Map" import="java.util.Map"
import="java.util.Set"
import="java.util.stream.Collectors" import="java.util.stream.Collectors"
import="java.time.ZonedDateTime" import="java.time.ZonedDateTime"
import="java.time.format.DateTimeFormatter" 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.client.RegionInfo" %>
<%@ page import="org.apache.hadoop.hbase.master.HbckChore" %> <%@ page import="org.apache.hadoop.hbase.master.HbckChore" %>
<%@ page import="org.apache.hadoop.hbase.master.HMaster" %> <%@ page import="org.apache.hadoop.hbase.master.HMaster" %>
@ -42,7 +42,7 @@
HbckChore hbckChore = master.getHbckChore(); HbckChore hbckChore = master.getHbckChore();
Map<String, Pair<ServerName, List<ServerName>>> inconsistentRegions = null; Map<String, Pair<ServerName, List<ServerName>>> inconsistentRegions = null;
Map<String, ServerName> orphanRegionsOnRS = null; Map<String, ServerName> orphanRegionsOnRS = null;
Set<String> orphanRegionsOnFS = null; Map<String, Path> orphanRegionsOnFS = null;
long startTimestamp = 0; long startTimestamp = 0;
long endTimestamp = 0; long endTimestamp = 0;
if (hbckChore != null) { if (hbckChore != null) {
@ -110,7 +110,7 @@
<table class="table table-striped"> <table class="table table-striped">
<tr> <tr>
<th>Region</th> <th>Region Encoded Name</th>
<th>Location in META</th> <th>Location in META</th>
<th>Reported Online RegionServers</th> <th>Reported Online RegionServers</th>
</tr> </tr>
@ -136,7 +136,7 @@
<% if (orphanRegionsOnRS != null && orphanRegionsOnRS.size() > 0) { %> <% if (orphanRegionsOnRS != null && orphanRegionsOnRS.size() > 0) { %>
<table class="table table-striped"> <table class="table table-striped">
<tr> <tr>
<th>Region</th> <th>Region Encoded Name</th>
<th>Reported Online RegionServer</th> <th>Reported Online RegionServer</th>
</tr> </tr>
<% for (Map.Entry<String, ServerName> entry : orphanRegionsOnRS.entrySet()) { %> <% for (Map.Entry<String, ServerName> entry : orphanRegionsOnRS.entrySet()) { %>
@ -159,11 +159,13 @@
<% if (orphanRegionsOnFS != null && orphanRegionsOnFS.size() > 0) { %> <% if (orphanRegionsOnFS != null && orphanRegionsOnFS.size() > 0) { %>
<table class="table table-striped"> <table class="table table-striped">
<tr> <tr>
<th>Region</th> <th>Region Encoded Name</th>
<th>FileSystem Path</th>
</tr> </tr>
<% for (String region : orphanRegionsOnFS) { %> <% for (Map.Entry<String, Path> entry : orphanRegionsOnFS.entrySet()) { %>
<tr> <tr>
<td><%= region %></td> <td><%= entry.getKey() %></td>
<td><%= entry.getValue() %></td>
</tr> </tr>
<% } %> <% } %>

View File

@ -192,7 +192,7 @@ public class TestHbckChore extends TestAssignmentManagerBase {
HRegion.createRegionDir(conf, regionInfo, FSUtils.getRootDir(conf)); HRegion.createRegionDir(conf, regionInfo, FSUtils.getRootDir(conf));
hbckChore.choreForTesting(); hbckChore.choreForTesting();
assertEquals(1, hbckChore.getOrphanRegionsOnFS().size()); assertEquals(1, hbckChore.getOrphanRegionsOnFS().size());
assertTrue(hbckChore.getOrphanRegionsOnFS().contains(regionInfo.getEncodedName())); assertTrue(hbckChore.getOrphanRegionsOnFS().containsKey(regionInfo.getEncodedName()));
FSUtils.deleteRegionDir(conf, new HRegionInfo(regionInfo)); FSUtils.deleteRegionDir(conf, new HRegionInfo(regionInfo));
hbckChore.choreForTesting(); hbckChore.choreForTesting();