Skip to content

Commit aaa9d93

Browse files
committed
HBASE-22824 Show filesystem path for the orphans regions on filesystem (#469)
Signed-off-by: Duo Zhang <[email protected]>
1 parent 2a707ad commit aaa9d93

File tree

3 files changed

+25
-16
lines changed

3 files changed

+25
-16
lines changed

hbase-server/src/main/java/org/apache/hadoop/hbase/master/HbckChore.java

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,16 @@ public class HbckChore extends ScheduledChore {
6161
*/
6262
private final Map<String, HbckRegionInfo> regionInfoMap = new HashMap<>();
6363

64+
private final Set<String> disabledTableRegions = new HashSet<>();
65+
6466
/**
6567
* The regions only opened on RegionServers, but no region info in meta.
6668
*/
6769
private final Map<String, ServerName> orphanRegionsOnRS = new HashMap<>();
6870
/**
6971
* The regions have directory on FileSystem, but no region info in meta.
7072
*/
71-
private final Set<String> orphanRegionsOnFS = new HashSet<>();
73+
private final Map<String, Path> orphanRegionsOnFS = new HashMap<>();
7274
/**
7375
* The inconsistent regions. There are three case:
7476
* case 1. Master thought this region opened, but no regionserver reported it.
@@ -82,7 +84,7 @@ public class HbckChore extends ScheduledChore {
8284
* The "snapshot" is used to save the last round's HBCK checking report.
8385
*/
8486
private final Map<String, ServerName> orphanRegionsOnRSSnapshot = new HashMap<>();
85-
private final Set<String> orphanRegionsOnFSSnapshot = new HashSet<>();
87+
private final Map<String, Path> orphanRegionsOnFSSnapshot = new HashMap<>();
8688
private final Map<String, Pair<ServerName, List<ServerName>>> inconsistentRegionsSnapshot =
8789
new HashMap<>();
8890

@@ -121,6 +123,7 @@ protected synchronized void chore() {
121123
}
122124
running = true;
123125
regionInfoMap.clear();
126+
disabledTableRegions.clear();
124127
orphanRegionsOnRS.clear();
125128
orphanRegionsOnFS.clear();
126129
inconsistentRegions.clear();
@@ -167,7 +170,8 @@ private void saveCheckResultToSnapshot() {
167170
orphanRegionsOnRS.entrySet()
168171
.forEach(e -> orphanRegionsOnRSSnapshot.put(e.getKey(), e.getValue()));
169172
orphanRegionsOnFSSnapshot.clear();
170-
orphanRegionsOnFSSnapshot.addAll(orphanRegionsOnFS);
173+
orphanRegionsOnFS.entrySet()
174+
.forEach(e -> orphanRegionsOnFSSnapshot.put(e.getKey(), e.getValue()));
171175
inconsistentRegionsSnapshot.clear();
172176
inconsistentRegions.entrySet()
173177
.forEach(e -> inconsistentRegionsSnapshot.put(e.getKey(), e.getValue()));
@@ -182,11 +186,9 @@ private void loadRegionsFromInMemoryState() {
182186
master.getAssignmentManager().getRegionStates().getRegionStates();
183187
for (RegionState regionState : regionStates) {
184188
RegionInfo regionInfo = regionState.getRegion();
185-
// Because the inconsistent regions are not absolutely right, only skip the offline regions
186-
// which belong to disabled table.
187189
if (master.getTableStateManager()
188190
.isTableState(regionInfo.getTable(), TableState.State.DISABLED)) {
189-
continue;
191+
disabledTableRegions.add(regionInfo.getEncodedName());
190192
}
191193
HbckRegionInfo.MetaEntry metaEntry =
192194
new HbckRegionInfo.MetaEntry(regionInfo, regionState.getServerName(),
@@ -220,6 +222,11 @@ private void loadRegionsFromRSReport() {
220222
HbckRegionInfo hri = entry.getValue();
221223
ServerName locationInMeta = hri.getMetaEntry().getRegionServer();
222224
if (hri.getDeployedOn().size() == 0) {
225+
// Because the inconsistent regions are not absolutely right, only skip the offline regions
226+
// which belong to disabled table.
227+
if (disabledTableRegions.contains(encodedRegionName)) {
228+
continue;
229+
}
223230
// Master thought this region opened, but no regionserver reported it.
224231
inconsistentRegions.put(encodedRegionName, new Pair<>(locationInMeta, new LinkedList<>()));
225232
} else if (hri.getDeployedOn().size() > 1) {
@@ -244,7 +251,7 @@ private void loadRegionsFromFS() throws IOException {
244251
String encodedRegionName = regionDir.getName();
245252
HbckRegionInfo hri = regionInfoMap.get(encodedRegionName);
246253
if (hri == null) {
247-
orphanRegionsOnFS.add(encodedRegionName);
254+
orphanRegionsOnFS.put(encodedRegionName, regionDir);
248255
continue;
249256
}
250257
HbckRegionInfo.HdfsEntry hdfsEntry = new HbckRegionInfo.HdfsEntry(regionDir);
@@ -279,7 +286,7 @@ public Map<String, ServerName> getOrphanRegionsOnRS() {
279286
/**
280287
* @return the regions have directory on FileSystem, but no region info in meta.
281288
*/
282-
public Set<String> getOrphanRegionsOnFS() {
289+
public Map<String, Path> getOrphanRegionsOnFS() {
283290
// Need synchronized here, as this "snapshot" may be changed after checking.
284291
rwLock.readLock().lock();
285292
try {

hbase-server/src/main/resources/hbase-webapps/master/hbck.jsp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@
2323
import="java.util.Date"
2424
import="java.util.List"
2525
import="java.util.Map"
26-
import="java.util.Set"
2726
import="java.util.stream.Collectors"
2827
import="java.time.ZonedDateTime"
2928
import="java.time.format.DateTimeFormatter"
3029
%>
30+
<%@ page import="org.apache.hadoop.fs.Path" %>
3131
<%@ page import="org.apache.hadoop.hbase.client.RegionInfo" %>
3232
<%@ page import="org.apache.hadoop.hbase.master.HbckChore" %>
3333
<%@ page import="org.apache.hadoop.hbase.master.HMaster" %>
@@ -42,7 +42,7 @@
4242
HbckChore hbckChore = master.getHbckChore();
4343
Map<String, Pair<ServerName, List<ServerName>>> inconsistentRegions = null;
4444
Map<String, ServerName> orphanRegionsOnRS = null;
45-
Set<String> orphanRegionsOnFS = null;
45+
Map<String, Path> orphanRegionsOnFS = null;
4646
long startTimestamp = 0;
4747
long endTimestamp = 0;
4848
if (hbckChore != null) {
@@ -110,7 +110,7 @@
110110

111111
<table class="table table-striped">
112112
<tr>
113-
<th>Region</th>
113+
<th>Region Encoded Name</th>
114114
<th>Location in META</th>
115115
<th>Reported Online RegionServers</th>
116116
</tr>
@@ -136,7 +136,7 @@
136136
<% if (orphanRegionsOnRS != null && orphanRegionsOnRS.size() > 0) { %>
137137
<table class="table table-striped">
138138
<tr>
139-
<th>Region</th>
139+
<th>Region Encoded Name</th>
140140
<th>Reported Online RegionServer</th>
141141
</tr>
142142
<% for (Map.Entry<String, ServerName> entry : orphanRegionsOnRS.entrySet()) { %>
@@ -159,11 +159,13 @@
159159
<% if (orphanRegionsOnFS != null && orphanRegionsOnFS.size() > 0) { %>
160160
<table class="table table-striped">
161161
<tr>
162-
<th>Region</th>
162+
<th>Region Encoded Name</th>
163+
<th>FileSystem Path</th>
163164
</tr>
164-
<% for (String region : orphanRegionsOnFS) { %>
165+
<% for (Map.Entry<String, Path> entry : orphanRegionsOnFS.entrySet()) { %>
165166
<tr>
166-
<td><%= region %></td>
167+
<td><%= entry.getKey() %></td>
168+
<td><%= entry.getValue() %></td>
167169
</tr>
168170
<% } %>
169171

hbase-server/src/test/java/org/apache/hadoop/hbase/master/assignment/TestHbckChore.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ public void testOrphanRegionsOnFS() throws Exception {
192192
HRegion.createRegionDir(conf, regionInfo, FSUtils.getRootDir(conf));
193193
hbckChore.choreForTesting();
194194
assertEquals(1, hbckChore.getOrphanRegionsOnFS().size());
195-
assertTrue(hbckChore.getOrphanRegionsOnFS().contains(regionInfo.getEncodedName()));
195+
assertTrue(hbckChore.getOrphanRegionsOnFS().containsKey(regionInfo.getEncodedName()));
196196

197197
FSUtils.deleteRegionDir(conf, new HRegionInfo(regionInfo));
198198
hbckChore.choreForTesting();

0 commit comments

Comments
 (0)