diff --git common/src/java/org/apache/hadoop/hive/conf/HiveConf.java common/src/java/org/apache/hadoop/hive/conf/HiveConf.java index 3c633a2..0bbe4aa 100644 --- common/src/java/org/apache/hadoop/hive/conf/HiveConf.java +++ common/src/java/org/apache/hadoop/hive/conf/HiveConf.java @@ -124,8 +124,6 @@ HiveConf.ConfVars.USERS_IN_ADMIN_ROLE, HiveConf.ConfVars.HIVE_AUTHORIZATION_MANAGER, HiveConf.ConfVars.HIVE_TXN_MANAGER, - HiveConf.ConfVars.HIVE_TXN_JDBC_DRIVER, - HiveConf.ConfVars.HIVE_TXN_JDBC_CONNECT_STRING, HiveConf.ConfVars.HIVE_TXN_TIMEOUT, HiveConf.ConfVars.HIVE_TXN_MAX_OPEN_BATCH, }; @@ -702,8 +700,6 @@ // Transactions HIVE_TXN_MANAGER("hive.txn.manager", "org.apache.hadoop.hive.ql.lockmgr.DummyTxnManager"), - HIVE_TXN_JDBC_DRIVER("hive.txn.driver", ""), - HIVE_TXN_JDBC_CONNECT_STRING("hive.txn.connection.string", ""), // time after which transactions are declared aborted if the client has // not sent a heartbeat, in seconds. HIVE_TXN_TIMEOUT("hive.txn.timeout", 300), diff --git metastore/src/java/org/apache/hadoop/hive/metastore/txn/TxnDbUtil.java metastore/src/java/org/apache/hadoop/hive/metastore/txn/TxnDbUtil.java index bbb0d28..3ab5827 100644 --- metastore/src/java/org/apache/hadoop/hive/metastore/txn/TxnDbUtil.java +++ metastore/src/java/org/apache/hadoop/hive/metastore/txn/TxnDbUtil.java @@ -30,8 +30,6 @@ * here in a separate class so it can be shared across unit tests. */ public class TxnDbUtil { - private final static String jdbcString = "jdbc:derby:;databaseName=metastore_db;create=true"; - private final static String jdbcDriver = "org.apache.derby.jdbc.EmbeddedDriver"; private final static String txnMgr = "org.apache.hadoop.hive.ql.lockmgr.DbTxnManager"; /** @@ -41,8 +39,6 @@ * @param conf HiveConf to add these values to. */ public static void setConfValues(HiveConf conf) { - conf.setVar(HiveConf.ConfVars.HIVE_TXN_JDBC_DRIVER, jdbcDriver); - conf.setVar(HiveConf.ConfVars.HIVE_TXN_JDBC_CONNECT_STRING, jdbcString); conf.setVar(HiveConf.ConfVars.HIVE_TXN_MANAGER, txnMgr); conf.setBoolVar(HiveConf.ConfVars.HIVE_SUPPORT_CONCURRENCY, true); } @@ -52,8 +48,7 @@ public static void prepDb() throws Exception { // intended for creating derby databases, and thus will inexorably get // out of date with it. I'm open to any suggestions on how to make this // read the file in a build friendly way. - Driver driver = (Driver)Class.forName(jdbcDriver).newInstance(); - Connection conn = driver.connect(jdbcString, new Properties()); + Connection conn = getConnection(); Statement s = conn.createStatement(); s.execute("CREATE TABLE TXNS (" + " TXN_ID bigint PRIMARY KEY," + @@ -115,8 +110,7 @@ public static void prepDb() throws Exception { } public static void cleanDb() throws Exception { - Driver driver = (Driver)Class.forName(jdbcDriver).newInstance(); - Connection conn = driver.connect(jdbcString, new Properties()); + Connection conn = getConnection(); Statement s = conn.createStatement(); // We want to try these, whether they succeed or fail. try { @@ -178,8 +172,7 @@ public static void cleanDb() throws Exception { * @return number of components, or 0 if there is no lock */ public static int countLockComponents(long lockId) throws Exception { - Driver driver = (Driver)Class.forName(jdbcDriver).newInstance(); - Connection conn = driver.connect(jdbcString, new Properties()); + Connection conn = getConnection(); Statement s = conn.createStatement(); ResultSet rs = s.executeQuery("select count(*) from hive_locks where " + "hl_lock_ext_id = " + lockId); @@ -191,8 +184,7 @@ public static int countLockComponents(long lockId) throws Exception { } public static int findNumCurrentLocks() throws Exception { - Driver driver = (Driver)Class.forName(jdbcDriver).newInstance(); - Connection conn = driver.connect(jdbcString, new Properties()); + Connection conn = getConnection(); Statement s = conn.createStatement(); ResultSet rs = s.executeQuery("select count(*) from hive_locks"); if (!rs.next()) return 0; @@ -202,4 +194,17 @@ public static int findNumCurrentLocks() throws Exception { return rc; } + private static Connection getConnection() throws Exception { + HiveConf conf = new HiveConf(); + String jdbcDriver = HiveConf.getVar(conf, HiveConf.ConfVars.METASTORE_CONNECTION_DRIVER); + Driver driver = (Driver)Class.forName(jdbcDriver).newInstance(); + Properties prop = new Properties(); + String driverUrl = HiveConf.getVar(conf, HiveConf.ConfVars.METASTORECONNECTURLKEY); + String user = HiveConf.getVar(conf, HiveConf.ConfVars.METASTORE_CONNECTION_USER_NAME); + String passwd = HiveConf.getVar(conf, HiveConf.ConfVars.METASTOREPWD); + prop.put("user", user); + prop.put("password", passwd); + return driver.connect(driverUrl, prop); + } + } diff --git metastore/src/java/org/apache/hadoop/hive/metastore/txn/TxnHandler.java metastore/src/java/org/apache/hadoop/hive/metastore/txn/TxnHandler.java index 4441c2f..6c2c62f 100644 --- metastore/src/java/org/apache/hadoop/hive/metastore/txn/TxnHandler.java +++ metastore/src/java/org/apache/hadoop/hive/metastore/txn/TxnHandler.java @@ -75,10 +75,8 @@ public TxnHandler(HiveConf conf) { checkQFileTestHack(); // Set up the JDBC connection pool - String connString = - HiveConf.getVar(conf, HiveConf.ConfVars.HIVE_TXN_JDBC_CONNECT_STRING); try { - setupJdbcConnectionPool(connString); + setupJdbcConnectionPool(); } catch (SQLException e) { String msg = "Unable to instantiate JDBC connection pooling, " + e.getMessage(); LOG.error(msg); @@ -1261,13 +1259,19 @@ private void timeOutLocks(Connection dbConn) throws MetaException { } } - private synchronized void setupJdbcConnectionPool(String driverUrl) throws SQLException { + private synchronized void setupJdbcConnectionPool() throws SQLException { if (connPool != null) return; + String driverUrl = HiveConf.getVar(conf, HiveConf.ConfVars.METASTORECONNECTURLKEY); + String user = HiveConf.getVar(conf, HiveConf.ConfVars.METASTORE_CONNECTION_USER_NAME); + String passwd = HiveConf.getVar(conf, HiveConf.ConfVars.METASTOREPWD); + BoneCPConfig config = new BoneCPConfig(); config.setJdbcUrl(driverUrl); config.setMaxConnectionsPerPartition(10); config.setPartitionCount(1); + config.setUser(user); + config.setPassword(passwd); connPool = new BoneCP(config); } diff --git metastore/src/test/org/apache/hadoop/hive/metastore/txn/TestTxnHandler.java metastore/src/test/org/apache/hadoop/hive/metastore/txn/TestTxnHandler.java index 560fd5a..71021e3 100644 --- metastore/src/test/org/apache/hadoop/hive/metastore/txn/TestTxnHandler.java +++ metastore/src/test/org/apache/hadoop/hive/metastore/txn/TestTxnHandler.java @@ -920,25 +920,6 @@ public void testHeartbeatNoLock() throws Exception { } } - @Ignore // This test breaks the others when it unsets the value - @Test - public void testNoJDBCDriver() throws Exception { - HiveConf confCopy = new HiveConf(conf); - confCopy.unset(HiveConf.ConfVars.HIVE_TXN_JDBC_DRIVER.varname); - boolean sawException = false; - try { - TxnHandler tt = new TxnHandler(confCopy); - } catch (Exception e) { - if (e instanceof RuntimeException && e.getMessage().contains("JDBC " + - "driver for transaction db not set")) { - sawException = true; - } else { - throw e; - } - } - assertTrue(sawException); - } - @Test public void testCompactMajorWithPartition() throws Exception { CompactionRequest rqst = new CompactionRequest("foo", "bar", CompactionType.MAJOR);