This is an automated email from the ASF dual-hosted git repository.

zjffdu pushed a commit to branch branch-0.9
in repository https://gitbox.apache.org/repos/asf/zeppelin.git


The following commit(s) were added to refs/heads/branch-0.9 by this push:
     new 10c73c0  [ZEPPELIN-5185]. HiveMonitor thread is never finished 
sometimes
10c73c0 is described below

commit 10c73c0e0088d35edc093c855b7dbb7f3ebea96e
Author: Jeff Zhang <[email protected]>
AuthorDate: Wed Jan 6 13:48:47 2021 +0800

    [ZEPPELIN-5185]. HiveMonitor thread is never finished sometimes
    
    ### What is this PR for?
    
    Sometimes, hive monitor thread will never exit when getting the following 
exception (see screenshot)
    
![image](https://user-images.githubusercontent.com/164491/103433552-b216a580-4c2d-11eb-9bd9-abb61d93c21a.png)
    
    This PR would exit the monitor thread when any exception happens and also 
introduce property `zeppelin.jdbc.hive.monitor.query_interval` to control the 
query interval.
    
    ### What type of PR is it?
    [Bug Fix]
    
    ### Todos
    * [ ] - Task
    
    ### What is the Jira issue?
    * https://issues.apache.org/jira/browse/ZEPPELIN-5185
    
    ### How should this be tested?
    * CI pass
    
    ### Screenshots (if appropriate)
    
    ### Questions:
    * Does the licenses files need update? No
    * Is there breaking changes for older versions? No
    * Does this needs documentation? No
    
    Author: Jeff Zhang <[email protected]>
    
    Closes #4010 from zjffdu/ZEPPELIN-5185 and squashes the following commits:
    
    a6dc388af [Jeff Zhang] address comment
    8d0cf88d8 [Jeff Zhang] swap try and while
    529a56889 [Jeff Zhang] address comment
    3f49c7875 [Jeff Zhang] [ZEPPELIN-5185]. HiveMonitor thread is never 
finished sometimes
    
    (cherry picked from commit 930bac193ad258e5308c5930e2d5fbadf92a24d4)
    Signed-off-by: Jeff Zhang <[email protected]>
---
 .../org/apache/zeppelin/jdbc/hive/HiveUtils.java   | 28 +++++++++-------------
 jdbc/src/main/resources/interpreter-setting.json   |  7 ++++++
 2 files changed, 18 insertions(+), 17 deletions(-)

diff --git a/jdbc/src/main/java/org/apache/zeppelin/jdbc/hive/HiveUtils.java 
b/jdbc/src/main/java/org/apache/zeppelin/jdbc/hive/HiveUtils.java
index 16a242c..dd3b837 100644
--- a/jdbc/src/main/java/org/apache/zeppelin/jdbc/hive/HiveUtils.java
+++ b/jdbc/src/main/java/org/apache/zeppelin/jdbc/hive/HiveUtils.java
@@ -71,11 +71,14 @@ public class HiveUtils {
     final ProgressBar progressBar = progressBarTemp;
     final long timeoutThreshold = Long.parseLong(
             
jdbcInterpreter.getProperty("zeppelin.jdbc.hive.timeout.threshold", "" + 60 * 
1000));
+    final long queryInterval = 
Long.parseLong(jdbcInterpreter.getProperty("zeppelin.jdbc.hive.monitor.query_interval",
+            DEFAULT_QUERY_PROGRESS_INTERVAL + ""));
     Thread thread = new Thread(() -> {
       boolean jobLaunched = false;
       long jobLastActiveTime = System.currentTimeMillis();
-      while (hiveStmt.hasMoreLogs() && !Thread.interrupted()) {
-        try {
+      try {
+        while (hiveStmt.hasMoreLogs() && !hiveStmt.isClosed() && 
!Thread.interrupted()) {
+          Thread.sleep(queryInterval);
           List<String> logs = hiveStmt.getQueryLog();
           String logsOutput = StringUtils.join(logs, System.lineSeparator());
           LOGGER.debug("Hive job output: " + logsOutput);
@@ -122,23 +125,14 @@ public class HiveUtils {
               break;
             }
           }
-          // refresh logs every 1 second.
-          Thread.sleep(DEFAULT_QUERY_PROGRESS_INTERVAL);
-        } catch (Exception e) {
-          LOGGER.warn("Fail to write output", e);
-        } finally {
-          try {
-            // Sometimes, maybe hiveStmt was closed unnormally, 
hiveStmt.hasMoreLogs() will be true,
-            // this loop cannot jump out, and exceptions thrown.
-            // Add the below codes in case.
-            if (hiveStmt.isClosed()){
-              break;
-            }
-          } catch (SQLException e) {
-            LOGGER.warn("hiveStmt closed unnormally", e);
-          }
         }
+      } catch (InterruptedException e) {
+        LOGGER.warn("Hive monitor thread is interrupted", e);
+        Thread.currentThread().interrupt();
+      } catch (Exception e) {
+        LOGGER.warn("Fail to monitor hive statement", e);
       }
+
       LOGGER.info("HiveMonitor-Thread is finished");
     });
     thread.setName("HiveMonitor-Thread");
diff --git a/jdbc/src/main/resources/interpreter-setting.json 
b/jdbc/src/main/resources/interpreter-setting.json
index 41fecd0..1b2b4d4 100644
--- a/jdbc/src/main/resources/interpreter-setting.json
+++ b/jdbc/src/main/resources/interpreter-setting.json
@@ -136,6 +136,13 @@
         "defaultValue": "60000",
         "description": "Timeout for hive job timeout",
         "type": "number"
+      },
+      "zeppelin.jdbc.hive.monitor.query_interval": {
+        "envName": null,
+        "propertyName": "zeppelin.jdbc.hive.monitor.query_interval",
+        "defaultValue": "1000",
+        "description": "Query interval for hive statement",
+        "type": "number"
       }
     },
     "editor": {

Reply via email to