deniskuzZ commented on code in PR #5474: URL: https://github.com/apache/hive/pull/5474#discussion_r1820781214
########## standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/PersistenceManagerProvider.java: ########## @@ -302,23 +307,33 @@ private static PersistenceManagerFactory initPMF(Configuration conf, boolean for pmf = JDOHelper.getPersistenceManagerFactory(dsProp); } else { String sourceName = forCompactor ? "objectstore-compactor" : "objectstore"; + DataSource ds = null, ds2 = null; try (DataSourceProvider.DataSourceNameConfigurator configurator = new DataSourceProvider.DataSourceNameConfigurator(conf, sourceName)) { - DataSource ds = (maxPoolSize > 0) ? dsp.create(conf, maxPoolSize) : dsp.create(conf); + ds = (maxPoolSize > 0) ? dsp.create(conf, maxPoolSize) : dsp.create(conf); // The secondary connection factory is used for schema generation, and for value generation operations. // We should use a different pool for the secondary connection factory to avoid resource starvation. // Since DataNucleus uses locks for schema generation and value generation, 2 connections should be sufficient. configurator.resetName("objectstore-secondary"); - DataSource ds2 = forCompactor ? ds : dsp.create(conf, /* maxPoolSize */ 2); + ds2 = forCompactor ? ds : dsp.create(conf, /* maxPoolSize */ 2); dsProp.put(PropertyNames.PROPERTY_CONNECTION_FACTORY, ds); dsProp.put(PropertyNames.PROPERTY_CONNECTION_FACTORY2, ds2); + databaseProduct = DatabaseProduct.determineDatabaseProduct(ds, conf); dsProp.put(ConfVars.MANAGER_FACTORY_CLASS.getVarname(), "org.datanucleus.api.jdo.JDOPersistenceManagerFactory"); pmf = JDOHelper.getPersistenceManagerFactory(dsProp); } catch (SQLException e) { LOG.warn("Could not create PersistenceManagerFactory using " + "connection pool properties, will fall back", e); pmf = JDOHelper.getPersistenceManagerFactory(prop); + } finally { + if (pmf == null && ds instanceof AutoCloseable) { + try (AutoCloseable close1 = (AutoCloseable) ds; Review Comment: can we add a `close` method to `DataSourceProvider` ```` static void close(DataSource ds) { if (ds instanceof AutoCloseable) { try { ((AutoCloseable)ds).close(); } catch (Exception e) { LOG.warn("Failed to close the DataSource", e); } } } } ```` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: gitbox-unsubscr...@hive.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: gitbox-unsubscr...@hive.apache.org For additional commands, e-mail: gitbox-h...@hive.apache.org