protected boolean cleanAndVerifyObsoleteDirectories(CompactionInfo info, String location,
                                                      ValidReaderWriteIdList validWriteIdList, Table table) throws MetaException, IOException {
    Path path = new Path(location);
    FileSystem fs = path.getFileSystem(conf);

    // Collect all the files/dirs
    Map<Path, AcidUtils.HdfsDirSnapshot> dirSnapshots = AcidUtils.getHdfsDirSnapshotsForCleaner(fs, path);
    AcidDirectory dir = AcidUtils.getAcidState(fs, path, conf, validWriteIdList, Ref.from(false), false,
            dirSnapshots);
    boolean isDynPartAbort = CompactorUtil.isDynPartAbort(table, info.partName);

    List<Path> obsoleteDirs = CompactorUtil.getObsoleteDirs(dir, isDynPartAbort);
    if (isDynPartAbort || dir.hasUncompactedAborts()) {
      info.setWriteIds(dir.hasUncompactedAborts(), dir.getAbortedWriteIds());
    }

    List<Path> deleted = fsRemover.clean(new CleanupRequest.CleanupRequestBuilder().setLocation(location)
            .setDbName(info.dbname).setFullPartitionName(info.getFullPartitionName())
            .setRunAs(info.runAs).setObsoleteDirs(obsoleteDirs).setPurge(true)
            .build());

    if (!deleted.isEmpty()) {
      AcidMetricService.updateMetricsFromCleaner(info.dbname, info.tableName, info.partName, dir.getObsolete(), conf,
              txnHandler);
    }

    // Make sure there are no leftovers below the compacted watermark
    boolean success = false;
    conf.set(ValidTxnList.VALID_TXNS_KEY, new ValidReadTxnList().toString());
    dir = AcidUtils.getAcidState(fs, path, conf, new ValidCleanerWriteIdList(info.getFullTableName(), info.highestWriteId),
            Ref.from(false), false, dirSnapshots);

    List<Path> remained = subtract(CompactorUtil.getObsoleteDirs(dir, isDynPartAbort), deleted);
    if (!remained.isEmpty()) {
      LOG.warn("Remained {} obsolete directories from {}. {}",
              remained.size(), location, CompactorUtil.getDebugInfo(remained));
    } else {
      LOG.debug("All cleared below the watermark: {} from {}", info.highestWriteId, location);
      success = true;
    }

    return success;
  }
An abstract class which defines the list of utility methods for performing cleanup activities.
ql/src/java/org/apache/hadoop/hive/ql/txn/compactor/handler/TaskHandler.java