You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kylin.apache.org by ma...@apache.org on 2015/09/11 12:41:54 UTC

incubator-kylin git commit: KYLIN-948 Hive connection resouce not close

Repository: incubator-kylin
Updated Branches:
  refs/heads/1.x-staging 876079b51 -> c0ef677cb


KYLIN-948 Hive connection resouce not close

Signed-off-by: honma <ho...@ebay.com>


Project: http://git-wip-us.apache.org/repos/asf/incubator-kylin/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-kylin/commit/c0ef677c
Tree: http://git-wip-us.apache.org/repos/asf/incubator-kylin/tree/c0ef677c
Diff: http://git-wip-us.apache.org/repos/asf/incubator-kylin/diff/c0ef677c

Branch: refs/heads/1.x-staging
Commit: c0ef677cbfaf19351ac8beeef839aec79138fe12
Parents: 876079b
Author: wangxiaoyu8 <wa...@jd.com>
Authored: Wed Sep 9 17:22:18 2015 +0800
Committer: honma <ho...@ebay.com>
Committed: Fri Sep 11 18:44:03 2015 +0800

----------------------------------------------------------------------
 .../apache/kylin/monitor/HiveJdbcClient.java    | 45 ++++++++++++++------
 1 file changed, 33 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-kylin/blob/c0ef677c/monitor/src/main/java/org/apache/kylin/monitor/HiveJdbcClient.java
----------------------------------------------------------------------
diff --git a/monitor/src/main/java/org/apache/kylin/monitor/HiveJdbcClient.java b/monitor/src/main/java/org/apache/kylin/monitor/HiveJdbcClient.java
index 2eda2e8..ffe3cc0 100644
--- a/monitor/src/main/java/org/apache/kylin/monitor/HiveJdbcClient.java
+++ b/monitor/src/main/java/org/apache/kylin/monitor/HiveJdbcClient.java
@@ -28,16 +28,16 @@ import java.sql.Statement;
 import java.text.SimpleDateFormat;
 import java.util.Calendar;
 
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+
 import org.apache.log4j.Logger;
 import org.datanucleus.util.StringUtils;
 import org.w3c.dom.Document;
 import org.w3c.dom.NodeList;
 import org.xml.sax.SAXException;
 
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.ParserConfigurationException;
-
 /**
  * @author jiazhong
  */
@@ -93,20 +93,20 @@ public class HiveJdbcClient {
 
         MAP_QUEUE_NAME = getQueueName();
 
-        if(org.apache.commons.lang.StringUtils.isEmpty(MAP_QUEUE_NAME)){
+        if (org.apache.commons.lang.StringUtils.isEmpty(MAP_QUEUE_NAME)) {
             MAP_QUEUE_NAME = monitorConfig.getKylinMapJobQueue();
         }
 
-        logger.info("mapred.job.queue.name:"+MAP_QUEUE_NAME);
+        logger.info("mapred.job.queue.name:" + MAP_QUEUE_NAME);
 
         String CON_URL = monitorConfig.getHiveJdbcConUrl();
 
         String USER_NAME = monitorConfig.getHiveJdbcConUserName();
         String PASSWD = monitorConfig.getHiveJdbcConPasswd();
 
-        Connection con = DriverManager.getConnection(CON_URL,USER_NAME,PASSWD);
+        Connection con = DriverManager.getConnection(CON_URL, USER_NAME, PASSWD);
         Statement stmt = con.createStatement();
-        stmt.execute("set mapred.job.queue.name="+MAP_QUEUE_NAME);
+        stmt.execute("set mapred.job.queue.name=" + MAP_QUEUE_NAME);
         ResultSet res = null;
 
         SQL_GENERATE_QUERY_LOG_TABLE = generateQueryLogSql();
@@ -187,7 +187,27 @@ public class HiveJdbcClient {
             FileUtils.appendResultToHdfs(each_day_percentile_file, new String[] { res.getString(1), res.getString(2), res.getString(3) });
             logger.info(res.getString(1) + "," + res.getString(2) + "," + res.getString(3));
         }
-
+        if (res != null) {
+            try {
+                res.close();
+            } catch (SQLException e) {
+                logger.error("failed to close", e);
+            }
+        }
+        if (stmt != null) {
+            try {
+                stmt.close();
+            } catch (SQLException e) {
+                logger.error("failed to close", e);
+            }
+        }
+        if (con != null) {
+            try {
+                con.close();
+            } catch (SQLException e) {
+                logger.error("failed to close", e);
+            }
+        }
     }
 
     public String generateQueryLogSql() {
@@ -228,8 +248,8 @@ public class HiveJdbcClient {
 
     public String getQueueName() throws IOException {
         String queueName = "";
-        InputStream stream =  this.getClass().getClassLoader().getResourceAsStream(KYLIN_JOB_CONF_XML);
-        if (stream!=null) {
+        InputStream stream = this.getClass().getClassLoader().getResourceAsStream(KYLIN_JOB_CONF_XML);
+        if (stream != null) {
             DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
             DocumentBuilder builder;
             Document doc;
@@ -253,6 +273,7 @@ public class HiveJdbcClient {
         }
         return queueName;
     }
+
     public String monthStasticSqlConvert(String sql) {
 
         SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
@@ -264,4 +285,4 @@ public class HiveJdbcClient {
         return sql.replace("[START_DATE]", "'" + startDate + "'").replace("[END_DATE]", "'" + endDate + "'");
     }
 
-}
\ No newline at end of file
+}