@VisibleForTesting
  public static void closePmfInternal(PersistenceManagerFactory pmf) {
    if (pmf != null) {
      LOG.debug("Closing PersistenceManagerFactory");
      pmf.close();
      // close the underlying connection pool to avoid leaks
      if (pmf.getConnectionFactory() instanceof AutoCloseable) {
        try (AutoCloseable closeable = (AutoCloseable) pmf.getConnectionFactory()) {
        } catch (Exception e) {
          LOG.warn("Failed to close connection factory of PersistenceManagerFactory: " + pmf, e);
        }
      }
      if (pmf.getConnectionFactory2() instanceof AutoCloseable) {
        try (AutoCloseable closeable = (AutoCloseable) pmf.getConnectionFactory2()) {
        } catch (Exception e) {
          LOG.warn("Failed to close connection factory2 of PersistenceManagerFactory: " + pmf, e);
        }
      }
      LOG.debug("PersistenceManagerFactory closed");
    }
  }
When closing PersistenceManagerFactory, the connection factory should be closed as well,
otherwise the underlying dangling connections would be accumulated resulting to connection leaks.
See TestDataSourceProviderFactory#testClosePersistenceManagerProvider for details.
@param pmf the PersistenceManagerFactory tended to be closed
standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/PersistenceManagerProvider.java