@Override
  public boolean isFileDeletable(FileStatus fStat) {
    lock.readLock().lock();
    try {
      if (this.fs == null) {
        return false;
      }
      Path filePath = fStat.getPath();
      // HFile Link is always deletable
      if (HFileLink.isHFileLink(filePath)) {
        return true;
      }

      // If the file is inside a link references directory, means that it is a back ref link.
      // The back ref can be deleted only if the referenced file doesn't exists.
      Path parentDir = filePath.getParent();
      if (HFileLink.isBackReferencesDir(parentDir)) {
        Path hfilePath = null;
        try {
          // Also check if the HFile is in the HBASE_TEMP_DIRECTORY; this is where the referenced
          // file gets created when cloning a snapshot.
          hfilePath = HFileLink.getHFileFromBackReference(
            new Path(CommonFSUtils.getRootDir(getConf()), HConstants.HBASE_TEMP_DIRECTORY),
            filePath);
          if (fs.exists(hfilePath)) {
            return false;
          }
          // check whether the HFileLink still exists in mob dir.
          hfilePath = HFileLink.getHFileFromBackReference(MobUtils.getMobHome(getConf()), filePath);
          if (fs.exists(hfilePath)) {
            return false;
          }
          hfilePath =
            HFileLink.getHFileFromBackReference(CommonFSUtils.getRootDir(getConf()), filePath);
          return !fs.exists(hfilePath);
        } catch (IOException e) {
          if (LOG.isDebugEnabled()) {
            LOG.debug("Couldn't verify if the referenced file still exists, keep it just in case: "
              + hfilePath);
          }
          return false;
        }
      }

      // HFile is deletable only if has no links
      Path backRefDir = HFileLink.getBackReferencesDir(parentDir, filePath.getName());
      try {
        FileStatus[] fileStatuses = CommonFSUtils.listStatus(fs, backRefDir);
        // for empty reference directory, retain the logic to be deletable
        if (fileStatuses == null) {
          return true;
        }
        // reuse the found back reference files, check if the forward reference exists.
        // with this optimization, the chore could save one round compute time if we're visiting
        // the archive HFile earlier than the HFile Link
        for (FileStatus fileStatus : fileStatuses) {
          if (!isFileDeletable(fileStatus)) {
            return false;
          }
        }
        // all the found back reference files are clear, we can delete it.
        return true;
      } catch (IOException e) {
        if (LOG.isDebugEnabled()) {
          LOG.debug("Couldn't get the references, not deleting file, just in case. filePath="
            + filePath + ", backRefDir=" + backRefDir);
        }
        return false;
      }
    } finally {
      lock.readLock().unlock();
    }
  }
HFileLink cleaner that determines if a hfile should be deleted. HFiles can be deleted only if
there're no links to them. When a HFileLink is created a back reference file is created in:
/hbase/archive/table/region/cf/.links-hfile/ref-region.ref-table To check if the hfile can be
deleted the back references folder must be empty.
hbase-server/src/main/java/org/apache/hadoop/hbase/master/cleaner/HFileLinkCleaner.java