yongzhi commented on a change in pull request #1559:
URL: https://github.com/apache/hive/pull/1559#discussion_r500433585



##########
File path: 
standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/txn/TxnHandler.java
##########
@@ -5250,20 +5252,22 @@ public LockHandle acquireLock(String key) throws 
MetaException {
           derbySemaphore.acquire();
         }
         LOG.debug(quoteString(key) + " locked by " + 
quoteString(TxnHandler.hostname));
+        needToCloseConn = false;  //The connection is good, we need not close 
it
         //OK, so now we have a lock
         return new LockHandleImpl(dbConn, stmt, rs, key, derbySemaphore);
       } catch (SQLException ex) {
-        rollbackDBConn(dbConn);
-        close(rs, stmt, dbConn);
         checkRetryable(dbConn, ex, "acquireLock(" + key + ")");
         throw new MetaException("Unable to lock " + quoteString(key) + " due 
to: " + getMessage(ex) + "; " + StringUtils.stringifyException(ex));
       }
       catch(InterruptedException ex) {
-        rollbackDBConn(dbConn);
-        close(rs, stmt, dbConn);
         throw new MetaException("Unable to lock " + quoteString(key) + " due 
to: " + ex.getMessage() + StringUtils.stringifyException(ex));
       }
       finally {
+        if (needToCloseConn) {
+          rollbackDBConn(dbConn);
+          close(rs, stmt, dbConn);
+          needToCloseConn = false;

Review comment:
       Will remove

##########
File path: 
standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/txn/TxnHandler.java
##########
@@ -5213,11 +5213,13 @@ public LockHandle acquireLock(String key) throws 
MetaException {
     Connection dbConn = null;
     Statement stmt = null;
     ResultSet rs = null;
+    boolean needToCloseConn = false;
     try {
       try {
         String sqlStmt = sqlGenerator.addForUpdateClause("SELECT 
\"MT_COMMENT\" FROM \"AUX_TABLE\" WHERE \"MT_KEY1\"=" + quoteString(key) + " 
and \"MT_KEY2\"=0");
         lockInternal();
         dbConn = getDbConn(Connection.TRANSACTION_READ_COMMITTED, 
connPoolMutex);
+        needToCloseConn = true;

Review comment:
       AutoCloseable may not be necessary, lockHandle implement releaseLocks()  
which close the connection.  It uses with acquireLock in our codes in following 
pattern:
      TxnStore.MutexAPI.LockHandle handle = null;
       try {
         handle = 
txnHandler.getMutexAPI().acquireLock(TxnStore.MUTEX_KEY.TxnCleaner.name());
         long start = System.currentTimeMillis();
         txnHandler.cleanEmptyAbortedAndCommittedTxns();
         LOG.debug("Txn cleaner service took: {} seconds.", 
elapsedSince(start));
       } catch (Throwable t) {
         LOG.error("Unexpected error in thread: {}, message: {}", 
Thread.currentThread().getName(), t.getMessage(), t);
       } finally {
         if (handle != null) {
           handle.releaseLocks();
         }
       }




----------------------------------------------------------------
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.

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