@VisibleForTesting
  Path getCmRoot(Path path) throws IOException {
    Path cmroot = null;
    //Default path if hive.repl.cm dir is encrypted
    String cmrootDir = fallbackNonEncryptedCmRootDir;
    String encryptionZonePath = NO_ENCRYPTION;
    if (enabled) {
      if (EncryptionZoneUtils.isPathEncrypted(path, conf)) {
        encryptionZonePath = path.getFileSystem(conf).getUri()
                + EncryptionZoneUtils.getEncryptionZoneForPath(path, conf).getPath();
        //For encryption zone, create cm at the relative path specified by hive.repl.cm.encryptionzone.rootdir
        //at the root of the encryption zone
        cmrootDir = encryptionZonePath + Path.SEPARATOR + encryptedCmRootDir;
      }
      if (encryptionZoneToCmrootMapping.containsKey(encryptionZonePath)) {
        cmroot = new Path(encryptionZoneToCmrootMapping.get(encryptionZonePath));
      } else {
        cmroot = new Path(cmrootDir);
        synchronized (instance) {
          if (!encryptionZoneToCmrootMapping.containsKey(encryptionZonePath)) {
            createCmRoot(cmroot);
            encryptionZoneToCmrootMapping.put(encryptionZonePath, cmrootDir);
          }
        }
      }
    }
    return cmroot;
  }
Thread to clear old files of cmroot recursively
standalone-metastore/metastore-common/src/main/java/org/apache/hadoop/hive/metastore/ReplChangeManager.java