3434import org .apache .hadoop .hbase .MetaTableAccessor ;
3535import org .apache .hadoop .hbase .ScheduledChore ;
3636import org .apache .hadoop .hbase .TableName ;
37- import org .apache .hadoop .hbase .client .ColumnFamilyDescriptor ;
3837import org .apache .hadoop .hbase .client .Connection ;
3938import org .apache .hadoop .hbase .client .ConnectionFactory ;
4039import org .apache .hadoop .hbase .client .Get ;
@@ -183,12 +182,12 @@ public int scan() throws IOException {
183182 for (Map .Entry <RegionInfo , Result > e : mergedRegions .entrySet ()) {
184183 if (this .services .isInMaintenanceMode ()) {
185184 // Stop cleaning if the master is in maintenance mode
186- LOG .debug ("In maintenence mode, not cleaning" );
185+ LOG .debug ("In maintenance mode, not cleaning" );
187186 break ;
188187 }
189188
190189 List <RegionInfo > parents = MetaTableAccessor .getMergeRegions (e .getValue ().rawCells ());
191- if (parents != null && cleanMergeRegion (e .getKey (), parents )) {
190+ if (parents != null && cleanMergeRegion (this . services , e .getKey (), parents )) {
192191 gcs ++;
193192 }
194193 }
@@ -201,7 +200,7 @@ public int scan() throws IOException {
201200 if (this .services .isInMaintenanceMode ()) {
202201 // Stop cleaning if the master is in maintenance mode
203202 if (LOG .isDebugEnabled ()) {
204- LOG .debug ("In maintenence mode, not cleaning" );
203+ LOG .debug ("In maintenance mode, not cleaning" );
205204 }
206205 break ;
207206 }
@@ -248,30 +247,24 @@ public CatalogJanitorReport getLastReport() {
248247 * @return true if we delete references in merged region on hbase:meta and archive the files on
249248 * the file system
250249 */
251- private boolean cleanMergeRegion (final RegionInfo mergedRegion , List < RegionInfo > parents )
252- throws IOException {
250+ static boolean cleanMergeRegion (MasterServices services , final RegionInfo mergedRegion ,
251+ List < RegionInfo > parents ) throws IOException {
253252 if (LOG .isDebugEnabled ()) {
254253 LOG .debug ("Cleaning merged region {}" , mergedRegion );
255254 }
256- FileSystem fs = this .services .getMasterFileSystem ().getFileSystem ();
257- Path rootdir = this .services .getMasterFileSystem ().getRootDir ();
258- Path tabledir = CommonFSUtils .getTableDir (rootdir , mergedRegion .getTable ());
259- TableDescriptor htd = getDescriptor (mergedRegion .getTable ());
260- HRegionFileSystem regionFs = null ;
261- try {
262- regionFs = HRegionFileSystem .openRegionFromFileSystem (this .services .getConfiguration (), fs ,
263- tabledir , mergedRegion , true );
264- } catch (IOException e ) {
265- LOG .warn ("Merged region does not exist: " + mergedRegion .getEncodedName ());
266- }
267- if (regionFs == null || !regionFs .hasReferences (htd )) {
255+
256+ Pair <Boolean , Boolean > result =
257+ checkRegionReferences (services , mergedRegion .getTable (), mergedRegion );
258+
259+ if (hasNoReferences (result )) {
268260 if (LOG .isDebugEnabled ()) {
269261 LOG .debug (
270262 "Deleting parents ({}) from fs; merged child {} no longer holds references" , parents
271263 .stream ().map (r -> RegionInfo .getShortNameToLog (r )).collect (Collectors .joining (", " )),
272264 mergedRegion );
273265 }
274- ProcedureExecutor <MasterProcedureEnv > pe = this .services .getMasterProcedureExecutor ();
266+
267+ ProcedureExecutor <MasterProcedureEnv > pe = services .getMasterProcedureExecutor ();
275268 GCMultipleMergedRegionsProcedure mergeRegionProcedure =
276269 new GCMultipleMergedRegionsProcedure (pe .getEnvironment (), mergedRegion , parents );
277270 pe .submitProcedure (mergeRegionProcedure );
@@ -280,7 +273,15 @@ private boolean cleanMergeRegion(final RegionInfo mergedRegion, List<RegionInfo>
280273 mergedRegion );
281274 }
282275 return true ;
276+ } else {
277+ if (LOG .isDebugEnabled ()) {
278+ LOG .debug (
279+ "Deferring cleanup up of {} parents of merged region {}, because references "
280+ + "still exist in merged region or we encountered an exception in checking" ,
281+ parents .size (), mergedRegion .getEncodedName ());
282+ }
283283 }
284+
284285 return false ;
285286 }
286287
@@ -332,8 +333,10 @@ static boolean cleanParent(MasterServices services, RegionInfo parent, Result ro
332333 }
333334 // Run checks on each daughter split.
334335 PairOfSameType <RegionInfo > daughters = MetaTableAccessor .getDaughterRegions (rowContent );
335- Pair <Boolean , Boolean > a = checkDaughterInFs (services , parent , daughters .getFirst ());
336- Pair <Boolean , Boolean > b = checkDaughterInFs (services , parent , daughters .getSecond ());
336+ Pair <Boolean , Boolean > a =
337+ checkRegionReferences (services , parent .getTable (), daughters .getFirst ());
338+ Pair <Boolean , Boolean > b =
339+ checkRegionReferences (services , parent .getTable (), daughters .getSecond ());
337340 if (hasNoReferences (a ) && hasNoReferences (b )) {
338341 String daughterA =
339342 daughters .getFirst () != null ? daughters .getFirst ().getShortNameToLog () : "null" ;
@@ -386,59 +389,45 @@ private static boolean hasNoReferences(final Pair<Boolean, Boolean> p) {
386389 }
387390
388391 /**
389- * Checks if a daughter region -- either splitA or splitB -- still holds references to parent.
390- * @param parent Parent region
391- * @param daughter Daughter region
392- * @return A pair where the first boolean says whether or not the daughter region directory exists
393- * in the filesystem and then the second boolean says whether the daughter has references
394- * to the parent.
392+ * Checks if a region still holds references to parent.
393+ * @param tableName The table for the region
394+ * @param region The region to check
395+ * @return A pair where the first boolean says whether the region directory exists in the
396+ * filesystem and then the second boolean says whether the region has references to a
397+ * parent.
395398 */
396- private static Pair <Boolean , Boolean > checkDaughterInFs (MasterServices services ,
397- final RegionInfo parent , final RegionInfo daughter ) throws IOException {
398- if (daughter == null ) {
399+ private static Pair <Boolean , Boolean > checkRegionReferences (MasterServices services ,
400+ TableName tableName , RegionInfo region ) throws IOException {
401+ if (region == null ) {
399402 return new Pair <>(Boolean .FALSE , Boolean .FALSE );
400403 }
401404
402405 FileSystem fs = services .getMasterFileSystem ().getFileSystem ();
403406 Path rootdir = services .getMasterFileSystem ().getRootDir ();
404- Path tabledir = CommonFSUtils .getTableDir (rootdir , daughter .getTable ());
405-
406- Path daughterRegionDir = new Path (tabledir , daughter .getEncodedName ());
407-
408- HRegionFileSystem regionFs ;
407+ Path tabledir = CommonFSUtils .getTableDir (rootdir , tableName );
408+ Path regionDir = new Path (tabledir , region .getEncodedName ());
409409
410410 try {
411- if (!CommonFSUtils .isExists (fs , daughterRegionDir )) {
411+ if (!CommonFSUtils .isExists (fs , regionDir )) {
412412 return new Pair <>(Boolean .FALSE , Boolean .FALSE );
413413 }
414414 } catch (IOException ioe ) {
415- LOG .error ("Error trying to determine if daughter region exists, "
416- + "assuming exists and has references" , ioe );
415+ LOG .error ("Error trying to determine if region exists, assuming exists and has references" ,
416+ ioe );
417417 return new Pair <>(Boolean .TRUE , Boolean .TRUE );
418418 }
419419
420- boolean references = false ;
421- TableDescriptor parentDescriptor = services .getTableDescriptors ().get (parent .getTable ());
420+ TableDescriptor tableDescriptor = services .getTableDescriptors ().get (tableName );
422421 try {
423- regionFs = HRegionFileSystem .openRegionFromFileSystem (services .getConfiguration (), fs ,
424- tabledir , daughter , true );
425-
426- for (ColumnFamilyDescriptor family : parentDescriptor .getColumnFamilies ()) {
427- references = regionFs .hasReferences (family .getNameAsString ());
428- if (references ) {
429- break ;
430- }
431- }
422+ HRegionFileSystem regionFs = HRegionFileSystem
423+ .openRegionFromFileSystem (services .getConfiguration (), fs , tabledir , region , true );
424+ boolean references = regionFs .hasReferences (tableDescriptor );
425+ return new Pair <>(Boolean .TRUE , references );
432426 } catch (IOException e ) {
433- LOG .error ("Error trying to determine referenced files from : " + daughter . getEncodedName ()
434- + ", to: " + parent .getEncodedName () + " assuming has references" , e );
427+ LOG .error ("Error trying to determine if region {} has references, assuming it does" ,
428+ region .getEncodedName (), e );
435429 return new Pair <>(Boolean .TRUE , Boolean .TRUE );
436430 }
437- return new Pair <>(Boolean .TRUE , references );
438- }
439-
440- private TableDescriptor getDescriptor (final TableName tableName ) throws IOException {
441- return this .services .getTableDescriptors ().get (tableName );
442431 }
443432
444433 private void updateAssignmentManagerMetrics () {
0 commit comments