You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hive.apache.org by jx...@apache.org on 2017/04/14 15:47:29 UTC

[2/2] hive git commit: HIVE-16433: Not nullify variable "rj" to avoid NPE due to race condition in ExecDriver (Zhihai Xu via Jimmy Xiang)

HIVE-16433: Not nullify variable "rj" to avoid NPE due to race condition in ExecDriver (Zhihai Xu via Jimmy Xiang)


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

Branch: refs/heads/master
Commit: a496e581152425773080aac48cf479e493cd5b74
Parents: e5a6b30
Author: Zhihai Xu <zh...@gmail.com>
Authored: Fri Apr 14 08:41:41 2017 -0700
Committer: Jimmy Xiang <jx...@apache.org>
Committed: Fri Apr 14 08:41:41 2017 -0700

----------------------------------------------------------------------
 .../hadoop/hive/ql/exec/mr/ExecDriver.java      | 38 +++++++++++++-------
 1 file changed, 26 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hive/blob/a496e581/ql/src/java/org/apache/hadoop/hive/ql/exec/mr/ExecDriver.java
----------------------------------------------------------------------
diff --git a/ql/src/java/org/apache/hadoop/hive/ql/exec/mr/ExecDriver.java b/ql/src/java/org/apache/hadoop/hive/ql/exec/mr/ExecDriver.java
index a5c0fcd..20ecbcd 100644
--- a/ql/src/java/org/apache/hadoop/hive/ql/exec/mr/ExecDriver.java
+++ b/ql/src/java/org/apache/hadoop/hive/ql/exec/mr/ExecDriver.java
@@ -117,6 +117,8 @@ public class ExecDriver extends Task<MapredWork> implements Serializable, Hadoop
   protected transient JobConf job;
   public static MemoryMXBean memoryMXBean;
   protected HadoopJobExecHelper jobExecHelper;
+  private transient boolean isShutdown = false;
+  private transient boolean jobKilled = false;
 
   protected static transient final Logger LOG = LoggerFactory.getLogger(ExecDriver.class);
 
@@ -413,10 +415,7 @@ public class ExecDriver extends Task<MapredWork> implements Serializable, Hadoop
 
       if (driverContext.isShutdown()) {
         LOG.warn("Task was cancelled");
-        if (rj != null) {
-          rj.killJob();
-          rj = null;
-        }
+        killJob();
         return 5;
       }
 
@@ -449,7 +448,7 @@ public class ExecDriver extends Task<MapredWork> implements Serializable, Hadoop
 
         if (rj != null) {
           if (returnVal != 0) {
-            rj.killJob();
+            killJob();
           }
           jobID = rj.getID().toString();
         }
@@ -857,22 +856,37 @@ public class ExecDriver extends Task<MapredWork> implements Serializable, Hadoop
     ss.getHiveHistory().logPlanProgress(queryPlan);
   }
 
+  public boolean isTaskShutdown() {
+    return isShutdown;
+  }
+
   @Override
   public void shutdown() {
     super.shutdown();
-    if (rj != null) {
+    killJob();
+    isShutdown = true;
+  }
+
+  @Override
+  public String getExternalHandle() {
+    return this.jobID;
+  }
+
+  private void killJob() {
+    boolean needToKillJob = false;
+    synchronized(this) {
+      if (rj != null && !jobKilled) {
+        jobKilled = true;
+        needToKillJob = true;
+      }
+    }
+    if (needToKillJob) {
       try {
         rj.killJob();
       } catch (Exception e) {
         LOG.warn("failed to kill job " + rj.getID(), e);
       }
-      rj = null;
     }
   }
-
-  @Override
-  public String getExternalHandle() {
-    return this.jobID;
-  }
 }