You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hive.apache.org by sa...@apache.org on 2018/12/21 09:39:34 UTC
hive git commit: HIVE-20989: JDBC - The GetOperationStatus + log can
block query progress via sleep() (Sankar Hariappan,
reviewed by Anishek Agarwal)
Repository: hive
Updated Branches:
refs/heads/master 6e7767bc3 -> 04cc68116
HIVE-20989: JDBC - The GetOperationStatus + log can block query progress via sleep() (Sankar Hariappan, reviewed by Anishek Agarwal)
Signed-off-by: Sankar Hariappan <sa...@apache.org>
Project: http://git-wip-us.apache.org/repos/asf/hive/repo
Commit: http://git-wip-us.apache.org/repos/asf/hive/commit/04cc6811
Tree: http://git-wip-us.apache.org/repos/asf/hive/tree/04cc6811
Diff: http://git-wip-us.apache.org/repos/asf/hive/diff/04cc6811
Branch: refs/heads/master
Commit: 04cc68116d8f3655204cf11c836f46460f948344
Parents: 6e7767b
Author: Sankar Hariappan <sa...@apache.org>
Authored: Fri Dec 21 15:08:57 2018 +0530
Committer: Sankar Hariappan <sa...@apache.org>
Committed: Fri Dec 21 15:08:57 2018 +0530
----------------------------------------------------------------------
.../org/apache/hive/service/cli/CLIService.java | 5 +++--
.../hive/service/cli/operation/Operation.java | 18 ++++++++++++++++++
2 files changed, 21 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/hive/blob/04cc6811/service/src/java/org/apache/hive/service/cli/CLIService.java
----------------------------------------------------------------------
diff --git a/service/src/java/org/apache/hive/service/cli/CLIService.java b/service/src/java/org/apache/hive/service/cli/CLIService.java
index 22c4026..957e11b 100644
--- a/service/src/java/org/apache/hive/service/cli/CLIService.java
+++ b/service/src/java/org/apache/hive/service/cli/CLIService.java
@@ -498,14 +498,15 @@ public class CLIService extends CompositeService implements ICLIService {
SessionState sessionState = operation.getParentSession().getSessionState();
long startTime = System.nanoTime();
int timeOutMs = 8;
+ boolean terminated = operation.isDone();
try {
- while (sessionState.getProgressMonitor() == null && !operation.isDone()) {
+ while ((sessionState.getProgressMonitor() == null) && !terminated) {
long remainingMs = (PROGRESS_MAX_WAIT_NS - (System.nanoTime() - startTime)) / 1000000l;
if (remainingMs <= 0) {
LOG.debug("timed out and hence returning progress log as NULL");
return new JobProgressUpdate(ProgressMonitor.NULL);
}
- Thread.sleep(Math.min(remainingMs, timeOutMs));
+ terminated = operation.waitToTerminate(Math.min(remainingMs, timeOutMs));
timeOutMs <<= 1;
}
} catch (InterruptedException e) {
http://git-wip-us.apache.org/repos/asf/hive/blob/04cc6811/service/src/java/org/apache/hive/service/cli/operation/Operation.java
----------------------------------------------------------------------
diff --git a/service/src/java/org/apache/hive/service/cli/operation/Operation.java b/service/src/java/org/apache/hive/service/cli/operation/Operation.java
index 32c24e8..5109981 100644
--- a/service/src/java/org/apache/hive/service/cli/operation/Operation.java
+++ b/service/src/java/org/apache/hive/service/cli/operation/Operation.java
@@ -22,6 +22,7 @@ import java.util.EnumSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
+import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.ScheduledExecutorService;
@@ -71,6 +72,7 @@ public abstract class Operation {
private long operationTimeout;
private volatile long lastAccessTime;
private final long beginTime;
+ private final CountDownLatch opTerminateMonitorLatch;
protected long operationStart;
protected long operationComplete;
@@ -89,6 +91,7 @@ public abstract class Operation {
Map<String, String> confOverlay, OperationType opType) {
this.parentSession = parentSession;
this.opHandle = new OperationHandle(opType, parentSession.getProtocolVersion());
+ opTerminateMonitorLatch = new CountDownLatch(1);
beginTime = System.currentTimeMillis();
lastAccessTime = beginTime;
operationTimeout = HiveConf.getTimeVar(parentSession.getHiveConf(),
@@ -209,6 +212,16 @@ public abstract class Operation {
return state.isTerminal();
}
+ /**
+ * Wait until the operation terminates and returns false if timeout.
+ * @param timeOutMs - timeout in milli-seconds
+ * @return true if operation is terminated or false if timed-out
+ * @throws InterruptedException
+ */
+ public boolean waitToTerminate(long timeOutMs) throws InterruptedException {
+ return opTerminateMonitorLatch.await(timeOutMs, TimeUnit.MILLISECONDS);
+ }
+
protected void createOperationLog() {
if (parentSession.isOperationLogEnabled()) {
File operationLogFile = new File(parentSession.getOperationLogSessionDir(), queryState.getQueryId());
@@ -400,6 +413,11 @@ public abstract class Operation {
markOperationCompletedTime();
break;
}
+
+ if (state.isTerminal()) {
+ // Unlock the execution thread as operation is already terminated.
+ opTerminateMonitorLatch.countDown();
+ }
}
public long getOperationComplete() {