Search in sources :

Example 1 with DataSourceProvider

use of org.apache.hadoop.hive.metastore.datasource.DataSourceProvider in project hive by apache.

the class ObjectStore method getPMF.

private static synchronized PersistenceManagerFactory getPMF() {
    if (pmf == null) {
        Configuration conf = MetastoreConf.newMetastoreConf();
        DataSourceProvider dsp = DataSourceProviderFactory.getDataSourceProvider(conf);
        if (dsp == null) {
            pmf = JDOHelper.getPersistenceManagerFactory(prop);
        } else {
            try {
                DataSource ds = dsp.create(conf);
                Map<Object, Object> dsProperties = new HashMap<>();
                // Any preexisting datanucleus property should be passed along
                dsProperties.putAll(prop);
                dsProperties.put("datanucleus.ConnectionFactory", ds);
                dsProperties.put("javax.jdo.PersistenceManagerFactoryClass", "org.datanucleus.api.jdo.JDOPersistenceManagerFactory");
                pmf = JDOHelper.getPersistenceManagerFactory(dsProperties);
            } catch (SQLException e) {
                LOG.warn("Could not create PersistenceManagerFactory using " + "connection pool properties, will fall back", e);
                pmf = JDOHelper.getPersistenceManagerFactory(prop);
            }
        }
        DataStoreCache dsc = pmf.getDataStoreCache();
        if (dsc != null) {
            String objTypes = MetastoreConf.getVar(conf, ConfVars.CACHE_PINOBJTYPES);
            LOG.info("Setting MetaStore object pin classes with hive.metastore.cache.pinobjtypes=\"{}\"", objTypes);
            if (org.apache.commons.lang.StringUtils.isNotEmpty(objTypes)) {
                String[] typeTokens = objTypes.toLowerCase().split(",");
                for (String type : typeTokens) {
                    type = type.trim();
                    if (PINCLASSMAP.containsKey(type)) {
                        dsc.pinAll(true, PINCLASSMAP.get(type));
                    } else {
                        LOG.warn("{} is not one of the pinnable object types: {}", type, org.apache.commons.lang.StringUtils.join(PINCLASSMAP.keySet(), " "));
                    }
                }
            }
        } else {
            LOG.warn("PersistenceManagerFactory returned null DataStoreCache object. Unable to initialize object pin types defined by hive.metastore.cache.pinobjtypes");
        }
    }
    return pmf;
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) HashMap(java.util.HashMap) SQLException(java.sql.SQLException) DataSourceProvider(org.apache.hadoop.hive.metastore.datasource.DataSourceProvider) DataStoreCache(javax.jdo.datastore.DataStoreCache) DataSource(javax.sql.DataSource)

Aggregations

SQLException (java.sql.SQLException)1 HashMap (java.util.HashMap)1 DataStoreCache (javax.jdo.datastore.DataStoreCache)1 DataSource (javax.sql.DataSource)1 Configuration (org.apache.hadoop.conf.Configuration)1 DataSourceProvider (org.apache.hadoop.hive.metastore.datasource.DataSourceProvider)1