You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-commits@hadoop.apache.org by st...@apache.org on 2019/03/22 10:30:37 UTC

[hadoop] branch trunk updated: HADOOP-16181. HadoopExecutors shutdown Cleanup.

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

stevel pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/hadoop.git


The following commit(s) were added to refs/heads/trunk by this push:
     new d18d085  HADOOP-16181. HadoopExecutors shutdown Cleanup.
d18d085 is described below

commit d18d0859ebfc46a18fd9140b42fb95f1da96380e
Author: David Mollitor <da...@cloudera.com>
AuthorDate: Fri Mar 22 10:29:27 2019 +0000

    HADOOP-16181. HadoopExecutors shutdown Cleanup.
    
    Author:    David Mollitor <da...@cloudera.com>
---
 .../hadoop/util/concurrent/HadoopExecutors.java    | 58 ++++++++++++++--------
 1 file changed, 38 insertions(+), 20 deletions(-)

diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/concurrent/HadoopExecutors.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/concurrent/HadoopExecutors.java
index 7a04c30..7c09d93 100644
--- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/concurrent/HadoopExecutors.java
+++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/concurrent/HadoopExecutors.java
@@ -92,33 +92,51 @@ public final class HadoopExecutors {
   }
 
   /**
-   * Helper routine to shutdown a executorService.
+   * Helper routine to shutdown a {@link ExecutorService}. Will wait up to a
+   * certain timeout for the ExecutorService to gracefully shutdown. If the
+   * ExecutorService did not shutdown and there are still tasks unfinished after
+   * the timeout period, the ExecutorService will be notified to forcibly shut
+   * down. Another timeout period will be waited before giving up. So, at most,
+   * a shutdown will be allowed to wait up to twice the timeout value before
+   * giving up.
    *
-   * @param executorService - executorService
-   * @param logger          - Logger
-   * @param timeout         - Timeout
-   * @param unit            - TimeUnits, generally seconds.
+   * @param executorService ExecutorService to shutdown
+   * @param logger Logger
+   * @param timeout the maximum time to wait
+   * @param unit the time unit of the timeout argument
    */
   public static void shutdown(ExecutorService executorService, Logger logger,
       long timeout, TimeUnit unit) {
+
+    if (executorService == null) {
+      return;
+    }
+
     try {
-      if (executorService != null) {
-        executorService.shutdown();
-        try {
-          if (!executorService.awaitTermination(timeout, unit)) {
-            executorService.shutdownNow();
-          }
-
-          if (!executorService.awaitTermination(timeout, unit)) {
-            logger.error("Unable to shutdown properly.");
-          }
-        } catch (InterruptedException e) {
-          logger.error("Error attempting to shutdown.", e);
-          executorService.shutdownNow();
-        }
+      executorService.shutdown();
+
+      logger.info(
+          "Gracefully shutting down executor service. Waiting max {} {}",
+          timeout, unit);
+      if (!executorService.awaitTermination(timeout, unit)) {
+        logger.info(
+            "Executor service has not shutdown yet. Forcing. "
+                + "Will wait up to an additional {} {} for shutdown",
+            timeout, unit);
+        executorService.shutdownNow();
+      }
+      if (executorService.awaitTermination(timeout, unit)) {
+        logger.info("Succesfully shutdown executor service");
+      } else {
+        logger.error("Unable to shutdown executor service after timeout {} {}",
+            (2 * timeout), unit);
       }
+    } catch (InterruptedException e) {
+      logger.error("Interrupted while attempting to shutdown", e);
+      executorService.shutdownNow();
     } catch (Exception e) {
-      logger.error("Error during shutdown: ", e);
+      logger.warn("Exception closing executor service {}", e.getMessage());
+      logger.debug("Exception closing executor service", e);
       throw e;
     }
   }


---------------------------------------------------------------------
To unsubscribe, e-mail: common-commits-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-commits-help@hadoop.apache.org