deniskuzZ commented on code in PR #5474:
URL: https://github.com/apache/hive/pull/5474#discussion_r1823295551


##########
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:
   c3p0 provides the same method for handling pooled DS. 
   
   1. why use try-with-resources if the block body is empty?? 
   2. what if `determineDatabaseProduct` throws an exception, I don't see you 
check ds2 for null



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to