Skip to content

Commit ee40d47

Browse files
committed
HBASE-22807 HBCK Report showed wrong orphans regions on FileSystem (#461)
Signed-off-by: Sakthi <[email protected]>
1 parent 225c6cd commit ee40d47

File tree

4 files changed

+45
-22
lines changed

4 files changed

+45
-22
lines changed

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

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@
1919

2020
import java.io.IOException;
2121
import java.util.HashMap;
22+
import java.util.HashSet;
2223
import java.util.LinkedList;
2324
import java.util.List;
2425
import java.util.Map;
2526
import java.util.Set;
2627
import java.util.concurrent.locks.ReentrantReadWriteLock;
2728

28-
import org.apache.hadoop.fs.FileStatus;
2929
import org.apache.hadoop.fs.FileSystem;
3030
import org.apache.hadoop.fs.Path;
3131
import org.apache.hadoop.hbase.ScheduledChore;
@@ -40,8 +40,6 @@
4040
import org.slf4j.Logger;
4141
import org.slf4j.LoggerFactory;
4242

43-
import org.apache.hbase.thirdparty.com.google.common.collect.Lists;
44-
4543
/**
4644
* Used to do the hbck checking job at master side.
4745
*/
@@ -69,7 +67,7 @@ public class HbckChore extends ScheduledChore {
6967
/**
7068
* The regions have directory on FileSystem, but no region info in meta.
7169
*/
72-
private final List<String> orphanRegionsOnFS = new LinkedList<>();
70+
private final Set<String> orphanRegionsOnFS = new HashSet<>();
7371
/**
7472
* The inconsistent regions. There are three case:
7573
* case 1. Master thought this region opened, but no regionserver reported it.
@@ -83,7 +81,7 @@ public class HbckChore extends ScheduledChore {
8381
* The "snapshot" is used to save the last round's HBCK checking report.
8482
*/
8583
private final Map<String, ServerName> orphanRegionsOnRSSnapshot = new HashMap<>();
86-
private final List<String> orphanRegionsOnFSSnapshot = new LinkedList<>();
84+
private final Set<String> orphanRegionsOnFSSnapshot = new HashSet<>();
8785
private final Map<String, Pair<ServerName, List<ServerName>>> inconsistentRegionsSnapshot =
8886
new HashMap<>();
8987

@@ -153,9 +151,11 @@ private void loadRegionsFromInMemoryState() {
153151
regionState.getStamp());
154152
regionInfoMap.put(regionInfo.getEncodedName(), new HbckRegionInfo(metaEntry));
155153
}
154+
LOG.info("Loaded {} regions from in-memory state of AssignmentManager", regionStates.size());
156155
}
157156

158157
private void loadRegionsFromRSReport() {
158+
int numRegions = 0;
159159
Map<ServerName, Set<byte[]>> rsReports = master.getAssignmentManager().getRSReports();
160160
for (Map.Entry<ServerName, Set<byte[]>> entry : rsReports.entrySet()) {
161161
ServerName serverName = entry.getKey();
@@ -168,7 +168,10 @@ private void loadRegionsFromRSReport() {
168168
}
169169
hri.addServer(hri.getMetaEntry(), serverName);
170170
}
171+
numRegions += entry.getValue().size();
171172
}
173+
LOG.info("Loaded {} regions from {} regionservers' reports and found {} orphan regions",
174+
numRegions, rsReports.size(), orphanRegionsOnFS.size());
172175

173176
for (Map.Entry<String, HbckRegionInfo> entry : regionInfoMap.entrySet()) {
174177
String encodedRegionName = entry.getKey();
@@ -191,27 +194,24 @@ private void loadRegionsFromFS() throws IOException {
191194
Path rootDir = master.getMasterFileSystem().getRootDir();
192195
FileSystem fs = master.getMasterFileSystem().getFileSystem();
193196

194-
// list all tables from HDFS
195-
List<FileStatus> tableDirs = Lists.newArrayList();
196-
List<Path> paths = FSUtils.getTableDirs(fs, rootDir);
197-
for (Path path : paths) {
198-
tableDirs.add(fs.getFileStatus(path));
199-
}
200-
201-
for (FileStatus tableDir : tableDirs) {
202-
FileStatus[] regionDirs = fs.listStatus(tableDir.getPath());
203-
for (FileStatus regionDir : regionDirs) {
204-
String encodedRegionName = regionDir.getPath().getName();
197+
int numRegions = 0;
198+
List<Path> tableDirs = FSUtils.getTableDirs(fs, rootDir);
199+
for (Path tableDir : tableDirs) {
200+
List<Path> regionDirs = FSUtils.getRegionDirs(fs, tableDir);
201+
for (Path regionDir : regionDirs) {
202+
String encodedRegionName = regionDir.getName();
205203
HbckRegionInfo hri = regionInfoMap.get(encodedRegionName);
206204
if (hri == null) {
207205
orphanRegionsOnFS.add(encodedRegionName);
208206
continue;
209207
}
210-
HbckRegionInfo.HdfsEntry hdfsEntry =
211-
new HbckRegionInfo.HdfsEntry(regionDir.getPath(), regionDir.getModificationTime());
208+
HbckRegionInfo.HdfsEntry hdfsEntry = new HbckRegionInfo.HdfsEntry(regionDir);
212209
hri.setHdfsEntry(hdfsEntry);
213210
}
211+
numRegions += regionDirs.size();
214212
}
213+
LOG.info("Loaded {} tables {} regions from filesyetem and found {} orphan regions",
214+
tableDirs.size(), numRegions, orphanRegionsOnFS.size());
215215
}
216216

217217
/**
@@ -237,7 +237,7 @@ public Map<String, ServerName> getOrphanRegionsOnRS() {
237237
/**
238238
* @return the regions have directory on FileSystem, but no region info in meta.
239239
*/
240-
public List<String> getOrphanRegionsOnFS() {
240+
public Set<String> getOrphanRegionsOnFS() {
241241
// Need synchronized here, as this "snapshot" may be changed after checking.
242242
rwLock.readLock().lock();
243243
try {

hbase-server/src/main/java/org/apache/hadoop/hbase/util/HbckRegionInfo.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -330,9 +330,8 @@ public static class HdfsEntry {
330330
HdfsEntry() {
331331
}
332332

333-
public HdfsEntry(Path regionDir, long regionDirModTime) {
333+
public HdfsEntry(Path regionDir) {
334334
this.regionDir = regionDir;
335-
this.regionDirModTime = regionDirModTime;
336335
}
337336
}
338337

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import="java.util.Date"
2424
import="java.util.List"
2525
import="java.util.Map"
26+
import="java.util.Set"
2627
import="java.util.stream.Collectors"
2728
import="java.time.ZonedDateTime"
2829
import="java.time.format.DateTimeFormatter"
@@ -41,7 +42,7 @@
4142
HbckChore hbckChore = master.getHbckChore();
4243
Map<String, Pair<ServerName, List<ServerName>>> inconsistentRegions = null;
4344
Map<String, ServerName> orphanRegionsOnRS = null;
44-
List<String> orphanRegionsOnFS = null;
45+
Set<String> orphanRegionsOnFS = null;
4546
long startTimestamp = 0;
4647
long endTimestamp = 0;
4748
if (hbckChore != null) {

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,18 @@
2626
import java.util.Map;
2727
import java.util.concurrent.Future;
2828

29+
import org.apache.hadoop.conf.Configuration;
2930
import org.apache.hadoop.hbase.HBaseClassTestRule;
31+
import org.apache.hadoop.hbase.HRegionInfo;
3032
import org.apache.hadoop.hbase.ServerName;
3133
import org.apache.hadoop.hbase.TableName;
3234
import org.apache.hadoop.hbase.client.RegionInfo;
3335
import org.apache.hadoop.hbase.client.RegionInfoBuilder;
3436
import org.apache.hadoop.hbase.master.HbckChore;
37+
import org.apache.hadoop.hbase.regionserver.HRegion;
3538
import org.apache.hadoop.hbase.testclassification.MasterTests;
3639
import org.apache.hadoop.hbase.testclassification.MediumTests;
40+
import org.apache.hadoop.hbase.util.FSUtils;
3741
import org.apache.hadoop.hbase.util.Pair;
3842
import org.junit.Before;
3943
import org.junit.ClassRule;
@@ -141,4 +145,23 @@ public void testForUserTable() throws Exception {
141145
inconsistentRegions = hbckChore.getInconsistentRegions();
142146
assertFalse(inconsistentRegions.containsKey(regionName));
143147
}
148+
149+
@Test
150+
public void testOrphanRegionsOnFS() throws Exception {
151+
TableName tableName = TableName.valueOf("testOrphanRegionsOnFS");
152+
RegionInfo regionInfo = RegionInfoBuilder.newBuilder(tableName).build();
153+
Configuration conf = util.getConfiguration();
154+
155+
hbckChore.choreForTesting();
156+
assertEquals(0, hbckChore.getOrphanRegionsOnFS().size());
157+
158+
HRegion.createRegionDir(conf, regionInfo, FSUtils.getRootDir(conf));
159+
hbckChore.choreForTesting();
160+
assertEquals(1, hbckChore.getOrphanRegionsOnFS().size());
161+
assertTrue(hbckChore.getOrphanRegionsOnFS().contains(regionInfo.getEncodedName()));
162+
163+
FSUtils.deleteRegionDir(conf, new HRegionInfo(regionInfo));
164+
hbckChore.choreForTesting();
165+
assertEquals(0, hbckChore.getOrphanRegionsOnFS().size());
166+
}
144167
}

0 commit comments

Comments
 (0)