From f07582bc84c5e73f22682ed09413f87bf943057f Mon Sep 17 00:00:00 2001 From: Eli Collins Date: Fri, 11 Jan 2013 22:21:21 +0000 Subject: [PATCH] HDFS-4274. BlockPoolSliceScanner does not close verification log during shutdown. Contributed by Chris Nauroth git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/branch-2@1432318 13f79535-47bb-0310-9956-ffa450edef68 --- hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt | 3 +++ .../datanode/BlockPoolSliceScanner.java | 12 ++++++++++- .../server/datanode/DataBlockScanner.java | 21 +++++++++++++++++-- 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt index cffa8482958..08e2d011ccf 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt +++ b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt @@ -399,6 +399,9 @@ Release 2.0.3-alpha - Unreleased HDFS-4328. TestLargeBlock#testLargeBlockSize is timing out. (Chris Nauroth via atm) + HDFS-4274. BlockPoolSliceScanner does not close verification log during + shutdown. (Chris Nauroth via suresh) + BREAKDOWN OF HDFS-3077 SUBTASKS HDFS-3077. Quorum-based protocol for reading and writing edit logs. diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/BlockPoolSliceScanner.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/BlockPoolSliceScanner.java index 3dafa329a27..d3d2f915ca4 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/BlockPoolSliceScanner.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/BlockPoolSliceScanner.java @@ -602,6 +602,15 @@ class BlockPoolSliceScanner { lastScanTime.set(Time.now()); } } + + /** + * Shuts down this BlockPoolSliceScanner and releases any internal resources. + */ + void shutdown() { + if (verificationLog != null) { + verificationLog.close(); + } + } private void scan() { if (LOG.isDebugEnabled()) { @@ -610,7 +619,8 @@ class BlockPoolSliceScanner { try { adjustThrottler(); - while (datanode.shouldRun && !Thread.interrupted() + while (datanode.shouldRun + && !datanode.blockScanner.blockScannerThread.isInterrupted() && datanode.isBPServiceAlive(blockPoolId)) { long now = Time.now(); synchronized (this) { diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/DataBlockScanner.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/DataBlockScanner.java index 95a883a87d3..cf80c99a58a 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/DataBlockScanner.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/DataBlockScanner.java @@ -100,6 +100,11 @@ public class DataBlockScanner implements Runnable { } bpScanner.scanBlockPoolSlice(); } + + // Call shutdown for each allocated BlockPoolSliceScanner. + for (BlockPoolSliceScanner bpss: blockPoolScannerMap.values()) { + bpss.shutdown(); + } } // Wait for at least one block pool to be up @@ -232,9 +237,21 @@ public class DataBlockScanner implements Runnable { } } - public synchronized void shutdown() { + public void shutdown() { + synchronized (this) { + if (blockScannerThread != null) { + blockScannerThread.interrupt(); + } + } + + // We cannot join within the synchronized block, because it would create a + // deadlock situation. blockScannerThread calls other synchronized methods. if (blockScannerThread != null) { - blockScannerThread.interrupt(); + try { + blockScannerThread.join(); + } catch (InterruptedException e) { + // shutting down anyway + } } }