Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,16 @@ public class HbckChore extends ScheduledChore {
*/
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.
*/
private final Map<String, ServerName> orphanRegionsOnRS = new HashMap<>();
/**
* 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:
* case 1. Master thought this region opened, but no regionserver reported it.
Expand All @@ -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<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 =
new HashMap<>();

Expand Down Expand Up @@ -121,6 +123,7 @@ protected synchronized void chore() {
}
running = true;
regionInfoMap.clear();
disabledTableRegions.clear();
orphanRegionsOnRS.clear();
orphanRegionsOnFS.clear();
inconsistentRegions.clear();
Expand Down Expand Up @@ -167,7 +170,8 @@ private void saveCheckResultToSnapshot() {
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()));
Expand All @@ -182,11 +186,9 @@ private void loadRegionsFromInMemoryState() {
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(),
Expand Down Expand Up @@ -220,6 +222,11 @@ private void loadRegionsFromRSReport() {
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) {
Expand All @@ -244,7 +251,7 @@ private void loadRegionsFromFS() throws IOException {
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);
Expand Down Expand Up @@ -279,7 +286,7 @@ public Map<String, ServerName> getOrphanRegionsOnRS() {
/**
* @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.
rwLock.readLock().lock();
try {
Expand Down
16 changes: 9 additions & 7 deletions hbase-server/src/main/resources/hbase-webapps/master/hbck.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -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" %>
Expand All @@ -42,7 +42,7 @@
HbckChore hbckChore = master.getHbckChore();
Map<String, Pair<ServerName, List<ServerName>>> inconsistentRegions = null;
Map<String, ServerName> orphanRegionsOnRS = null;
Set<String> orphanRegionsOnFS = null;
Map<String, Path> orphanRegionsOnFS = null;
long startTimestamp = 0;
long endTimestamp = 0;
if (hbckChore != null) {
Expand Down Expand Up @@ -110,7 +110,7 @@

<table class="table table-striped">
<tr>
<th>Region</th>
<th>Region Encoded Name</th>
<th>Location in META</th>
<th>Reported Online RegionServers</th>
</tr>
Expand All @@ -136,7 +136,7 @@
<% if (orphanRegionsOnRS != null && orphanRegionsOnRS.size() > 0) { %>
<table class="table table-striped">
<tr>
<th>Region</th>
<th>Region Encoded Name</th>
<th>Reported Online RegionServer</th>
</tr>
<% for (Map.Entry<String, ServerName> entry : orphanRegionsOnRS.entrySet()) { %>
Expand All @@ -159,11 +159,13 @@
<% if (orphanRegionsOnFS != null && orphanRegionsOnFS.size() > 0) { %>
<table class="table table-striped">
<tr>
<th>Region</th>
<th>Region Encoded Name</th>
<th>FileSystem Path</th>
</tr>
<% for (String region : orphanRegionsOnFS) { %>
<% for (Map.Entry<String, Path> entry : orphanRegionsOnFS.entrySet()) { %>
<tr>
<td><%= region %></td>
<td><%= entry.getKey() %></td>
<td><%= entry.getValue() %></td>
</tr>
<% } %>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ public void testOrphanRegionsOnFS() throws Exception {
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();
Expand Down