@Override
    public void run() {
      try {
        LOG.info("CMClearer started");
        for (String cmrootString : encryptionZones.values()) {
          Path cmroot = new Path(cmrootString);
          long now = System.currentTimeMillis();
          FileSystem fs = cmroot.getFileSystem(conf);
          FileStatus[] files = fs.listStatus(cmroot);

          for (FileStatus file : files) {
            long modifiedTime = file.getModificationTime();
            if (now - modifiedTime > secRetain * 1000) {
              try {
                if (fs.getXAttrs(file.getPath()).containsKey(REMAIN_IN_TRASH_TAG)) {
                  boolean succ = Trash.moveToAppropriateTrash(fs, file.getPath(), conf);
                  if (succ) {
                    LOG.debug("Move " + file.toString() + " to trash");
                  } else {
                    LOG.warn("Fail to move " + file.toString() + " to trash");
                  }
                } else {
                  boolean succ = fs.delete(file.getPath(), false);
                  if (succ) {
                    LOG.debug("Remove " + file.toString());
                  } else {
                    LOG.warn("Fail to remove " + file.toString());
                  }
                }
              } catch (UnsupportedOperationException e) {
                LOG.warn("Error getting xattr for " + file.getPath().toString());
              }
            }
          }
        }
      } catch (IOException e) {
        LOG.error("Exception when clearing cmroot", e);
      }
    }
Thread to clear old files of cmroot recursively
standalone-metastore/metastore-common/src/main/java/org/apache/hadoop/hive/metastore/ReplChangeManager.java