You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hive.apache.org by ek...@apache.org on 2015/12/09 02:04:03 UTC
hive git commit: HIVE-12585 - fix TxnHandler connection leak(Eugene
Koifman, reviewd by Sergey Shelukhin)
Repository: hive
Updated Branches:
refs/heads/master b19b6952a -> 60a5ff1e2
HIVE-12585 - fix TxnHandler connection leak(Eugene Koifman, reviewd by Sergey Shelukhin)
Project: http://git-wip-us.apache.org/repos/asf/hive/repo
Commit: http://git-wip-us.apache.org/repos/asf/hive/commit/60a5ff1e
Tree: http://git-wip-us.apache.org/repos/asf/hive/tree/60a5ff1e
Diff: http://git-wip-us.apache.org/repos/asf/hive/diff/60a5ff1e
Branch: refs/heads/master
Commit: 60a5ff1e2d14f26ea5f1cb4d7793b2a003d894be
Parents: b19b695
Author: Eugene Koifman <ek...@hortonworks.com>
Authored: Tue Dec 8 16:06:15 2015 -0800
Committer: Eugene Koifman <ek...@hortonworks.com>
Committed: Tue Dec 8 16:59:06 2015 -0800
----------------------------------------------------------------------
.../hadoop/hive/metastore/txn/TxnHandler.java | 31 ++++++++++++++------
1 file changed, 22 insertions(+), 9 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/hive/blob/60a5ff1e/metastore/src/java/org/apache/hadoop/hive/metastore/txn/TxnHandler.java
----------------------------------------------------------------------
diff --git a/metastore/src/java/org/apache/hadoop/hive/metastore/txn/TxnHandler.java b/metastore/src/java/org/apache/hadoop/hive/metastore/txn/TxnHandler.java
index 4c5043b..8ff2195 100644
--- a/metastore/src/java/org/apache/hadoop/hive/metastore/txn/TxnHandler.java
+++ b/metastore/src/java/org/apache/hadoop/hive/metastore/txn/TxnHandler.java
@@ -17,6 +17,7 @@
*/
package org.apache.hadoop.hive.metastore.txn;
+import com.google.common.annotations.VisibleForTesting;
import com.jolbox.bonecp.BoneCPConfig;
import com.jolbox.bonecp.BoneCPDataSource;
import org.apache.commons.dbcp.ConnectionFactory;
@@ -528,6 +529,7 @@ public class TxnHandler {
else {
heartbeatLock(dbConn, extLockId);
}
+ closeDbConn(dbConn);
dbConn = getDbConn(Connection.TRANSACTION_SERIALIZABLE);
return checkLock(dbConn, extLockId);
} catch (SQLException e) {
@@ -936,22 +938,24 @@ public class TxnHandler {
/**
* For testing only, do not use.
*/
+ @VisibleForTesting
int numLocksInLockTable() throws SQLException, MetaException {
- Connection dbConn = getDbConn(Connection.TRANSACTION_READ_COMMITTED);
+ Connection dbConn = null;
Statement stmt = null;
+ ResultSet rs = null;
try {
+ dbConn = getDbConn(Connection.TRANSACTION_READ_COMMITTED);
stmt = dbConn.createStatement();
String s = "select count(*) from HIVE_LOCKS";
LOG.debug("Going to execute query <" + s + ">");
- ResultSet rs = stmt.executeQuery(s);
+ rs = stmt.executeQuery(s);
rs.next();
int rc = rs.getInt(1);
// Necessary to clean up the transaction in the db.
dbConn.rollback();
return rc;
} finally {
- closeDbConn(dbConn);
- closeStmt(stmt);
+ close(rs, stmt, dbConn);
}
}
@@ -978,7 +982,8 @@ public class TxnHandler {
return dbConn;
} catch (SQLException e){
if ((--rc) <= 0) throw e;
- LOG.error("There is a problem with a connection from the pool, retrying", e);
+ LOG.error("There is a problem with a connection from the pool, retrying(rc=" + rc + "): " +
+ getMessage(e), e);
}
}
}
@@ -1953,7 +1958,7 @@ public class TxnHandler {
}
if (!sawAtLeastOne) {
throw new MetaException("This should never happen! We already " +
- "checked the lock existed but now we can't find it!");
+ "checked the lock(" + JavaUtils.lockIdToString(extLockId) + ") existed but now we can't find it!");
}
return ourLockInfo;
} finally {
@@ -2118,6 +2123,9 @@ public class TxnHandler {
if ("bonecp".equals(connectionPooler)) {
BoneCPConfig config = new BoneCPConfig();
config.setJdbcUrl(driverUrl);
+ //if we are waiting for connection for 60s, something is really wrong
+ //better raise an error than hang forever
+ config.setConnectionTimeoutInMs(60000);
config.setMaxConnectionsPerPartition(10);
config.setPartitionCount(1);
config.setUser(user);
@@ -2276,9 +2284,14 @@ public class TxnHandler {
*/
private int getRequiredIsolationLevel() throws MetaException, SQLException {
if(dbProduct == null) {
- Connection tmp = getDbConn(Connection.TRANSACTION_READ_COMMITTED);
- determineDatabaseProduct(tmp);
- closeDbConn(tmp);
+ Connection tmp = null;
+ try {
+ tmp = getDbConn(Connection.TRANSACTION_READ_COMMITTED);
+ determineDatabaseProduct(tmp);
+ }
+ finally {
+ closeDbConn(tmp);
+ }
}
switch (dbProduct) {
case DERBY: