From 08f061b3665935b8c9c368c21b3483e064968ab4 Mon Sep 17 00:00:00 2001 From: Eli Collins Date: Wed, 12 Sep 2012 04:12:49 +0000 Subject: [PATCH] HDFS-3664. BlockManager race when stopping active services. Contributed by Colin Patrick McCabe git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/branch-2@1383756 13f79535-47bb-0310-9956-ffa450edef68 --- hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt | 3 +++ .../hadoop/hdfs/server/blockmanagement/BlockManager.java | 7 +++---- .../hdfs/server/blockmanagement/DatanodeManager.java | 8 +++++++- .../hdfs/server/blockmanagement/HeartbeatManager.java | 5 +++++ 4 files changed, 18 insertions(+), 5 deletions(-) diff --git a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt index c60c67daaf6..bdaf7a7880a 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt +++ b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt @@ -590,6 +590,9 @@ Release 2.0.2-alpha - 2012-09-07 HDFS-2757. Cannot read a local block that's being written to when using the local read short circuit. (Jean-Daniel Cryans via eli) + + HDFS-3664. BlockManager race when stopping active services. + (Colin Patrick McCabe via eli) BREAKDOWN OF HDFS-3042 SUBTASKS diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/BlockManager.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/BlockManager.java index 45612186d98..e851279ba07 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/BlockManager.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/BlockManager.java @@ -364,11 +364,10 @@ public class BlockManager { replicationThread.join(3000); } } catch (InterruptedException ie) { - } finally { - if (pendingReplications != null) pendingReplications.stop(); - blocksMap.close(); - datanodeManager.close(); } + datanodeManager.close(); + pendingReplications.stop(); + blocksMap.close(); } /** @return the datanodeManager */ diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/DatanodeManager.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/DatanodeManager.java index 3ccbc8462a3..5f28f99c7df 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/DatanodeManager.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/DatanodeManager.java @@ -183,7 +183,13 @@ public class DatanodeManager { } void close() { - if (decommissionthread != null) decommissionthread.interrupt(); + if (decommissionthread != null) { + decommissionthread.interrupt(); + try { + decommissionthread.join(3000); + } catch (InterruptedException e) { + } + } heartbeatManager.close(); } diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/HeartbeatManager.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/HeartbeatManager.java index 449619ced72..30300077077 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/HeartbeatManager.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/HeartbeatManager.java @@ -74,6 +74,11 @@ class HeartbeatManager implements DatanodeStatistics { void close() { heartbeatThread.interrupt(); + try { + // This will no effect if the thread hasn't yet been started. + heartbeatThread.join(3000); + } catch (InterruptedException e) { + } } synchronized int getLiveDatanodeCount() {