nrg4878 commented on PR #3388:
URL: https://github.com/apache/hive/pull/3388#issuecomment-1231084456

   I had tested this change locally and it seemed to have worked. I was able to 
test it after keeping beeline session idle for a while before trying another 
command.
   diff --git 
a/standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/dataconnector/jdbc/AbstractJDBCConnectorProvider.java
 
b/standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/dataconnector/jdbc/AbstractJDBCConnectorProvider.java
   index d392a2567a..8d161f72ae 100644
   --- 
a/standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/dataconnector/jdbc/AbstractJDBCConnectorProvider.java
   +++ 
b/standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/dataconnector/jdbc/AbstractJDBCConnectorProvider.java
   @@ -116,6 +116,7 @@ public AbstractJDBCConnectorProvider(String dbName, 
DataConnector dataConn, Stri
      }
    
      protected Connection getConnection() {
   +    Connection conn;
        try {
          if (!isOpen)
            open();
   @@ -123,8 +124,29 @@ protected Connection getConnection() {
          throw new RuntimeException(ce.getMessage(), ce);
        }
    
   -    if (handle instanceof Connection)
   -      return (Connection)handle;
   +    if (handle instanceof Connection) {
   +      conn = (Connection) handle;
   +      try {
   +        if (conn.isValid(3))
   +          return conn;
   +      } catch (SQLException sqle) {
   +        // not error, just re-open the connection
   +        LOG.warn("Connection validation failed, resetting connection", 
sqle);
   +      }
   +
   +      try {
   +        close();
   +      } catch (Exception e) {
   +        LOG.warn("Connection close failed, could have timed out. 
Resetting", e);
   +      }
   +
   +      try {
   +        open();
   +        return (Connection) handle;
   +      } catch (ConnectException ce) {
   +        throw new RuntimeException(ce.getMessage(), ce);
   +      }
   +    }
    
        throw new RuntimeException("unexpected type for connection handle");
      }
   @@ -136,6 +158,8 @@ protected Connection getConnection() {
          } catch (SQLException sqle) {
            LOG.warn("Could not close jdbc connection to " + jdbcUrl, sqle);
            throw new RuntimeException(sqle);
   +      } finally {
   +        isOpen = false;
          }
        }
      }
   
   Let me know what you think. logically, it is similar to ur implementation. I 
am using the boolean isOpen while you are using a method. 
   


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

To unsubscribe, e-mail: [email protected]

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