You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hive.apache.org by ha...@apache.org on 2014/03/25 20:47:41 UTC
svn commit: r1581486 - in /hive/trunk:
common/src/java/org/apache/hadoop/hive/conf/
metastore/src/java/org/apache/hadoop/hive/metastore/txn/
metastore/src/test/org/apache/hadoop/hive/metastore/txn/
Author: hashutosh
Date: Tue Mar 25 19:47:41 2014
New Revision: 1581486
URL: http://svn.apache.org/r1581486
Log:
HIVE-6606 : Stand alone metastore fails to start if new transaction values not defined in config (Alan Gates via Ashutosh Chauhan)
Modified:
hive/trunk/common/src/java/org/apache/hadoop/hive/conf/HiveConf.java
hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/txn/TxnDbUtil.java
hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/txn/TxnHandler.java
hive/trunk/metastore/src/test/org/apache/hadoop/hive/metastore/txn/TestTxnHandler.java
Modified: hive/trunk/common/src/java/org/apache/hadoop/hive/conf/HiveConf.java
URL: http://svn.apache.org/viewvc/hive/trunk/common/src/java/org/apache/hadoop/hive/conf/HiveConf.java?rev=1581486&r1=1581485&r2=1581486&view=diff
==============================================================================
--- hive/trunk/common/src/java/org/apache/hadoop/hive/conf/HiveConf.java (original)
+++ hive/trunk/common/src/java/org/apache/hadoop/hive/conf/HiveConf.java Tue Mar 25 19:47:41 2014
@@ -125,8 +125,6 @@ public class HiveConf extends Configurat
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,
};
@@ -718,8 +716,6 @@ public class HiveConf extends Configurat
// 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),
Modified: hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/txn/TxnDbUtil.java
URL: http://svn.apache.org/viewvc/hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/txn/TxnDbUtil.java?rev=1581486&r1=1581485&r2=1581486&view=diff
==============================================================================
--- hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/txn/TxnDbUtil.java (original)
+++ hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/txn/TxnDbUtil.java Tue Mar 25 19:47:41 2014
@@ -30,8 +30,6 @@ import java.util.Properties;
* 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 @@ public class TxnDbUtil {
* @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 class TxnDbUtil {
// 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 class TxnDbUtil {
}
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 class TxnDbUtil {
* @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 class TxnDbUtil {
}
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 class TxnDbUtil {
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);
+ }
+
}
Modified: hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/txn/TxnHandler.java
URL: http://svn.apache.org/viewvc/hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/txn/TxnHandler.java?rev=1581486&r1=1581485&r2=1581486&view=diff
==============================================================================
--- hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/txn/TxnHandler.java (original)
+++ hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/txn/TxnHandler.java Tue Mar 25 19:47:41 2014
@@ -75,10 +75,8 @@ public class TxnHandler {
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 @@ public class TxnHandler {
}
}
- 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);
}
Modified: hive/trunk/metastore/src/test/org/apache/hadoop/hive/metastore/txn/TestTxnHandler.java
URL: http://svn.apache.org/viewvc/hive/trunk/metastore/src/test/org/apache/hadoop/hive/metastore/txn/TestTxnHandler.java?rev=1581486&r1=1581485&r2=1581486&view=diff
==============================================================================
--- hive/trunk/metastore/src/test/org/apache/hadoop/hive/metastore/txn/TestTxnHandler.java (original)
+++ hive/trunk/metastore/src/test/org/apache/hadoop/hive/metastore/txn/TestTxnHandler.java Tue Mar 25 19:47:41 2014
@@ -920,25 +920,6 @@ public class TestTxnHandler {
}
}
- @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);