hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From su...@apache.org
Subject [05/50] [abbrv] hadoop git commit: HDFS-9849. DiskBalancer: reduce lock path in shutdown code. Contributed by Yuanbo Liu.
Date Wed, 14 Sep 2016 02:43:43 GMT
HDFS-9849. DiskBalancer: reduce lock path in shutdown code. Contributed by Yuanbo Liu.


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

Branch: refs/heads/YARN-2915
Commit: baab48922a301d639ea84ecf00d8a7616acd950d
Parents: 35c5943
Author: Anu Engineer <aengineer@apache.org>
Authored: Thu Sep 8 20:00:42 2016 -0700
Committer: Anu Engineer <aengineer@apache.org>
Committed: Thu Sep 8 20:00:42 2016 -0700

----------------------------------------------------------------------
 .../hdfs/server/datanode/DiskBalancer.java       | 19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hadoop/blob/baab4892/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/DiskBalancer.java
----------------------------------------------------------------------
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/DiskBalancer.java
b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/DiskBalancer.java
index ec72d97..e9e2e5b 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/DiskBalancer.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/DiskBalancer.java
@@ -121,17 +121,23 @@ public class DiskBalancer {
    */
   public void shutdown() {
     lock.lock();
+    boolean needShutdown = false;
     try {
       this.isDiskBalancerEnabled = false;
       this.currentResult = Result.NO_PLAN;
       if ((this.future != null) && (!this.future.isDone())) {
         this.currentResult = Result.PLAN_CANCELLED;
         this.blockMover.setExitFlag();
-        shutdownExecutor();
+        scheduler.shutdown();
+        needShutdown = true;
       }
     } finally {
       lock.unlock();
     }
+    // no need to hold lock while shutting down executor.
+    if (needShutdown) {
+      shutdownExecutor();
+    }
   }
 
   /**
@@ -139,7 +145,6 @@ public class DiskBalancer {
    */
   private void shutdownExecutor() {
     final int secondsTowait = 10;
-    scheduler.shutdown();
     try {
       if (!scheduler.awaitTermination(secondsTowait, TimeUnit.SECONDS)) {
         scheduler.shutdownNow();
@@ -228,6 +233,7 @@ public class DiskBalancer {
    */
   public void cancelPlan(String planID) throws DiskBalancerException {
     lock.lock();
+    boolean needShutdown = false;
     try {
       checkDiskBalancerEnabled();
       if (this.planID == null ||
@@ -239,13 +245,18 @@ public class DiskBalancer {
             DiskBalancerException.Result.NO_SUCH_PLAN);
       }
       if (!this.future.isDone()) {
-        this.blockMover.setExitFlag();
-        shutdownExecutor();
         this.currentResult = Result.PLAN_CANCELLED;
+        this.blockMover.setExitFlag();
+        scheduler.shutdown();
+        needShutdown = true;
       }
     } finally {
       lock.unlock();
     }
+    // no need to hold lock while shutting down executor.
+    if (needShutdown) {
+      shutdownExecutor();
+    }
   }
 
   /**


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


Mime
View raw message