You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hive.apache.org by pr...@apache.org on 2015/05/19 10:04:34 UTC

hive git commit: HIVE-10744: LLAP: dags get stuck in yet another way (Prasanth Jayachandran)

Repository: hive
Updated Branches:
  refs/heads/llap 0db5368c0 -> 41d123412


HIVE-10744: LLAP: dags get stuck in yet another way (Prasanth Jayachandran)


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

Branch: refs/heads/llap
Commit: 41d1234121cc922e6dda704001d332224c3e6a69
Parents: 0db5368
Author: Prasanth Jayachandran <j....@gmail.com>
Authored: Tue May 19 01:04:18 2015 -0700
Committer: Prasanth Jayachandran <j....@gmail.com>
Committed: Tue May 19 01:04:18 2015 -0700

----------------------------------------------------------------------
 .../impl/EvictingPriorityBlockingQueue.java     |  8 +-
 .../llap/daemon/impl/TaskExecutorService.java   | 91 +++++++-------------
 .../llap/daemon/impl/TaskRunnerCallable.java    | 31 +++++--
 3 files changed, 61 insertions(+), 69 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hive/blob/41d12341/llap-server/src/java/org/apache/hadoop/hive/llap/daemon/impl/EvictingPriorityBlockingQueue.java
----------------------------------------------------------------------
diff --git a/llap-server/src/java/org/apache/hadoop/hive/llap/daemon/impl/EvictingPriorityBlockingQueue.java b/llap-server/src/java/org/apache/hadoop/hive/llap/daemon/impl/EvictingPriorityBlockingQueue.java
index f042562..e8d789b 100644
--- a/llap-server/src/java/org/apache/hadoop/hive/llap/daemon/impl/EvictingPriorityBlockingQueue.java
+++ b/llap-server/src/java/org/apache/hadoop/hive/llap/daemon/impl/EvictingPriorityBlockingQueue.java
@@ -49,19 +49,19 @@ public class EvictingPriorityBlockingQueue<E> {
     }
   }
 
-  public boolean isEmpty() {
+  public synchronized boolean isEmpty() {
     return deque.isEmpty();
   }
 
-  public E peek() {
+  public synchronized E peek() {
     return deque.peek();
   }
 
-  public E take() throws InterruptedException {
+  public synchronized E take() throws InterruptedException {
     return deque.take();
   }
 
-  public void remove(E e) {
+  public synchronized void remove(E e) {
     deque.remove(e);
   }
 }

http://git-wip-us.apache.org/repos/asf/hive/blob/41d12341/llap-server/src/java/org/apache/hadoop/hive/llap/daemon/impl/TaskExecutorService.java
----------------------------------------------------------------------
diff --git a/llap-server/src/java/org/apache/hadoop/hive/llap/daemon/impl/TaskExecutorService.java b/llap-server/src/java/org/apache/hadoop/hive/llap/daemon/impl/TaskExecutorService.java
index 5253e5b..08af1e2 100644
--- a/llap-server/src/java/org/apache/hadoop/hive/llap/daemon/impl/TaskExecutorService.java
+++ b/llap-server/src/java/org/apache/hadoop/hive/llap/daemon/impl/TaskExecutorService.java
@@ -18,9 +18,7 @@
 package org.apache.hadoop.hive.llap.daemon.impl;
 
 import java.util.Comparator;
-import java.util.Map;
 import java.util.concurrent.BlockingQueue;
-import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
 import java.util.concurrent.PriorityBlockingQueue;
@@ -30,6 +28,7 @@ import java.util.concurrent.ThreadPoolExecutor;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicInteger;
 
+import org.apache.commons.lang3.exception.ExceptionUtils;
 import org.apache.tez.runtime.task.EndReason;
 import org.apache.tez.runtime.task.TaskRunner2Result;
 import org.slf4j.Logger;
@@ -66,7 +65,6 @@ public class TaskExecutorService implements Scheduler<TaskRunnerCallable> {
   private static final Logger LOG = LoggerFactory.getLogger(TaskExecutorService.class);
   private static final boolean isInfoEnabled = LOG.isInfoEnabled();
   private static final boolean isDebugEnabled = LOG.isDebugEnabled();
-  private static final boolean isTraceEnabled = LOG.isTraceEnabled();
   private static final String TASK_EXECUTOR_THREAD_NAME_FORMAT = "Task-Executor-%d";
   private static final String WAIT_QUEUE_SCHEDULER_THREAD_NAME_FORMAT = "Wait-Queue-Scheduler-%d";
 
@@ -76,7 +74,6 @@ public class TaskExecutorService implements Scheduler<TaskRunnerCallable> {
   private final ListeningExecutorService executorService;
   private final EvictingPriorityBlockingQueue<TaskRunnerCallable> waitQueue;
   private final ListeningExecutorService waitQueueExecutorService;
-  private final Map<String, TaskRunnerCallable> idToTaskMap;
   private final BlockingQueue<TaskRunnerCallable> preemptionQueue;
   private final boolean enablePreemption;
   private final ThreadPoolExecutor threadPoolExecutor;
@@ -91,7 +88,6 @@ public class TaskExecutorService implements Scheduler<TaskRunnerCallable> {
         new SynchronousQueue<Runnable>(), // direct hand-off
         new ThreadFactoryBuilder().setNameFormat(TASK_EXECUTOR_THREAD_NAME_FORMAT).build());
     this.executorService = MoreExecutors.listeningDecorator(threadPoolExecutor);
-    this.idToTaskMap = new ConcurrentHashMap<>();
     this.preemptionQueue = new PriorityBlockingQueue<>(numExecutors,
         new PreemptionQueueComparator());
     this.enablePreemption = enablePreemption;
@@ -114,8 +110,9 @@ public class TaskExecutorService implements Scheduler<TaskRunnerCallable> {
     @Override
     public void run() {
       try {
-        if (waitQueue.isEmpty()) {
-          synchronized (waitLock) {
+
+        synchronized (waitLock) {
+          while (waitQueue.isEmpty()) {
             waitLock.wait();
           }
         }
@@ -140,8 +137,8 @@ public class TaskExecutorService implements Scheduler<TaskRunnerCallable> {
             waitQueue.remove(task);
           }
 
-          if (waitQueue.isEmpty()) {
-            synchronized (waitLock) {
+          synchronized (waitLock) {
+            while (waitQueue.isEmpty()) {
               waitLock.wait();
             }
           }
@@ -172,8 +169,8 @@ public class TaskExecutorService implements Scheduler<TaskRunnerCallable> {
   public void schedule(TaskRunnerCallable task) throws RejectedExecutionException {
     TaskRunnerCallable evictedTask = waitQueue.offer(task);
     if (evictedTask == null) {
-      if (isDebugEnabled) {
-        LOG.debug(task.getRequestId() + " added to wait queue.");
+      if (isInfoEnabled) {
+        LOG.info(task.getRequestId() + " added to wait queue.");
       }
 
       synchronized (waitLock) {
@@ -192,8 +189,7 @@ public class TaskExecutorService implements Scheduler<TaskRunnerCallable> {
     boolean scheduled = false;
     try {
       ListenableFuture<TaskRunner2Result> future = executorService.submit(task);
-      FutureCallback<TaskRunner2Result> wrappedCallback =
-          new InternalCompletionListener(task.getCallback());
+      FutureCallback<TaskRunner2Result> wrappedCallback = new InternalCompletionListener(task);
       Futures.addCallback(future, wrappedCallback);
 
       if (isInfoEnabled) {
@@ -203,11 +199,10 @@ public class TaskExecutorService implements Scheduler<TaskRunnerCallable> {
       // only tasks that cannot finish immediately are pre-emptable. In other words, if all inputs
       // to the tasks are not ready yet, the task is eligible for pre-emptable.
       if (enablePreemption && !task.canFinish()) {
-        if (isDebugEnabled) {
-          LOG.debug(task.getRequestId() + " is not finishable and pre-emption is enabled."
-              + "Adding it to pre-emption queue.");
+        if (isInfoEnabled) {
+          LOG.info(task.getRequestId() + " is not finishable. Adding it to pre-emption queue.");
         }
-        addTaskToPreemptionList(task);
+        preemptionQueue.add(task);
       }
 
       numSlotsAvailable.decrementAndGet();
@@ -216,21 +211,18 @@ public class TaskExecutorService implements Scheduler<TaskRunnerCallable> {
 
       if (enablePreemption && task.canFinish() && !preemptionQueue.isEmpty()) {
 
-        if (isTraceEnabled) {
-          LOG.trace("idToTaskMap: " + idToTaskMap.keySet());
+        if (isDebugEnabled) {
           LOG.trace("preemptionQueue: " + preemptionQueue);
         }
 
-        TaskRunnerCallable pRequest = preemptionQueue.peek();
+        TaskRunnerCallable pRequest = preemptionQueue.remove();
+        if (pRequest != null && !pRequest.isCompleted() && !pRequest.isKillInvoked()) {
 
-        // if some task completes, it will remove itself from pre-emption lists, making this null.
-        // if it happens bail out and schedule it again as a free slot will be available.
-        if (pRequest != null) {
-
-          if (isDebugEnabled) {
-            LOG.debug("Kill task invoked for " + pRequest.getRequestId() + " due to pre-emption");
+          if (isInfoEnabled) {
+            LOG.info("Kill task invoked for " + pRequest.getRequestId() + " due to pre-emption");
           }
 
+          pRequest.setKillInvoked();
           pRequest.killTask();
         }
       }
@@ -239,46 +231,37 @@ public class TaskExecutorService implements Scheduler<TaskRunnerCallable> {
     return scheduled;
   }
 
-  private synchronized void removeTaskFromPreemptionList(TaskRunnerCallable pRequest,
-      String requestId) {
-    idToTaskMap.remove(requestId);
-    preemptionQueue.remove(pRequest);
-  }
-
-  private synchronized void addTaskToPreemptionList(TaskRunnerCallable task) {
-    idToTaskMap.put(task.getRequestId(), task);
-    preemptionQueue.add(task);
-  }
-
   private final class InternalCompletionListener implements
       FutureCallback<TaskRunner2Result> {
-    private TaskRunnerCallable.TaskRunnerCallback wrappedCallback;
+    private TaskRunnerCallable task;
 
-    public InternalCompletionListener(TaskRunnerCallable.TaskRunnerCallback wrappedCallback) {
-      this.wrappedCallback = wrappedCallback;
+    public InternalCompletionListener(TaskRunnerCallable task) {
+      this.task = task;
     }
 
     @Override
     public void onSuccess(TaskRunner2Result result) {
-      wrappedCallback.onSuccess(result);
+      task.setCompleted();
+      task.getCallback().onSuccess(result);
       updatePreemptionListAndNotify(result.getEndReason());
     }
 
     @Override
     public void onFailure(Throwable t) {
-      wrappedCallback.onFailure(t);
+      task.setCompleted();
+      task.getCallback().onFailure(t);
       updatePreemptionListAndNotify(null);
+      LOG.error("Failed notification received: Stacktrace: " + ExceptionUtils.getStackTrace(t));
     }
 
     private void updatePreemptionListAndNotify(EndReason reason) {
       // if this task was added to pre-emption list, remove it
-      String taskId = wrappedCallback.getRequestId();
-      TaskRunnerCallable task = idToTaskMap.get(taskId);
-      String state = reason == null ? "FAILED" : reason.name();
-      if (enablePreemption && task != null) {
-        removeTaskFromPreemptionList(task, taskId);
-        if (isDebugEnabled) {
-          LOG.debug(task.getRequestId() + " request " + state + "! Removed from preemption list.");
+      if (enablePreemption) {
+        String state = reason == null ? "FAILED" : reason.name();
+        preemptionQueue.remove(task.getRequest());
+        if (isInfoEnabled) {
+          LOG.info(TaskRunnerCallable.getTaskIdentifierString(task.getRequest())
+              + " request " + state + "! Removed from preemption list.");
         }
       }
 
@@ -327,16 +310,6 @@ public class TaskExecutorService implements Scheduler<TaskRunnerCallable> {
   }
 
   @VisibleForTesting
-  public int getPreemptionListSize() {
-    return preemptionQueue.size();
-  }
-
-  @VisibleForTesting
-  public TaskRunnerCallable getPreemptionTask() {
-    return preemptionQueue.peek();
-  }
-
-  @VisibleForTesting
   public static class WaitQueueComparator implements Comparator<TaskRunnerCallable> {
 
     @Override

http://git-wip-us.apache.org/repos/asf/hive/blob/41d12341/llap-server/src/java/org/apache/hadoop/hive/llap/daemon/impl/TaskRunnerCallable.java
----------------------------------------------------------------------
diff --git a/llap-server/src/java/org/apache/hadoop/hive/llap/daemon/impl/TaskRunnerCallable.java b/llap-server/src/java/org/apache/hadoop/hive/llap/daemon/impl/TaskRunnerCallable.java
index 72fcf3b..e505070 100644
--- a/llap-server/src/java/org/apache/hadoop/hive/llap/daemon/impl/TaskRunnerCallable.java
+++ b/llap-server/src/java/org/apache/hadoop/hive/llap/daemon/impl/TaskRunnerCallable.java
@@ -26,6 +26,7 @@ import java.util.Map;
 import java.util.concurrent.ConcurrentMap;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
+import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.concurrent.atomic.AtomicLong;
 
 import org.apache.hadoop.conf.Configuration;
@@ -101,6 +102,8 @@ public class TaskRunnerCallable extends CallableWithNdc<TaskRunner2Result> {
   private boolean shouldRunTask = true;
   final Stopwatch runtimeWatch = new Stopwatch();
   final Stopwatch killtimerWatch = new Stopwatch();
+  private AtomicBoolean isCompleted;
+  private AtomicBoolean killInvoked;
 
   TaskRunnerCallable(LlapDaemonProtocolProtos.SubmitWorkRequestProto request, Configuration conf,
       ExecutionContext executionContext, Map<String, String> envMap,
@@ -130,6 +133,24 @@ public class TaskRunnerCallable extends CallableWithNdc<TaskRunner2Result> {
     this.metrics = metrics;
     this.requestId = getTaskAttemptId(request);
     this.killedTaskHandler = killedTaskHandler;
+    this.isCompleted = new AtomicBoolean(false);
+    this.killInvoked = new AtomicBoolean(false);
+  }
+
+  public void setCompleted() {
+    isCompleted.set(true);
+  }
+
+  public boolean isCompleted() {
+    return isCompleted.get();
+  }
+
+  public boolean isKillInvoked() {
+    return killInvoked.get();
+  }
+
+  public void setKillInvoked() {
+    killInvoked.set(true);
   }
 
   @Override
@@ -342,21 +363,19 @@ public class TaskRunnerCallable extends CallableWithNdc<TaskRunner2Result> {
     return new TaskRunnerCallback(request, this);
   }
 
+  public SubmitWorkRequestProto getRequest() {
+    return request;
+  }
+
   final class TaskRunnerCallback implements FutureCallback<TaskRunner2Result> {
 
     private final LlapDaemonProtocolProtos.SubmitWorkRequestProto request;
     private final TaskRunnerCallable taskRunnerCallable;
-    private final String requestId;
 
     TaskRunnerCallback(LlapDaemonProtocolProtos.SubmitWorkRequestProto request,
         TaskRunnerCallable taskRunnerCallable) {
       this.request = request;
       this.taskRunnerCallable = taskRunnerCallable;
-      this.requestId = getTaskIdentifierString(request);
-    }
-
-    public String getRequestId() {
-      return requestId;
     }
 
     // Errors are handled on the way over. FAIL/SUCCESS is informed via regular heartbeats. Killed