1919
2020import java .io .IOException ;
2121import java .util .HashMap ;
22+ import java .util .HashSet ;
2223import java .util .LinkedList ;
2324import java .util .List ;
2425import java .util .Map ;
2526import java .util .Set ;
2627import java .util .concurrent .locks .ReentrantReadWriteLock ;
2728
28- import org .apache .hadoop .fs .FileStatus ;
2929import org .apache .hadoop .fs .FileSystem ;
3030import org .apache .hadoop .fs .Path ;
3131import org .apache .hadoop .hbase .ScheduledChore ;
4040import org .slf4j .Logger ;
4141import 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 {
0 commit comments