Repository: hive
Updated Branches:
  refs/heads/branch-2 6dbec04dd -> 042296fbc


HIVE-18671: Lock not released after Hive on Spark query was cancelled (Yongzhi 
Chen, reviewed by Aihua Xu)


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

Branch: refs/heads/branch-2
Commit: 042296fbcd4f3a6dee6f06aa3c997a594bc73391
Parents: 6dbec04
Author: Yongzhi Chen <ych...@apache.org>
Authored: Tue Feb 13 10:03:53 2018 -0500
Committer: Yongzhi Chen <ych...@apache.org>
Committed: Tue Feb 13 10:35:59 2018 -0500

----------------------------------------------------------------------
 .../ql/exec/spark/status/RemoteSparkJobMonitor.java |  6 ++++++
 .../hadoop/hive/ql/exec/spark/TestSparkTask.java    | 16 ++++++++++++++++
 2 files changed, 22 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hive/blob/042296fb/ql/src/java/org/apache/hadoop/hive/ql/exec/spark/status/RemoteSparkJobMonitor.java
----------------------------------------------------------------------
diff --git 
a/ql/src/java/org/apache/hadoop/hive/ql/exec/spark/status/RemoteSparkJobMonitor.java
 
b/ql/src/java/org/apache/hadoop/hive/ql/exec/spark/status/RemoteSparkJobMonitor.java
index dd73f3e..dc6e951 100644
--- 
a/ql/src/java/org/apache/hadoop/hive/ql/exec/spark/status/RemoteSparkJobMonitor.java
+++ 
b/ql/src/java/org/apache/hadoop/hive/ql/exec/spark/status/RemoteSparkJobMonitor.java
@@ -148,6 +148,12 @@ public class RemoteSparkJobMonitor extends SparkJobMonitor 
{
           done = true;
           rc = 3;
           break;
+        case CANCELLED:
+          console.printInfo("Status: Cancelled");
+          running = false;
+          done = true;
+          rc = 3;
+          break;
         }
 
         if (!done) {

http://git-wip-us.apache.org/repos/asf/hive/blob/042296fb/ql/src/test/org/apache/hadoop/hive/ql/exec/spark/TestSparkTask.java
----------------------------------------------------------------------
diff --git 
a/ql/src/test/org/apache/hadoop/hive/ql/exec/spark/TestSparkTask.java 
b/ql/src/test/org/apache/hadoop/hive/ql/exec/spark/TestSparkTask.java
index 4c7ec76..3229ea8 100644
--- a/ql/src/test/org/apache/hadoop/hive/ql/exec/spark/TestSparkTask.java
+++ b/ql/src/test/org/apache/hadoop/hive/ql/exec/spark/TestSparkTask.java
@@ -20,11 +20,18 @@ package org.apache.hadoop.hive.ql.exec.spark;
 import static org.mockito.Mockito.never;
 import static org.mockito.Mockito.times;
 import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
 
 import java.io.IOException;
 
 import org.apache.hadoop.hive.common.metrics.common.Metrics;
 import org.apache.hadoop.hive.common.metrics.common.MetricsConstant;
+import org.apache.hadoop.hive.conf.HiveConf;
+import org.apache.hadoop.hive.ql.exec.spark.status.RemoteSparkJobMonitor;
+import org.apache.hadoop.hive.ql.exec.spark.status.impl.RemoteSparkJobStatus;
+import org.apache.hadoop.hive.ql.plan.SparkWork;
+import org.apache.hive.spark.client.JobHandle.State;
+import org.junit.Assert;
 import org.junit.Test;
 import org.mockito.Mockito;
 
@@ -43,4 +50,13 @@ public class TestSparkTask {
     verify(mockMetrics, 
never()).incrementCounter(MetricsConstant.HIVE_MR_TASKS);
   }
 
+  @Test
+  public void testRemoteSparkCancel() {
+    RemoteSparkJobStatus jobSts = Mockito.mock(RemoteSparkJobStatus.class);
+    when(jobSts.getRemoteJobState()).thenReturn(State.CANCELLED);
+    when(jobSts.isRemoteActive()).thenReturn(true);
+    HiveConf hiveConf = new HiveConf();
+    RemoteSparkJobMonitor remoteSparkJobMonitor = new 
RemoteSparkJobMonitor(hiveConf, jobSts);
+    Assert.assertEquals(remoteSparkJobMonitor.startMonitor(), 3);
+  }
 }

Reply via email to