private static void createCmRoot(Path cmroot) throws IOException {
    Retry<Void> retriable = new Retry<Void>(IOException.class) {
      @Override
      public Void execute() throws IOException {
        FileSystem cmFs = cmroot.getFileSystem(conf);
        // Create cmroot if not exist
        if (!cmFs.exists(cmroot)) {
          cmFs.mkdirs(cmroot);
          setCmRootPermissions(cmroot);
        }
        return null;
      }
    };
    try {
      retriable.run();
    } catch (Exception e) {
      throw new IOException("Failed to createCmRoot", e);
    }
  }
Thread to clear old files of cmroot recursively
standalone-metastore/metastore-common/src/main/java/org/apache/hadoop/hive/metastore/ReplChangeManager.java