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 ;
@@ -184,13 +183,13 @@ public int scan() throws IOException {
184183 if (this .services .isInMaintenanceMode ()) {
185184 // Stop cleaning if the master is in maintenance mode
186185 if (LOG .isDebugEnabled ()) {
187- LOG .debug ("In maintenence mode, not cleaning" );
186+ LOG .debug ("In mainteneace mode, not cleaning" );
188187 }
189188 break ;
190189 }
191190
192191 List <RegionInfo > parents = MetaTableAccessor .getMergeRegions (e .getValue ().rawCells ());
193- if (parents != null && cleanMergeRegion (e .getKey (), parents )) {
192+ if (parents != null && cleanMergeRegion (this . services , e .getKey (), parents )) {
194193 gcs ++;
195194 }
196195 }
@@ -203,7 +202,7 @@ public int scan() throws IOException {
203202 if (this .services .isInMaintenanceMode ()) {
204203 // Stop cleaning if the master is in maintenance mode
205204 if (LOG .isDebugEnabled ()) {
206- LOG .debug ("In maintenence mode, not cleaning" );
205+ LOG .debug ("In maintenance mode, not cleaning" );
207206 }
208207 break ;
209208 }
@@ -250,30 +249,24 @@ public CatalogJanitorReport getLastReport() {
250249 * @return true if we delete references in merged region on hbase:meta and archive the files on
251250 * the file system
252251 */
253- private boolean cleanMergeRegion (final RegionInfo mergedRegion , List < RegionInfo > parents )
254- throws IOException {
252+ static boolean cleanMergeRegion (MasterServices services , final RegionInfo mergedRegion ,
253+ List < RegionInfo > parents ) throws IOException {
255254 if (LOG .isDebugEnabled ()) {
256255 LOG .debug ("Cleaning merged region {}" , mergedRegion );
257256 }
258- FileSystem fs = this .services .getMasterFileSystem ().getFileSystem ();
259- Path rootdir = this .services .getMasterFileSystem ().getRootDir ();
260- Path tabledir = CommonFSUtils .getTableDir (rootdir , mergedRegion .getTable ());
261- TableDescriptor htd = getDescriptor (mergedRegion .getTable ());
262- HRegionFileSystem regionFs = null ;
263- try {
264- regionFs = HRegionFileSystem .openRegionFromFileSystem (this .services .getConfiguration (), fs ,
265- tabledir , mergedRegion , true );
266- } catch (IOException e ) {
267- LOG .warn ("Merged region does not exist: " + mergedRegion .getEncodedName ());
268- }
269- if (regionFs == null || !regionFs .hasReferences (htd )) {
257+
258+ Pair <Boolean , Boolean > result =
259+ checkRegionReferences (services , mergedRegion .getTable (), mergedRegion );
260+
261+ if (hasNoReferences (result )) {
270262 if (LOG .isDebugEnabled ()) {
271263 LOG .debug (
272264 "Deleting parents ({}) from fs; merged child {} no longer holds references" , parents
273265 .stream ().map (r -> RegionInfo .getShortNameToLog (r )).collect (Collectors .joining (", " )),
274266 mergedRegion );
275267 }
276- ProcedureExecutor <MasterProcedureEnv > pe = this .services .getMasterProcedureExecutor ();
268+
269+ ProcedureExecutor <MasterProcedureEnv > pe = services .getMasterProcedureExecutor ();
277270 GCMultipleMergedRegionsProcedure mergeRegionProcedure =
278271 new GCMultipleMergedRegionsProcedure (pe .getEnvironment (), mergedRegion , parents );
279272 pe .submitProcedure (mergeRegionProcedure );
@@ -282,7 +275,15 @@ private boolean cleanMergeRegion(final RegionInfo mergedRegion, List<RegionInfo>
282275 mergedRegion );
283276 }
284277 return true ;
278+ } else {
279+ if (LOG .isDebugEnabled ()) {
280+ LOG .debug (
281+ "Deferring cleanup up of {} parents of merged region {}, because references "
282+ + "still exist in merged region or we encountered an exception in checking" ,
283+ parents .size (), mergedRegion .getEncodedName ());
284+ }
285285 }
286+
286287 return false ;
287288 }
288289
@@ -334,8 +335,10 @@ static boolean cleanParent(MasterServices services, RegionInfo parent, Result ro
334335 }
335336 // Run checks on each daughter split.
336337 PairOfSameType <RegionInfo > daughters = MetaTableAccessor .getDaughterRegions (rowContent );
337- Pair <Boolean , Boolean > a = checkDaughterInFs (services , parent , daughters .getFirst ());
338- Pair <Boolean , Boolean > b = checkDaughterInFs (services , parent , daughters .getSecond ());
338+ Pair <Boolean , Boolean > a =
339+ checkRegionReferences (services , parent .getTable (), daughters .getFirst ());
340+ Pair <Boolean , Boolean > b =
341+ checkRegionReferences (services , parent .getTable (), daughters .getSecond ());
339342 if (hasNoReferences (a ) && hasNoReferences (b )) {
340343 String daughterA =
341344 daughters .getFirst () != null ? daughters .getFirst ().getShortNameToLog () : "null" ;
@@ -388,59 +391,45 @@ private static boolean hasNoReferences(final Pair<Boolean, Boolean> p) {
388391 }
389392
390393 /**
391- * Checks if a daughter region -- either splitA or splitB -- still holds references to parent.
392- * @param parent Parent region
393- * @param daughter Daughter region
394- * @return A pair where the first boolean says whether or not the daughter region directory exists
395- * in the filesystem and then the second boolean says whether the daughter has references
396- * to the parent.
394+ * Checks if a region still holds references to parent.
395+ * @param tableName The table for the region
396+ * @param region The region to check
397+ * @return A pair where the first boolean says whether the region directory exists in the
398+ * filesystem and then the second boolean says whether the region has references to a
399+ * parent.
397400 */
398- private static Pair <Boolean , Boolean > checkDaughterInFs (MasterServices services ,
399- final RegionInfo parent , final RegionInfo daughter ) throws IOException {
400- if (daughter == null ) {
401+ private static Pair <Boolean , Boolean > checkRegionReferences (MasterServices services ,
402+ TableName tableName , RegionInfo region ) throws IOException {
403+ if (region == null ) {
401404 return new Pair <>(Boolean .FALSE , Boolean .FALSE );
402405 }
403406
404407 FileSystem fs = services .getMasterFileSystem ().getFileSystem ();
405408 Path rootdir = services .getMasterFileSystem ().getRootDir ();
406- Path tabledir = CommonFSUtils .getTableDir (rootdir , daughter .getTable ());
407-
408- Path daughterRegionDir = new Path (tabledir , daughter .getEncodedName ());
409-
410- HRegionFileSystem regionFs ;
409+ Path tabledir = CommonFSUtils .getTableDir (rootdir , tableName );
410+ Path regionDir = new Path (tabledir , region .getEncodedName ());
411411
412412 try {
413- if (!CommonFSUtils .isExists (fs , daughterRegionDir )) {
413+ if (!CommonFSUtils .isExists (fs , regionDir )) {
414414 return new Pair <>(Boolean .FALSE , Boolean .FALSE );
415415 }
416416 } catch (IOException ioe ) {
417- LOG .error ("Error trying to determine if daughter region exists, "
418- + "assuming exists and has references" , ioe );
417+ LOG .error ("Error trying to determine if region exists, assuming exists and has references" ,
418+ ioe );
419419 return new Pair <>(Boolean .TRUE , Boolean .TRUE );
420420 }
421421
422- boolean references = false ;
423- TableDescriptor parentDescriptor = services .getTableDescriptors ().get (parent .getTable ());
422+ TableDescriptor tableDescriptor = services .getTableDescriptors ().get (tableName );
424423 try {
425- regionFs = HRegionFileSystem .openRegionFromFileSystem (services .getConfiguration (), fs ,
426- tabledir , daughter , true );
427-
428- for (ColumnFamilyDescriptor family : parentDescriptor .getColumnFamilies ()) {
429- references = regionFs .hasReferences (family .getNameAsString ());
430- if (references ) {
431- break ;
432- }
433- }
424+ HRegionFileSystem regionFs = HRegionFileSystem
425+ .openRegionFromFileSystem (services .getConfiguration (), fs , tabledir , region , true );
426+ boolean references = regionFs .hasReferences (tableDescriptor );
427+ return new Pair <>(Boolean .TRUE , references );
434428 } catch (IOException e ) {
435- LOG .error ("Error trying to determine referenced files from : " + daughter . getEncodedName ()
436- + ", to: " + parent .getEncodedName () + " assuming has references" , e );
429+ LOG .error ("Error trying to determine if region {} has references, assuming it does" ,
430+ region .getEncodedName (), e );
437431 return new Pair <>(Boolean .TRUE , Boolean .TRUE );
438432 }
439- return new Pair <>(Boolean .TRUE , references );
440- }
441-
442- private TableDescriptor getDescriptor (final TableName tableName ) throws IOException {
443- return this .services .getTableDescriptors ().get (tableName );
444433 }
445434
446435 private void updateAssignmentManagerMetrics () {
0 commit comments